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

Some fixes; add speak command.

parent 7c9247e1
...@@ -17,6 +17,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -17,6 +17,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
print 'Run %s to %s at speed %s' % (parts[1], parts[2], parts[3]) print 'Run %s to %s at speed %s' % (parts[1], parts[2], parts[3])
d = MediumMotor(parts[1]) 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_response(200)
self.send_header('Content-Type', 'text/html') self.send_header('Content-Type', 'text/html')
......
...@@ -12,7 +12,7 @@ EV3_PORT = 8192 ...@@ -12,7 +12,7 @@ EV3_PORT = 8192
EV3_CONNECTION = 'root@10.42.0.51' EV3_CONNECTION = 'root@10.42.0.51'
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self): def do_GET(self):
if self.path == '/snap-ev3': if self.path == '/snap-ev3':
f = open('snap-ev3.xml', 'rb') f = open('snap-ev3.xml', 'rb')
self.send_response(200) self.send_response(200)
...@@ -22,10 +22,15 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -22,10 +22,15 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
self.send_header("Access-Control-Allow-Origin", "*") self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers() self.end_headers()
return f self.copyfile(f, self.wfile)
f.close()
else: else:
SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
urllib2.urlopen("http://10.42.0.51:%d%s" % (EV3_PORT, self.path), timeout=5).read() 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): class TCPServer(SocketServer.TCPServer):
def server_bind(self): def server_bind(self):
......
...@@ -26,4 +26,25 @@ ...@@ -26,4 +26,25 @@
</block> </block>
</script> </script>
</block-definition> </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> </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