def main(): global epaper global shutting_down global details_to_display epaper = EPaper(debug_mode=DEBUG_MODE) atexit.register(shutdown_hook) signal.signal(signal.SIGTERM, signal_hook) buttons = None if not DEBUG_MODE and (os.environ.get("EPAPER_BUTTONS_ENABLED", "true") == "true"): from buttons import Buttons buttons = Buttons([ int(os.environ.get("EPAPER_GPIO_PIN_FOR_KEY1", "5")), int(os.environ.get("EPAPER_GPIO_PIN_FOR_KEY2", "6")), int(os.environ.get("EPAPER_GPIO_PIN_FOR_KEY3", "13")), int(os.environ.get("EPAPER_GPIO_PIN_FOR_KEY4", "19")) ], lambda key: action_button(key, epaper)) notifier = sdnotify.SystemdNotifier() notifier.notify("READY=1") while True: if shutting_down: logging.info("App is shutting down.....") break notifier.notify("WATCHDOG=1") if details_to_display is not None: logging.info( "Going to refresh the main screen with details view...") details_to_display() details_to_display = None buttons.set_not_busy() for i in range(10): time.sleep(0.5) if details_to_display is not None: logging.info("Got button pressed while in details!") break if details_to_display is not None: continue logging.info("Ok, enough - going back to standard view") refresh_main_screen(epaper, force=True) else: logging.info("Going to refresh the main screen...") refresh_main_screen(epaper) for i in range(300 if buttons is not None else 1 ): # lower the CPU usage when no buttons handled if shutting_down: logging.info("App is shutting down...") break if details_to_display is not None: logging.info("Got button pressed!") break time.sleep(1 if buttons is not None else 300)