kopia lustrzana https://github.com/jamesgao/kiln_controller
Only display temperature above 50 C
rodzic
d1f5faef36
commit
7d72bfb803
|
@ -172,13 +172,17 @@ class AlphaScroller(threading.Thread):
|
||||||
def __init__(self, address=0x70, interval=.25):
|
def __init__(self, address=0x70, interval=.25):
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
self.disp = Alphanumeric(address)
|
self.disp = Alphanumeric(address)
|
||||||
self.text = [(' ',)]*4
|
self.text = ''
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
self.pause = threading.Event()
|
||||||
|
self.pause.set()
|
||||||
|
self.shown = True
|
||||||
|
|
||||||
super(AlphaScroller, self).__init__()
|
super(AlphaScroller, self).__init__()
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.pause.set()
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
def set_text(self, text, pad=True, reset=True):
|
def set_text(self, text, pad=True, reset=True):
|
||||||
|
@ -201,6 +205,19 @@ class AlphaScroller(threading.Thread):
|
||||||
def set_speed(self, interval):
|
def set_speed(self, interval):
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
self.pause.set()
|
||||||
|
self.shown = True
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
self.pause.clear()
|
||||||
|
self.clear()
|
||||||
|
self.shown = False
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
for i in range(4):
|
||||||
|
self.disp.writeChar(i, ' ')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
|
@ -213,8 +230,8 @@ class AlphaScroller(threading.Thread):
|
||||||
self.disp.writeChar(i, *char)
|
self.disp.writeChar(i, *char)
|
||||||
time.sleep(self.interval)
|
time.sleep(self.interval)
|
||||||
self.counter += 1
|
self.counter += 1
|
||||||
for i in range(4):
|
self.pause.wait()
|
||||||
self.disp.writeChar(i, ' ')
|
self.clear()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
scroller = AlphaScroller(interval=.4)
|
scroller = AlphaScroller(interval=.4)
|
||||||
|
|
|
@ -2,33 +2,18 @@ import time
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
||||||
device_file = "/sys/bus/w1/devices/3b-000000182b57/w1_slave"
|
|
||||||
def read_temp_raw():
|
|
||||||
f = open(device_file, 'r')
|
|
||||||
lines = f.readlines()
|
|
||||||
f.close()
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def read_temp():
|
|
||||||
lines = read_temp_raw()
|
|
||||||
while lines[0].strip()[-3:] != 'YES':
|
|
||||||
time.sleep(0.2)
|
|
||||||
lines = read_temp_raw()
|
|
||||||
equals_pos = lines[1].find('t=')
|
|
||||||
if equals_pos != -1:
|
|
||||||
temp_string = lines[1][equals_pos+2:]
|
|
||||||
temp_c = float(temp_string) / 1000.0
|
|
||||||
temp_f = temp_c * 9.0 / 5.0 + 32.0
|
|
||||||
return temp_c, temp_f
|
|
||||||
|
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
|
def initialize(self, monitor):
|
||||||
|
self.monitor = monitor
|
||||||
def get(self):
|
def get(self):
|
||||||
self.write("<!doctype html><head><meta http-equiv='refresh' content='5' ></head><p>Current temperature: %.2f°C, %.2f°F"%read_temp())
|
self.write("<!doctype html><head><meta http-equiv='refresh' content='5' ></head><p>Current temperature: %.2f°C, %.2f°F"%read_temp())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler, dict(monitor=mon)),
|
||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
application.listen(8888)
|
application.listen(8888)
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import time
|
|
||||||
import re
|
import re
|
||||||
import threading
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
logger = logging.getLogger("thermo")
|
||||||
|
|
||||||
def temp_to_cone(temp):
|
def temp_to_cone(temp):
|
||||||
"""Convert the current temperature to cone value using linear interpolation"""
|
"""Convert the current temperature to cone value using linear interpolation"""
|
||||||
cones = [600,614,635,683,717,747,792,804,838,852,884,894,900,923,955,984,999,1046,1060,1101,1120,1137,1154,1162,1168,1186,1196,1222,1240,1263,1280,1305,1315,1326,1346]
|
cones = [600,614,635,683,717,747,792,804,838,852,884,894,900,923,955,984,999,1046,1060,1101,1120,1137,1154,1162,1168,1186,1196,1222,1240,1263,1280,1305,1315,1326,1346]
|
||||||
|
@ -20,9 +23,15 @@ class Monitor(threading.Thread):
|
||||||
self.device = "/sys/bus/w1/devices/%s/w1_slave"%name
|
self.device = "/sys/bus/w1/devices/%s/w1_slave"%name
|
||||||
self.history = deque(maxlen=1024)
|
self.history = deque(maxlen=1024)
|
||||||
|
|
||||||
|
try:
|
||||||
from Adafruit_alphanumeric import AlphaScroller
|
from Adafruit_alphanumeric import AlphaScroller
|
||||||
self.display = AlphaScroller(interval=.4)
|
self.display = AlphaScroller(interval=.4)
|
||||||
self.display.start()
|
self.display.start()
|
||||||
|
self.display.hide()
|
||||||
|
except ImportError:
|
||||||
|
logger.info("Could not start AlphaScroller")
|
||||||
|
self.display = None
|
||||||
|
|
||||||
super(Monitor, self).__init__()
|
super(Monitor, self).__init__()
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
|
@ -41,6 +50,7 @@ class Monitor(threading.Thread):
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
if self.display is not None:
|
||||||
self.display.stop()
|
self.display.stop()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -54,12 +64,16 @@ class Monitor(threading.Thread):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
self.history.append((now, temp))
|
self.history.append((now, temp))
|
||||||
|
|
||||||
|
if self.display is not None:
|
||||||
|
if temp > 50:
|
||||||
|
if not self.display.shown:
|
||||||
|
self.display.show()
|
||||||
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))
|
||||||
|
|
||||||
self.display.set_text(text, reset=False)
|
self.display.set_text(text, reset=False)
|
||||||
|
elif self.display.shown:
|
||||||
|
self.display.hide()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mon = Monitor()
|
mon = Monitor()
|
||||||
|
|
Ładowanie…
Reference in New Issue