-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacklight.py
More file actions
52 lines (40 loc) · 1.08 KB
/
stacklight.py
File metadata and controls
52 lines (40 loc) · 1.08 KB
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
import logging
import socket
import time
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel('DEBUG')
HOST = '10.0.0.7'
PORT = 135
address = (HOST, PORT)
if __name__ == '__main__':
# neutral command
basis = ''.join(['W']
+ [b.decode('hex') for b in ['00'] + ['64']*5 + ['64']]
)
lamp_index = {
'red': 0,
'yellow': 1,
'green': 2,
'blue': 3,
'white': 4,
}
# s = socket.socket()
# stacklight off
command = ''.join(['W']
+ [b.decode('hex') for b in ['00'] + ['00']*5 + ['00']]
)
logger.debug('command: %r' % command)
# s.send(command)
# stacklight red on
i = lamp_index['red']
command = basis[:2+i] + '01'.decode('hex') + basis[2+i+1:]
logger.debug('command: %r' % command)
# s.send(command)
time.sleep(0.500)
# stacklight red off
i = lamp_index['red']
command = basis[:2+i] + '00'.decode('hex') + basis[2+i+1:]
logger.debug('command: %r' % command)
# s.send(command)
time.sleep(3)