Skip to content

Added resume_video() #17

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 3 commits into from
Sep 13, 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
20 changes: 12 additions & 8 deletions adafruit_vc0706.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@

class VC0706:
"""Driver for VC0706 serial TTL camera module.
:param ~busio.UART uart: uart serial or compatible interface
:param int buffer_size: Receive buffer size
:param ~busio.UART uart: uart serial or compatible interface
:param int buffer_size: Receive buffer size
"""

def __init__(self, uart, *, buffer_size=100):
Expand Down Expand Up @@ -148,7 +148,7 @@ def baudrate(self, baud):
@property
def image_size(self):
"""Get the current image size, will return a value of IMAGE_SIZE_640x480,
IMAGE_SIZE_320x240, or IMAGE_SIZE_160x120.
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!")
Expand All @@ -157,7 +157,7 @@ def image_size(self):
@image_size.setter
def image_size(self, size):
"""Set the image size to a value of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or
IMAGE_SIZE_160x120.
IMAGE_SIZE_160x120.
"""
if size not in (IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, IMAGE_SIZE_160x120):
raise ValueError(
Expand All @@ -170,8 +170,7 @@ def image_size(self, size):

@property
def frame_length(self):
"""Return the length in bytes of the currently capture frame/picture.
"""
"""Return the length in bytes of the currently capture frame/picture."""
if not self._run_command(_GET_FBUF_LEN, b"\x01\x00", 9):
return 0
frame_length = self._buffer[5]
Expand All @@ -184,11 +183,16 @@ def frame_length(self):
return frame_length

def take_picture(self):
"""Tell the camera to take a picture. Returns True if successful.
"""
"""Tell the camera to take a picture. Returns True if successful."""
self._frame_ptr = 0
return self._run_command(_FBUF_CTRL, bytes([0x1, _STOPCURRENTFRAME]), 5)

def resume_video(self):
"""Tell the camera to resume being a camera after the video has stopped
(Such as what happens when a picture is taken).
"""
return self._run_command(_FBUF_CTRL, bytes([0x1, _RESUMEFRAME]), 5)

def read_picture_into(self, buf):
"""Read the next bytes of frame/picture data into the provided buffer.
Returns the number of bytes written to the buffer (might be less than
Expand Down
5 changes: 5 additions & 0 deletions examples/vc0706_snapshot_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# You MUST keep the buffer size under 100!
print("Writing image: {}".format(IMAGE_FILE), end="", flush=True)
stamp = time.monotonic()
# Pylint doesn't like the wcount variable being lowercase, but uppercase makes less sense
# pylint: disable=invalid-name
with open(IMAGE_FILE, "wb") as outfile:
wcount = 0
while frame_length > 0:
Expand All @@ -84,4 +86,7 @@
print(".", end="", flush=True)
wcount = 0
print()
# pylint: enable=invalid-name
print("Finished in %0.1f seconds!" % (time.monotonic() - stamp))
# Turn the camera back into video mode.
vc0706.resume_video()
9 changes: 7 additions & 2 deletions examples/vc0706_snapshot_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
storage.mount(vfs, "/sd")

# Create a serial connection for the VC0706 connection, speed is auto-detected.
uart = busio.UART(board.TX, board.RX, timeout=250)
uart = busio.UART(board.TX, board.RX)
# Setup VC0706 camera
vc0706 = adafruit_vc0706.VC0706(uart)

Expand Down Expand Up @@ -72,6 +72,8 @@
# This will write 50 bytes at a time using a small buffer.
# You MUST keep the buffer size under 100!
print("Writing image: {}".format(IMAGE_FILE), end="")
stamp = time.monotonic()
# pylint: disable=invalid-name
with open(IMAGE_FILE, "wb") as outfile:
wcount = 0
while frame_length > 0:
Expand All @@ -91,5 +93,8 @@
if wcount >= 64:
print(".", end="")
wcount = 0
# pylint: enable=invalid-name
print()
print("Finished!")
print("Finished in %0.1f seconds!" % (time.monotonic() - stamp))
# Turn the camera back into video mode.
vc0706.resume_video()