Commit 76f316f1 authored by Carl Hetherington's avatar Carl Hetherington

Some fixes; add speak command.

parent 7c9247e1
......@@ -16,7 +16,12 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
if len(parts) == 4 and parts[0] == 'motor':
print 'Run %s to %s at speed %s' % (parts[1], parts[2], parts[3])
d = MediumMotor(parts[1])
d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
elif len(parts) == 2 and parts[0] == 'say':
phrase = parts[1]
phrase = phrase.replace('%20', ' ')
print 'Say %s' % phrase
os.system('espeak -a 200 -s 130 -v en-sc --stdout "%s" | aplay' % phrase)
self.send_response(200)
self.send_header('Content-Type', 'text/html')
......
......@@ -12,7 +12,7 @@ EV3_PORT = 8192
EV3_CONNECTION = 'root@10.42.0.51'
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
def do_GET(self):
if self.path == '/snap-ev3':
f = open('snap-ev3.xml', 'rb')
self.send_response(200)
......@@ -22,11 +22,16 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
return f
self.copyfile(f, self.wfile)
f.close()
else:
SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
urllib2.urlopen("http://10.42.0.51:%d%s" % (EV3_PORT, self.path), timeout=5).read()
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write('OK')
self.wfile.close()
class TCPServer(SocketServer.TCPServer):
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
......
......@@ -26,4 +26,25 @@
</block>
</script>
</block-definition>
<block-definition category="control" s="speak %&apos;words&apos;" type="command">
<inputs>
<input type="%txt">hello</input>
</inputs>
<script>
<block s="doRun">
<block s="reifyReporter">
<autolambda>
<block s="reportURL">
<block s="reportJoinWords">
<list>
<l>localhost:1330/say/</l>
<block var="words"/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
</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