mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
keeping button state in python
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import sys
|
||||
import spidev
|
||||
import time
|
||||
|
||||
is_on_raspberry_pi = False
|
||||
|
||||
@@ -13,12 +15,16 @@ 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" )
|
||||
EV_SYN = 0
|
||||
EV_KEY = 1
|
||||
EV_REL = 2
|
||||
EV_ABS = 3
|
||||
|
||||
fff = open(sys.argv[1], "rb" )
|
||||
while 1:
|
||||
data = fff.read(24)
|
||||
data = list(data)
|
||||
data = list(fff.read(16))
|
||||
print(data)
|
||||
spi.xfer(data)
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ SPI_MISO_MSG_KB_LED_REQ = 1
|
||||
|
||||
SPI_MOSI_MAGIC = 0xde
|
||||
SPI_MISO_MAGIC = 0xcd
|
||||
|
||||
keyboard_spi_msg_header = [SPI_MOSI_MAGIC, 0, SPI_MOSI_MSG_KEYBOARD_EVENT, 0]
|
||||
mouse_spi_msg_template = [SPI_MOSI_MAGIC, 0, SPI_MOSI_MSG_MOUSE_EVENT, 0] + [0]*28
|
||||
|
||||
@@ -122,6 +123,7 @@ def change_kb_led(ps2kb_led_byte):
|
||||
|
||||
def raw_input_event_worker():
|
||||
mouse_spi_packet_dict = {}
|
||||
mouse_button_state_list = [0] * 5
|
||||
print("raw_input_event_parser_thread started")
|
||||
while 1:
|
||||
for key in list(keyboard_opened_device_dict):
|
||||
@@ -149,6 +151,7 @@ def raw_input_event_worker():
|
||||
if data is None:
|
||||
continue
|
||||
data = list(data[8:])
|
||||
# print(data)
|
||||
if data[0] == EV_REL:
|
||||
if data[2] == REL_X:
|
||||
mouse_spi_packet_dict["x"] = data[4:6]
|
||||
@@ -157,21 +160,22 @@ def raw_input_event_worker():
|
||||
if data[2] == REL_WHEEL:
|
||||
mouse_spi_packet_dict["scroll"] = data[4:6]
|
||||
if data[0] == EV_KEY:
|
||||
mouse_spi_packet_dict["button"] = data[2:6]
|
||||
mouse_button_state_list[data[2]-16] = data[4]
|
||||
to_transfer = list(mouse_spi_msg_template)
|
||||
to_transfer[10:13] = data[2:5]
|
||||
to_transfer[13:18] = mouse_button_state_list[:]
|
||||
to_transfer[3] = mouse_opened_device_dict[key][1]
|
||||
spi.xfer(to_transfer)
|
||||
|
||||
if data[0] == EV_SYN and data[2] == SYN_REPORT:
|
||||
print(mouse_spi_packet_dict)
|
||||
if data[0] == EV_SYN and data[2] == SYN_REPORT and len(mouse_spi_packet_dict) > 0:
|
||||
to_transfer = list(mouse_spi_msg_template)
|
||||
if 'x' in mouse_spi_packet_dict:
|
||||
to_transfer[4:6] = mouse_spi_packet_dict['x']
|
||||
if 'y' in mouse_spi_packet_dict:
|
||||
to_transfer[6:8] = mouse_spi_packet_dict['y']
|
||||
if 'button' in mouse_spi_packet_dict:
|
||||
to_transfer[8:12] = mouse_spi_packet_dict['button']
|
||||
if 'scroll' in mouse_spi_packet_dict:
|
||||
to_transfer[12:14] = mouse_spi_packet_dict['scroll']
|
||||
to_transfer[8:10] = mouse_spi_packet_dict['scroll']
|
||||
to_transfer[3] = mouse_opened_device_dict[key][1]
|
||||
print(to_transfer[:16])
|
||||
mouse_spi_packet_dict.clear()
|
||||
spi.xfer(to_transfer)
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import sys
|
||||
import spidev
|
||||
import time
|
||||
|
||||
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 = 2000000
|
||||
|
||||
EV_SYN = 0
|
||||
EV_KEY = 1
|
||||
EV_REL = 2
|
||||
EV_ABS = 3
|
||||
|
||||
fff = open(sys.argv[1], "rb" )
|
||||
while 1:
|
||||
data = list(fff.read(16))
|
||||
print(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user