Added route for camera zoom

This commit is contained in:
Joel Collins 2019-01-16 11:50:05 +00:00
parent f70da25c1c
commit 0c5af96890
2 changed files with 57 additions and 3 deletions

View file

@ -2,7 +2,7 @@ from openflexure_microscope.api.v1.views import MicroscopeView
from flask import Blueprint from flask import Blueprint
from . import capture, record, preview, config, overlay from . import capture, record, preview, config, function
def construct_blueprint(microscope_obj): def construct_blueprint(microscope_obj):
@ -31,9 +31,13 @@ def construct_blueprint(microscope_obj):
'/preview/<string:operation>', '/preview/<string:operation>',
view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj)) view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj))
# Overlay routes # Function routes
blueprint.add_url_rule( blueprint.add_url_rule(
'/overlay', '/overlay',
view_func=overlay.OverlayAPI.as_view('overlay', microscope=microscope_obj)) view_func=function.OverlayAPI.as_view('overlay', microscope=microscope_obj))
blueprint.add_url_rule(
'/zoom',
view_func=function.ZoomAPI.as_view('zoom', microscope=microscope_obj))
return(blueprint) return(blueprint)

View file

@ -3,6 +3,56 @@ from openflexure_microscope.api.utilities import JsonPayload
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
import logging
class ZoomAPI(MicroscopeView):
def get(self):
"""
Get the current zoom value
.. :quickref: Zoom; Get the zoom value
:>header Accept: application/json
:<header Content-Type: application/json
:status 200: preview started/stopped
"""
zoom_value = self.microscope.camera.state['zoom_value']
return jsonify({'zoom_value': zoom_value})
def post(self):
"""
Change the current zoom value
.. :quickref: Zoom; Set the zoom value
**Example requests**:
.. sourcecode:: http
POST /camera/zoom HTTP/1.1
Accept: application/json
{
"zoom_value": 2.5,
}
:>header Accept: application/json
:<header Content-Type: application/json
:status 200: preview started/stopped
"""
payload = JsonPayload(request)
zoom_value = payload.param('zoom_value', default=1.0, convert=float)
self.microscope.camera.set_zoom(zoom_value)
return jsonify(self.microscope.state)
class OverlayAPI(MicroscopeView): class OverlayAPI(MicroscopeView):
def get(self): def get(self):