forked from jonnor/UnlockOslo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_hardware.py
77 lines (65 loc) · 2.05 KB
/
check_hardware.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
import dlockoslo
import time
import sys
"""Tool for testing the hardware board
Uses I/O utilities and pin definitions from firmware,
to also ensure that these are correct"""
def check_inputs(delay):
print('check inputs')
for number, pin in dlockoslo.ins.items():
print('setup', number, pin)
dlockoslo.setup_gpio_pin(pin, 'in')
while True:
c = []
for number, pin in dlockoslo.ins.items():
p = dlockoslo.gpio_file_path(pin)
s = dlockoslo.read_boolean(p)
c.append(s)
print(c)
time.sleep(delay)
def check_outputs(delay):
print('check outputs')
for number, pin in dlockoslo.outs.items():
print('setup', number, pin)
dlockoslo.setup_gpio_pin(pin, 'out')
state = False
while True:
c = []
for number, pin in dlockoslo.outs.items():
p = dlockoslo.gpio_file_path(pin)
print('writing to', p, state)
dlockoslo.set_gpio(p, state)
time.sleep(delay)
state = not state
def check_status(delay):
print('check status leds')
for number, pin in dlockoslo.status.items():
print('setup', number, pin)
dlockoslo.setup_gpio_pin(pin, 'out')
state = False
while True:
c = []
for number, pin in dlockoslo.status.items():
p = dlockoslo.gpio_file_path(pin)
print('writing to', p, state)
dlockoslo.set_gpio(p, state)
time.sleep(delay)
state = not state
# NOTE: could do an automated test by connecting each output to corresponding input,
# then generating output patterns and ensuring that they are read correctly on input
def main():
prog, args = sys.argv[0], sys.argv[1:]
mode = 'input'
if len(args) >= 1:
mode = args[0]
delay = 0.15
if len(args) >= 2:
delay = float(args[1])
if 'output' in mode:
check_outputs(delay)
elif 'status' in mode:
check_status(delay)
elif 'input' in mode:
check_inputs(delay)
if __name__ == '__main__':
main()