HID Input: socketIO test

This commit is contained in:
Petr Kracik 2020-06-05 16:32:24 +02:00
parent ce4842d93e
commit fb2c4b4874
2 changed files with 21 additions and 9 deletions

View File

@ -34,6 +34,9 @@ a1 01 // Collection Application
c0 // End collection c0 // End collection
00010101
00100101
input bytes (4 bytes) input bytes (4 bytes)
0 - 0 data / 1 constant 0 - 0 data / 1 constant
1 - 0 array / 1 variable 1 - 0 array / 1 variable

View File

@ -2,6 +2,7 @@ from flask import Response
from flask import Flask from flask import Flask
from flask import render_template from flask import render_template
from flask import request from flask import request
from flask_socketio import SocketIO
import threading import threading
import argparse import argparse
import json import json
@ -14,11 +15,13 @@ lock = threading.Lock()
# initialize a flask object # initialize a flask object
app = Flask(__name__) app = Flask(__name__)
socketio = SocketIO(app)
hiddev = None hiddev = None
hidmouse = None hidmouse = None
hidmouseabs = None hidmouseabs = None
hid_init()
def hid_init(): def hid_init():
global hiddev, hidmouse, hidmouseabs global hiddev, hidmouse, hidmouseabs
@ -130,7 +133,6 @@ def mouse():
def mouseabs(): def mouseabs():
mouseevent = json.loads(request.data) mouseevent = json.loads(request.data)
print(mouseevent) print(mouseevent)
btn = mouseevent['btn'] btn = mouseevent['btn']
x = mouseevent['x'] x = mouseevent['x']
y = mouseevent['y'] y = mouseevent['y']
@ -143,6 +145,20 @@ def mouseabs():
return Response("", mimetype="text/plain") return Response("", mimetype="text/plain")
@socketio.on('mouseEvent')
def handle_my_custom_event(json):
mouseevent = json.loads(json)
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)
@app.route("/hid/keyboard", methods=["POST"]) @app.route("/hid/keyboard", methods=["POST"])
def keypress(): def keypress():
keyevent = json.loads(request.data) keyevent = json.loads(request.data)
@ -177,12 +193,5 @@ if __name__ == '__main__':
help="# of frames used to construct the background model") help="# of frames used to construct the background model")
args = vars(ap.parse_args()) args = vars(ap.parse_args())
hid_init()
app.run(host=args["ip"], port=args["port"], debug=True, app.run(host=args["ip"], port=args["port"], debug=True,
threaded=True, use_reloader=False) use_reloader=False)
# Clean up
if hiddev is not None:
print("Closing hid")
hiddev.close()