-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSuspend.py
89 lines (59 loc) · 2.45 KB
/
Suspend.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
79
80
81
82
83
84
85
86
87
import pygame, sys, Common, TaskHandler, Configuration
import os,subprocess
class Suspend():
suspendTaskId = None
brightnessTaskId = None
config = Configuration.getConfiguration()
displayDark = False
def handleEvents(self, events):
if(len(events) > 0):
self.addSuspendTask()
self.restoreScreen()
self.addBrignessTask()
def configUpdated(self):
self.config = Configuration.getConfiguration()
self.addSuspendTask()
self.addBrignessTask()
def suspend(self):
try:
subprocess.Popen(["poweroff"])
TaskHandler.removePeriodicTask(self.suspendTaskId)
except Exception as identifier:
pass
def disableScreen(self):
if(Configuration.isOpenDinguX()):
return
os.system('echo 0 > /proc/jz/backlight')
self.displayDark = True
TaskHandler.removePeriodicTask(self.brightnessTaskId)
def restoreScreen(self):
if(Configuration.isOpenDinguX()):
return
if(self.displayDark):
if("lcd_backlight" not in self.config):
self.config["lcd_backlight"] = 30
Configuration.saveConfiguration()
backlight = self.config["lcd_backlight"]
os.system('echo ' + str(backlight) + ' > /proc/jz/backlight')
self.displayDark = False
def disableSuspend(self):
if(self.suspendTaskId is not None):
TaskHandler.removePeriodicTask(self.suspendTaskId)
def addSuspendTask(self):
if(self.suspendTaskId is not None):
TaskHandler.removePeriodicTask(self.suspendTaskId)
suspendTime = self.config["options"]["suspendTimeout"]
if(suspendTime == "off"):
return
self.suspendTaskId = TaskHandler.addPeriodicTask(0, self.suspend, float(suspendTime) * 1000 * 60)
def addBrignessTask(self):
if(self.brightnessTaskId is not None):
TaskHandler.removePeriodicTask(self.brightnessTaskId)
displayTimeout = self.config["options"]["displayTimeout"]
if(displayTimeout == "off"):
return
self.brightnessTaskId = TaskHandler.addPeriodicTask(0, self.disableScreen, float(displayTimeout) * 1000)
def __init__(self):
Configuration.addConfigChangedCallback(self.configUpdated)
self.addSuspendTask()
self.addBrignessTask()