Adding temp monitor code

master
James Gao 2014-10-15 23:18:47 -07:00
rodzic 5dd1729765
commit 0ca929ce96
3 zmienionych plików z 210 dodań i 156 usunięć

BIN
BOM.ods 100644

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -12,162 +12,162 @@ from Adafruit_LEDBackpack import LEDBackpack
# displays available from Adafruit
class Alphanumeric(object):
disp = None
disp = None
# Hexadecimal character lookup table
lut = [
0b0000000000000001,
0b0000000000000010,
0b0000000000000100,
0b0000000000001000,
0b0000000000010000,
0b0000000000100000,
0b0000000001000000,
0b0000000010000000,
0b0000000100000000,
0b0000001000000000,
0b0000010000000000,
0b0000100000000000,
0b0001000000000000,
0b0010000000000000,
0b0100000000000000,
0b1000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0001001011001001,
0b0001010111000000,
0b0001001011111001,
0b0000000011100011,
0b0000010100110000,
0b0001001011001000,
0b0011101000000000,
0b0001011100000000,
0b0000000000000000, #
0b0000000000000110, # !
0b0000001000100000, # "
0b0001001011001110, # #
0b0001001011101101, # $
0b0000110000100100, # %
0b0010001101011101, # &
0b0000010000000000, # '
0b0010010000000000, # (
0b0000100100000000, # )
0b0011111111000000, # *
0b0001001011000000, # +
0b0000100000000000, # ,
0b0000000011000000, # -
0b0000000000000000, # .
0b0000110000000000, # /
0b0000110000111111, # 0
0b0000000000000110, # 1
0b0000000011011011, # 2
0b0000000010001111, # 3
0b0000000011100110, # 4
0b0010000001101001, # 5
0b0000000011111101, # 6
0b0000000000000111, # 7
0b0000000011111111, # 8
0b0000000011101111, # 9
0b0001001000000000, # :
0b0000101000000000, # ;
0b0010010000000000, # <
0b0000000011001000, # =
0b0000100100000000, # >
0b0001000010000011, # ?
0b0000001010111011, # @
0b0000000011110111, # A
0b0001001010001111, # B
0b0000000000111001, # C
0b0001001000001111, # D
0b0000000011111001, # E
0b0000000001110001, # F
0b0000000010111101, # G
0b0000000011110110, # H
0b0001001000000000, # I
0b0000000000011110, # J
0b0010010001110000, # K
0b0000000000111000, # L
0b0000010100110110, # M
0b0010000100110110, # N
0b0000000000111111, # O
0b0000000011110011, # P
0b0010000000111111, # Q
0b0010000011110011, # R
0b0000000011101101, # S
0b0001001000000001, # T
0b0000000000111110, # U
0b0000110000110000, # V
0b0010100000110110, # W
0b0010110100000000, # X
0b0001010100000000, # Y
0b0000110000001001, # Z
0b0000000000111001, # [
0b0010000100000000, #
0b0000000000001111, # ]
0b0000110000000011, # ^
0b0000000000001000, # _
0b0000000100000000, # `
0b0001000001011000, # a
0b0010000001111000, # b
0b0000000011011000, # c
0b0000100010001110, # d
0b0000100001011000, # e
0b0000000001110001, # f
0b0000010010001110, # g
0b0001000001110000, # h
0b0001000000000000, # i
0b0000000000001110, # j
0b0011011000000000, # k
0b0000000000110000, # l
0b0001000011010100, # m
0b0001000001010000, # n
0b0000000011011100, # o
0b0000000101110000, # p
0b0000010010000110, # q
0b0000000001010000, # r
0b0010000010001000, # s
0b0000000001111000, # t
0b0000000000011100, # u
0b0010000000000100, # v
0b0010100000010100, # w
0b0010100011000000, # x
0b0010000000001100, # y
0b0000100001001000, # z
0b0000100101001001, # {
0b0001001000000000, # |
0b0010010010001001, # }
0b0000010100100000, # ~
0b0011111111111111]
# Hexadecimal character lookup table
lut = [
0b0000000000000001,
0b0000000000000010,
0b0000000000000100,
0b0000000000001000,
0b0000000000010000,
0b0000000000100000,
0b0000000001000000,
0b0000000010000000,
0b0000000100000000,
0b0000001000000000,
0b0000010000000000,
0b0000100000000000,
0b0001000000000000,
0b0010000000000000,
0b0100000000000000,
0b1000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0000000000000000,
0b0001001011001001,
0b0001010111000000,
0b0001001011111001,
0b0000000011100011,
0b0000010100110000,
0b0001001011001000,
0b0011101000000000,
0b0001011100000000,
0b0000000000000000, #
0b0000000000000110, # !
0b0000001000100000, # "
0b0001001011001110, # #
0b0001001011101101, # $
0b0000110000100100, # %
0b0010001101011101, # &
0b0000010000000000, # '
0b0010010000000000, # (
0b0000100100000000, # )
0b0011111111000000, # *
0b0001001011000000, # +
0b0000100000000000, # ,
0b0000000011000000, # -
0b0000000000000000, # .
0b0000110000000000, # /
0b0000110000111111, # 0
0b0000000000000110, # 1
0b0000000011011011, # 2
0b0000000010001111, # 3
0b0000000011100110, # 4
0b0010000001101001, # 5
0b0000000011111101, # 6
0b0000000000000111, # 7
0b0000000011111111, # 8
0b0000000011101111, # 9
0b0001001000000000, # :
0b0000101000000000, # ;
0b0010010000000000, # <
0b0000000011001000, # =
0b0000100100000000, # >
0b0001000010000011, # ?
0b0000001010111011, # @
0b0000000011110111, # A
0b0001001010001111, # B
0b0000000000111001, # C
0b0001001000001111, # D
0b0000000011111001, # E
0b0000000001110001, # F
0b0000000010111101, # G
0b0000000011110110, # H
0b0001001000000000, # I
0b0000000000011110, # J
0b0010010001110000, # K
0b0000000000111000, # L
0b0000010100110110, # M
0b0010000100110110, # N
0b0000000000111111, # O
0b0000000011110011, # P
0b0010000000111111, # Q
0b0010000011110011, # R
0b0000000011101101, # S
0b0001001000000001, # T
0b0000000000111110, # U
0b0000110000110000, # V
0b0010100000110110, # W
0b0010110100000000, # X
0b0001010100000000, # Y
0b0000110000001001, # Z
0b0000000000111001, # [
0b0010000100000000, #
0b0000000000001111, # ]
0b0000110000000011, # ^
0b0000000000001000, # _
0b0000000100000000, # `
0b0001000001011000, # a
0b0010000001111000, # b
0b0000000011011000, # c
0b0000100010001110, # d
0b0000100001011000, # e
0b0000000001110001, # f
0b0000010010001110, # g
0b0001000001110000, # h
0b0001000000000000, # i
0b0000000000001110, # j
0b0011011000000000, # k
0b0000000000110000, # l
0b0001000011010100, # m
0b0001000001010000, # n
0b0000000011011100, # o
0b0000000101110000, # p
0b0000010010000110, # q
0b0000000001010000, # r
0b0010000010001000, # s
0b0000000001111000, # t
0b0000000000011100, # u
0b0010000000000100, # v
0b0010100000010100, # w
0b0010100011000000, # x
0b0010000000001100, # y
0b0000100001001000, # z
0b0000100101001001, # {
0b0001001000000000, # |
0b0010010010001001, # }
0b0000010100100000, # ~
0b0011111111111111]
special = dict(degree= 0b0000000011100011, cone=0b0010100000001000)
special = dict(degree= 0b0000000011100011, cone=0b0010100000001000)
# Constructor
def __init__(self, address=0x70, debug=False):
self.disp = LEDBackpack(address=address, debug=debug)
def __init__(self, address=0x70, debug=False):
self.disp = LEDBackpack(address=address, debug=debug)
def writeCharRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
if (charNumber > 4):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value)
def writeCharRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
if (charNumber > 4):
return
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value)
def writeChar(self, charNumber, value, dot=False):
"Sets a single decimal or hexademical value (0..9 and A..F)"
if (charNumber > 4):
return
if value in special:
value = self.special[value]
else:
value = self.lut[ord(value)]
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value | (dot << 14))
def writeChar(self, charNumber, value, dot=False):
"Sets a single decimal or hexademical value (0..9 and A..F)"
if (charNumber > 4):
return
if value in special:
value = self.special[value]
else:
value = self.lut[ord(value)]
# Set the appropriate digit
self.disp.setBufferRow(charNumber, value | (dot << 14))
class AlphaScoller(threading.Thread):
def __init__(self, address=0x70, interval=.25):
@ -175,6 +175,7 @@ class AlphaScoller(threading.Thread):
self.disp = Alphanumeric(address)
super(AlphaScroller, self).__init__()
self.value = " "
self.counter = 0
def set_text(self, text, pad=True):
self.text = text
@ -186,11 +187,9 @@ class AlphaScoller(threading.Thread):
self.interval = interval
def run(self):
counter = 0
while True:
for i in range(4):
char = self.value[(counter+i) % len(self.value)]
char = self.value[(self.counter+i) % len(self.value)]
self.disp.writeChar(i, char)
time.sleep(interval)
counter += 1
self.counter += 1

55
kiln/thermo.py 100644
Wyświetl plik

@ -0,0 +1,55 @@
import time
import threading
import datetime
from collections import deque
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]
names = [str(i).replace('-', '0') for i in range(-22,0)] + [str(i) for i in range(1, 14)]
for i in range(len(cones)-1):
low, high = cones[i], cones[i+1]
if low <= temp < high:
frac = (temp - low) / float(high - low)
return names[i]+'.%d'%int(frac*10)
return "13+"
class Monitor(threading.Thread):
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()
def _read_temp(self):
with open(self.device, 'r') as f:
lines = f.readlines()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
with open(self.device, 'r') as f:
lines = f.readlines()
match = re.match(r'^[0-9a-f\s]{27}t=(\d+)$', lines[1])
if match is not None:
return float(match.group(1)) / 1000.0
@property
def temperature(self):
return self.history[-1][1]
def run(self):
while True:
temp = self._read_temp()
fahr = temp * 9. / 5. + 32.
now = datetime.datetime()
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))
text += ' '
self.display.text = text