parsing raw input stream working kb

This commit is contained in:
dekunukem
2021-10-22 23:38:24 +01:00
parent 49480dd1d8
commit 2254199414
10 changed files with 105 additions and 19 deletions

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -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

View File

@@ -1,6 +1,7 @@
import sys
import libevdev
fd = open("/dev/input/event0", "rb" )
fd = open(sys.argv[1], "rb" )
d = libevdev.Device(fd)

View File

@@ -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")

View 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)

View File

@@ -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('----')

View File

@@ -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)