|
|
@ -1,5 +1,7 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
#!/usr/bin/env python3 |
|
|
|
from flask import Flask |
|
|
|
from flask import Flask |
|
|
|
|
|
|
|
import time |
|
|
|
|
|
|
|
import threading |
|
|
|
import cereal.messaging as messaging |
|
|
|
import cereal.messaging as messaging |
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
app = Flask(__name__) |
|
|
@ -29,8 +31,10 @@ setInterval(function(){ |
|
|
|
def hello_world(): |
|
|
|
def hello_world(): |
|
|
|
return index |
|
|
|
return index |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_send_time = time.time() |
|
|
|
@app.route("/control/<x>/<y>") |
|
|
|
@app.route("/control/<x>/<y>") |
|
|
|
def control(x, y): |
|
|
|
def control(x, y): |
|
|
|
|
|
|
|
global last_send_time |
|
|
|
x,y = float(x), float(y) |
|
|
|
x,y = float(x), float(y) |
|
|
|
x = max(-1, min(1, x)) |
|
|
|
x = max(-1, min(1, x)) |
|
|
|
y = max(-1, min(1, y)) |
|
|
|
y = max(-1, min(1, y)) |
|
|
@ -38,8 +42,21 @@ def control(x, y): |
|
|
|
dat.testJoystick.axes = [y,x] |
|
|
|
dat.testJoystick.axes = [y,x] |
|
|
|
dat.testJoystick.buttons = [False] |
|
|
|
dat.testJoystick.buttons = [False] |
|
|
|
pm.send('testJoystick', dat) |
|
|
|
pm.send('testJoystick', dat) |
|
|
|
|
|
|
|
last_send_time = time.time() |
|
|
|
return "" |
|
|
|
return "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_timeout(): |
|
|
|
|
|
|
|
while 1: |
|
|
|
|
|
|
|
this_time = time.time() |
|
|
|
|
|
|
|
if (last_send_time+0.5) < this_time: |
|
|
|
|
|
|
|
print("timeout, no web in %.2f s" % (this_time-last_send_time)) |
|
|
|
|
|
|
|
dat = messaging.new_message('testJoystick') |
|
|
|
|
|
|
|
dat.testJoystick.axes = [0,0] |
|
|
|
|
|
|
|
dat.testJoystick.buttons = [False] |
|
|
|
|
|
|
|
pm.send('testJoystick', dat) |
|
|
|
|
|
|
|
time.sleep(0.1) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
|
threading.Thread(target=handle_timeout, daemon=True).start() |
|
|
|
app.run(host="0.0.0.0") |
|
|
|
app.run(host="0.0.0.0") |
|
|
|
|
|
|
|
|
|
|
|