-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·75 lines (68 loc) · 2.16 KB
/
main.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
import argparse, time, os
import brightness, model
from runcmd import run_cmd
def parseArgs():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Automatically adjust the brightness of screen based on content",
)
parser.add_argument(
"--sleep-interval",
type=float,
default=0.5,
help="Time to sleep between backlight brightness checks in seconds",
)
parser.add_argument(
"--transition-time",
type=float,
default=500,
help="Time to transition between brightness levels in milliseconds",
)
parser.add_argument(
"--min-brightness",
type=float,
default=1,
help="Minimum brightness",
)
parser.add_argument(
"--max-brightness",
type=float,
default=100,
help="Maximum brightness",
)
parser.add_argument(
"--file",
type=str,
default=os.path.expanduser("~/.config/lux/model.pickle"),
help="Location to save the model",
)
return parser.parse_args()
def main():
args = parseArgs()
controller = brightness.Xbacklight()
brightnessModel = model.SimpleModel(
minB=args.min_brightness,
maxB=args.max_brightness,
)
brightnessGetter = brightness.ScreenBrightnessGetter()
lastScreen = brightnessGetter.get()
lastBacklight = controller.get()
brightnessModel.addObservation(lastScreen, lastBacklight)
brightnessModel.load(args.file)
while True:
time.sleep(args.sleep_interval)
screen = brightnessGetter.get()
backlight = controller.get()
if backlight != lastBacklight:
brightnessModel.addObservation(screen, backlight)
brightnessModel.saveIfNecessary(args.file)
else:
newBacklight = brightnessModel.predict(screen)
controller.set(newBacklight, args.transition_time)
time.sleep(max(0, args.transition_time / 1000 - args.sleep_interval))
backlight = newBacklight
lastScreen = screen
lastBacklight = backlight
pass
if __name__ == "__main__":
main()