Commit 265eed7b authored by Joel Collins's avatar Joel Collins
Browse files

Fixed picamera setup

parent 7458d278
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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))
+1 −1
Original line number Diff line number Diff line
@@ -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
+5 −5
Original line number Diff line number Diff line
@@ -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))
+10 −13
Original line number Diff line number Diff line
@@ -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:
            if stage_type in ("SangaBoard", "SangaStage"):
                self.stage = SangaStage(port=stage_port)
                except Exception as e:
                    logging.error(e)
                    logging.warning("No compatible stage hardware found.")

        ### Fallbacks
        if not self.camera:
@@ -180,6 +176,7 @@ class Microscope:
                # Read LST. Returns None if no LST is active
                lst_arr = self.camera.read_lens_shading_table()

                if lst_arr:
                    b64_string, dtype, shape = serialise_array_b64(lst_arr)

                    settings_current["camera"]["lens_shading_table"] = {