-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfirmware.py
62 lines (48 loc) · 1.25 KB
/
firmware.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
"""Test uploading firmware"""
import time
import unittest
from multiprocessing import Process, Queue
from queue import Empty
from gpiozero import DigitalOutputDevice
RESET_GPIO_NUMBER = 4
BOOT0_GPIO_NUMBER = 22
def resethat():
"""Reset the HAT"""
reset = DigitalOutputDevice(RESET_GPIO_NUMBER)
boot0 = DigitalOutputDevice(BOOT0_GPIO_NUMBER)
boot0.off()
reset.off()
time.sleep(0.01)
reset.on()
time.sleep(0.01)
boot0.close()
reset.close()
time.sleep(0.5)
def reboot(exc):
"""Reboot hat and load firmware
:param exc: Queue to pass exceptions
"""
try:
from buildhat import Hat
resethat()
h = Hat(debug=True)
print(h.get())
except Exception as e:
exc.put(e)
class TestFirmware(unittest.TestCase):
"""Test firmware uploading functions"""
def test_upload(self):
"""Test upload firmware
:raises exc.get: Raised if exception in subprocess
"""
for _ in range(500):
exc = Queue()
p = Process(target=reboot, args=(exc,))
p.start()
p.join()
try:
raise exc.get(False)
except Empty:
pass
if __name__ == '__main__':
unittest.main()