Skip to content
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
12 changes: 12 additions & 0 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,18 @@ def start_(self):
if self.started:
return
controls = self.controls.get_libcamera_controls()

# The latest libcamera requires is to set "ExposureTimeMode" to manual if we are setting
# a fixed value, or to "auto" if we're going back to auto mode.
exposure_time = controls.get(libcamera.controls.ExposureTime, None)
if exposure_time is not None:
controls[libcamera.controls.ExposureTimeMode] = 0 if exposure_time == 0 else 1

# Ditto for the analogue gain.
analogue_gain = controls.get(libcamera.controls.AnalogueGain, None)
if analogue_gain is not None:
controls[libcamera.controls.AnalogueGainMode] = 0 if analogue_gain == 0 else 1

self.controls = Controls(self)
# camera.start() now throws an error if it fails.
self.camera.start(controls)
Expand Down
25 changes: 25 additions & 0 deletions tests/aegc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ def test_control_auto(control):
test_control_fixed("AnalogueGain", 1.5)
test_control_fixed("AnalogueGain", 3.0)
test_control_auto("AnalogueGain")


# Also test that it works when we start the camera.

def test_control_start(control, value):
controls = {control: value}
config = picam2.create_preview_configuration(controls=controls)
picam2.start(config)

# The very first frame should have the given values.
metadata = picam2.capture_metadata()
picam2.stop()
check = metadata[control]
print(f"Camera started with {control} {check}")

if abs(value - check) > 0.05 * value:
print(f"ERROR: request {control} of {value} but got {check}")


picam2.stop()

test_control_start("ExposureTime", 12345)
test_control_start("ExposureTime", 23456)
test_control_start("AnalogueGain", 1.5)
test_control_start("AnalogueGain", 3.0)