Loading openflexure_microscope/api/v1/blueprints/base.py +1 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,7 @@ class ConfigAPI(MicroscopeView): return jsonify(self.microscope.config) def construct_blueprint(microscope_obj): blueprint = Blueprint('base_blueprint', __name__) Loading openflexure_microscope/api/v1/blueprints/stage.py +2 −69 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import gen, axes_to_array, JsonPayload from openflexure_microscope.api.utilities import gen, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from openflexure_microscope.utilities import axes_to_array from flask import Response, Blueprint, jsonify, request Loading Loading @@ -80,69 +81,6 @@ class PositionAPI(MicroscopeView): return jsonify(self.microscope.state['stage']['position']) class StageParamsAPI(MicroscopeView): def get(self): """ Return current parameters of the stage. .. :quickref: Stage params; Get current stage parameters **Example request**: .. sourcecode:: http GET /stage/params HTTP/1.1 Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: application/json { "backlash": { "x": 0, "y": 0, "z": 128 }, } """ return jsonify(self.microscope.state['stage']) def post(self): """ Set parameters of the stage. .. :quickref: Stage params; Set current stage parameters :reqheader Accept: application/json :<json json backlash: - **x** *(int)*: x-axis backlash in steps - **y** *(int)*: y-axis backlash in steps - **z** *(int)*: x-axis backlash in steps """ # Get payload payload = JsonPayload(request) logging.debug(payload.json) # BACKLASH if payload.param('backlash'): # Construct backlash array backlash = axes_to_array(payload.param('backlash'), ['x', 'y', 'z'], [0, 0, 0]) logging.debug("BACKLASH: {}".format(backlash)) # Apply backlash self.microscope.stage.backlash = backlash return jsonify(self.microscope.state['stage']) def construct_blueprint(microscope_obj): blueprint = Blueprint('stage_blueprint', __name__) Loading @@ -152,9 +90,4 @@ def construct_blueprint(microscope_obj): view_func=PositionAPI.as_view('position', microscope=microscope_obj) ) blueprint.add_url_rule( '/params', view_func=StageParamsAPI.as_view('stage_params', microscope=microscope_obj) ) return(blueprint) openflexure_microscope/microscope.py +16 −7 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from .camera.pi import StreamingCamera from .plugins import PluginMount from .config import load_config, save_config, convert_config from .utilities import axes_to_array class Microscope(object): Loading Loading @@ -141,13 +142,6 @@ class Microscope(object): 'z': position[2], } backlash = self.stage.backlash.tolist() state['stage']['backlash'] = { 'x': backlash[0], 'y': backlash[1], 'z': backlash[2], } # Add camera state state['camera'] = self.camera.state Loading @@ -160,6 +154,14 @@ class Microscope(object): # Update camera config params from StreamingCamera object self._config.update(self.camera.config) # If attached to a stage backlash = self.stage.backlash.tolist() self._config['backlash'] = { 'x': backlash[0], 'y': backlash[1], 'z': backlash[2], } return self._config @config.setter Loading @@ -169,5 +171,12 @@ class Microscope(object): # Update camera config self.camera.config = config # If attached to a stage if self.stage: if 'backlash' in config: # Construct backlash array backlash = axes_to_array(config['backlash'], ['x', 'y', 'z'], [0, 0, 0]) self.stage.backlash = backlash # Cache config self._config.update(config) No newline at end of file Loading
openflexure_microscope/api/v1/blueprints/base.py +1 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,7 @@ class ConfigAPI(MicroscopeView): return jsonify(self.microscope.config) def construct_blueprint(microscope_obj): blueprint = Blueprint('base_blueprint', __name__) Loading
openflexure_microscope/api/v1/blueprints/stage.py +2 −69 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import gen, axes_to_array, JsonPayload from openflexure_microscope.api.utilities import gen, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from openflexure_microscope.utilities import axes_to_array from flask import Response, Blueprint, jsonify, request Loading Loading @@ -80,69 +81,6 @@ class PositionAPI(MicroscopeView): return jsonify(self.microscope.state['stage']['position']) class StageParamsAPI(MicroscopeView): def get(self): """ Return current parameters of the stage. .. :quickref: Stage params; Get current stage parameters **Example request**: .. sourcecode:: http GET /stage/params HTTP/1.1 Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Vary: Accept Content-Type: application/json { "backlash": { "x": 0, "y": 0, "z": 128 }, } """ return jsonify(self.microscope.state['stage']) def post(self): """ Set parameters of the stage. .. :quickref: Stage params; Set current stage parameters :reqheader Accept: application/json :<json json backlash: - **x** *(int)*: x-axis backlash in steps - **y** *(int)*: y-axis backlash in steps - **z** *(int)*: x-axis backlash in steps """ # Get payload payload = JsonPayload(request) logging.debug(payload.json) # BACKLASH if payload.param('backlash'): # Construct backlash array backlash = axes_to_array(payload.param('backlash'), ['x', 'y', 'z'], [0, 0, 0]) logging.debug("BACKLASH: {}".format(backlash)) # Apply backlash self.microscope.stage.backlash = backlash return jsonify(self.microscope.state['stage']) def construct_blueprint(microscope_obj): blueprint = Blueprint('stage_blueprint', __name__) Loading @@ -152,9 +90,4 @@ def construct_blueprint(microscope_obj): view_func=PositionAPI.as_view('position', microscope=microscope_obj) ) blueprint.add_url_rule( '/params', view_func=StageParamsAPI.as_view('stage_params', microscope=microscope_obj) ) return(blueprint)
openflexure_microscope/microscope.py +16 −7 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from .camera.pi import StreamingCamera from .plugins import PluginMount from .config import load_config, save_config, convert_config from .utilities import axes_to_array class Microscope(object): Loading Loading @@ -141,13 +142,6 @@ class Microscope(object): 'z': position[2], } backlash = self.stage.backlash.tolist() state['stage']['backlash'] = { 'x': backlash[0], 'y': backlash[1], 'z': backlash[2], } # Add camera state state['camera'] = self.camera.state Loading @@ -160,6 +154,14 @@ class Microscope(object): # Update camera config params from StreamingCamera object self._config.update(self.camera.config) # If attached to a stage backlash = self.stage.backlash.tolist() self._config['backlash'] = { 'x': backlash[0], 'y': backlash[1], 'z': backlash[2], } return self._config @config.setter Loading @@ -169,5 +171,12 @@ class Microscope(object): # Update camera config self.camera.config = config # If attached to a stage if self.stage: if 'backlash' in config: # Construct backlash array backlash = axes_to_array(config['backlash'], ['x', 'y', 'z'], [0, 0, 0]) self.stage.backlash = backlash # Cache config self._config.update(config) No newline at end of file