attempt idle timeout fix

This commit is contained in:
janeptrv 2020-11-03 20:44:08 -05:00
parent 76715d1dc2
commit 3217cf177d

44
leds.py
View file

@ -239,23 +239,33 @@ class Adafruit_CharLCD:
self.write4bits(ord(char), True) self.write4bits(ord(char), True)
debug_statements = True
def debug(msg):
if debug_statements:
print(msg)
def lightlevel(lcd, level): def lightlevel(lcd, level):
print("display level") debug("display level")
lcd.clear() lcd.clear()
lcd.message("Light Level:\n]" + "-"*level + "[") lcd.message("Light Level:\n]" + "-"*level + "[")
def querylightlevel(): def querylightlevel():
print("NYI") debug("NYI")
return 7 return 7
def color(lcd, col): def color(lcd, col):
lcd.clear() lcd.clear()
lcd.message("new color:\n#" + col) lcd.message("new color:\n#{}".format(col))
print("NYI") debug("NYI")
def querycolor(): def querycolor():
print("NYI") debug("NYI")
return "ffffff" return "ffffff"
@ -267,22 +277,30 @@ def loop():
idle = 0 idle = 0
idle_max = 15 idle_max = 15
cur_color = "ffffff" cur_color = "ffffff"
print("loop") debug("loop")
query_color = querycolor() query_color = querycolor()
level = querylightlevel() query_level = querylightlevel()
idle = idle + 1 idle = idle + 1
if idle >= idle_max: debug("idle value: {}".format(idle))
idle = idle_max
lcd.noDisplay() if query_color != cur_color:
elif query_color != cur_color:
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display() lcd.display()
ccolor = query_color ccolor = query_color
idle = 0
color(lcd, cur_color) color(lcd, cur_color)
else: elif query_level != level:
level = query_level
idle = 0
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display() lcd.display()
lightlevel(lcd, level) lightlevel(lcd, level)
elif idle >= idle_max:
debug("hit idle threshold")
idle = idle_max
lcd.noDisplay()
else:
lightlevel(lcd, level)
sleep(1) sleep(1)