Skip to content

Updated LED and UART test #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions adafruit_boardtest/boardtest_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,47 @@
# Constants
LED_ON_DELAY_TIME = 0.2 # Seconds
LED_OFF_DELAY_TIME = 0.2 # Seconds
LED_PIN_NAMES = ['L', 'LED', 'RED_LED', 'GREEN_LED', 'BLUE_LED']
LED_PIN_NAMES = ['L', 'LED', 'RED_LED', 'YELLOW_LED', 'GREEN_LED', 'BLUE_LED']

# Test result strings
PASS = "PASS"
FAIL = "FAIL"
NA = "N/A"

# Release pins
def _deinit_pins(gpios):
for g in gpios:
g.deinit()

# Toggle IO pins while waiting for answer
def _toggle_wait(gpios):

def _toggle_wait(led_pins):
timestamp = time.monotonic()
led_state = False
print("Are the pins listed above toggling? [y/n]")
while True:
if led_state:
if time.monotonic() > timestamp + LED_ON_DELAY_TIME:
led_state = False
timestamp = time.monotonic()
else:
if time.monotonic() > timestamp + LED_OFF_DELAY_TIME:
led_state = True
timestamp = time.monotonic()
for gpio in gpios:
gpio.value = led_state
if supervisor.runtime.serial_bytes_available:
answer = input()
if answer == 'y':
return True
return False

# Cycle through each pin in the list
for pin in led_pins:
led = digitalio.DigitalInOut(getattr(board, pin))
led.direction = digitalio.Direction.OUTPUT
blinking = True

# Blink each LED once while looking for input
while blinking:
if led_state:
if time.monotonic() > timestamp + LED_ON_DELAY_TIME:
led_state = False
led.value = led_state
led.deinit()
blinking = False
timestamp = time.monotonic()
else:
if time.monotonic() > timestamp + LED_OFF_DELAY_TIME:
led_state = True
led.value = led_state
timestamp = time.monotonic()

# Look for user input
if supervisor.runtime.serial_bytes_available:
answer = input()
if answer == 'y':
return True
return False

def run_test(pins):

Expand All @@ -107,18 +114,8 @@ def run_test(pins):
print(pin, end=' ')
print('\n')

# Create a list of IO objects for us to toggle
leds = [digitalio.DigitalInOut(getattr(board, p)) for p in led_pins]

# Set all LEDs to output
for led in leds:
led.direction = digitalio.Direction.OUTPUT

# Blink LEDs and wait for user to verify test
result = _toggle_wait(leds)

# Release pins
_deinit_pins(leds)
result = _toggle_wait(led_pins)

if result:
return PASS, led_pins
Expand Down
2 changes: 1 addition & 1 deletion adafruit_boardtest/boardtest_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def run_test(pins, tx_pin=TX_PIN_NAME, rx_pin=RX_PIN_NAME, baud_rate=BAUD_RATE):
test_str += chr(random.randint(ASCII_MIN, ASCII_MAX))

# Transmit test string
uart.write(test_str)
uart.write(bytearray(test_str))
print("Transmitting:\t" + test_str)

# Wait for received string
Expand Down