-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPConfig.py
78 lines (52 loc) · 2.63 KB
/
PPConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#User editable config file. Change triggers here as you see fit.
import PPButtonMon, PPActions
from PPTypes import *
import time
XorgUser = 'ben' #User account Xorg is running on
SoftLockResleepSecs = 5 #Shut the display off again after this amount of time if awoken by an event and NOT the user
HardLockResleepSecs = 30 #After 30 seconds of a wakeup event, if the user hasn't unlocked us, go back to sleep
def CheckForSoftLock(ButtonStates): #Soft press power
if any([ButtonStates[S].IsPressed for S in (ButtonType.VOLDOWN, ButtonType.VOLUP)]):
return False #Probably a hard lock
PowButton = ButtonStates[ButtonType.POWER]
if not PowButton.IsPressed or PowButton.ChangeTime and PowButton.ChangeTime + 2000 < int(time.time_ns() // 1_000_000):
return False
#Wait for them to let go.
PPButtonMon.ButtonMonitor.Instance.WaitForButtonState(ButtonType.POWER, False)
if all((PowButton.ChangeTime, PowButton.LastChangeTime)) and PowButton.ChangeTime - PowButton.LastChangeTime <= 75: #Obviously a bug in the kernel driver, nobody's that fast
return False
if PPLockState.Instance.HardLocked or PPLockState.Instance.SoftLocked:
PPActions.PerformUnlock()
else:
PPActions.PerformSoftLock()
return True
def CheckForHardLock(ButtonStates): #Vol down + power at same time
if PPLockState.Instance.HardLocked:
return False #Don't re-lock if we're already locked.
Relevant = (ButtonType.VOLDOWN, ButtonType.POWER)
if not all([ButtonStates[S].IsPressed for S in Relevant]):
return False
for R in Relevant: #Wait for them to let go
PPButtonMon.ButtonMonitor.Instance.WaitForButtonState(R, False)
PPActions.PerformHardLock()
return True
def CheckForRotate(ButtonStates):
if PPLockState.Instance.SoftLocked or PPLockState.Instance.HardLocked:
return False #Don't allow us to do this by accident when it's in our pocket
if not all([not ButtonStates[S].IsPressed for S in ButtonStates]):
return False #Can't have a button held down to trigger this
VolDown = ButtonStates[ButtonType.VOLDOWN]
VolUp = ButtonStates[ButtonType.VOLUP]
if not VolDown.ChangeTime or not VolUp.ChangeTime:
return False
Distance = VolDown.ChangeTime - VolUp.ChangeTime
PushTime = max((VolDown.ChangeTime, VolUp.ChangeTime))
print(f'PUSH TIME {PushTime}')
if Distance < 0:
return False
if Distance > 1500 or PushTime + 1000 < (time.time_ns() // 1_000_000): #No longer than 1.5secs distance, and not more than a second ago.
print(f'Got rejection by {(time.time_ns()//1_000_000) - PushTime + 1000} milliseconds')
return False
PPActions.PerformRotate()
return True
EventTriggerFuncs = (CheckForHardLock, CheckForSoftLock, CheckForRotate)