61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
import sys
|
|
import threading
|
|
|
|
from character_display import CharacterDisplay
|
|
from signal import signal, 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
|
|
DISPLAY_UPDATE_INTERVAL_IN_SECONDS = 0.5
|
|
CONFIG_FILE = 'chutney.cfg'
|
|
|
|
|
|
def cleanExit(unicorn, haltEvent):
|
|
def _exit_(signum, frame):
|
|
unicorn.off()
|
|
haltEvent.set()
|
|
sys.exit(0)
|
|
|
|
return _exit_
|
|
|
|
|
|
def weatherLoop(haltEvent):
|
|
weatherUpdater = WeatherUpdater(configFile=CONFIG_FILE)
|
|
|
|
while not haltEvent.is_set():
|
|
weatherUpdater.updateWeather()
|
|
sleep(WEATHER_UPDATE_INTERVAL_IN_SECONDS)
|
|
|
|
|
|
def main():
|
|
haltEvent = threading.Event()
|
|
signal(SIGTERM, cleanExit(unicorn, haltEvent))
|
|
unicorn.brightness(0.3)
|
|
|
|
weatherThread = threading.Thread(target=weatherLoop, args=[haltEvent])
|
|
weatherThread.start()
|
|
|
|
characterDisplay = CharacterDisplay(unicorn)
|
|
timeDisplay = TimeDisplay(characterDisplay, topRow=15)
|
|
weatherDisplay = WeatherDisplay(characterDisplay, topRow=9)
|
|
|
|
while True:
|
|
timeDisplay.showTime()
|
|
weatherDisplay.showWeather()
|
|
sleep(DISPLAY_UPDATE_INTERVAL_IN_SECONDS)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|