mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-30 19:33:42 +08:00
adjust shutdownd logic
This commit is contained in:
@@ -9,7 +9,6 @@ from selfdrive.dragonpilot.dragonconf import dp_get_last_modified
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
thermal_sock = messaging.sub_sock('thermal')
|
thermal_sock = messaging.sub_sock('thermal')
|
||||||
last_ts = 0
|
|
||||||
secs = 0
|
secs = 0
|
||||||
last_secs = None
|
last_secs = None
|
||||||
shutdown_at = 0
|
shutdown_at = 0
|
||||||
@@ -20,29 +19,28 @@ def main():
|
|||||||
dp_last_modified = None
|
dp_last_modified = None
|
||||||
while 1:
|
while 1:
|
||||||
cur_time = sec_since_boot()
|
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:
|
if enabled:
|
||||||
msg = messaging.recv_sock(thermal_sock, wait=True)
|
secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60
|
||||||
started = msg.thermal.started
|
dp_last_modified = modified
|
||||||
usb_online = msg.thermal.usbOnline
|
|
||||||
|
|
||||||
if last_enabled != enabled or last_secs != secs or started or usb_online:
|
if last_enabled != enabled or last_secs != secs or started or usb_online:
|
||||||
shutdown_at = cur_time + secs
|
shutdown_at = cur_time + secs
|
||||||
|
|
||||||
last_enabled = enabled
|
if enabled:
|
||||||
last_secs = secs
|
msg = messaging.recv_sock(thermal_sock, wait=True)
|
||||||
last_ts = cur_time
|
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)
|
time.sleep(10)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user