mirror of
				https://github.com/dekuNukem/USB4VC.git
				synced 2025-10-24 11:20:50 -07:00 
			
		
		
		
	parsing raw input stream working kb
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								captures/libevdev delay, EV_MSC fastest, EV_KEY 20ms slower.sal
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								captures/libevdev delay, EV_MSC fastest, EV_KEY 20ms slower.sal
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -16,4 +16,10 @@ while 1: | ||||
|   print(data) | ||||
|  | ||||
| using queue to despatch SPI on raspberry 3: 700 to 800us | ||||
| on lichee 3.5ms  | ||||
| on lichee 3.5ms  | ||||
|  | ||||
| hand parse raw dev/input: 470us on pi3, 1ms on lichee | ||||
|  | ||||
|  | ||||
| 32 byte fixed | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import sys | ||||
| import libevdev | ||||
| 
 | ||||
| fd = open("/dev/input/event0", "rb" ) | ||||
| fd = open(sys.argv[1], "rb" ) | ||||
| 
 | ||||
| d = libevdev.Device(fd) | ||||
| 
 | ||||
| @@ -1,5 +1,6 @@ | ||||
| import sys | ||||
| import time | ||||
| import struct | ||||
| import libevdev | ||||
| import spidev | ||||
| import threading | ||||
| 
 | ||||
| @@ -15,18 +16,19 @@ else: | ||||
|     spi = spidev.SpiDev(1, 0) # lichee | ||||
|     print("I'm on custom board!") | ||||
| 
 | ||||
| spi.max_speed_hz = 500000 | ||||
| spi.max_speed_hz = 2000000 | ||||
| 
 | ||||
| fff = open("/dev/input/event0", "rb" ) | ||||
| # fff = open("/dev/input/event1", "rb" ) | ||||
| fff = open(sys.argv[1], "rb" ) | ||||
| this_device = libevdev.Device(fff) | ||||
| # this_device.disable(libevdev.EV_MSC) | ||||
| 
 | ||||
| def keyboard_worker(): | ||||
|     print("keyboard_thread started") | ||||
|     while 1: | ||||
|         data = fff.read(24) | ||||
|         print(data) | ||||
|         print(struct.unpack('4IHHI', data)) | ||||
|         # print(len(data)) | ||||
|         print('------------') | ||||
|         for e in this_device.events(): | ||||
|             spi.xfer([0x5]*32) | ||||
|             print(e) | ||||
| 
 | ||||
| def mouse_worker(): | ||||
|     print("mouse_thread started") | ||||
							
								
								
									
										24
									
								
								user_program/old/u2p2_main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								user_program/old/u2p2_main.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| import spidev | ||||
|  | ||||
| is_on_raspberry_pi = False | ||||
|  | ||||
| with open('/etc/os-release') as os_version_file: | ||||
|     is_on_raspberry_pi = 'raspbian' in os_version_file.read().lower() | ||||
|  | ||||
| spi = None | ||||
| if is_on_raspberry_pi: | ||||
|     spi = spidev.SpiDev(0, 0) # rasp | ||||
|     print("I'm on Raspberry Pi!") | ||||
| else: | ||||
|     spi = spidev.SpiDev(1, 0) # lichee | ||||
|     print("I'm on custom board!") | ||||
|  | ||||
| spi.max_speed_hz = 500000 | ||||
|  | ||||
| fff = open("/dev/input/event0", "rb" ) | ||||
| while 1: | ||||
|     data = fff.read(24) | ||||
|     data = list(data) | ||||
|     print(data) | ||||
|     spi.xfer(data) | ||||
|      | ||||
| @@ -48,4 +48,14 @@ while True: | ||||
|         if e.matches(libevdev.EV_KEY.BTN_LEFT): | ||||
|             print('Left button event') | ||||
|         elif e.matches(libevdev.EV_KEY.BTN_RIGHT): | ||||
|             print('Right button event') | ||||
|             print('Right button event') | ||||
|  | ||||
| print(struct.unpack('4IHHI', data)) | ||||
|  | ||||
|  | ||||
| data = list(fff.read(16)[8:]) | ||||
|         # https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/input-event-codes.h#L38 | ||||
|         if data[0] == 1: # Keys | ||||
|             spi.xfer(data) | ||||
|             # print(data) | ||||
|             # print('----') | ||||
| @@ -1,7 +1,9 @@ | ||||
| import sys | ||||
| import time | ||||
| import spidev | ||||
| import threading | ||||
|  | ||||
| is_on_raspberry_pi = False | ||||
|  | ||||
| with open('/etc/os-release') as os_version_file: | ||||
|     is_on_raspberry_pi = 'raspbian' in os_version_file.read().lower() | ||||
|  | ||||
| @@ -13,12 +15,53 @@ else: | ||||
|     spi = spidev.SpiDev(1, 0) # lichee | ||||
|     print("I'm on custom board!") | ||||
|  | ||||
| spi.max_speed_hz = 500000 | ||||
| spi.max_speed_hz = 2000000 | ||||
|  | ||||
| fff = open(sys.argv[1], "rb" ) | ||||
|  | ||||
|  | ||||
| """ | ||||
| https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/input-event-codes.h#L38 | ||||
|  | ||||
| xbox gamepad: | ||||
| EVENT TYPE: EV_ABS | ||||
| dpad: ABS_HAT0X ABS_HAT1X | ||||
| buttons: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/input-event-codes.h#L385 | ||||
| sticks: ABS_X, ABS_Y, ABS_RX, ABS_RY | ||||
| """ | ||||
|  | ||||
| EV_KEY = 0x01 | ||||
| EV_REL = 0x02 | ||||
| EV_ABS = 0x03 | ||||
|  | ||||
| SPI_MSG_KEYBOARD_EVENT = 1 | ||||
| SPI_MSG_MOUSE_EVENT = 2 | ||||
| SPI_MSG_GAMEPAD_EVENT = 3 | ||||
|  | ||||
| KEYBOARD_ID_PLACEHOLDER = 0 | ||||
|  | ||||
| keyboard_spi_msg_header = [0xde, 0, SPI_MSG_KEYBOARD_EVENT, KEYBOARD_ID_PLACEHOLDER] | ||||
|  | ||||
| def keyboard_worker(): | ||||
|     print("keyboard_thread started") | ||||
|     while 1: | ||||
|         data = list(fff.read(16)[8:]) | ||||
|         if data[0] == EV_KEY: | ||||
|             spi.xfer(keyboard_spi_msg_header + data) | ||||
|             # print(data) | ||||
|             # print('----') | ||||
|  | ||||
| def mouse_worker(): | ||||
|     print("mouse_thread started") | ||||
|     while 1: | ||||
|         time.sleep(0.2) | ||||
|  | ||||
| keyboard_thread = threading.Thread(target=keyboard_worker, daemon=True) | ||||
| keyboard_thread.start() | ||||
|  | ||||
| mouse_thread = threading.Thread(target=mouse_worker, daemon=True) | ||||
| mouse_thread.start() | ||||
|  | ||||
| fff = open("/dev/input/event0", "rb" ) | ||||
| while 1: | ||||
|     data = fff.read(24) | ||||
|     data = list(data) | ||||
|     print(data) | ||||
|     spi.xfer(data) | ||||
|      | ||||
|     # print("main loop") | ||||
|     time.sleep(1) | ||||
		Reference in New Issue
	
	Block a user