testing TM1637 display addition

This commit is contained in:
Tanaes 2022-01-08 21:55:02 -05:00
parent 8f88ecc5c7
commit ef5f011e40
5 changed files with 81 additions and 4 deletions

View File

@ -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

27
lib/display.py Normal file
View File

@ -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])

View File

@ -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):

View File

@ -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):

View File

@ -7,3 +7,4 @@ RPi.GPIO
Adafruit-MAX31855
Adafruit-GPIO
websocket-client
raspberrypi-tm1637