Skip to content

Ran black, updated to pylint 2.x #13

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 1 commit into from
Mar 16, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ spelling-store-unknown-words=no
[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
notes=FIXME,XXX


[TYPECHECK]
Expand Down
139 changes: 80 additions & 59 deletions adafruit_vc0706.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,50 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VC0706.git"

# pylint: disable=bad-whitespace
_SERIAL = const(0x00)
_RESET = const(0x26)
_GEN_VERSION = const(0x11)
_SET_PORT = const(0x24)
_READ_FBUF = const(0x32)
_GET_FBUF_LEN = const(0x34)
_FBUF_CTRL = const(0x36)
_DOWNSIZE_CTRL = const(0x54)
_DOWNSIZE_STATUS = const(0x55)
_READ_DATA = const(0x30)
_WRITE_DATA = const(0x31)
_COMM_MOTION_CTRL = const(0x37)
_COMM_MOTION_STATUS = const(0x38)
_SERIAL = const(0x00)
_RESET = const(0x26)
_GEN_VERSION = const(0x11)
_SET_PORT = const(0x24)
_READ_FBUF = const(0x32)
_GET_FBUF_LEN = const(0x34)
_FBUF_CTRL = const(0x36)
_DOWNSIZE_CTRL = const(0x54)
_DOWNSIZE_STATUS = const(0x55)
_READ_DATA = const(0x30)
_WRITE_DATA = const(0x31)
_COMM_MOTION_CTRL = const(0x37)
_COMM_MOTION_STATUS = const(0x38)
_COMM_MOTION_DETECTED = const(0x39)
_MOTION_CTRL = const(0x42)
_MOTION_STATUS = const(0x43)
_TVOUT_CTRL = const(0x44)
_OSD_ADD_CHAR = const(0x45)
_MOTION_CTRL = const(0x42)
_MOTION_STATUS = const(0x43)
_TVOUT_CTRL = const(0x44)
_OSD_ADD_CHAR = const(0x45)

_STOPCURRENTFRAME = const(0x0)
_STOPNEXTFRAME = const(0x1)
_RESUMEFRAME = const(0x3)
_STEPFRAME = const(0x2)
_STOPCURRENTFRAME = const(0x0)
_STOPNEXTFRAME = const(0x1)
_RESUMEFRAME = const(0x3)
_STEPFRAME = const(0x2)

# pylint doesn't like the lowercase x but it makes it more readable.
# pylint: disable=invalid-name
IMAGE_SIZE_640x480 = const(0x00)
IMAGE_SIZE_320x240 = const(0x11)
IMAGE_SIZE_160x120 = const(0x22)
IMAGE_SIZE_640x480 = const(0x00)
IMAGE_SIZE_320x240 = const(0x11)
IMAGE_SIZE_160x120 = const(0x22)
# pylint: enable=invalid-name
_BAUDRATE_9600 = const(0xAEC8)
_BAUDRATE_19200 = const(0x56E4)
_BAUDRATE_38400 = const(0x2AF2)
_BAUDRATE_57600 = const(0x1C1C)
_BAUDRATE_115200 = const(0x0DA6)
_BAUDRATE_9600 = const(0xAEC8)
_BAUDRATE_19200 = const(0x56E4)
_BAUDRATE_38400 = const(0x2AF2)
_BAUDRATE_57600 = const(0x1C1C)
_BAUDRATE_115200 = const(0x0DA6)

_MOTIONCONTROL = const(0x0)
_UARTMOTION = const(0x01)
_ACTIVATEMOTION = const(0x01)
_MOTIONCONTROL = const(0x0)
_UARTMOTION = const(0x01)
_ACTIVATEMOTION = const(0x01)

__SET_ZOOM = const(0x52)
__GET_ZOOM = const(0x53)
__SET_ZOOM = const(0x52)
__GET_ZOOM = const(0x53)

_CAMERA_DELAY = const(10)
_CAMERA_DELAY = const(10)
# pylint: enable=bad-whitespace


Expand All @@ -100,26 +100,27 @@ class VC0706:
:param ~busio.UART uart: uart serial or compatible interface
:param int buffer_size: Receive buffer size
"""

def __init__(self, uart, *, buffer_size=100):
self._uart = uart
self._buffer = bytearray(buffer_size)
self._frame_ptr = 0
self._command_header = bytearray(3)
for _ in range(2): # 2 retries to reset then check resetted baudrate
for _ in range(2): # 2 retries to reset then check resetted baudrate
for baud in (9600, 19200, 38400, 57600, 115200):
self._uart.baudrate = baud
if self._run_command(_RESET, b'\x00', 5):
if self._run_command(_RESET, b"\x00", 5):
break
else: # for:else rocks! http://book.pythontips.com/en/latest/for_-_else.html
raise RuntimeError('Failed to get response from VC0706, check wiring!')
else: # for:else rocks! http://book.pythontips.com/en/latest/for_-_else.html
raise RuntimeError("Failed to get response from VC0706, check wiring!")

@property
def version(self):
"""Return camera version byte string."""
# Clear buffer to ensure the end of a string can be found.
self._send_command(_GEN_VERSION, b'\x01')
self._send_command(_GEN_VERSION, b"\x01")
readlen = self._read_response(self._buffer, len(self._buffer))
return str(self._buffer[:readlen], 'ascii')
return str(self._buffer[:readlen], "ascii")

@property
def baudrate(self):
Expand All @@ -142,7 +143,7 @@ def baudrate(self, baud):
divider = _BAUDRATE_115200
else:
raise ValueError("Unsupported baud rate")
args = [0x03, 0x01, (divider>>8) & 0xFF, divider & 0xFF]
args = [0x03, 0x01, (divider >> 8) & 0xFF, divider & 0xFF]
self._run_command(_SET_PORT, bytes(args), 7)
self._uart.baudrate = baud

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

@image_size.setter
Expand All @@ -163,15 +162,19 @@ def image_size(self, size):
IMAGE_SIZE_160x120.
"""
if size not in (IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, IMAGE_SIZE_160x120):
raise ValueError("Size must be one of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or "
"IMAGE_SIZE_160x120!")
return self._run_command(_WRITE_DATA, bytes([0x05, 0x04, 0x01, 0x00, 0x19, size & 0xFF]), 5)
raise ValueError(
"Size must be one of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or "
"IMAGE_SIZE_160x120!"
)
return self._run_command(
_WRITE_DATA, bytes([0x05, 0x04, 0x01, 0x00, 0x19, size & 0xFF]), 5
)

@property
def frame_length(self):
"""Return the length in bytes of the currently capture frame/picture.
"""
if not self._run_command(_GET_FBUF_LEN, b'\x01\x00', 9):
if not self._run_command(_GET_FBUF_LEN, b"\x01\x00", 9):
return 0
frame_length = self._buffer[5]
frame_length <<= 8
Expand All @@ -195,16 +198,30 @@ def read_picture_into(self, buf):
less. Suggested buffer size is 32.
"""
n = len(buf)
if n > 256 or n > (len(self._buffer)-5):
raise ValueError('Buffer is too large!')
if n > 256 or n > (len(self._buffer) - 5):
raise ValueError("Buffer is too large!")
if n % 4 != 0:
raise ValueError('Buffer must be a multiple of 4! Try 32.')
args = bytes([0x0C, 0x0, 0x0A, 0, 0, (self._frame_ptr >> 8) & 0xFF,
self._frame_ptr & 0xFF, 0, 0, 0, n & 0xFF,
(_CAMERA_DELAY >> 8) & 0xFF, _CAMERA_DELAY & 0xFF])
raise ValueError("Buffer must be a multiple of 4! Try 32.")
args = bytes(
[
0x0C,
0x0,
0x0A,
0,
0,
(self._frame_ptr >> 8) & 0xFF,
self._frame_ptr & 0xFF,
0,
0,
0,
n & 0xFF,
(_CAMERA_DELAY >> 8) & 0xFF,
_CAMERA_DELAY & 0xFF,
]
)
if not self._run_command(_READ_FBUF, args, 5, flush=False):
return 0
if self._read_response(self._buffer, n+5) == 0:
if self._read_response(self._buffer, n + 5) == 0:
return 0
self._frame_ptr += n
for i in range(n):
Expand All @@ -225,8 +242,12 @@ def _read_response(self, result, numbytes):
return self._uart.readinto(memoryview(result)[0:numbytes])

def _verify_response(self, cmd):
return (self._buffer[0] == 0x76 and self._buffer[1] == _SERIAL and
self._buffer[2] == cmd & 0xFF and self._buffer[3] == 0x00)
return (
self._buffer[0] == 0x76
and self._buffer[1] == _SERIAL
and self._buffer[2] == cmd & 0xFF
and self._buffer[3] == 0x00
)

def _send_command(self, cmd, args=None):
self._command_header[0] = 0x56
Expand Down
Loading