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
import SocketServer
from http.server import BaseHTTPRequestHandler, HTTPServer
import socketserver
import socket
import os
import sys
from ev3.lego import MediumMotor
import ev3dev.ev3 as ev3
if len(sys.argv) != 2:
print>>sys.stderr,'Syntax: %s <port>' % (sys.argv[0])
sys.exit(1)
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(BaseHTTPRequestHandler):
color_sensor_mode = None
......@@ -41,16 +41,17 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
parts = self.path[1:].split('/')
print parts
print (parts)
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)
print ('Run %s to %s at speed %s' % (parts[1], parts[2], parts[3]))
d = ev3.MediumMotor('out' + parts[1])
d.run_timed(time_sp=3000, speed_sp=500)
#d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
self.respond('OK')
elif len(parts) == 2 and parts[0] == 'say':
phrase = parts[1]
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)
self.respond('OK')
elif len(parts) == 2 and parts[0] == 'ir-sensor' and parts[1] == 'proximity':
......@@ -73,11 +74,11 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
f.close()
self.respond(v)
class TCPServer(SocketServer.TCPServer):
class TCPServer(socketserver.TCPServer):
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
httpd = TCPServer(("", int(sys.argv[1])), Handler)
print 'EV3 ready.'
print ('EV3 ready.')
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