From b8429275d2bc64be8cfcd1dc673332d2a00f01c4 Mon Sep 17 00:00:00 2001 From: chrono Date: Thu, 28 Nov 2013 17:44:06 +0100 Subject: [PATCH] Updated to 0.5sec update interval and fixed jerky progress bar --- oven.py | 26 ++--- ovenWatcher.py | 8 +- public/assets/js/picoreflow.js | 189 ++++++++++++++++++++++++++++++- public/index.html | 199 +-------------------------------- 4 files changed, 208 insertions(+), 214 deletions(-) diff --git a/oven.py b/oven.py index 535fcc9..58eee68 100644 --- a/oven.py +++ b/oven.py @@ -20,7 +20,7 @@ class Oven (threading.Thread): self.temp_sensor = TempSensor(self) self.temp_sensor.start() self.start() - + def reset(self): self.profile = None self.start_time = 0 @@ -29,7 +29,7 @@ class Oven (threading.Thread): self.target = 0 self.power = 0.0 self.state = Oven.STATE_IDLE - + def run_profile(self, profile): log.info("Running profile %s"%profile.name) self.profile = profile @@ -47,14 +47,14 @@ class Oven (threading.Thread): self.runtime = (datetime.datetime.now() - self.start_time).total_seconds() log.info("running at %.1f deg C (Target: %.1f) , power %.2f (%.1fs/%.0f)"%(self.temp_sensor.temperature,self.target,self.power,self.runtime,self.totaltime)) 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 if self.runtime >= self.totaltime: self.reset() - time.sleep(1) + time.sleep(0.5) def get_state(self): state = { @@ -71,10 +71,10 @@ class TempSensor(threading.Thread): def __init__(self,oven): threading.Thread.__init__(self) self.daemon = True - + self.temperature = 0 self.oven = oven - + if not sensor_dummy: cs_pin = 27 clock_pin = 22 @@ -90,31 +90,31 @@ class TempSensor(threading.Thread): time_delta = (20.0 - self.temperature)/40 power_delta = 8.0*self.oven.power self.temperature += (time_delta+power_delta) - - time.sleep(1) + + time.sleep(0.5) class Profile(): def __init__(self,json_data): obj = json.loads(json_data) self.name = obj["name"] 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-1] next_point = self.data[i] break - + incl = float(next_point[1] - prev_point[1]) / float(next_point[0] - prev_point[0]) temp = prev_point[1] + (time - prev_point[0]) * incl return temp diff --git a/ovenWatcher.py b/ovenWatcher.py index 8222d88..706f539 100644 --- a/ovenWatcher.py +++ b/ovenWatcher.py @@ -7,7 +7,7 @@ class OvenWatcher(threading.Thread): self.observers = [] threading.Thread.__init__(self) self.daemon = True - + self.oven = oven self.start() @@ -15,11 +15,11 @@ class OvenWatcher(threading.Thread): while True: oven_state = self.oven.get_state() self.notifyAll(oven_state) - time.sleep(1) - + time.sleep(0.5) + def addObserver(self,observer): self.observers.append(observer) - + def notifyAll(self,message): message_json = json.dumps(message) log.debug("sending to %d clients: %s"%(len(self.observers),message_json)) diff --git a/public/assets/js/picoreflow.js b/public/assets/js/picoreflow.js index 4abfe05..6522b4f 100644 --- a/public/assets/js/picoreflow.js +++ b/public/assets/js/picoreflow.js @@ -4,7 +4,7 @@ function updateProgress(percentage){ if(state=="RUNNING") { if(percentage > 100) percentage = 100; $('#progressBar').css('width', percentage+'%'); - if(percentage>=5) $('#progressBar').html(percentage+'%'); + if(percentage>=5) $('#progressBar').html(parseInt(percentage)+'%'); } else { $('#progressBar').css('width', 0+'%'); $('#progressBar').html(''); @@ -347,3 +347,190 @@ function update_profile(id) { textColor: '#E0E0E0', maskColor: 'rgba(255,255,255,0.3)' }; + + + + +function getHCOptions() { + + var options = + { + title: { text: '' }, + xAxis: { + title: { text: 'Time (s)' }, + type: 'integer', + tickPixelInterval: 60 + }, + yAxis: { + title: { text: 'Temperature (\xB0C)' }, + tickInterval: 25, + min: 0, + max: 300 + }, + tooltip: { + formatter: function() { + return Highcharts.numberFormat(this.y, 0); + } + }, + chart: { + type: 'line', + renderTo: 'graph_container', + animation: true, + zoomType: 'x', + marginTop: 30, + marginRight: 30, + events: { + load: function() { + var series = this.series[1]; + + + ws_status.onmessage = function(e) + { + x = JSON.parse(e.data); + + if(state!="EDIT") + { + state = x.state; + } + + $('#state').html(state); + + updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100); + + $('#act_temp').html(Highcharts.numberFormat(x.temperature, 0) + ' \xB0C'); + $('#power').css("background-color", (x.power > 0.5 ? "#75890c" : "#1F1E1A") ); + + + if (x.target == 0) + { + $('#target_temp').html('OFF'); + } + else + { + $('#target_temp').html(Highcharts.numberFormat(x.target, 0) + ' \xB0C'); + } + //console.log (e.data); + //console.log('Percent finished:' + perc); + + if(state!="EDIT") + { + + if(state=="RUNNING") + { + $("#nav_start").hide(); + $("#nav_stop").show(); + series.addPoint([x.runtime, x.temperature], true, false); + + left = parseInt(x.totaltime-x.runtime); + var minutes = Math.floor(left / 60); + var seconds = left - minutes * 60; + $('#eta').html(minutes+':'+ (seconds < 10 ? "0" : "") + seconds); + + } + else + { + $("#nav_start").show(); + $("#nav_stop").hide(); + } + } + + } + + /* + var socket = io.connect('http://10.1.1.110:8080'); + socket.on('sample', function (sample) { + // when a sample arrives we plot it + series.addPoint([sample.x, sample.y], true, false); + $('#act_temp').html(Highcharts.numberFormat(sample.y, 0) + ' \xB0C'); + + + }); + + socket.on('error', function () { + + $(document).trigger("add-alerts", [ + { + 'message': "No communication to control server", + 'priority': 'error' + } + ]); + + + }) + + // Called when the connection to the server is opened. + socket.onopen = function () { + alert("Connection with server open."); + }; + + // Called when the connection to the server is closed. + socket.onclose = function () { + alert("Connection with server closed; Maybe the server wasn't found, it shut down or you're behind a firewall/proxy."); + }; +*/ + } + }, + resetZoomButton: { + position: { + align: 'right', + verticalAlign: 'top' + } + } + }, + + plotOptions: { + series: { + cursor: 'all-scroll', + point: { + events: { + /* + drag: function (e) { + $('#drag').html('Dragging ' + this.series.name + ', ' + this.category + ' to ' + Highcharts.numberFormat(e.newY, 0) + ''); + }, + drop: function () { + $('#drop').html('In ' + this.series.name + ', ' + this.category + ' was set to ' + Highcharts.numberFormat(this.y, 0) + ''); + }*/ + } + }, + stickyTracking: false + }, + + }, + + credits: { + enabled: false + }, + + series: [{ + name: 'Ref', + data: [ + [1, 25 ], + [70, 150 ], + [180, 183 ], + [210, 230 ], + [240, 183 ], + [300, 25 ] + ], + draggableX: false, + draggableY: false, + dragMinY: 0, + dragMaxY: 250, + marker: { + enabled: false + } + }, + { + name: 'Act', + data: [ + [0,0] + ], + marker: { + enabled: false + } + }] + + }; + + return (options); + +} diff --git a/public/index.html b/public/index.html index fb476e1..68ccd2e 100644 --- a/public/index.html +++ b/public/index.html @@ -22,7 +22,6 @@
-
25 °C @@ -41,7 +40,6 @@
-
@@ -73,9 +71,7 @@
-
- - + - -