diff --git a/openflexure_microscope/api/utilities.py b/openflexure_microscope/api/utilities.py index 88dff82a..90262048 100644 --- a/openflexure_microscope/api/utilities.py +++ b/openflexure_microscope/api/utilities.py @@ -9,9 +9,16 @@ class JsonPayload: """ # Try to load as json self.json = request.get_json() #: dict: Dictionary representation of request JSON + + if self.json is None: + self.json = {} + # Store raw response data self.data = request.get_data() #: str: String representation of request data + if self.data is None: + self.data = "" + def param(self, key, default=None, convert=None): """ Check if a key exists in a JSON/dictionary payload, and returns it. diff --git a/openflexure_microscope/api/v1/blueprints/camera/__init__.py b/openflexure_microscope/api/v1/blueprints/camera/__init__.py index c367c97c..27eb9a51 100644 --- a/openflexure_microscope/api/v1/blueprints/camera/__init__.py +++ b/openflexure_microscope/api/v1/blueprints/camera/__init__.py @@ -2,7 +2,7 @@ from openflexure_microscope.api.v1.views import MicroscopeView from flask import Blueprint -from . import capture, record, preview +from . import capture, record, preview, config def construct_blueprint(microscope_obj): @@ -31,4 +31,9 @@ def construct_blueprint(microscope_obj): '/preview/', view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj)) + # Config routes + blueprint.add_url_rule( + '/config', + view_func=config.ConfigAPI.as_view('camera_config', microscope=microscope_obj)) + return(blueprint) \ No newline at end of file diff --git a/openflexure_microscope/api/v1/blueprints/camera/config.py b/openflexure_microscope/api/v1/blueprints/camera/config.py new file mode 100644 index 00000000..c2ba7d18 --- /dev/null +++ b/openflexure_microscope/api/v1/blueprints/camera/config.py @@ -0,0 +1,73 @@ +from openflexure_microscope.api.utilities import JsonPayload +from openflexure_microscope.api.v1.views import MicroscopeView + +from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file + +import logging + + +class ConfigAPI(MicroscopeView): + + def get(self): + """ + Get camera configuration + + .. :quickref: Camera config; Get camera configuration + """ + + return jsonify(self.microscope.camera.config) + + def post(self): + """ + Modify camera configuration + + .. :quickref: Camera config; Set camera configuration + + **Example request**: + + .. sourcecode:: http + + POST /camera/capture HTTP/1.1 + Accept: application/json + + { + "analog_gain": 1.0, + "digital_gain": 1.0, + "jpeg_quality": 75, + "picamera_params": { + "framerate": 24.0, + "saturation": 0, + "shutter_speed": 5000 + } + } + + :>header Accept: application/json + + :