Loading openflexure_microscope/api/v2/views/actions/camera.py +18 −10 Original line number Diff line number Diff line Loading @@ -25,13 +25,19 @@ class CaptureAPI(Resource): @use_args( { "filename": fields.String(), "temporary": fields.Boolean(missing=False), "filename": fields.String(example="MyFileName"), "temporary": fields.Boolean( missing=False, description="Delete capture on shutdown" ), "use_video_port": fields.Boolean(missing=False), "bayer": fields.Boolean(missing=False), "metadata": fields.Dict(missing={}), "tags": fields.List(fields.String, missing=[]), "resize": fields.Dict(missing=None), # TODO: Validate keys "bayer": fields.Boolean( missing=False, description="Store raw bayer data in file" ), "metadata": fields.Dict(missing={}, example={"Client": "SwaggerUI"}), "tags": fields.List(fields.String, missing=[], example=["docs"]), "resize": fields.Dict( missing=None, example={"width": 640, "height": 480} ), # TODO: Validate keys } ) @marshal_with(capture_schema) Loading Loading @@ -85,6 +91,9 @@ class GPUPreviewStartAPI(Resource): """ def post(self): """ Start the onboard GPU preview. """ microscope = find_device("openflexure_microscope") payload = JsonResponse(request) Loading @@ -104,11 +113,10 @@ class GPUPreviewStartAPI(Resource): class GPUPreviewStopAPI(Resource): def post(self): """ Start the onboard GPU preview. Stop the onboard GPU preview. """ def post(self): microscope = find_device("openflexure_microscope") microscope.camera.stop_preview() return jsonify(microscope.state) openflexure_microscope/api/v2/views/actions/stage.py +26 −17 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import JsonResponse from openflexure_microscope.common.flask_labthings.resource import Resource from openflexure_microscope.common.flask_labthings.find import find_device from openflexure_microscope.common.flask_labthings.decorators import ( use_args, marshal_with, doc, ) from openflexure_microscope.common.flask_labthings import fields from openflexure_microscope.utilities import axes_to_array, filter_dict from flask import Blueprint, jsonify, request Loading @@ -9,21 +16,23 @@ import logging class MoveStageAPI(Resource): @use_args( { "absolute": fields.Boolean(default=False, example=False), "x": fields.Int(default=0, example=100), "y": fields.Int(default=0, example=100), "z": fields.Int(default=0, example=20), } ) def post(self, args): """ Handle stage movements. Move the microscope stage in x, y, z """ def post(self): microscope = find_device("openflexure_microscope") # Create response object payload = JsonResponse(request) logging.debug(payload.json) # Handle absolute positioning (calculate a relative move from current position and target) if (payload.param("absolute") is True) and ( microscope.stage ): # Only if stage exists target_position = axes_to_array(payload.json, ["x", "y", "z"]) if (args.get("absolute")) and (microscope.stage): # Only if stage exists target_position = axes_to_array(args, ["x", "y", "z"]) logging.debug("TARGET: {}".format(target_position)) position = [ target_position[i] - microscope.stage.position[i] for i in range(3) Loading @@ -32,7 +41,7 @@ class MoveStageAPI(Resource): else: # Get coordinates from payload position = axes_to_array(payload.json, ["x", "y", "z"], [0, 0, 0]) position = axes_to_array(args, ["x", "y", "z"], [0, 0, 0]) logging.debug(position) Loading @@ -48,11 +57,11 @@ class MoveStageAPI(Resource): class ZeroStageAPI(Resource): def post(self): """ Zero stage coordinates Zero the stage coordinates. Does not move the stage, but rather makes the current position read as [0, 0, 0] """ def post(self): microscope = find_device("openflexure_microscope") microscope.stage.zero_position() Loading Loading
openflexure_microscope/api/v2/views/actions/camera.py +18 −10 Original line number Diff line number Diff line Loading @@ -25,13 +25,19 @@ class CaptureAPI(Resource): @use_args( { "filename": fields.String(), "temporary": fields.Boolean(missing=False), "filename": fields.String(example="MyFileName"), "temporary": fields.Boolean( missing=False, description="Delete capture on shutdown" ), "use_video_port": fields.Boolean(missing=False), "bayer": fields.Boolean(missing=False), "metadata": fields.Dict(missing={}), "tags": fields.List(fields.String, missing=[]), "resize": fields.Dict(missing=None), # TODO: Validate keys "bayer": fields.Boolean( missing=False, description="Store raw bayer data in file" ), "metadata": fields.Dict(missing={}, example={"Client": "SwaggerUI"}), "tags": fields.List(fields.String, missing=[], example=["docs"]), "resize": fields.Dict( missing=None, example={"width": 640, "height": 480} ), # TODO: Validate keys } ) @marshal_with(capture_schema) Loading Loading @@ -85,6 +91,9 @@ class GPUPreviewStartAPI(Resource): """ def post(self): """ Start the onboard GPU preview. """ microscope = find_device("openflexure_microscope") payload = JsonResponse(request) Loading @@ -104,11 +113,10 @@ class GPUPreviewStartAPI(Resource): class GPUPreviewStopAPI(Resource): def post(self): """ Start the onboard GPU preview. Stop the onboard GPU preview. """ def post(self): microscope = find_device("openflexure_microscope") microscope.camera.stop_preview() return jsonify(microscope.state)
openflexure_microscope/api/v2/views/actions/stage.py +26 −17 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import JsonResponse from openflexure_microscope.common.flask_labthings.resource import Resource from openflexure_microscope.common.flask_labthings.find import find_device from openflexure_microscope.common.flask_labthings.decorators import ( use_args, marshal_with, doc, ) from openflexure_microscope.common.flask_labthings import fields from openflexure_microscope.utilities import axes_to_array, filter_dict from flask import Blueprint, jsonify, request Loading @@ -9,21 +16,23 @@ import logging class MoveStageAPI(Resource): @use_args( { "absolute": fields.Boolean(default=False, example=False), "x": fields.Int(default=0, example=100), "y": fields.Int(default=0, example=100), "z": fields.Int(default=0, example=20), } ) def post(self, args): """ Handle stage movements. Move the microscope stage in x, y, z """ def post(self): microscope = find_device("openflexure_microscope") # Create response object payload = JsonResponse(request) logging.debug(payload.json) # Handle absolute positioning (calculate a relative move from current position and target) if (payload.param("absolute") is True) and ( microscope.stage ): # Only if stage exists target_position = axes_to_array(payload.json, ["x", "y", "z"]) if (args.get("absolute")) and (microscope.stage): # Only if stage exists target_position = axes_to_array(args, ["x", "y", "z"]) logging.debug("TARGET: {}".format(target_position)) position = [ target_position[i] - microscope.stage.position[i] for i in range(3) Loading @@ -32,7 +41,7 @@ class MoveStageAPI(Resource): else: # Get coordinates from payload position = axes_to_array(payload.json, ["x", "y", "z"], [0, 0, 0]) position = axes_to_array(args, ["x", "y", "z"], [0, 0, 0]) logging.debug(position) Loading @@ -48,11 +57,11 @@ class MoveStageAPI(Resource): class ZeroStageAPI(Resource): def post(self): """ Zero stage coordinates Zero the stage coordinates. Does not move the stage, but rather makes the current position read as [0, 0, 0] """ def post(self): microscope = find_device("openflexure_microscope") microscope.stage.zero_position() Loading