kopia lustrzana https://github.com/jamesgao/kiln_controller
Add some test code
rodzic
1b824d2ecd
commit
eb3412945b
|
@ -1,48 +1,41 @@
|
||||||
var margin = {top: 20, right: 20, bottom: 30, left: 50};
|
var tempgraph = (function(module) {
|
||||||
var width = $("#graph").width() - margin.left - margin.right;
|
module.graph_defaults = {
|
||||||
var height = $("#graph").height() - margin.top - margin.bottom;
|
margin: {top: 20, right: 20, bottom: 30, left: 50},
|
||||||
|
object: "#graph",
|
||||||
|
show_axes: true,
|
||||||
|
}
|
||||||
|
module.Graph = function(options) {
|
||||||
|
//Options: margin, width, height, object
|
||||||
|
if (options === undefined)
|
||||||
|
options = module.graph_defaults;
|
||||||
|
|
||||||
var x = d3.time.scale()
|
if (options.object !== undefined)
|
||||||
.range([0, width]);
|
this.obj = options.object;
|
||||||
|
else
|
||||||
|
this.obj = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||||
|
|
||||||
var y = d3.scale.linear()
|
this.width = options.width ? options.width : $(this.obj).width() - options.margin.left - options.margin.right;
|
||||||
.range([height, 0]);
|
this.height = options.height ? options.height : $(this.obj).height() - options.margin.top - options.margin.bottom;
|
||||||
|
this.margin = options.margin;
|
||||||
|
|
||||||
var xAxis = d3.svg.axis()
|
this.svg = d3.select(this.obj).append("g").attr("transform", "translate("+options.margin.left+","+options.margin.top+")");
|
||||||
.scale(x)
|
|
||||||
.orient("bottom");
|
|
||||||
|
|
||||||
var yAxis = d3.svg.axis()
|
this.x = d3.time.scale().range([0, this.width]);
|
||||||
.scale(y)
|
this.y = d3.scale.linear().range([this.height, 0]);
|
||||||
.orient("left");
|
|
||||||
|
|
||||||
var line = d3.svg.line()
|
if (options.show_axes === undefined || options.show_axes) {
|
||||||
.x(function(d) { return x(d.time); })
|
this.x_axis = d3.svg.axis().scale(this.x).orient("bottom");
|
||||||
.y(function(d) { return y(d.temp); });
|
this.y_axis = d3.svg.axis().scale(this.y).orient("left");
|
||||||
|
|
||||||
var svg = d3.select("svg#graph")
|
//setup axies labels and ticks
|
||||||
.attr("width", width + margin.left + margin.right)
|
this.svg.append("g")
|
||||||
.attr("height", height + margin.top + margin.bottom)
|
|
||||||
.append("g")
|
|
||||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
|
||||||
|
|
||||||
var data = [{"time":1413571601.55382, "temp":14.4}, {"time":1413571606.291054, "temp":14.6}, {"time":1413571629.841126, "temp":15.8}];
|
|
||||||
data.forEach(function(d) {
|
|
||||||
d.time = new Date(d.time*1000.);
|
|
||||||
d.temp = +d.temp;
|
|
||||||
});
|
|
||||||
|
|
||||||
x.domain(d3.extent(data, function(d) { return d.time; }));
|
|
||||||
y.domain(d3.extent(data, function(d) { return d.temp; }));
|
|
||||||
|
|
||||||
svg.append("g")
|
|
||||||
.attr("class", "x axis")
|
.attr("class", "x axis")
|
||||||
.attr("transform", "translate(0," + height + ")")
|
.attr("transform", "translate(0," + this.height + ")")
|
||||||
.call(xAxis);
|
.call(this.x_axis);
|
||||||
|
|
||||||
svg.append("g")
|
this.svg.append("g")
|
||||||
.attr("class", "y axis")
|
.attr("class", "y axis")
|
||||||
.call(yAxis)
|
.call(this.y_axis)
|
||||||
.append("text")
|
.append("text")
|
||||||
.attr("transform", "rotate(-90)")
|
.attr("transform", "rotate(-90)")
|
||||||
.attr("y", 6)
|
.attr("y", 6)
|
||||||
|
@ -50,29 +43,92 @@ svg.append("g")
|
||||||
.style("text-anchor", "end")
|
.style("text-anchor", "end")
|
||||||
.text("Temperature (°C)");
|
.text("Temperature (°C)");
|
||||||
|
|
||||||
svg.append("path")
|
}
|
||||||
|
|
||||||
|
this.lines = [];
|
||||||
|
};
|
||||||
|
module.Graph.prototype.plot = function(data, marker) {
|
||||||
|
var line = d3.svg.line()
|
||||||
|
.x(function(d) { return this.x(d.time); }.bind(this))
|
||||||
|
.y(function(d) { return this.y(d.temp); }.bind(this));
|
||||||
|
this.svg.append("path")
|
||||||
.datum(data)
|
.datum(data)
|
||||||
.attr("class", "line")
|
.attr("class", "line")
|
||||||
.attr("d", line);
|
.attr("d", line);
|
||||||
|
if (marker !== undefined && marker) {
|
||||||
svg.selectAll(".dot")
|
var marker = this.svg.selectAll(".dot").data(data)
|
||||||
.data(data)
|
|
||||||
.enter().append("circle")
|
.enter().append("circle")
|
||||||
.attr("class", "dot")
|
.attr("class", "dot")
|
||||||
.attr("r", 3.5)
|
.attr("r", 5)
|
||||||
.attr("cx", function(d) { return x(d.time); })
|
.attr("cx", function(d) { return this.x(d.time); }.bind(this))
|
||||||
.attr("cy", function(d) { return y(d.temp); });
|
.attr("cy", function(d) { return this.y(d.temp); }.bind(this));
|
||||||
|
}
|
||||||
|
this.lines.push({line:line, data:data, marker:marker});
|
||||||
|
|
||||||
|
this.x.domain(d3.extent(data, function(d) { return d.time; }));
|
||||||
|
this.y.domain(d3.extent(data, function(d) { return d.temp; }));
|
||||||
|
this.draw();
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
module.Graph.prototype.draw = function() {
|
||||||
|
this.svg.select("g.x.axis").call(this.x_axis);
|
||||||
|
this.svg.select("g.y.axis").call(this.y_axis);
|
||||||
|
var line, data, marker;
|
||||||
|
for (var i = 0; i < this.lines.length; i++) {
|
||||||
|
line = this.lines[i].line;
|
||||||
|
data = this.lines[i].data;
|
||||||
|
marker = this.lines[i].marker;
|
||||||
|
if (marker !== undefined) {
|
||||||
|
this.svg.selectAll(".dot").data(data)
|
||||||
|
.attr("cx", function(d) { return this.x(d.time)}.bind(this))
|
||||||
|
.attr("cy", function(d) { return this.y(d.temp)}.bind(this));
|
||||||
|
}
|
||||||
|
this.svg.select("path.line").attr("d", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.Graph.prototype.resize = function() {
|
||||||
|
this.svg
|
||||||
|
.attr("width", width + margin.left + margin.right)
|
||||||
|
.attr("height", height + margin.top + margin.bottom)
|
||||||
|
this.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.Graph.prototype.update = function(line, data) {
|
||||||
|
for (var i = 0; i < this.lines.length; i++) {
|
||||||
|
if (this.lines[i].line === line) {
|
||||||
|
this.svg.select("path.line").datum(data).attr("d", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.draw();
|
||||||
|
}
|
||||||
|
module.Graph.prototype.xlim = function(min, max) {
|
||||||
|
this.x.domain([min, max]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return module;
|
||||||
|
}(tempgraph || {}));
|
||||||
|
|
||||||
|
var data = d3.tsv("data.txt", function(error, data) {
|
||||||
|
data.forEach(function(d) {
|
||||||
|
d.time = new Date(d.time*1000.);
|
||||||
|
d.temp = +d.temp;
|
||||||
|
});
|
||||||
|
|
||||||
|
graph = new tempgraph.Graph()
|
||||||
|
line = graph.plot(data.slice(0, 400), false);
|
||||||
|
});
|
||||||
|
|
||||||
function draw() {
|
|
||||||
svg.select("g.x.axis").call(xAxis);
|
|
||||||
svg.select("g.y.axis").call(yAxis);
|
|
||||||
svg.select("path.line").attr("d", line);
|
|
||||||
svg.selectAll(".dot").data(data)
|
|
||||||
.attr("cx", function(d) {return x(d.time);})
|
|
||||||
.attr("cy", function(d) {return y(d.temp);});
|
|
||||||
}
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
x.domain([new Date(data[0].time.getTime() - 5000), new Date(data[2].time.getTime() + 5000)]);
|
d3.tsv("data2.txt", function(error, data) {
|
||||||
draw();
|
data.forEach(function(d) {
|
||||||
|
d.time = new Date(d.time*1000.);
|
||||||
|
d.temp = +d.temp;
|
||||||
|
});
|
||||||
|
|
||||||
|
var lim = d3.extent(data, function(d){return d.time;});
|
||||||
|
graph.xlim(lim[0], lim[1]);
|
||||||
|
graph.update(line, data);
|
||||||
|
console.log("done!");
|
||||||
|
})
|
||||||
}
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import time
|
||||||
|
import stepper
|
||||||
|
|
||||||
|
def test_noblock():
|
||||||
|
reg = Regulator(ignite_pin=None)
|
||||||
|
reg.start()
|
||||||
|
|
||||||
|
reg.ignite()
|
||||||
|
reg.set(.5)
|
||||||
|
time.sleep(.5)
|
||||||
|
reg.set(.1)
|
||||||
|
time.sleep(.5)
|
||||||
|
reg.set(.5, block=True)
|
|
@ -19,9 +19,10 @@ def temp_to_cone(temp):
|
||||||
return "13+"
|
return "13+"
|
||||||
|
|
||||||
class Monitor(threading.Thread):
|
class Monitor(threading.Thread):
|
||||||
def __init__(self, name="3b-000000182b57"):
|
def __init__(self, name="3b-000000182b57", callback=None):
|
||||||
self.device = "/sys/bus/w1/devices/%s/w1_slave"%name
|
self.device = "/sys/bus/w1/devices/%s/w1_slave"%name
|
||||||
self.history = deque(maxlen=1048576)
|
self.history = deque(maxlen=1048576)
|
||||||
|
self.callback = callback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Adafruit_alphanumeric import AlphaScroller
|
from Adafruit_alphanumeric import AlphaScroller
|
||||||
|
@ -60,14 +61,16 @@ class Monitor(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
temp = self._read_temp()
|
temp = self._read_temp()
|
||||||
fahr = temp * 9. / 5. + 32.
|
now = time.time()
|
||||||
now = datetime.datetime.now()
|
|
||||||
self.history.append((now, temp))
|
self.history.append((now, temp))
|
||||||
|
if self.callback is not None:
|
||||||
|
self.callback(now, temp)
|
||||||
|
|
||||||
if self.display is not None:
|
if self.display is not None:
|
||||||
if temp > 50:
|
if temp > 50:
|
||||||
if not self.display.shown:
|
if not self.display.shown:
|
||||||
self.display.show()
|
self.display.show()
|
||||||
|
fahr = temp * 9. / 5. + 32.
|
||||||
text = list('%0.0f'%temp) + ['degree'] + list('C %0.0f'%fahr)+['degree'] + list("F")
|
text = list('%0.0f'%temp) + ['degree'] + list('C %0.0f'%fahr)+['degree'] + list("F")
|
||||||
if 600 <= temp:
|
if 600 <= temp:
|
||||||
text += [' ', ' ', 'cone']+list("%0.1f"%temp_to_cone(temp))
|
text += [' ', ' ', 'cone']+list("%0.1f"%temp_to_cone(temp))
|
||||||
|
@ -78,8 +81,3 @@ class Monitor(threading.Thread):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mon = Monitor()
|
mon = Monitor()
|
||||||
mon.start()
|
mon.start()
|
||||||
try:
|
|
||||||
while mon.isAlive():
|
|
||||||
mon.join(1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
mon.stop()
|
|
||||||
|
|
Ładowanie…
Reference in New Issue