HID Input: socketIO test
This commit is contained in:
		@@ -34,6 +34,9 @@ a1 01 // Collection Application
 | 
			
		||||
c0 // End collection
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
00010101
 | 
			
		||||
00100101
 | 
			
		||||
 | 
			
		||||
input bytes (4 bytes)
 | 
			
		||||
 0 - 0 data / 1 constant
 | 
			
		||||
 1 - 0 array / 1 variable
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								hidinput.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								hidinput.py
									
									
									
									
									
								
							@@ -2,6 +2,7 @@ from flask import Response
 | 
			
		||||
from flask import Flask
 | 
			
		||||
from flask import render_template
 | 
			
		||||
from flask import request
 | 
			
		||||
from flask_socketio import SocketIO
 | 
			
		||||
import threading
 | 
			
		||||
import argparse
 | 
			
		||||
import json
 | 
			
		||||
@@ -14,11 +15,13 @@ lock = threading.Lock()
 | 
			
		||||
 | 
			
		||||
# initialize a flask object
 | 
			
		||||
app = Flask(__name__)
 | 
			
		||||
socketio = SocketIO(app)
 | 
			
		||||
 | 
			
		||||
hiddev = None
 | 
			
		||||
hidmouse = None
 | 
			
		||||
hidmouseabs = None
 | 
			
		||||
 | 
			
		||||
hid_init()
 | 
			
		||||
 | 
			
		||||
def hid_init():
 | 
			
		||||
    global hiddev, hidmouse, hidmouseabs
 | 
			
		||||
@@ -130,7 +133,6 @@ def mouse():
 | 
			
		||||
def mouseabs():
 | 
			
		||||
    mouseevent = json.loads(request.data)
 | 
			
		||||
    print(mouseevent)
 | 
			
		||||
 | 
			
		||||
    btn = mouseevent['btn']
 | 
			
		||||
    x = mouseevent['x']
 | 
			
		||||
    y = mouseevent['y']
 | 
			
		||||
@@ -143,6 +145,20 @@ def mouseabs():
 | 
			
		||||
    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"])
 | 
			
		||||
def keypress():
 | 
			
		||||
    keyevent = json.loads(request.data)
 | 
			
		||||
@@ -177,12 +193,5 @@ if __name__ == '__main__':
 | 
			
		||||
        help="# of frames used to construct the background model")
 | 
			
		||||
    args = vars(ap.parse_args())
 | 
			
		||||
 | 
			
		||||
    hid_init()
 | 
			
		||||
 | 
			
		||||
    app.run(host=args["ip"], port=args["port"], debug=True,
 | 
			
		||||
            threaded=True, use_reloader=False)
 | 
			
		||||
 | 
			
		||||
    # Clean up
 | 
			
		||||
    if hiddev is not None:
 | 
			
		||||
        print("Closing hid")
 | 
			
		||||
        hiddev.close()
 | 
			
		||||
            use_reloader=False)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user