leds/leds.py

74 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
level = 0
level_max = 14
level_state = 0
color_state = 0
def lightlevel(lcd, level):
logging.debug("display level")
lcd.clear()
lcd.message("Light Level:\n]" + "-"*level + "[")
def query():
level_state = 2
def color(lcd):
lcd.clear()
lcd.message("new pattern loaded.")
logging.debug("NYI")
def get_state():
if level_state > 0:
level_state -= 1
return "level"
elif color_state > 0:
color_state -= 1
return "color"
else:
return "idle"
def displayon(lcd):
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display()
def loop():
lcd = lcd_manager.Adafruit_CharLCD()
lights = light_manager.LightStrip()
while True:
logging.debug("loop")
lights.tick()
query()
state = get_state()
if state == "level":
if lights.get_light_level() != (level / level_max):
lights.set_light_level(level / level_max)
lightlevel(lcd, level)
elif state == "color":
color(lcd)
else:
lcd.noDisplay()
sleep(0.1)
if __name__ == '__main__':
loop()