From 1c8f6caa72d97c7a868ac0a143d4901583f2342d Mon Sep 17 00:00:00 2001 From: dherrada Date: Sun, 15 Mar 2020 15:34:13 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_bluefruitspi.py | 126 +++++++++++++----------- docs/conf.py | 116 +++++++++++++--------- examples/bluefruitspi_neocolorpicker.py | 20 ++-- examples/bluefruitspi_ruggedechotest.py | 20 ++-- examples/bluefruitspi_simpletest.py | 8 +- setup.py | 52 +++++----- 7 files changed, 188 insertions(+), 156 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_bluefruitspi.py b/adafruit_bluefruitspi.py index 3f13ef5..aa96d85 100644 --- a/adafruit_bluefruitspi.py +++ b/adafruit_bluefruitspi.py @@ -52,37 +52,37 @@ from micropython import const # pylint: disable=bad-whitespace -_MSG_COMMAND = const(0x10) # Command message -_MSG_RESPONSE = const(0x20) # Response message -_MSG_ALERT = const(0x40) # Alert message -_MSG_ERROR = const(0x80) # Error message - -_SDEP_INITIALIZE = const(0xBEEF) # Resets the Bluefruit device -_SDEP_ATCOMMAND = const(0x0A00) # AT command wrapper -_SDEP_BLEUART_TX = const(0x0A01) # BLE UART transmit data -_SDEP_BLEUART_RX = const(0x0A02) # BLE UART read data - -_ARG_STRING = const(0x0100) # String data type -_ARG_BYTEARRAY = const(0x0200) # Byte array data type -_ARG_INT32 = const(0x0300) # Signed 32-bit integer data type -_ARG_UINT32 = const(0x0400) # Unsigned 32-bit integer data type -_ARG_INT16 = const(0x0500) # Signed 16-bit integer data type -_ARG_UINT16 = const(0x0600) # Unsigned 16-bit integer data type -_ARG_INT8 = const(0x0700) # Signed 8-bit integer data type -_ARG_UINT8 = const(0x0800) # Unsigned 8-bit integer data type - -_ERROR_INVALIDMSGTYPE = const(0x8021) # SDEP: Unexpected SDEP MsgType -_ERROR_INVALIDCMDID = const(0x8022) # SDEP: Unknown command ID -_ERROR_INVALIDPAYLOAD = const(0x8023) # SDEP: Payload problem -_ERROR_INVALIDLEN = const(0x8024) # SDEP: Indicated len too large -_ERROR_INVALIDINPUT = const(0x8060) # AT: Invalid data -_ERROR_UNKNOWNCMD = const(0x8061) # AT: Unknown command name -_ERROR_INVALIDPARAM = const(0x8062) # AT: Invalid param value -_ERROR_UNSUPPORTED = const(0x8063) # AT: Unsupported command +_MSG_COMMAND = const(0x10) # Command message +_MSG_RESPONSE = const(0x20) # Response message +_MSG_ALERT = const(0x40) # Alert message +_MSG_ERROR = const(0x80) # Error message + +_SDEP_INITIALIZE = const(0xBEEF) # Resets the Bluefruit device +_SDEP_ATCOMMAND = const(0x0A00) # AT command wrapper +_SDEP_BLEUART_TX = const(0x0A01) # BLE UART transmit data +_SDEP_BLEUART_RX = const(0x0A02) # BLE UART read data + +_ARG_STRING = const(0x0100) # String data type +_ARG_BYTEARRAY = const(0x0200) # Byte array data type +_ARG_INT32 = const(0x0300) # Signed 32-bit integer data type +_ARG_UINT32 = const(0x0400) # Unsigned 32-bit integer data type +_ARG_INT16 = const(0x0500) # Signed 16-bit integer data type +_ARG_UINT16 = const(0x0600) # Unsigned 16-bit integer data type +_ARG_INT8 = const(0x0700) # Signed 8-bit integer data type +_ARG_UINT8 = const(0x0800) # Unsigned 8-bit integer data type + +_ERROR_INVALIDMSGTYPE = const(0x8021) # SDEP: Unexpected SDEP MsgType +_ERROR_INVALIDCMDID = const(0x8022) # SDEP: Unknown command ID +_ERROR_INVALIDPAYLOAD = const(0x8023) # SDEP: Payload problem +_ERROR_INVALIDLEN = const(0x8024) # SDEP: Indicated len too large +_ERROR_INVALIDINPUT = const(0x8060) # AT: Invalid data +_ERROR_UNKNOWNCMD = const(0x8061) # AT: Unknown command name +_ERROR_INVALIDPARAM = const(0x8062) # AT: Invalid param value +_ERROR_UNSUPPORTED = const(0x8063) # AT: Unsupported command # For the Bluefruit Connect packets -_PACKET_BUTTON_LEN = const(5) -_PACKET_COLOR_LEN = const(6) +_PACKET_BUTTON_LEN = const(5) +_PACKET_COLOR_LEN = const(6) # pylint: enable=bad-whitespace @@ -90,7 +90,9 @@ class BluefruitSPI: """Helper for the Bluefruit LE SPI Friend""" - def __init__(self, spi, cs, irq, reset, debug=False): # pylint: disable=too-many-arguments + def __init__( + self, spi, cs, irq, reset, debug=False + ): # pylint: disable=too-many-arguments self._irq = irq self._buf_tx = bytearray(20) self._buf_rx = bytearray(20) @@ -114,8 +116,7 @@ def __init__(self, spi, cs, irq, reset, debug=False): # pylint: disable=too-many self._irq.direction = Direction.INPUT self._irq.pull = Pull.DOWN - self._spi_device = SPIDevice(spi, cs, - baudrate=4000000, phase=0, polarity=0) + self._spi_device = SPIDevice(spi, cs, baudrate=4000000, phase=0, polarity=0) def _cmd(self, cmd): # pylint: disable=too-many-branches """ @@ -129,9 +130,9 @@ def _cmd(self, cmd): # pylint: disable=too-many-branches if len(cmd) > 127: if self._debug: print("ERROR: Command too long.") - raise ValueError('Command too long.') + raise ValueError("Command too long.") - more = 0x80 # More bit is in pos 8, 1 = more data available + more = 0x80 # More bit is in pos 8, 1 = more data available pos = 0 while len(cmd) - pos: # Construct the SDEP packet @@ -142,9 +143,15 @@ def _cmd(self, cmd): # pylint: disable=too-many-branches if plen > 16: plen = 16 # Note the 'more' value in bit 8 of the packet len - struct.pack_into("BHB', self._buf_rx[0:4]) + msgtype, rspid, rsplen = struct.unpack(">BHB", self._buf_rx[0:4]) if rsplen >= 16: rsp += self._buf_rx[4:20] else: - rsp += self._buf_rx[4:rsplen+4] + rsp += self._buf_rx[4 : rsplen + 4] if self._debug: print("Reading: ", [hex(b) for b in self._buf_rx]) else: @@ -200,14 +207,13 @@ def init(self): This command should complete in under 1s. """ # Construct the SDEP packet - struct.pack_into("