83 lines
2.1 KiB
Python
83 lines
2.1 KiB
Python
import sys
|
|
|
|
from character_display import CharacterDisplay
|
|
from garage_display import GarageDisplay
|
|
from garage_updater import GarageUpdater
|
|
from multiprocessing import Event
|
|
from multiprocessing import Process
|
|
from signal import signal
|
|
from signal import SIGTERM
|
|
from time import sleep
|
|
from time_display import TimeDisplay
|
|
from weather_display import WeatherDisplay
|
|
from weather_updater import WeatherUpdater
|
|
|
|
try:
|
|
import unicornhathd as unicorn
|
|
unicorn.rotation(90)
|
|
except ImportError:
|
|
from unicorn_hat_sim import unicornhathd as unicorn
|
|
unicorn.rotation(180)
|
|
|
|
|
|
WEATHER_UPDATE_INTERVAL_IN_SECONDS = 10
|
|
GARAGE_UPDATE_INTERVAL_IN_SECONDS = 10
|
|
DISPLAY_UPDATE_INTERVAL_IN_SECONDS = 0.5
|
|
CONFIG_FILE = 'chutney.cfg'
|
|
|
|
|
|
def main():
|
|
haltEvent = Event()
|
|
signal(SIGTERM, cleanExit(unicorn, haltEvent))
|
|
unicorn.brightness(0.3)
|
|
|
|
weatherThread = Process(target=weatherLoop, args=[haltEvent])
|
|
weatherThread.start()
|
|
|
|
garageThread = Process(target=garageLoop, args=[haltEvent])
|
|
garageThread.start()
|
|
|
|
characterDisplay = CharacterDisplay(unicorn)
|
|
timeDisplay = TimeDisplay(characterDisplay, topRow=15)
|
|
weatherDisplay = WeatherDisplay(characterDisplay, topRow=9)
|
|
garageDisplay = GarageDisplay(characterDisplay, topRow=3)
|
|
|
|
while True:
|
|
timeDisplay.showTime()
|
|
weatherDisplay.showWeather()
|
|
garageDisplay.showGarageState()
|
|
sleep(DISPLAY_UPDATE_INTERVAL_IN_SECONDS)
|
|
|
|
|
|
def weatherLoop(haltEvent):
|
|
weatherUpdater = WeatherUpdater(configFile=CONFIG_FILE)
|
|
|
|
while not haltEvent.is_set():
|
|
weatherUpdater.updateWeather()
|
|
haltEvent.wait(timeout=WEATHER_UPDATE_INTERVAL_IN_SECONDS)
|
|
|
|
weatherUpdater.clearWeather()
|
|
|
|
|
|
def garageLoop(haltEvent):
|
|
garageUpdater = GarageUpdater(configFile=CONFIG_FILE)
|
|
|
|
while not haltEvent.is_set():
|
|
garageUpdater.updateGarageState()
|
|
haltEvent.wait(timeout=GARAGE_UPDATE_INTERVAL_IN_SECONDS)
|
|
|
|
garageUpdater.clearGarageState()
|
|
|
|
|
|
def cleanExit(unicorn, haltEvent):
|
|
def _exit_(signum, frame):
|
|
unicorn.off()
|
|
haltEvent.set()
|
|
sys.exit(0)
|
|
|
|
return _exit_
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|