diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index fe1d9e815..cc0b1bf45 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -4,25 +4,32 @@ import os import time from common.params import Params params = Params() +import cereal +import cereal.messaging as messaging + def main(gctx=None): shutdown_count = 0 auto_shutdown_at = get_shutdown_val() frame = 0 - last_shutdown_val = get_shutdown_val() + last_shutdown_val = auto_shutdown_at + thermal_sock = messaging.sub_sock('thermal') + started = False while 1: - with open("/sys/class/power_supply/usb/present") as f: - usb_online = bool(int(f.read())) + if frame % 5 == 0: + msg = messaging.recv_sock(thermal_sock, wait=True) + started = msg.thermal.started + with open("/sys/class/power_supply/usb/present") as f: + usb_online = bool(int(f.read())) + auto_shutdown_at = get_shutdown_val() - if not usb_online: - # we update the value every 5 seconds in case of user updates it - if frame % 5 == 0: - auto_shutdown_at = get_shutdown_val() - shutdown_count += 1 - else: + if started or usb_online: shutdown_count = 0 + else: + if not usb_online: + shutdown_count += 1 if not last_shutdown_val == auto_shutdown_at: shutdown_count = 0