Skip to content

Commit d68291b

Browse files
authored
Merge pull request #13 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 7983218 + 3f7c7b0 commit d68291b

File tree

7 files changed

+204
-168
lines changed

7 files changed

+204
-168
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

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123+
notes=FIXME,XXX
123124

124125

125126
[TYPECHECK]

adafruit_vc0706.py

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,50 @@
4848
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VC0706.git"
4949

5050
# pylint: disable=bad-whitespace
51-
_SERIAL = const(0x00)
52-
_RESET = const(0x26)
53-
_GEN_VERSION = const(0x11)
54-
_SET_PORT = const(0x24)
55-
_READ_FBUF = const(0x32)
56-
_GET_FBUF_LEN = const(0x34)
57-
_FBUF_CTRL = const(0x36)
58-
_DOWNSIZE_CTRL = const(0x54)
59-
_DOWNSIZE_STATUS = const(0x55)
60-
_READ_DATA = const(0x30)
61-
_WRITE_DATA = const(0x31)
62-
_COMM_MOTION_CTRL = const(0x37)
63-
_COMM_MOTION_STATUS = const(0x38)
51+
_SERIAL = const(0x00)
52+
_RESET = const(0x26)
53+
_GEN_VERSION = const(0x11)
54+
_SET_PORT = const(0x24)
55+
_READ_FBUF = const(0x32)
56+
_GET_FBUF_LEN = const(0x34)
57+
_FBUF_CTRL = const(0x36)
58+
_DOWNSIZE_CTRL = const(0x54)
59+
_DOWNSIZE_STATUS = const(0x55)
60+
_READ_DATA = const(0x30)
61+
_WRITE_DATA = const(0x31)
62+
_COMM_MOTION_CTRL = const(0x37)
63+
_COMM_MOTION_STATUS = const(0x38)
6464
_COMM_MOTION_DETECTED = const(0x39)
65-
_MOTION_CTRL = const(0x42)
66-
_MOTION_STATUS = const(0x43)
67-
_TVOUT_CTRL = const(0x44)
68-
_OSD_ADD_CHAR = const(0x45)
65+
_MOTION_CTRL = const(0x42)
66+
_MOTION_STATUS = const(0x43)
67+
_TVOUT_CTRL = const(0x44)
68+
_OSD_ADD_CHAR = const(0x45)
6969

70-
_STOPCURRENTFRAME = const(0x0)
71-
_STOPNEXTFRAME = const(0x1)
72-
_RESUMEFRAME = const(0x3)
73-
_STEPFRAME = const(0x2)
70+
_STOPCURRENTFRAME = const(0x0)
71+
_STOPNEXTFRAME = const(0x1)
72+
_RESUMEFRAME = const(0x3)
73+
_STEPFRAME = const(0x2)
7474

7575
# pylint doesn't like the lowercase x but it makes it more readable.
7676
# pylint: disable=invalid-name
77-
IMAGE_SIZE_640x480 = const(0x00)
78-
IMAGE_SIZE_320x240 = const(0x11)
79-
IMAGE_SIZE_160x120 = const(0x22)
77+
IMAGE_SIZE_640x480 = const(0x00)
78+
IMAGE_SIZE_320x240 = const(0x11)
79+
IMAGE_SIZE_160x120 = const(0x22)
8080
# pylint: enable=invalid-name
81-
_BAUDRATE_9600 = const(0xAEC8)
82-
_BAUDRATE_19200 = const(0x56E4)
83-
_BAUDRATE_38400 = const(0x2AF2)
84-
_BAUDRATE_57600 = const(0x1C1C)
85-
_BAUDRATE_115200 = const(0x0DA6)
81+
_BAUDRATE_9600 = const(0xAEC8)
82+
_BAUDRATE_19200 = const(0x56E4)
83+
_BAUDRATE_38400 = const(0x2AF2)
84+
_BAUDRATE_57600 = const(0x1C1C)
85+
_BAUDRATE_115200 = const(0x0DA6)
8686

87-
_MOTIONCONTROL = const(0x0)
88-
_UARTMOTION = const(0x01)
89-
_ACTIVATEMOTION = const(0x01)
87+
_MOTIONCONTROL = const(0x0)
88+
_UARTMOTION = const(0x01)
89+
_ACTIVATEMOTION = const(0x01)
9090

91-
__SET_ZOOM = const(0x52)
92-
__GET_ZOOM = const(0x53)
91+
__SET_ZOOM = const(0x52)
92+
__GET_ZOOM = const(0x53)
9393

94-
_CAMERA_DELAY = const(10)
94+
_CAMERA_DELAY = const(10)
9595
# pylint: enable=bad-whitespace
9696

9797

