加入斷電自動關機功能

This commit is contained in:
Rick Lan
2019-06-27 14:46:24 +10:00
committed by eFini
parent a7ad4488b9
commit bf5e361b26
4 changed files with 39 additions and 3 deletions
@@ -34,6 +34,13 @@ class dragonconf():
if has_new_def:
self.write(config)
# Auto shutdown, default 0 (disable)
if "autoShutdownAt" not in config:
config["autoShutdownAt"] = 0
has_new_def = True
if has_new_def:
self.write(config)
return config
def write(self, config):
@@ -0,0 +1,27 @@
#!/usr/bin/env python2.7
import os
import time
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
dragonconf = dragonconf()
def main(gctx=None):
shutdown_count = 0
while 1:
with open("/sys/class/power_supply/usb/present") as f:
usb_online = bool(int(f.read()))
if not usb_online:
shutdown_count += 1
else:
shutdown_count = 0
if shutdown_count >= dragonconf.conf["autoShutdownAt"] > 0:
os.system('LD_LIBRARY_PATH="" svc power shutdown')
time.sleep(1)
if __name__ == "__main__":
main()
+5 -3
View File
@@ -108,8 +108,9 @@ managed_processes = {
"gpsd": ("selfdrive/sensord", ["./gpsd"]),
"updated": "selfdrive.updated",
"athena": "selfdrive.athena.athenad",
"dashcam": "selfdrive.dragonpilot.dashcamd.dashcamd",
"safeguard": "selfdrive.dragonpilot.safeguardd.safeguardd"
"dashcamd": "selfdrive.dragonpilot.dashcamd.dashcamd",
"safeguardd": "selfdrive.dragonpilot.safeguardd.safeguardd",
"shutdownd": "selfdrive.dragonpilot.shutdownd.shutdownd",
}
android_packages = ("ai.comma.plus.offroad", "ai.comma.plus.frame")
@@ -133,6 +134,7 @@ persistent_processes = [
'updated',
'athena',
'safeguardd',
'shutdownd',
]
car_started_processes = [
@@ -148,7 +150,7 @@ car_started_processes = [
'ubloxd',
'gpsd',
'deleter',
'dashcam',
'dashcamd',
]
def register_managed_process(name, desc, car_started=False):