Skip to content

Commit 712b223

Browse files
Merge pull request #29 from labthings/wait_param
Optional wait parameters on captures
2 parents c99b356 + 29ac1cf commit 712b223

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/labthings_picamera2/thing.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import tempfile
99
import time
1010
from tempfile import TemporaryDirectory
11-
import uuid
1211

1312
from pydantic import BaseModel, BeforeValidator, RootModel
1413

@@ -529,7 +528,7 @@ def snap_image(self) -> ArrayModel:
529528
def capture_array(
530529
self,
531530
stream_name: Literal["main", "lores", "raw"] = "main",
532-
wait: Optional[float] = None,
531+
wait: Optional[float] = 0.9,
533532
) -> ArrayModel:
534533
"""Acquire one image from the camera and return as an array
535534
@@ -538,7 +537,9 @@ def capture_array(
538537
binary image formats will be added in due course.
539538
540539
stream_name: (Optional) The PiCamera2 stream to use, should be one of ["main", "lores", "raw"]. Default = "main"
541-
wait: (Optional, float) Set a timeout in seconds. A TimeoutError is raised if this time is exceeded during capture. Default = None
540+
wait: (Optional, float) Set a timeout in seconds.
541+
A TimeoutError is raised if this time is exceeded during capture.
542+
Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
542543
"""
543544
with self.picamera() as cam:
544545
return cam.capture_array(stream_name, wait = wait)
@@ -549,19 +550,24 @@ def capture_raw(
549550
states_getter: GetThingStates,
550551
get_states: bool=True,
551552
get_processing_inputs: bool=True,
553+
wait: Optional[float] = 0.9,
552554
) -> RawImageModel:
553555
"""Capture a raw image
554556
555557
This function is intended to be as fast as possible, and will return
556558
as soon as an image has been captured. The output format is not intended
557559
to be useful, except as input to `raw_to_png`.
558-
560+
561+
wait: (Optional, float) Set a timeout in seconds.
562+
A TimeoutError is raised if this time is exceeded during capture.
563+
Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
564+
559565
When used via the HTTP interface, this function returns the data as a
560566
`Blob` object, meaning it can be passed to another action without
561567
transferring it over the network.
562568
"""
563569
with self.picamera() as cam:
564-
(buffer, ), parameters = cam.capture_buffers(["raw"])
570+
(buffer, ), parameters = cam.capture_buffers(["raw"], wait=wait)
565571
configuration = cam.camera_configuration()
566572
return RawImageModel(
567573
image_data = RawBlob.from_bytes(buffer.tobytes()),
@@ -703,6 +709,7 @@ def capture_jpeg(
703709
self,
704710
metadata_getter: GetThingStates,
705711
resolution: Literal["lores", "main", "full"] = "main",
712+
wait: Optional[float] = 0.9,
706713
) -> JPEGBlob:
707714
"""Acquire one image from the camera as a JPEG
708715
@@ -716,6 +723,10 @@ def capture_jpeg(
716723
MJPEG stream and reconfigure the camera to capture a full
717724
resolution image.
718725
726+
wait: (Optional, float) Set a timeout in seconds.
727+
A TimeoutError is raised if this time is exceeded during capture.
728+
Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
729+
719730
Note that this always uses the image processing pipeline - to
720731
bypass this, you must use a raw capture.
721732
"""
@@ -727,7 +738,7 @@ def capture_jpeg(
727738
# to reconfigure for these
728739
if resolution in ("lores", "main") and config[resolution]:
729740
with self.picamera() as cam:
730-
cam.capture_file(path, name=resolution, format="jpeg")
741+
cam.capture_file(path, name=resolution, format="jpeg", wait=wait)
731742
else:
732743
if resolution != "full":
733744
logging.warning(
@@ -738,7 +749,7 @@ def capture_jpeg(
738749
cam.configure(cam.create_still_configuration())
739750
cam.start()
740751
logging.info("capturing")
741-
cam.capture_file(path, name="main", format="jpeg")
752+
cam.capture_file(path, name="main", format="jpeg", wait=wait)
742753
logging.info("done")
743754
# After the file is written, add metadata about the current Things
744755
exif_dict = piexif.load(path)

0 commit comments

Comments
 (0)