Unverified Commit e6913ee0 authored by Cédric Bonhomme's avatar Cédric Bonhomme
Browse files

Test of the color sensor through the API.

parent b1c5816f
......@@ -13,7 +13,7 @@
import json
from functools import wraps
from threading import Thread
from flask import Response, request, session, jsonify, current_app
from flask import Response
from web.lib.utils import default_handler
def async(f):
......@@ -26,17 +26,17 @@ def async(f):
return wrapper
def to_response(func):
"""Will cast results of func as a result, and try to extract
a status_code for the Response object"""
Cast results of func as a result, and try to extract
a status_code for the Response object.
def wrapper(*args, **kwargs):
status_code = 200
result = func(*args, **kwargs)
if isinstance(result, Response):
return result
if isinstance(result, list) and len(result) == 1:
result = result[0]
elif isinstance(result, tuple):
result, status_code = result
return Response(json.dumps(result, default=default_handler),
......@@ -118,15 +118,15 @@ def move(direction="forward", speed=800):
@app.route('/sensor/<sensor_name>', methods=['GET'])
def sensor(sensor_name=""):
Returns the value of the selected sensor.
if sensor_name == "ir_sensor":
return {"distance": ir_sensor.prox}
elif sensor_name == "color_sensor":
return {"rgb": color_sensor.rgb,
"ambiant": color_sensor.ambiant,
"reflect": color_sensor.reflect,
"mode": color_sensor.mode}
elif sensor_name == "button":
......@@ -136,4 +136,7 @@ def sensor(sensor_name=""):
@app.route('/', methods=['GET'])
def index():
Graphical Web interface to command the robot.
return render_template('index.html')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment