mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-21 22:12:05 +08:00
自動關機改為可調時長
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user