2020-11-03 23:51:13 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
#
|
|
|
|
# based on code from lrvick and LiquidCrystal
|
|
|
|
# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py
|
|
|
|
# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp
|
|
|
|
#
|
|
|
|
|
|
|
|
from time import sleep
|
2020-11-07 04:00:23 +00:00
|
|
|
import lcd_manager
|
|
|
|
import light_manager
|
2020-11-03 23:51:13 +00:00
|
|
|
|
2020-11-04 01:38:58 +00:00
|
|
|
|
2020-11-04 01:44:08 +00:00
|
|
|
debug_statements = True
|
|
|
|
|
|
|
|
|
|
|
|
def debug(msg):
|
|
|
|
if debug_statements:
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
|
2020-11-04 01:38:58 +00:00
|
|
|
def lightlevel(lcd, level):
|
2020-11-04 01:44:08 +00:00
|
|
|
debug("display level")
|
2020-11-04 01:38:58 +00:00
|
|
|
lcd.clear()
|
|
|
|
lcd.message("Light Level:\n]" + "-"*level + "[")
|
|
|
|
|
2020-11-04 01:44:08 +00:00
|
|
|
|
2020-11-04 01:38:58 +00:00
|
|
|
def querylightlevel():
|
2020-11-04 01:44:08 +00:00
|
|
|
debug("NYI")
|
|
|
|
return 7
|
|
|
|
|
2020-11-04 01:38:58 +00:00
|
|
|
|
2020-11-07 01:22:15 +00:00
|
|
|
def color(lcd):
|
2020-11-04 01:38:58 +00:00
|
|
|
lcd.clear()
|
2020-11-07 01:22:15 +00:00
|
|
|
lcd.message("new pattern loaded.")
|
2020-11-04 01:44:08 +00:00
|
|
|
debug("NYI")
|
2020-11-04 01:38:58 +00:00
|
|
|
|
|
|
|
|
2020-11-03 23:51:13 +00:00
|
|
|
def loop():
|
2020-11-07 04:00:23 +00:00
|
|
|
lcd = lcd_manager.Adafruit_CharLCD()
|
|
|
|
lights = light_manager.LightStrip()
|
2020-11-04 01:48:08 +00:00
|
|
|
level = 0
|
2020-11-06 23:01:22 +00:00
|
|
|
level_max = 14
|
2020-11-04 01:48:08 +00:00
|
|
|
idle = 0
|
|
|
|
idle_max = 15
|
2020-11-07 01:22:15 +00:00
|
|
|
cur_color = (255, 255, 255)
|
2020-11-04 01:38:58 +00:00
|
|
|
while True:
|
2020-11-04 01:44:08 +00:00
|
|
|
debug("loop")
|
|
|
|
query_level = querylightlevel()
|
2020-11-04 01:38:58 +00:00
|
|
|
idle = idle + 1
|
2020-11-04 01:44:08 +00:00
|
|
|
debug("idle value: {}".format(idle))
|
2020-11-07 04:00:23 +00:00
|
|
|
lights.tick()
|
2020-11-07 01:22:15 +00:00
|
|
|
if query_level != level:
|
2020-11-04 01:44:08 +00:00
|
|
|
level = query_level
|
2020-11-07 01:22:15 +00:00
|
|
|
lights.set_light_level(level / level_max)
|
2020-11-04 01:44:08 +00:00
|
|
|
idle = 0
|
2020-11-04 01:38:58 +00:00
|
|
|
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
|
|
|
|
lcd.display()
|
|
|
|
lightlevel(lcd, level)
|
2020-11-04 01:44:08 +00:00
|
|
|
elif idle >= idle_max:
|
|
|
|
debug("hit idle threshold")
|
|
|
|
idle = idle_max
|
|
|
|
lcd.noDisplay()
|
|
|
|
else:
|
|
|
|
lightlevel(lcd, level)
|
2020-11-04 01:38:58 +00:00
|
|
|
sleep(1)
|
|
|
|
|
2020-11-03 23:51:13 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-11-04 01:38:58 +00:00
|
|
|
loop()
|