Divide up tuning file modification from camera actions for recalibration.

* Ensure that funtions only called locally by recalibrate utils are private
* Move public API to the top of the recalibrate utils file
* Move files that only alter the tuning dictionary to their own file

This makes the recalibration API used by PiCamera much more clearly defined, which
helps to plan out how to allow for different models.
This commit is contained in:
Julian Stirling 2025-09-17 21:18:48 +01:00
parent 5566125e6e
commit c16a0391df
4 changed files with 238 additions and 233 deletions

View file

@ -8,20 +8,17 @@ from picamera2 import Picamera2
from openflexure_microscope_server.things.camera import (
picamera_recalibrate_utils as recalibrate_utils,
)
from openflexure_microscope_server.things.camera import (
picamera_tuning_file_utils as tf_utils,
)
MODEL = Picamera2.global_camera_info()[0]["Model"]
def load_default_tuning():
"""Return the default tuning file for the connected camera."""
fname = f"{MODEL}.json"
return Picamera2.load_tuning_file(fname)
def generate_bad_tuning():
"""Return a tuning file with an invalid version number to force an error when loaded."""
default_tuning = load_default_tuning()
default_tuning = tf_utils.load_default_tuning()
bad_tuning = default_tuning.copy()
bad_tuning["version"] = 999
return bad_tuning
@ -58,7 +55,7 @@ def _test_bad_tuning_after_good_tuning(configure: bool = False):
PiCamera2 behaviour does not expect the tuning file to be reloaded.
"""
bad_tuning = generate_bad_tuning()
default_tuning = load_default_tuning()
default_tuning = tf_utils.load_default_tuning()
print_tuning()
print("opening camera with default tuning")
with Picamera2(tuning=default_tuning) as cam: