diff --git a/drive.py b/drive.py new file mode 100644 index 0000000..4865afd --- /dev/null +++ b/drive.py @@ -0,0 +1,20 @@ +import errors +import web + +class drive: + def GET(self): + print "VROOOOM!" + raise errors.NotSupportedError + return "This should return a 405 - Not Supported Error" + + #POST excepts a single command in plain teext. + #Current supported commands: forward', 'reverse', 'left', or 'right' + def POST(self): + print ("web.data: %s" % web.data()) #'forward', 'reverse', 'left', or 'right' + direction = web.data() + if direction not in ['forward', 'reverse', 'left', 'right']: + raise errors.BadRequestError + + #Set robot direction here... + + return "Updated direction" \ No newline at end of file diff --git a/errors.py b/errors.py new file mode 100644 index 0000000..e1c61e9 --- /dev/null +++ b/errors.py @@ -0,0 +1,17 @@ +import web + +#405 error when incorrect action is used on a resource +class NotSupportedError(web.HTTPError): + def __init__(self): + status = '405 Method Not Alloweds' + headers = {'Content-Type': 'text/html'} + data = 'That method is not valid for this action.' + web.HTTPError.__init__(self, status, headers, data) + +#400 error when invalid data is sent to a resource +class BadRequestError(web.HTTPError): + def __init__(self): + status = '400' + headers = {'Content-Type': 'text/html'} + data = 'Invalid data supplied in request.' + web.HTTPError.__init__(self, status, headers, data) \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000..bd534a3 --- /dev/null +++ b/server.py @@ -0,0 +1,34 @@ +import web +from drive import drive + +urls = ( + '/', 'index', + '/drive', 'drive', +) +app = web.application(urls, globals()) + +#index raises a 301 error pointing to the index.html page +class index: + def GET(self): + raise web.seeother('/static/index.html') + +#405 error when incorrect action is used on a resource +class NotSupportedError(web.HTTPError): + def __init__(self): + status = '405 Method Not Alloweds' + headers = {'Content-Type': 'text/html'} + data = 'That method is not valid for this action.' + web.HTTPError.__init__(self, status, headers, data) + +#400 error when invalid data is sent to a resource +class BadRequestError(web.HTTPError): + def __init__(self): + status = '400' + headers = {'Content-Type': 'text/html'} + data = 'Invalid data supplied in request.' + web.HTTPError.__init__(self, status, headers, data) + + + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/static/forward.png b/static/forward.png new file mode 100644 index 0000000..da01de5 Binary files /dev/null and b/static/forward.png differ diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..a8fd0fc --- /dev/null +++ b/static/index.html @@ -0,0 +1,56 @@ + + + + + + +

Project Battleaxe Controls

+ +
+ + + + + + + + + + + + + + + + + +
A
+ + + \ No newline at end of file diff --git a/static/left.png b/static/left.png new file mode 100644 index 0000000..09ea168 Binary files /dev/null and b/static/left.png differ diff --git a/static/ocr_pi.png b/static/ocr_pi.png new file mode 100644 index 0000000..35e0252 Binary files /dev/null and b/static/ocr_pi.png differ diff --git a/static/reverse.png b/static/reverse.png new file mode 100644 index 0000000..0405d9a Binary files /dev/null and b/static/reverse.png differ diff --git a/static/right.png b/static/right.png new file mode 100644 index 0000000..3db8e84 Binary files /dev/null and b/static/right.png differ