Commit 0c5af968 authored by Joel Collins's avatar Joel Collins
Browse files

Added route for camera zoom

parent f70da25c
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ from openflexure_microscope.api.v1.views import MicroscopeView

from flask import Blueprint

from . import capture, record, preview, config, overlay
from . import capture, record, preview, config, function


def construct_blueprint(microscope_obj):
@@ -31,9 +31,13 @@ def construct_blueprint(microscope_obj):
        '/preview/<string:operation>', 
        view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj))

    # Overlay routes
    # Function routes
    blueprint.add_url_rule(
        '/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)
 No newline at end of file
+50 −0
Original line number Diff line number Diff line
@@ -3,6 +3,56 @@ from openflexure_microscope.api.utilities import JsonPayload

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):

    def get(self):