Skip to content

Commit

Permalink
Only display temperature above 50 C
Browse files Browse the repository at this point in the history
  • Loading branch information
James Gao committed Oct 16, 2014
1 parent d1f5fae commit 7d72bfb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
23 changes: 20 additions & 3 deletions kiln/Adafruit_alphanumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -200,6 +204,19 @@ def set_text(self, text, pad=True, reset=True):

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:
Expand All @@ -213,8 +230,8 @@ def run(self):
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)
Expand Down
29 changes: 7 additions & 22 deletions kiln/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,18 @@
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&deg;C, %.2f&deg;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()
38 changes: 26 additions & 12 deletions kiln/thermo.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -20,9 +23,15 @@ def __init__(self, name="3b-000000182b57"):
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

Expand All @@ -41,7 +50,8 @@ def _read_temp(self):

def stop(self):
self.running = False
self.display.stop()
if self.display is not None:
self.display.stop()

@property
def temperature(self):
Expand All @@ -53,13 +63,17 @@ def run(self):
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()
Expand Down

0 comments on commit 7d72bfb

Please sign in to comment.