Fixed picamera setup

This commit is contained in:
Joel Collins 2020-01-29 16:16:09 +00:00
parent 7458d278d8
commit 265eed7bfa
4 changed files with 18 additions and 21 deletions

View file

@ -21,8 +21,8 @@ def recalibrate(microscope):
"""
scamera = microscope.camera
with scamera.lock:
assert not scamera.status["record_active"], "Can't recalibrate while recording!"
streaming = scamera.status["stream_active"]
assert not scamera.record_active, "Can't recalibrate while recording!"
streaming = scamera.stream_active
if streaming:
logging.info("Stopping stream before recalibration")
scamera.stop_stream_recording(resolution=(640, 480))

View file

@ -53,7 +53,7 @@ class MoveStageAPI(View):
logging.warning("Unable to move. No stage found.")
# TODO: Make schema for microscope status
return jsonify(microscope.status["stage"]["position"])
return jsonify(microscope.state["stage"]["position"])
@ThingAction

View file

@ -333,13 +333,13 @@ class PiCameraStreamer(BaseCamera):
Change the camera zoom, handling re-centering and scaling.
"""
with self.lock:
self.status["zoom_value"] = float(zoom_value)
if self.status["zoom_value"] < 1:
self.status["zoom_value"] = 1
self.zoom_value = float(zoom_value)
if self.zoom_value < 1:
self.zoom_value = 1
# Richard's code for zooming !
fov = self.camera.zoom
centre = np.array([fov[0] + fov[2] / 2.0, fov[1] + fov[3] / 2.0])
size = 1.0 / self.status["zoom_value"]
size = 1.0 / self.zoom_value
# If the new zoom value would be invalid, move the centre to
# keep it within the camera's sensor (this is only relevant
# when zooming out, if the FoV is not centred on (0.5, 0.5)
@ -552,7 +552,7 @@ class PiCameraStreamer(BaseCamera):
if isinstance(output, CaptureObject):
target = output.file
else:
target = target
target = output
with self.lock:
logging.info("Capturing to {}".format(output))

View file

@ -76,7 +76,7 @@ class Microscope:
### Detector
if configuration.get("camera"):
camera_type = configuration["camera"].get("type")
if camera_type == "PiCamera" or camera_type == "PiCameraStreamer":
if camera_type in ("PiCamera", "PiCameraStreamer"):
try:
self.camera = PiCameraStreamer()
except Exception as e:
@ -87,12 +87,8 @@ class Microscope:
if configuration.get("stage"):
stage_type = configuration["stage"].get("type")
stage_port = configuration["stage"].get("port")
if stage_type == "SangaBoard" or camera_type == "SangaStage":
try:
self.stage = SangaStage(port=stage_port)
except Exception as e:
logging.error(e)
logging.warning("No compatible stage hardware found.")
if stage_type in ("SangaBoard", "SangaStage"):
self.stage = SangaStage(port=stage_port)
### Fallbacks
if not self.camera:
@ -180,13 +176,14 @@ class Microscope:
# Read LST. Returns None if no LST is active
lst_arr = self.camera.read_lens_shading_table()
b64_string, dtype, shape = serialise_array_b64(lst_arr)
if lst_arr:
b64_string, dtype, shape = serialise_array_b64(lst_arr)
settings_current["camera"]["lens_shading_table"] = {
"b64_string": b64_string,
"dtype": dtype,
"shape": shape,
}
settings_current["camera"]["lens_shading_table"] = {
"b64_string": b64_string,
"dtype": dtype,
"shape": shape,
}
# If attached to a stage
if self.stage: