Commit dcba4b6b authored by isaac.thompson's avatar isaac.thompson

Some fixes for python 3; use ev3dev rather than ev3 as it's being maintained;...

Some fixes for python 3; use ev3dev rather than ev3 as it's being maintained; partially fix motor command (at least the motor moves).
parent f7ca0134
import SimpleHTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer
import SocketServer import socketserver
import socket import socket
import os import os
import sys import sys
from ev3.lego import MediumMotor import ev3dev.ev3 as ev3
if len(sys.argv) != 2: if len(sys.argv) != 2:
print>>sys.stderr,'Syntax: %s <port>' % (sys.argv[0]) print>>sys.stderr,'Syntax: %s <port>' % (sys.argv[0])
sys.exit(1) sys.exit(1)
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): class Handler(BaseHTTPRequestHandler):
color_sensor_mode = None color_sensor_mode = None
...@@ -41,16 +41,17 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -41,16 +41,17 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self): def do_GET(self):
parts = self.path[1:].split('/') parts = self.path[1:].split('/')
print parts print (parts)
if len(parts) == 4 and parts[0] == 'motor': if len(parts) == 4 and parts[0] == 'motor':
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 = ev3.MediumMotor('out' + parts[1])
d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False) d.run_timed(time_sp=3000, speed_sp=500)
#d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
self.respond('OK') self.respond('OK')
elif len(parts) == 2 and parts[0] == 'say': elif len(parts) == 2 and parts[0] == 'say':
phrase = parts[1] phrase = parts[1]
phrase = phrase.replace('%20', ' ') phrase = phrase.replace('%20', ' ')
print 'Say %s' % phrase print ('Say %s' % phrase)
os.system('espeak -a 200 -s 130 -v en-sc --stdout "%s" | aplay' % phrase) os.system('espeak -a 200 -s 130 -v en-sc --stdout "%s" | aplay' % phrase)
self.respond('OK') self.respond('OK')
elif len(parts) == 2 and parts[0] == 'ir-sensor' and parts[1] == 'proximity': elif len(parts) == 2 and parts[0] == 'ir-sensor' and parts[1] == 'proximity':
...@@ -73,11 +74,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -73,11 +74,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
f.close() f.close()
self.respond(v) self.respond(v)
class TCPServer(SocketServer.TCPServer): class TCPServer(socketserver.TCPServer):
def server_bind(self): def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address) self.socket.bind(self.server_address)
httpd = TCPServer(("", int(sys.argv[1])), Handler) httpd = TCPServer(("", int(sys.argv[1])), Handler)
print 'EV3 ready.' print ('EV3 ready.')
httpd.serve_forever() httpd.serve_forever()
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