51
51
# Constants
52
52
LED_ON_DELAY_TIME = 0.2 # Seconds
53
53
LED_OFF_DELAY_TIME = 0.2 # Seconds
54
- LED_PIN_NAMES = ['L' , 'LED' , 'RED_LED' , 'GREEN_LED' , 'BLUE_LED' ]
54
+ LED_PIN_NAMES = ['L' , 'LED' , 'RED_LED' , 'YELLOW_LED' , ' GREEN_LED' , 'BLUE_LED' ]
55
55
56
56
# Test result strings
57
57
PASS = "PASS"
58
58
FAIL = "FAIL"
59
59
NA = "N/A"
60
60
61
- # Release pins
62
- def _deinit_pins (gpios ):
63
- for g in gpios :
64
- g .deinit ()
65
-
66
61
# Toggle IO pins while waiting for answer
67
- def _toggle_wait (gpios ):
68
-
62
+ def _toggle_wait (led_pins ):
69
63
timestamp = time .monotonic ()
70
64
led_state = False
71
65
print ("Are the pins listed above toggling? [y/n]" )
72
66
while True :
73
- if led_state :
74
- if time .monotonic () > timestamp + LED_ON_DELAY_TIME :
75
- led_state = False
76
- timestamp = time .monotonic ()
77
- else :
78
- if time .monotonic () > timestamp + LED_OFF_DELAY_TIME :
79
- led_state = True
80
- timestamp = time .monotonic ()
81
- for gpio in gpios :
82
- gpio .value = led_state
83
- if supervisor .runtime .serial_bytes_available :
84
- answer = input ()
85
- if answer == 'y' :
86
- return True
87
- return False
67
+
68
+ # Cycle through each pin in the list
69
+ for pin in led_pins :
70
+ led = digitalio .DigitalInOut (getattr (board , pin ))
71
+ led .direction = digitalio .Direction .OUTPUT
72
+ blinking = True
73
+
74
+ # Blink each LED once while looking for input
75
+ while blinking :
76
+ if led_state :
77
+ if time .monotonic () > timestamp + LED_ON_DELAY_TIME :
78
+ led_state = False
79
+ led .value = led_state
80
+ led .deinit ()
81
+ blinking = False
82
+ timestamp = time .monotonic ()
83
+ else :
84
+ if time .monotonic () > timestamp + LED_OFF_DELAY_TIME :
85
+ led_state = True
86
+ led .value = led_state
87
+ timestamp = time .monotonic ()
88
+
89
+ # Look for user input
90
+ if supervisor .runtime .serial_bytes_available :
91
+ answer = input ()
92
+ if answer == 'y' :
93
+ return True
94
+ return False
88
95
89
96
def run_test (pins ):
90
97
@@ -107,18 +114,8 @@ def run_test(pins):
107
114
print (pin , end = ' ' )
108
115
print ('\n ' )
109
116
110
- # Create a list of IO objects for us to toggle
111
- leds = [digitalio .DigitalInOut (getattr (board , p )) for p in led_pins ]
112
-
113
- # Set all LEDs to output
114
- for led in leds :
115
- led .direction = digitalio .Direction .OUTPUT
116
-
117
117
# Blink LEDs and wait for user to verify test
118
- result = _toggle_wait (leds )
119
-
120
- # Release pins
121
- _deinit_pins (leds )
118
+ result = _toggle_wait (led_pins )
122
119
123
120
if result :
124
121
return PASS , led_pins
0 commit comments