diff --git a/config.py b/config.py index 60dd6fb..3126e32 100644 --- a/config.py +++ b/config.py @@ -43,11 +43,14 @@ gpio_fan = 22 # pin 15 # energized the safety relay. ## Display outputs -gpio_disp1_clk = 20 # pin 38 -gpio_disp1_dat = 21 # pin 40 -gpio_disp2_clk = 16 # pin 36 -gpio_disp2_dat = 26 # pin 37 +time_disp = {'type': 'TMC1637', + 'pins': {'clock': 16, # pin 36 + 'data': 26}} # pin 37 + +time_disp = {'type': 'TMC1637', + 'pins': {'clock': 20, # pin 38 + 'data': 21}} # pin 40 gpio_dotstar_clk = 19 # pin 35 gpio_dotstar_dat = 13 # pin 33 diff --git a/lib/display.py b/lib/display.py new file mode 100644 index 0000000..e4e00ae --- /dev/null +++ b/lib/display.py @@ -0,0 +1,27 @@ +class TM1637(object): + def __init__(self, + clk_pin, + dat_pin): + + self.clk_pin = clock_pin + self.dat_pin = dat_pin + + try: + import tm1637 + self.tm = tm1637.TM1637(clk=clk_pin, + dio=dat_pin) + def temp(self, + t): + self.tm.number(t) + + def time(self, + h, + m): + self.tm.numbers(h, m, True) + + def text(self, + text): + self.tm.show(text[0:4]) + + def off(self): + self.tm.write([0, 0, 0, 0]) diff --git a/lib/oven.py b/lib/oven.py index e20d36a..380010b 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -45,6 +45,7 @@ class Output(object): self.GPIO.output(config.gpio_heat, self.GPIO.LOW) time.sleep(sleepfor) + # FIX - Board class needs to be completely removed class Board(object): def __init__(self): diff --git a/lib/ovenWatcher.py b/lib/ovenWatcher.py index 3e47e4f..991ce16 100644 --- a/lib/ovenWatcher.py +++ b/lib/ovenWatcher.py @@ -1,7 +1,33 @@ import threading,logging,json,time,datetime from oven import Oven +from display import TM1637 +import config + log = logging.getLogger(__name__) + +class Display(object): + def __init__(self, + type, + pins): + + if type == "TMC1637": + self.disp = TM1637(pins['clock'] + pins['data']) + + def temp(self, t): + self.disp.temp(t) + + def time(self, h, m): + self.disp.time(h, m) + + def off(self): + self.disp.off() + + def text(self, text): + self.disp.text(text) + + class OvenWatcher(threading.Thread): def __init__(self,oven): self.last_profile = None @@ -13,6 +39,21 @@ class OvenWatcher(threading.Thread): self.daemon = True self.oven = oven self.start() + self.time_disp = None + self.temp_disp = None + + try: + self.time_disp = Display(config.time_disp['type'], + config.time_disp['pins']) + except NameError: + self.time_disp = None + + try: + self.temp_disp = Display(config.temp_disp['type'], + config.temp_disp['pins']) + except NameErro: + self.temp_disp = None + # FIXME - need to save runs of schedules in near-real-time # FIXME - this will enable re-start in case of power outage @@ -32,6 +73,10 @@ class OvenWatcher(threading.Thread): else: self.recording = False self.notify_all(oven_state) + if self.time_disp: + self.time_disp.time(oven_state['runtime']) + if self.temp_disp: + self.temp_disp.temp(oven_state['temperature']) time.sleep(self.oven.time_step) def lastlog_subset(self,maxpts=50): diff --git a/requirements.txt b/requirements.txt index cbe34f2..4bdeeb2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ RPi.GPIO Adafruit-MAX31855 Adafruit-GPIO websocket-client +raspberrypi-tm1637