mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-13 05:04:40 +08:00
shutdownd to take car start stats into account.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user