diff --git a/hidinput.py b/hidinput.py index 8b8171c..7ddad43 100644 --- a/hidinput.py +++ b/hidinput.py @@ -18,15 +18,13 @@ app = Flask(__name__) socketio = SocketIO(app) hiddev = None -hidmouse = None hidmouseabs = None def hid_init(): - global hiddev, hidmouse, hidmouseabs + global hiddev, hidmouseabs hiddev = open('/dev/hidg0', 'rb+') - hidmouse = open('/dev/hidg1', 'rb+') - hidmouseabs = open('/dev/hidg2', 'rb+') + hidmouseabs = open('/dev/hidg1', 'rb+') def hid_write(data): @@ -37,20 +35,6 @@ def hid_write(data): hiddev.flush() -def hid_mouse_write(btn, x, y, wheel): - if hidmouse is None: - return False - - data = bytearray(4) - data[0] = btn - data[1] = x - data[2] = y - data[3] = wheel - - hidmouse.write(data) - hidmouse.flush() - - def hid_mouse_writeabs(btn, x, y, wheel): if hidmouseabs is None: return False @@ -101,6 +85,7 @@ def get_hid_by_jscode(rawkeycode): return hidkeycode, (hidkeyname is not None and "MOD" in hidkeyname) + @app.route("/") def index(): return render_template("hid.html") @@ -109,39 +94,9 @@ def index(): def mouseindex(): return render_template("mouse.html") -@app.route("/hid/mouse", methods=["POST"]) -def mouse(): - mouseevent = json.loads(request.data) - print(mouseevent) - - btn = mouseevent['btn'] - x = mouseevent['x'] - y = mouseevent['y'] - wheel = mouseevent['wheel'] - - x = x if x >= 0 else 255-abs(x) - y = y if y >= 0 else 255-abs(y) - - print("X: {}, Y: {}".format(x, y)) - - hid_mouse_write(btn, x, y, wheel) - - return Response("", mimetype="text/plain") - -@app.route("/hid/mouseabs", methods=["POST"]) -def mouseabs(): - mouseevent = json.loads(request.data) - print(mouseevent) - btn = mouseevent['btn'] - x = mouseevent['x'] - y = mouseevent['y'] - wheel = mouseevent['wheel'] - - print("X: {}, Y: {}".format(x, y)) - - hid_mouse_writeabs(btn, x, y, wheel) - - return Response("", mimetype="text/plain") +@app.route("/keyboard.html") +def keyboardIndex(): + return render_template("keyboard.html") @socketio.on('mouseEvent') @@ -158,6 +113,7 @@ def handle_my_custom_event(data): hid_mouse_writeabs(btn, x, y, wheel) + @app.route("/hid/keyboard", methods=["POST"]) def keypress(): keyevent = json.loads(request.data) @@ -179,6 +135,7 @@ def keypress(): return Response("Press {}".format(hidkeycode), mimetype="text/plain") + hid_init() # check to see if this is the main thread of execution