From 748c9b8b20a0812f617e3be632e52a301f2942ae Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 21 Jan 2019 10:49:46 +0000 Subject: [PATCH] Routes now return position as a microscope stage sub-section --- .../api/v1/blueprints/stage.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/openflexure_microscope/api/v1/blueprints/stage.py b/openflexure_microscope/api/v1/blueprints/stage.py index b0ee5a6b..12b215f5 100644 --- a/openflexure_microscope/api/v1/blueprints/stage.py +++ b/openflexure_microscope/api/v1/blueprints/stage.py @@ -1,6 +1,6 @@ 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 openflexure_microscope.utilities import axes_to_array, filter_dict from flask import Response, Blueprint, jsonify, request @@ -11,7 +11,8 @@ class PositionAPI(MicroscopeView): def get(self): """ - Return current x, y and z positions of the stage. + Return current x, y and z positions of the stage. + The response is formatted as a sub-section of the general microscope state. .. :quickref: Position; Get current position @@ -31,16 +32,18 @@ class PositionAPI(MicroscopeView): Content-Type: application/json { - "x": 0, - "y": 0, - "z": 0 + "stage": { + "position": { + "x": -6629, + "y": 7489, + "z": -3844 + } + } } - :>json int x: x steps - :>json int y: y steps - :>json int z: z steps """ - return jsonify(self.microscope.state['stage']['position']) + out = filter_dict(self.microscope.state, ('stage', 'position')) + return jsonify(out) def post(self): """ @@ -78,7 +81,9 @@ class PositionAPI(MicroscopeView): self.microscope.stage.move_rel(position) - return jsonify(self.microscope.state['stage']['position']) + out = filter_dict(self.microscope.state, ('stage', 'position')) + + return jsonify(out) def construct_blueprint(microscope_obj):