Commit bbbf9cb3 authored by Carl Hetherington's avatar Carl Hetherington

Basic support for the colour sensor.

parent 07438798
...@@ -10,6 +10,19 @@ if len(sys.argv) != 2: ...@@ -10,6 +10,19 @@ if len(sys.argv) != 2:
sys.exit(1) sys.exit(1)
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
color_sensor_mode = None
def ensure_color_sensor_mode(self, dir, mode):
if self.color_sensor_mode == mode:
return
f = open('%s/mode' % dir, 'w')
print>>f,mode
f.close()
self.color_sensor_mode = mode
def respond(self, reply): def respond(self, reply):
self.send_response(200) self.send_response(200)
self.send_header('Content-Type', 'text/plain') self.send_header('Content-Type', 'text/plain')
...@@ -52,6 +65,13 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -52,6 +65,13 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
v = f.readline().strip() v = f.readline().strip()
f.close() f.close()
self.respond(v) self.respond(v)
elif len(parts) == 2 and parts[0] == 'color-sensor' and parts[1] == 'ambient-level':
dir = self.find_sensor('lego-ev3-color')
self.ensure_color_sensor_mode(dir, 'COL-AMBIENT')
f = open('%s/value0' % dir, 'r')
v = f.readline().strip()
f.close()
self.respond(v)
class TCPServer(SocketServer.TCPServer): class TCPServer(SocketServer.TCPServer):
def server_bind(self): def server_bind(self):
......
...@@ -67,4 +67,14 @@ ...@@ -67,4 +67,14 @@
</block> </block>
</script> </script>
</block-definition> </block-definition>
<block-definition category="sensing" s="color sensor ambient level" type="reporter">
<inputs></inputs>
<script>
<block s="doReport">
<block s="reportURL">
<l>localhost:1330/color-sensor/ambient-level</l>
</block>
</block>
</script>
</block-definition>
</blocks> </blocks>
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