63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
#!/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
|
|
import lcd_manager
|
|
import light_manager
|
|
import logging
|
|
|
|
|
|
def lightlevel(lcd, level):
|
|
logging.debug("display level")
|
|
lcd.clear()
|
|
lcd.message("Light Level:\n]" + "-"*level + "[")
|
|
|
|
|
|
def querylightlevel():
|
|
logging.debug("NYI")
|
|
return 7
|
|
|
|
|
|
def color(lcd):
|
|
lcd.clear()
|
|
lcd.message("new pattern loaded.")
|
|
logging.debug("NYI")
|
|
|
|
|
|
def loop():
|
|
lcd = lcd_manager.Adafruit_CharLCD()
|
|
lights = light_manager.LightStrip()
|
|
level = 0
|
|
level_max = 14
|
|
idle = 0
|
|
idle_max = 15
|
|
cur_color = (255, 255, 255)
|
|
while True:
|
|
logging.debug("loop")
|
|
query_level = querylightlevel()
|
|
idle = idle + 1
|
|
logging.debug("idle value: {}".format(idle))
|
|
lights.tick()
|
|
if query_level != level:
|
|
level = query_level
|
|
lights.set_light_level(level / level_max)
|
|
idle = 0
|
|
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
|
|
lcd.display()
|
|
lightlevel(lcd, level)
|
|
elif idle >= idle_max:
|
|
logging.debug("hit idle threshold")
|
|
idle = idle_max
|
|
lcd.noDisplay()
|
|
else:
|
|
lightlevel(lcd, level)
|
|
sleep(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
loop()
|