leds/leds.py

64 lines
1.5 KiB
Python
Raw Normal View History

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
import lcd_manager
import light_manager
2020-11-07 04:12:10 +00:00
import logging
2020-11-04 01:44:08 +00:00
def lightlevel(lcd, level):
2020-11-07 04:12:10 +00:00
logging.debug("display level")
lcd.clear()
lcd.message("Light Level:\n]" + "-"*level + "[")
2020-11-04 01:44:08 +00:00
def querylightlevel():
2020-11-07 04:12:10 +00:00
logging.debug("NYI")
2020-11-04 01:44:08 +00:00
return 7
2020-11-07 01:22:15 +00:00
def color(lcd):
lcd.clear()
2020-11-07 01:22:15 +00:00
lcd.message("new pattern loaded.")
2020-11-07 04:12:10 +00:00
logging.debug("NYI")
2020-11-03 23:51:13 +00:00
def loop():
lcd = lcd_manager.Adafruit_CharLCD()
lights = light_manager.LightStrip()
level = 0
2020-11-06 23:01:22 +00:00
level_max = 14
idle = 0
idle_max = 15
2020-11-07 01:22:15 +00:00
cur_color = (255, 255, 255)
while True:
2020-11-07 04:12:10 +00:00
logging.debug("loop")
2020-11-04 01:44:08 +00:00
query_level = querylightlevel()
idle = idle + 1
2020-11-07 04:12:10 +00:00
logging.debug("idle value: {}".format(idle))
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
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:
2020-11-07 04:12:10 +00:00
logging.debug("hit idle threshold")
2020-11-04 01:44:08 +00:00
idle = idle_max
lcd.noDisplay()
else:
lightlevel(lcd, level)
sleep(1)
2020-11-03 23:51:13 +00:00
if __name__ == '__main__':
loop()