Skip to content

Commit

Permalink
Run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tekktrik committed May 11, 2023
1 parent 612957e commit 809b5dd
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 27 deletions.
4 changes: 1 addition & 3 deletions adafruit_boardtest/boardtest_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
FAIL = "FAIL"
NA = "N/A"


# Determine if given value is a number
def _is_number(val: Any) -> bool:
try:
Expand All @@ -64,7 +65,6 @@ def _deinit_pins(gpios: Sequence[digitalio.DigitalInOut]) -> None:

# Toggle IO pins while waiting for answer
def _toggle_wait(gpios: Sequence[digitalio.DigitalInOut]) -> bool:

timestamp = time.monotonic()
led_state = False
print("Are the pins listed above toggling? [y/n]")
Expand All @@ -85,7 +85,6 @@ def _toggle_wait(gpios: Sequence[digitalio.DigitalInOut]) -> bool:


def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:

"""
Toggles all available GPIO on and off repeatedly.
Expand All @@ -102,7 +101,6 @@ def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:
# Toggle LEDs if we find any
gpio_pins = analog_pins + digital_pins
if gpio_pins:

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

Expand Down
7 changes: 1 addition & 6 deletions adafruit_boardtest/boardtest_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
FAIL = "FAIL"
NA = "N/A"


# Open comms to I2C EEPROM by trying a write to memory address
def _eeprom_i2c_wait(
i2c: busio.I2C, i2c_addr: int, mem_addr: int, timeout: float = 1.0
) -> bool:

# Try to access the I2C EEPROM (it becomes unresonsive during a write)
timestamp = time.monotonic()
while time.monotonic() < timestamp + timeout:
Expand All @@ -76,7 +76,6 @@ def _eeprom_i2c_wait(
def _eeprom_i2c_write_byte(
i2c: busio.I2C, i2c_addr: int, mem_addr: int, mem_data: int
) -> bool:

# Make sure address is only one byte:
if mem_addr > 255:
return False
Expand All @@ -98,7 +97,6 @@ def _eeprom_i2c_write_byte(
def _eeprom_i2c_read_byte(
i2c: busio.I2C, i2c_addr: int, mem_addr: int, timeout: float = 1.0
) -> Tuple[bool, bytearray]:

# Make sure address is only one byte:
if mem_addr > 255:
return False, bytearray()
Expand All @@ -117,7 +115,6 @@ def _eeprom_i2c_read_byte(
def run_test(
pins: Sequence[str], sda_pin: str = SDA_PIN_NAME, scl_pin: str = SCL_PIN_NAME
) -> Tuple[str, List[str]]:

"""
Performs random writes and reads to I2C EEPROM.
Expand All @@ -129,7 +126,6 @@ def run_test(

# Write values to I2C EEPROM and verify the values match
if list(set(pins).intersection(set([sda_pin, scl_pin]))):

# Tell user to connect EEPROM chip
print(
"Connect a Microchip AT24HC04B EEPROM I2C chip. "
Expand All @@ -147,7 +143,6 @@ def run_test(
# Pick a random address, write to it, read from it, and see if they match
pass_test = True
for _ in range(NUM_I2C_TESTS):

# Randomly pick an address and a data value (one byte)
mem_addr = random.randint(0, EEPROM_I2C_MAX_ADDR)
mem_data = random.randint(0, 255)
Expand Down
4 changes: 1 addition & 3 deletions adafruit_boardtest/boardtest_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
FAIL = "FAIL"
NA = "N/A"


# Toggle IO pins while waiting for answer
def _toggle_wait(led_pins: Sequence[str]) -> bool:
timestamp = time.monotonic()
led_state = False
print("Are the pins listed above toggling? [y/n]")
while True:

# Cycle through each pin in the list
for pin in led_pins:
led = digitalio.DigitalInOut(getattr(board, pin))
Expand Down Expand Up @@ -83,7 +83,6 @@ def _toggle_wait(led_pins: Sequence[str]) -> bool:


def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:

"""
Toggles the onboard LED(s) on and off.
Expand All @@ -96,7 +95,6 @@ def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:

# Toggle LEDs if we find any
if led_pins:

# Print out the LEDs found
print("LEDs found:", end=" ")
for pin in led_pins:
Expand Down
2 changes: 0 additions & 2 deletions adafruit_boardtest/boardtest_sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def run_test( # pylint: disable=too-many-arguments,too-many-locals
cs_pin: str = CS_PIN_NAME,
filename: str = FILENAME,
) -> Tuple[str, List[str]]:

"""
Performs random writes and reads to file on attached SD card.
Expand All @@ -85,7 +84,6 @@ def run_test( # pylint: disable=too-many-arguments,too-many-locals

# Write characters to file on SD card and verify they were written
if list(set(pins).intersection(set([mosi_pin, miso_pin, sck_pin]))):

# Tell user to connect SD card
print("Insert SD card into holder and connect SPI lines to holder.")
print("Connect " + cs_pin + " to the CS (DAT3) pin on the SD " + "card holder.")
Expand Down
2 changes: 0 additions & 2 deletions adafruit_boardtest/boardtest_sd_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
def run_test(
pins: Sequence[str], cd_pin: str = SD_CD_PIN_NAME
) -> Tuple[str, List[str]]:

"""
Checks status of CD pin as user inserts and removes SD card.
Expand All @@ -60,7 +59,6 @@ def run_test(

# Ask user to insert and remove SD card
if list(set(pins).intersection(set([cd_pin]))):

# Configure CD pin as input with pullup
cdt = digitalio.DigitalInOut(getattr(board, cd_pin))
cdt.direction = digitalio.Direction.INPUT
Expand Down
8 changes: 1 addition & 7 deletions adafruit_boardtest/boardtest_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@
FAIL = "FAIL"
NA = "N/A"


# Wait for WIP bit to go low
def _eeprom_spi_wait(
spi: busio.SPI, csel: digitalio.DigitalInOut, timeout: float = 1.0
) -> bool:

# Continually read from STATUS register
timestamp = time.monotonic()
while time.monotonic() < timestamp + timeout:

# Perfrom RDSR operation
csel.value = False
result = bytearray(1)
Expand All @@ -99,7 +98,6 @@ def _eeprom_spi_write_byte(
data: int,
timeout: float = 1.0,
) -> bool:

# Make sure address is only one byte:
if address > 255:
return False
Expand Down Expand Up @@ -129,7 +127,6 @@ def _eeprom_spi_write_byte(
def _eeprom_spi_read_byte(
spi: busio.SPI, csel: digitalio.DigitalInOut, address: int, timeout: float = 1.0
) -> Tuple[bool, bytearray]:

# Make sure address is only one byte:
if address > 255:
return False, bytearray()
Expand All @@ -155,7 +152,6 @@ def run_test(
sck_pin: str = SCK_PIN_NAME,
cs_pin: str = CS_PIN_NAME,
) -> Tuple[str, List[str]]:

"""
Performs random writes and reads to file on attached SD card.
Expand All @@ -169,7 +165,6 @@ def run_test(

# Write values to SPI EEPROM and verify the values match
if list(set(pins).intersection(set([mosi_pin, miso_pin, sck_pin]))):

# Tell user to connect EEPROM chip
print("Connect a Microchip 25AA040A EEPROM SPI chip.")
print("Connect " + cs_pin + " to the CS pin on the 25AA040.")
Expand All @@ -196,7 +191,6 @@ def run_test(
# Pick a random address, write to it, read from it, and see if they match
pass_test = True
for _ in range(NUM_SPI_TESTS):

# Randomly pick an address and a data value (one byte)
mem_addr = random.randint(0, EEPROM_SPI_MAX_ADDR)
mem_data = random.randint(0, 255)
Expand Down
2 changes: 0 additions & 2 deletions adafruit_boardtest/boardtest_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def run_test(
rx_pin: str = RX_PIN_NAME,
baud_rate: int = BAUD_RATE,
) -> Tuple[str, List[str]]:

"""
Performs random writes out of TX pin and reads on RX.
Expand All @@ -70,7 +69,6 @@ def run_test(

# Echo some values over the UART
if list(set(pins).intersection(set([tx_pin, rx_pin]))):

# Tell user to create loopback connection
print("Connect a wire from TX to RX. Press enter to continue.")
input()
Expand Down
2 changes: 0 additions & 2 deletions adafruit_boardtest/boardtest_voltage_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@


def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:

"""
Prints out voltage on the battery monitor or voltage monitor pin.
Expand All @@ -64,7 +63,6 @@ def run_test(pins: Sequence[str]) -> Tuple[str, List[str]]:

# Print out voltage found on these pins
if monitor_pins:

# Print out the monitor pins found
print("Voltage monitor pins found:", end=" ")
for pin in monitor_pins:
Expand Down

0 comments on commit 809b5dd

Please sign in to comment.