Skip to content

Commit af8fa2a

Browse files
authored
Merge pull request #32 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 42192bf + d488bbd commit af8fa2a

File tree

10 files changed

+355
-301
lines changed

10 files changed

+355
-301
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_pn532/adafruit_pn532.py

Lines changed: 162 additions & 147 deletions
Large diffs are not rendered by default.

adafruit_pn532/i2c.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
from adafruit_pn532.adafruit_pn532 import PN532, BusyError, _reset
4545

4646
# pylint: disable=bad-whitespace
47-
_I2C_ADDRESS = const(0x24)
47+
_I2C_ADDRESS = const(0x24)
48+
4849

4950
class PN532_I2C(PN532):
5051
"""Driver for the PN532 connected over I2C."""
52+
5153
def __init__(self, i2c, *, irq=None, reset=None, req=None, debug=False):
5254
"""Create an instance of the PN532 class using I2C. Note that PN532
5355
uses clock stretching. Optional IRQ pin (not used),
@@ -61,7 +63,7 @@ def __init__(self, i2c, *, irq=None, reset=None, req=None, debug=False):
6163
self._i2c = i2c_device.I2CDevice(i2c, _I2C_ADDRESS)
6264
super().__init__(debug=debug, reset=reset)
6365

64-
def _wakeup(self): # pylint: disable=no-self-use
66+
def _wakeup(self): # pylint: disable=no-self-use
6567
"""Send any special commands/data to wake up PN532"""
6668
if self._req:
6769
self._req.direction = Direction.OUTPUT
@@ -83,27 +85,26 @@ def _wait_ready(self, timeout=1):
8385
except OSError:
8486
self._wakeup()
8587
continue
86-
if status == b'\x01':
88+
if status == b"\x01":
8789
return True # No longer busy
88-
else:
89-
time.sleep(0.05) # lets ask again soon!
90+
time.sleep(0.05) # lets ask again soon!
9091
# Timed out!
9192
return False
9293

9394
def _read_data(self, count):
9495
"""Read a specified count of bytes from the PN532."""
9596
# Build a read request frame.
96-
frame = bytearray(count+1)
97+
frame = bytearray(count + 1)
9798
with self._i2c as i2c:
98-
i2c.readinto(frame, end=1) # read status byte!
99-
if frame[0] != 0x01: # not ready
99+
i2c.readinto(frame, end=1) # read status byte!
100+
if frame[0] != 0x01: # not ready
100101
raise BusyError
101-
i2c.readinto(frame) # ok get the data, plus statusbyte
102+
i2c.readinto(frame) # ok get the data, plus statusbyte
102103
if self.debug:
103104
print("Reading: ", [hex(i) for i in frame[1:]])
104105
else:
105106
time.sleep(0.1)
106-
return frame[1:] # don't return the status byte
107+
return frame[1:] # don't return the status byte
107108

108109
def _write_data(self, framebytes):
109110
"""Write a specified count of bytes to the PN532"""

adafruit_pn532/spi.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,28 @@
4343
from adafruit_pn532.adafruit_pn532 import PN532
4444

4545
# pylint: disable=bad-whitespace
46-
_SPI_STATREAD = const(0x02)
47-
_SPI_DATAWRITE = const(0x01)
48-
_SPI_DATAREAD = const(0x03)
49-
_SPI_READY = const(0x01)
46+
_SPI_STATREAD = const(0x02)
47+
_SPI_DATAWRITE = const(0x01)
48+
_SPI_DATAREAD = const(0x03)
49+
_SPI_READY = const(0x01)
50+
5051

5152
def reverse_bit(num):
5253
"""Turn an LSB byte to an MSB byte, and vice versa. Used for SPI as
5354
it is LSB for the PN532, but 99% of SPI implementations are MSB only!"""
5455
result = 0
5556
for _ in range(8):
5657
result <<= 1
57-
result += (num & 1)
58+
result += num & 1
5859
num >>= 1
5960
return result
6061

62+
6163
class PN532_SPI(PN532):
6264
"""Driver for the PN532 connected over SPI. Pass in a hardware or bitbang
6365
SPI device & chip select digitalInOut pin. Optional IRQ pin (not used),
6466
reset pin and debugging output."""
67+
6568
def __init__(self, spi, cs_pin, *, irq=None, reset=None, debug=False):
6669
"""Create an instance of the PN532 class using SPI"""
6770
self.debug = debug
@@ -73,7 +76,7 @@ def _wakeup(self):
7376
"""Send any special commands/data to wake up PN532"""
7477
with self._spi as spi:
7578
time.sleep(1)
76-
spi.write(bytearray([0x00])) #pylint: disable=no-member
79+
spi.write(bytearray([0x00])) # pylint: disable=no-member
7780
time.sleep(1)
7881

7982
def _wait_ready(self, timeout=1):
@@ -83,27 +86,28 @@ def _wait_ready(self, timeout=1):
8386
timestamp = time.monotonic()
8487
with self._spi as spi:
8588
while (time.monotonic() - timestamp) < timeout:
86-
time.sleep(0.02) # required
87-
spi.write_readinto(status_cmd, status_response) #pylint: disable=no-member
89+
time.sleep(0.02) # required
90+
spi.write_readinto(
91+
status_cmd, status_response
92+
) # pylint: disable=no-member
8893
if reverse_bit(status_response[1]) == 0x01: # LSB data is read in MSB
89-
return True # Not busy anymore!
90-
else:
91-
time.sleep(0.01) # pause a bit till we ask again
94+
return True # Not busy anymore!
95+
time.sleep(0.01) # pause a bit till we ask again
9296
# We timed out!
9397
return False
9498

9599
def _read_data(self, count):
96100
"""Read a specified count of bytes from the PN532."""
97101
# Build a read request frame.
98-
frame = bytearray(count+1)
102+
frame = bytearray(count + 1)
99103
# Add the SPI data read signal byte, but LSB'ify it
100104
frame[0] = reverse_bit(_SPI_DATAREAD)
101105

102106
with self._spi as spi:
103-
time.sleep(0.02) # required
104-
spi.write_readinto(frame, frame) #pylint: disable=no-member
107+
time.sleep(0.02) # required
108+
spi.write_readinto(frame, frame) # pylint: disable=no-member
105109
for i, val in enumerate(frame):
106-
frame[i] = reverse_bit(val) # turn LSB data to MSB
110+
frame[i] = reverse_bit(val) # turn LSB data to MSB
107111
if self.debug:
108112
print("Reading: ", [hex(i) for i in frame[1:]])
109113
return frame[1:]
@@ -116,5 +120,5 @@ def _write_data(self, framebytes):
116120
if self.debug:
117121
print("Writing: ", [hex(i) for i in rev_frame])
118122
with self._spi as spi:
119-
time.sleep(0.02) # required
120-
spi.write(bytes(rev_frame)) #pylint: disable=no-member
123+
time.sleep(0.02) # required
124+
spi.write(bytes(rev_frame)) # pylint: disable=no-member

adafruit_pn532/uart.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
import time
4242
from adafruit_pn532.adafruit_pn532 import PN532, BusyError
4343

44+
4445
class PN532_UART(PN532):
4546
"""Driver for the PN532 connected over Serial UART"""
47+
4648
def __init__(self, uart, *, irq=None, reset=None, debug=False):
4749
"""Create an instance of the PN532 class using Serial connection.
4850
Optional IRQ pin (not used), reset pin and debugging output.
@@ -54,7 +56,7 @@ def __init__(self, uart, *, irq=None, reset=None, debug=False):
5456

5557
def _wakeup(self):
5658
"""Send any special commands/data to wake up PN532"""
57-
#self._write_frame([_HOSTTOPN532, _COMMAND_SAMCONFIGURATION, 0x01])
59+
# self._write_frame([_HOSTTOPN532, _COMMAND_SAMCONFIGURATION, 0x01])
5860
self.SAM_configuration()
5961

6062
def _wait_ready(self, timeout=1):
@@ -75,7 +77,11 @@ def _read_data(self, count):
7577

7678
def _write_data(self, framebytes):
7779
"""Write a specified count of bytes to the PN532"""
78-
while self._uart.read(1): # this would be a lot nicer if we could query the # of bytes
80+
while self._uart.read(
81+
1
82+
): # this would be a lot nicer if we could query the # of bytes
7983
pass
80-
self._uart.write('\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') # wake up!
84+
self._uart.write(
85+
"\x55\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
86+
) # wake up!
8187
self._uart.write(framebytes)

0 commit comments

Comments
 (0)