Skip to content

Commit

Permalink
Add Timer Thread stopper
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshith111 committed Aug 28, 2022
1 parent 1b619e8 commit 18c04e4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ def __init__(self):
# int value of the AC power setting index
self.current_sleeper_seconds = int(searchhex[24:], 16)
self.input_seconds = 0
self.last_thread_state = False
print(self.current_sleeper_seconds)

def sleeper_action(self, state=True):
if state and self.input_seconds > 10:
print(f"Activated for {self.input_seconds-10} seconds")
subprocess.run(["powercfg ", "/SETACVALUEINDEX", f'{self.current_power_scheme_guid}', "SUB_VIDEO", "VIDEOIDLE", "30"], shell=False,
stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
t = Timer(self.input_seconds-10, self.sleep_reset)
t.start()
if not self.last_thread_state:
self.t = Timer(self.input_seconds-10, self.sleep_reset)
self.t.start()
self.last_thread_state = True
else:
self.t.cancle()

def sleep_reset(self):
print("restting")

# TO set custom sleep time
subprocess.run(["powercfg ", "/SETACVALUEINDEX", f'{self.current_power_scheme_guid}', "SUB_VIDEO", "VIDEOIDLE", f"{self.current_sleeper_seconds}"], shell=False,
stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Expand Down

0 comments on commit 18c04e4

Please sign in to comment.