-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
executable file
·41 lines (33 loc) · 939 Bytes
/
demo.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
#!/usr/bin/python -u
import time
import switch
import display
import backlight
def changed(pos, prev):
print "NOW: " + str(pos)
display.show_picture(img_set[pos])
def moved(pos, prev, curr):
backlight.turn_on()
print "now: " + str(pos)
if curr == pos:
display.show_picture(img_set[pos])
else:
display.show_picture(img_move[pos])
display.initialize()
switch.initialize()
switch.new_transition = moved
switch.new_setting = changed
print "Switch positions: " + str(switch.positions())
img_set = [ [] for _ in range(switch.positions()+1) ]
img_move = [ [] for _ in range(switch.positions()+1) ]
for i in range(switch.positions()+1):
img = "images/set" + str(i) + ".graphic"
print "load images: " + img
img_set[i] = display.load_picture(img)
img = "images/move" + str(i) + ".graphic"
img_move[i] = display.load_picture(img)
while True:
switch.service()
time.sleep(switch.tick_rate)
switch.shutdown()
display.shutdown()