profile handling for server and oven
This commit is contained in:
parent
e02d0eb1e8
commit
117c0571ea
27
oven.py
27
oven.py
@ -22,6 +22,7 @@ class Oven (threading.Thread):
|
||||
self.start_time = 0
|
||||
self.runtime = 0
|
||||
self.totaltime = 0
|
||||
self.target = 0
|
||||
self.power = 0.0
|
||||
self.state = Oven.STATE_IDLE
|
||||
self.temp_sensor = TempSensor(self)
|
||||
@ -29,6 +30,7 @@ class Oven (threading.Thread):
|
||||
self.start()
|
||||
|
||||
def run_profile(self, profile):
|
||||
log.info("Running profile %s"%profile.name)
|
||||
self.profile = profile
|
||||
self.totaltime = 300.0
|
||||
self.state = Oven.STATE_RUNNING
|
||||
@ -43,7 +45,9 @@ class Oven (threading.Thread):
|
||||
if self.state == Oven.STATE_RUNNING:
|
||||
self.runtime = (datetime.datetime.now() - self.start_time).total_seconds()
|
||||
log.info("running at %.1f deg C, power %.2f (%.1fs/%.0f)"%(self.temp_sensor.temperature,self.power,self.runtime,self.totaltime))
|
||||
if self.temp_sensor.temperature < 250:
|
||||
self.target = self.profile.get_target_temperature(self.runtime)
|
||||
|
||||
if self.temp_sensor.temperature < self.target:
|
||||
self.power = 1.0
|
||||
else:
|
||||
self.power = 0.0
|
||||
@ -61,6 +65,7 @@ class Oven (threading.Thread):
|
||||
state = {
|
||||
'runtime': self.runtime,
|
||||
'temperature': self.temp_sensor.temperature,
|
||||
'target': self.target,
|
||||
'state': self.state,
|
||||
'power': self.power,
|
||||
'totaltime': self.totaltime
|
||||
@ -97,11 +102,29 @@ class Profile():
|
||||
def __init__(self,json_data):
|
||||
obj = json.loads(json_data)
|
||||
self.name = obj["name"]
|
||||
self.data = obj["data"]
|
||||
self.data = sorted(obj["data"])
|
||||
|
||||
def get_duration(self):
|
||||
return max([t for (t,x) in self.data])
|
||||
|
||||
def get_target_temperature(self,time):
|
||||
if time > self.get_duration():
|
||||
return 0
|
||||
|
||||
prev_point = None
|
||||
next_point = None
|
||||
|
||||
for i in range(len(self.data)):
|
||||
if time > self.data[i][0]:
|
||||
prev_point = self.data[i]
|
||||
next_point = self.data[i+1]
|
||||
break
|
||||
|
||||
incl = (next_point[1] - prev_point[1]) / (next_point[0] - prev_point[0])
|
||||
|
||||
temp = prev_point[1] + (time - prev_point[0]) * incl
|
||||
return temp
|
||||
|
||||
if __name__ == "__main__":
|
||||
#my_oven = Oven()
|
||||
#my_oven.run_profile("abc")
|
||||
|
||||
@ -9,7 +9,7 @@ logging.basicConfig(level = logging.INFO, format = log_format)
|
||||
log = logging.getLogger("picoreflowd")
|
||||
log.info("Starting picoreflowd")
|
||||
|
||||
from oven import Oven
|
||||
from oven import Oven, Profile
|
||||
from ovenWatcher import OvenWatcher
|
||||
|
||||
app = bottle.Bottle()
|
||||
@ -40,10 +40,16 @@ def handle_control():
|
||||
try:
|
||||
message = wsock.receive()
|
||||
wsock.send("Your message was: %r" % message)
|
||||
if message == "start":
|
||||
log.info("Start command received")
|
||||
oven.run_profile("abc")
|
||||
elif message == "stop":
|
||||
log.info("Received (control): %s"% message)
|
||||
msgdict = json.loads(message)
|
||||
if msgdict.get("cmd") == "RUN":
|
||||
log.info("RUN command received")
|
||||
profile_obj = msgdict.get('profile')
|
||||
if profile_obj:
|
||||
profile_json = json.dumps(profile_obj)
|
||||
profile = Profile(profile_json)
|
||||
oven.run_profile(profile)
|
||||
elif msgdict.get("cmd") == "STOP":
|
||||
log.info("Stop command received")
|
||||
oven.abort_run()
|
||||
except WebSocketError:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user