Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Lego_Robots
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matthew Baxter
Lego_Robots
Commits
bbbf9cb3
Commit
bbbf9cb3
authored
Jun 29, 2015
by
Carl Hetherington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic support for the colour sensor.
parent
07438798
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
listen.py
listen.py
+20
-0
snap-ev3.xml
snap-ev3.xml
+10
-0
No files found.
listen.py
View file @
bbbf9cb3
...
...
@@ -10,6 +10,19 @@ if len(sys.argv) != 2:
sys
.
exit
(
1
)
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
):
self
.
send_response
(
200
)
self
.
send_header
(
'Content-Type'
,
'text/plain'
)
...
...
@@ -52,6 +65,13 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
v
=
f
.
readline
()
.
strip
()
f
.
close
()
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
):
def
server_bind
(
self
):
...
...
snap-ev3.xml
View file @
bbbf9cb3
...
...
@@ -67,4 +67,14 @@
</block>
</script>
</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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment