Improved documentation

This commit is contained in:
Joel Collins 2020-01-07 15:04:47 +00:00
parent a2bb1a1a38
commit ed13749abe
2 changed files with 44 additions and 27 deletions

View file

@ -25,13 +25,19 @@ class CaptureAPI(Resource):
@use_args( @use_args(
{ {
"filename": fields.String(), "filename": fields.String(example="MyFileName"),
"temporary": fields.Boolean(missing=False), "temporary": fields.Boolean(
missing=False, description="Delete capture on shutdown"
),
"use_video_port": fields.Boolean(missing=False), "use_video_port": fields.Boolean(missing=False),
"bayer": fields.Boolean(missing=False), "bayer": fields.Boolean(
"metadata": fields.Dict(missing={}), missing=False, description="Store raw bayer data in file"
"tags": fields.List(fields.String, missing=[]), ),
"resize": fields.Dict(missing=None), # TODO: Validate keys "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) @marshal_with(capture_schema)
@ -85,6 +91,9 @@ class GPUPreviewStartAPI(Resource):
""" """
def post(self): def post(self):
"""
Start the onboard GPU preview.
"""
microscope = find_device("openflexure_microscope") microscope = find_device("openflexure_microscope")
payload = JsonResponse(request) payload = JsonResponse(request)
@ -104,11 +113,10 @@ class GPUPreviewStartAPI(Resource):
class GPUPreviewStopAPI(Resource): class GPUPreviewStopAPI(Resource):
"""
Start the onboard GPU preview.
"""
def post(self): def post(self):
"""
Stop the onboard GPU preview.
"""
microscope = find_device("openflexure_microscope") microscope = find_device("openflexure_microscope")
microscope.camera.stop_preview() microscope.camera.stop_preview()
return jsonify(microscope.state) return jsonify(microscope.state)

View file

@ -1,6 +1,13 @@
from openflexure_microscope.api.utilities import JsonResponse from openflexure_microscope.api.utilities import JsonResponse
from openflexure_microscope.common.flask_labthings.resource import Resource 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.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 openflexure_microscope.utilities import axes_to_array, filter_dict
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
@ -9,21 +16,23 @@ import logging
class MoveStageAPI(Resource): class MoveStageAPI(Resource):
""" @use_args(
Handle stage movements. {
""" "absolute": fields.Boolean(default=False, example=False),
"x": fields.Int(default=0, example=100),
def post(self): "y": fields.Int(default=0, example=100),
"z": fields.Int(default=0, example=20),
}
)
def post(self, args):
"""
Move the microscope stage in x, y, z
"""
microscope = find_device("openflexure_microscope") 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) # Handle absolute positioning (calculate a relative move from current position and target)
if (payload.param("absolute") is True) and ( if (args.get("absolute")) and (microscope.stage): # Only if stage exists
microscope.stage target_position = axes_to_array(args, ["x", "y", "z"])
): # Only if stage exists
target_position = axes_to_array(payload.json, ["x", "y", "z"])
logging.debug("TARGET: {}".format(target_position)) logging.debug("TARGET: {}".format(target_position))
position = [ position = [
target_position[i] - microscope.stage.position[i] for i in range(3) target_position[i] - microscope.stage.position[i] for i in range(3)
@ -32,7 +41,7 @@ class MoveStageAPI(Resource):
else: else:
# Get coordinates from payload # 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) logging.debug(position)
@ -48,11 +57,11 @@ class MoveStageAPI(Resource):
class ZeroStageAPI(Resource): class ZeroStageAPI(Resource):
"""
Zero stage coordinates
"""
def post(self): def post(self):
"""
Zero the stage coordinates.
Does not move the stage, but rather makes the current position read as [0, 0, 0]
"""
microscope = find_device("openflexure_microscope") microscope = find_device("openflexure_microscope")
microscope.stage.zero_position() microscope.stage.zero_position()