自動關機改為可調時長

This commit is contained in:
dragonpilot
2019-08-27 11:49:00 +10:00
parent 1b75ac55ac
commit 96330c25ce
+8 -4
View File
@@ -8,21 +8,25 @@ params = Params()
def main(gctx=None):
shutdown_count = 0
autoShutdownAt = get_shutdown_val()
auto_shutdown_at = get_shutdown_val()
frame = 0
while 1:
with open("/sys/class/power_supply/usb/present") as f:
usb_online = bool(int(f.read()))
if not usb_online:
# we update the value every 3 seconds in case of user updates it
if frame % 3 == 0:
auto_shutdown_at = get_shutdown_val()
shutdown_count += 1
else:
shutdown_count = 0
if autoShutdownAt is None:
autoShutdownAt = get_shutdown_val()
if auto_shutdown_at is None:
auto_shutdown_at = get_shutdown_val()
else:
if shutdown_count >= autoShutdownAt > 0:
if shutdown_count >= auto_shutdown_at > 0:
os.system('LD_LIBRARY_PATH="" svc power shutdown')
time.sleep(1)