From 3217cf177d1b2e9358c20331f83ce1a9bf0e8290 Mon Sep 17 00:00:00 2001 From: janeptrv Date: Tue, 3 Nov 2020 20:44:08 -0500 Subject: [PATCH] attempt idle timeout fix --- leds.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/leds.py b/leds.py index 114f60d..70c7b48 100644 --- a/leds.py +++ b/leds.py @@ -239,23 +239,33 @@ class Adafruit_CharLCD: self.write4bits(ord(char), True) +debug_statements = True + + +def debug(msg): + if debug_statements: + print(msg) + + def lightlevel(lcd, level): - print("display level") + debug("display level") lcd.clear() lcd.message("Light Level:\n]" + "-"*level + "[") + def querylightlevel(): - print("NYI") - return 7 + debug("NYI") + return 7 + def color(lcd, col): lcd.clear() - lcd.message("new color:\n#" + col) - print("NYI") + lcd.message("new color:\n#{}".format(col)) + debug("NYI") def querycolor(): - print("NYI") + debug("NYI") return "ffffff" @@ -267,22 +277,30 @@ def loop(): idle = 0 idle_max = 15 cur_color = "ffffff" - print("loop") + debug("loop") query_color = querycolor() - level = querylightlevel() + query_level = querylightlevel() idle = idle + 1 - if idle >= idle_max: - idle = idle_max - lcd.noDisplay() - elif query_color != cur_color: + debug("idle value: {}".format(idle)) + + if query_color != cur_color: if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: lcd.display() ccolor = query_color + idle = 0 color(lcd, cur_color) - else: + elif query_level != level: + level = query_level + idle = 0 if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: lcd.display() lightlevel(lcd, level) + elif idle >= idle_max: + debug("hit idle threshold") + idle = idle_max + lcd.noDisplay() + else: + lightlevel(lcd, level) sleep(1)