diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index 702bda718..ac92ec713 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -9,7 +9,6 @@ from selfdrive.dragonpilot.dragonconf import dp_get_last_modified def main(): thermal_sock = messaging.sub_sock('thermal') - last_ts = 0 secs = 0 last_secs = None shutdown_at = 0 @@ -20,29 +19,28 @@ def main(): dp_last_modified = None while 1: cur_time = sec_since_boot() - if cur_time - last_ts >= 10.: - modified = dp_get_last_modified() - if dp_last_modified != modified: - enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False - if enabled: - secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 - - dp_last_modified = modified + modified = dp_get_last_modified() + if dp_last_modified != modified: + enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False if enabled: - msg = messaging.recv_sock(thermal_sock, wait=True) - started = msg.thermal.started - usb_online = msg.thermal.usbOnline + secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 + dp_last_modified = modified - if last_enabled != enabled or last_secs != secs or started or usb_online: - shutdown_at = cur_time + secs + if last_enabled != enabled or last_secs != secs or started or usb_online: + shutdown_at = cur_time + secs - last_enabled = enabled - last_secs = secs - last_ts = cur_time + if enabled: + msg = messaging.recv_sock(thermal_sock, wait=True) + started = msg.thermal.started + usb_online = msg.thermal.usbOnline + + if not started and not usb_online and secs > 0 and cur_time >= shutdown_at: + os.system('LD_LIBRARY_PATH="" svc power shutdown') + + last_enabled = enabled + last_secs = secs - if enabled and not started and not usb_online and secs > 0 and cur_time >= shutdown_at: - os.system('LD_LIBRARY_PATH="" svc power shutdown') time.sleep(10) if __name__ == "__main__":