@@ -100,26 +100,27 @@ class VC0706:
100100
:param ~busio.UART uart: uart serial or compatible interface
101101
:param int buffer_size: Receive buffer size
102102
"""
103+
103104
def __init__(self, uart, *, buffer_size=100):
104105
self._uart = uart
105106
self._buffer = bytearray(buffer_size)
106107
self._frame_ptr = 0
107108
self._command_header = bytearray(3)
108-
for _ in range(2): # 2 retries to reset then check resetted baudrate
109+
for _ in range(2): # 2 retries to reset then check resetted baudrate
109110
for baud in (9600, 19200, 38400, 57600, 115200):
110111
self._uart.baudrate = baud
111-
if self._run_command(_RESET, b'\x00', 5):
112+
if self._run_command(_RESET, b"\x00", 5):
112113
break
113-
else: # for:else rocks! http://book.pythontips.com/en/latest/for_-_else.html
114-
raise RuntimeError('Failed to get response from VC0706, check wiring!')
114+
else: # for:else rocks! http://book.pythontips.com/en/latest/for_-_else.html
115+
raise RuntimeError("Failed to get response from VC0706, check wiring!")
115116

116117
@property
117118
def version(self):
118119
"""Return camera version byte string."""
119120
# Clear buffer to ensure the end of a string can be found.
120-
self._send_command(_GEN_VERSION, b'\x01')
121+
self._send_command(_GEN_VERSION, b"\x01")
121122
readlen = self._read_response(self._buffer, len(self._buffer))
122-
return str(self._buffer[:readlen], 'ascii')
123+
return str(self._buffer[:readlen], "ascii")
123124

124125
@property
125126
def baudrate(self):
@@ -142,7 +143,7 @@ def baudrate(self, baud):
142143
divider = _BAUDRATE_115200
143144
else:
144145
raise ValueError("Unsupported baud rate")
145-
args = [0x03, 0x01, (divider>>8) & 0xFF, divider & 0xFF]
146+
args = [0x03, 0x01, (divider >> 8) & 0xFF, divider & 0xFF]
146147
self._run_command(_SET_PORT, bytes(args), 7)
147148
self._uart.baudrate = baud
148149

@@ -151,10 +152,8 @@ def image_size(self):
151152
"""Get the current image size, will return a value of IMAGE_SIZE_640x480,
152153
IMAGE_SIZE_320x240, or IMAGE_SIZE_160x120.
153154
"""
154-
if not self._run_command(_READ_DATA,
155-
b'\0x04\x04\x01\x00\x19',
156-
6):
157-
raise RuntimeError('Failed to read image size!')
155+
if not self._run_command(_READ_DATA, b"\0x04\x04\x01\x00\x19", 6):
156+
raise RuntimeError("Failed to read image size!")
158157
return self._buffer[5]
159158

160159
@image_size.setter
@@ -163,15 +162,19 @@ def image_size(self, size):
163162
IMAGE_SIZE_160x120.
164163
"""
165164
if size not in (IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, IMAGE_SIZE_160x120):
166-
raise ValueError("Size must be one of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or "
167-
"IMAGE_SIZE_160x120!")
168-
return self._run_command(_WRITE_DATA, bytes([0x05, 0x04, 0x01, 0x00, 0x19, size & 0xFF]), 5)
165+
raise ValueError(
166+
"Size must be one of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or "
167+
"IMAGE_SIZE_160x120!"
168+
)
169+
return self._run_command(
170+
_WRITE_DATA, bytes([0x05, 0x04, 0x01, 0x00, 0x19, size & 0xFF]), 5
171+
)
169172

170173
@property
171174
def frame_length(self):
172175
"""Return the length in bytes of the currently capture frame/picture.
173176
"""
174-
if not self._run_command(_GET_FBUF_LEN, b'\x01\x00', 9):
177+
if not self._run_command(_GET_FBUF_LEN, b"\x01\x00", 9):
175178
return 0
176179
frame_length = self._buffer[5]
177180
frame_length <<= 8
@@ -195,16 +198,30 @@ def read_picture_into(self, buf):
195198
less. Suggested buffer size is 32.
196199
"""
197200
n = len(buf)
198-
if n > 256 or n > (len(self._buffer)-5):
199-
raise ValueError('Buffer is too large!')
201+
if n > 256 or n > (len(self._buffer) - 5):
202+
raise ValueError("Buffer is too large!")
200203
if n % 4 != 0:
201-
raise ValueError('Buffer must be a multiple of 4! Try 32.')
202-
args = bytes([0x0C, 0x0, 0x0A, 0, 0, (self._frame_ptr >> 8) & 0xFF,
203-
self._frame_ptr & 0xFF, 0, 0, 0, n & 0xFF,
204-
(_CAMERA_DELAY >> 8) & 0xFF, _CAMERA_DELAY & 0xFF])
204+
raise ValueError("Buffer must be a multiple of 4! Try 32.")
205+
args = bytes(
206+
[
207+
0x0C,
208+
0x0,
209+
0x0A,
210+
0,
211+
0,
212+
(self._frame_ptr >> 8) & 0xFF,
213+
self._frame_ptr & 0xFF,
214+
0,
215+
0,
216+
0,
217+
n & 0xFF,
218+
(_CAMERA_DELAY >> 8) & 0xFF,
219+
_CAMERA_DELAY & 0xFF,
220+
]
221+
)
205222
if not self._run_command(_READ_FBUF, args, 5, flush=False):
206223
return 0
207-
if self._read_response(self._buffer, n+5) == 0:
224+
if self._read_response(self._buffer, n + 5) == 0:
208225
return 0
209226
self._frame_ptr += n
210227
for i in range(n):
@@ -225,8 +242,12 @@ def _read_response(self, result, numbytes):
225242
return self._uart.readinto(memoryview(result)[0:numbytes])
226243

227244
def _verify_response(self, cmd):
228-
return (self._buffer[0] == 0x76 and self._buffer[1] == _SERIAL and
229-
self._buffer[2] == cmd & 0xFF and self._buffer[3] == 0x00)
245+
return (
246+
self._buffer[0] == 0x76
247+
and self._buffer[1] == _SERIAL
248+
and self._buffer[2] == cmd & 0xFF
249+
and self._buffer[3] == 0x00
250+
)
230251

231252
def _send_command(self, cmd, args=None):
232253
self._command_header[0] = 0x56

0 commit comments

Comments
 (0)