add enable auto shutdown toggle

This commit is contained in:
dragonpilot
2020-03-09 22:46:52 +10:00
parent 785791333f
commit fe5a3de1b9
4 changed files with 35 additions and 36 deletions
Binary file not shown.
+1
View File
@@ -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],
@@ -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',
+33 -36
View File
@@ -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()