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):
|
||||
self.interval = interval
|
||||
self.disp = Alphanumeric(address)
|
||||
self.text = [(' ',)]*4
|
||||
self.text = ''
|
||||
self.counter = 0
|
||||
self.pause = threading.Event()
|
||||
self.pause.set()
|
||||
self.shown = True
|
||||
|
||||
super(AlphaScroller, self).__init__()
|
||||
self.running = True
|
||||
|
||||
def stop(self):
|
||||
self.pause.set()
|
||||
self.running = False
|
||||
|
||||
def set_text(self, text, pad=True, reset=True):
|
||||
|
@ -200,6 +204,19 @@ class AlphaScroller(threading.Thread):
|
|||
|
||||
def set_speed(self, 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):
|
||||
while self.running:
|
||||
|
@ -213,8 +230,8 @@ class AlphaScroller(threading.Thread):
|
|||
self.disp.writeChar(i, *char)
|
||||
time.sleep(self.interval)
|
||||
self.counter += 1
|
||||
for i in range(4):
|
||||
self.disp.writeChar(i, ' ')
|
||||
self.pause.wait()
|
||||
self.clear()
|
||||
|
||||
if __name__ == "__main__":
|
||||
scroller = AlphaScroller(interval=.4)
|
||||
|
|
|
@ -2,33 +2,18 @@ import time
|
|||
import tornado.ioloop
|
||||
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):
|
||||
def initialize(self, monitor):
|
||||
self.monitor = monitor
|
||||
def get(self):
|
||||
self.write("<!doctype html><head><meta http-equiv='refresh' content='5' ></head><p>Current temperature: %.2f°C, %.2f°F"%read_temp())
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
])
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/", MainHandler, dict(monitor=mon)),
|
||||
])
|
||||
|
||||
application.listen(8888)
|
||||
tornado.ioloop.IOLoop.instance().start()
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import time
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import threading
|
||||
from collections import deque
|
||||
|
||||
logger = logging.getLogger("thermo")
|
||||
|
||||
def temp_to_cone(temp):
|
||||
"""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]
|
||||
|
@ -20,9 +23,15 @@ class Monitor(threading.Thread):
|
|||
self.device = "/sys/bus/w1/devices/%s/w1_slave"%name
|
||||
self.history = deque(maxlen=1024)
|
||||
|
||||
from Adafruit_alphanumeric import AlphaScroller
|
||||
self.display = AlphaScroller(interval=.4)
|
||||
self.display.start()
|
||||
try:
|
||||
from Adafruit_alphanumeric import AlphaScroller
|
||||
self.display = AlphaScroller(interval=.4)
|
||||
self.display.start()
|
||||
self.display.hide()
|
||||
except ImportError:
|
||||
logger.info("Could not start AlphaScroller")
|
||||
self.display = None
|
||||
|
||||
super(Monitor, self).__init__()
|
||||
self.running = True
|
||||
|
||||
|
@ -41,7 +50,8 @@ class Monitor(threading.Thread):
|
|||
|
||||
def stop(self):
|
||||
self.running = False
|
||||
self.display.stop()
|
||||
if self.display is not None:
|
||||
self.display.stop()
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
|
@ -53,13 +63,17 @@ class Monitor(threading.Thread):
|
|||
fahr = temp * 9. / 5. + 32.
|
||||
now = datetime.datetime.now()
|
||||
self.history.append((now, temp))
|
||||
|
||||
text = list('%0.0f'%temp) + ['degree'] + list('C %0.0f'%fahr)+['degree'] + list("F")
|
||||
|
||||
if 600 <= temp:
|
||||
text += [' ', ' ', 'cone']+list("%0.1f"%temp_to_cone(temp))
|
||||
|
||||
self.display.set_text(text, reset=False)
|
||||
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")
|
||||
if 600 <= temp:
|
||||
text += [' ', ' ', 'cone']+list("%0.1f"%temp_to_cone(temp))
|
||||
self.display.set_text(text, reset=False)
|
||||
elif self.display.shown:
|
||||
self.display.hide()
|
||||
|
||||
if __name__ == "__main__":
|
||||
mon = Monitor()
|
||||
|
|
Ładowanie…
Reference in New Issue