diff --git a/apk/ai.comma.plus.offroad.apk b/apk/ai.comma.plus.offroad.apk index c86eb22d5..4804ad0f2 100644 Binary files a/apk/ai.comma.plus.offroad.apk and b/apk/ai.comma.plus.offroad.apk differ diff --git a/common/params.py b/common/params.py index 111810ef6..f90ccfdca 100755 --- a/common/params.py +++ b/common/params.py @@ -106,6 +106,7 @@ keys = { #dragonpilot config "DragonEnableDashcam": [TxType.PERSISTENT], "DragonEnableDriverSafetyCheck": [TxType.PERSISTENT], + "DragonEnableAutoShutdown": [TxType.PERSISTENT], "DragonAutoShutdownAt": [TxType.PERSISTENT], "DragonEnableSteeringOnSignal": [TxType.PERSISTENT], "DragonEnableLogger": [TxType.PERSISTENT], diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 020864dd7..89697146c 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -4,6 +4,7 @@ from common.params import Params, put_nonblocking default_conf = { 'DragonEnableDashcam': '0', 'DragonEnableDriverSafetyCheck': '1', + 'DragonEnableAutoShutdown': '1', 'DragonAutoShutdownAt': '0', # in minute 'DragonEnableSteeringOnSignal': '0', 'DragonEnableLogger': '1', diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index a467415de..f6cd8a17d 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -1,53 +1,50 @@ #!/usr/bin/env python3 - import os import time from common.params import Params params = Params() -import cereal import cereal.messaging as messaging +from common.realtime import sec_since_boot - -def main(gctx=None): - - shutdown_count = 0 - auto_shutdown_at = get_shutdown_val() - frame = 0 - last_shutdown_val = auto_shutdown_at +def main(): thermal_sock = messaging.sub_sock('thermal') + last_ts = 0 + secs = 0 + last_secs = 0 + shutdown_at = 0 started = False - + usb_online = False + enabled = False + last_enabled = False while 1: - 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 last_shutdown_val == auto_shutdown_at: - shutdown_count = 0 - last_shutdown_val = auto_shutdown_at + cur_time = sec_since_boot() + if cur_time - last_ts >= 10.: + enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False + # reset timer when enabled status has changed + if not last_enabled and enabled: + shutdown_at = cur_time + secs + last_enabled = enabled - if not started and not usb_online: - shutdown_count += 1 - else: - shutdown_count = 0 + if enabled: + secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 + # reset timer when secs num has changed + if last_secs != secs: + shutdown_at = cur_time + secs + last_secs = secs - if auto_shutdown_at is None: - auto_shutdown_at = get_shutdown_val() - else: - if shutdown_count >= auto_shutdown_at > 0: - os.system('LD_LIBRARY_PATH="" svc power shutdown') + 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())) - time.sleep(1) - -def get_shutdown_val(): - val = params.get("DragonAutoShutdownAt", encoding='utf8') - if val is None: - return None - else: - return int(val)*60 # convert to seconds + if enabled: + if started or usb_online: + shutdown_at = cur_time + secs + else: + if secs > 0 and cur_time >= shutdown_at: + os.system('LD_LIBRARY_PATH="" svc power shutdown') + time.sleep(10) if __name__ == "__main__": main() \ No newline at end of file