Skip to content

Commit af27d51

Browse files
authored
Merge pull request #17 from Andon-A/resume_video
Added resume_video()
2 parents 3cd51f0 + 4dc77fb commit af27d51

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

adafruit_vc0706.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595

9696
class VC0706:
9797
"""Driver for VC0706 serial TTL camera module.
98-
:param ~busio.UART uart: uart serial or compatible interface
99-
:param int buffer_size: Receive buffer size
98+
:param ~busio.UART uart: uart serial or compatible interface
99+
:param int buffer_size: Receive buffer size
100100
"""
101101

102102
def __init__(self, uart, *, buffer_size=100):
@@ -148,7 +148,7 @@ def baudrate(self, baud):
148148
@property
149149
def image_size(self):
150150
"""Get the current image size, will return a value of IMAGE_SIZE_640x480,
151-
IMAGE_SIZE_320x240, or IMAGE_SIZE_160x120.
151+
IMAGE_SIZE_320x240, or IMAGE_SIZE_160x120.
152152
"""
153153
if not self._run_command(_READ_DATA, b"\0x04\x04\x01\x00\x19", 6):
154154
raise RuntimeError("Failed to read image size!")
@@ -157,7 +157,7 @@ def image_size(self):
157157
@image_size.setter
158158
def image_size(self, size):
159159
"""Set the image size to a value of IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, or
160-
IMAGE_SIZE_160x120.
160+
IMAGE_SIZE_160x120.
161161
"""
162162
if size not in (IMAGE_SIZE_640x480, IMAGE_SIZE_320x240, IMAGE_SIZE_160x120):
163163
raise ValueError(
@@ -170,8 +170,7 @@ def image_size(self, size):
170170

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

186185
def take_picture(self):
187-
"""Tell the camera to take a picture. Returns True if successful.
188-
"""
186+
"""Tell the camera to take a picture. Returns True if successful."""
189187
self._frame_ptr = 0
190188
return self._run_command(_FBUF_CTRL, bytes([0x1, _STOPCURRENTFRAME]), 5)
191189

190+
def resume_video(self):
191+
"""Tell the camera to resume being a camera after the video has stopped
192+
(Such as what happens when a picture is taken).
193+
"""
194+
return self._run_command(_FBUF_CTRL, bytes([0x1, _RESUMEFRAME]), 5)
195+
192196
def read_picture_into(self, buf):
193197
"""Read the next bytes of frame/picture data into the provided buffer.
194198
Returns the number of bytes written to the buffer (might be less than

examples/vc0706_snapshot_filesystem.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
# You MUST keep the buffer size under 100!
6464
print("Writing image: {}".format(IMAGE_FILE), end="", flush=True)
6565
stamp = time.monotonic()
66+
# Pylint doesn't like the wcount variable being lowercase, but uppercase makes less sense
67+
# pylint: disable=invalid-name
6668
with open(IMAGE_FILE, "wb") as outfile:
6769
wcount = 0
6870
while frame_length > 0:
@@ -84,4 +86,7 @@
8486
print(".", end="", flush=True)
8587
wcount = 0
8688
print()
89+
# pylint: enable=invalid-name
8790
print("Finished in %0.1f seconds!" % (time.monotonic() - stamp))
91+
# Turn the camera back into video mode.
92+
vc0706.resume_video()

examples/vc0706_snapshot_simpletest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
storage.mount(vfs, "/sd")
3434

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

@@ -72,6 +72,8 @@
7272
# This will write 50 bytes at a time using a small buffer.
7373
# You MUST keep the buffer size under 100!
7474
print("Writing image: {}".format(IMAGE_FILE), end="")
75+
stamp = time.monotonic()
76+
# pylint: disable=invalid-name
7577
with open(IMAGE_FILE, "wb") as outfile:
7678
wcount = 0
7779
while frame_length > 0:
@@ -91,5 +93,8 @@
9193
if wcount >= 64:
9294
print(".", end="")
9395
wcount = 0
96+
# pylint: enable=invalid-name
9497
print()
95-
print("Finished!")
98+
print("Finished in %0.1f seconds!" % (time.monotonic() - stamp))
99+
# Turn the camera back into video mode.
100+
vc0706.resume_video()

0 commit comments

Comments
 (0)