diff --git a/openflexure_microscope/api/v1/blueprints/base.py b/openflexure_microscope/api/v1/blueprints/base.py index cf14617c..5e71aa4f 100644 --- a/openflexure_microscope/api/v1/blueprints/base.py +++ b/openflexure_microscope/api/v1/blueprints/base.py @@ -1,7 +1,7 @@ -from openflexure_microscope.api.utilities import gen +from openflexure_microscope.api.utilities import gen, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView -from flask import Response, Blueprint, jsonify +from flask import Response, Blueprint, jsonify, request class StreamAPI(MicroscopeView): @@ -81,7 +81,7 @@ class ConfigAPI(MicroscopeView): """ JSON representation of the microscope config. - .. :quickref: Config; Microscope config + .. :quickref: Config; Get microscope config **Example request**: @@ -138,6 +138,44 @@ class ConfigAPI(MicroscopeView): """ return jsonify(self.microscope.config) + def post(self): + """ + Modify microscope configuration + + .. :quickref: Config; Set microscope config + + **Example request**: + + .. sourcecode:: http + + POST /config 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 + + :
', 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 deleted file mode 100644 index c2ba7d18..00000000 --- a/openflexure_microscope/api/v1/blueprints/camera/config.py +++ /dev/null @@ -1,73 +0,0 @@ -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 - - : None: + # If attached to a camera + if self.camera: + # Update camera config + self.camera.config = config + + # Cache config + self._config.update(config) \ No newline at end of file