From 0aaee8873d2e187e7db793d102b824e8a17beed6 Mon Sep 17 00:00:00 2001 From: dekunukem Date: Thu, 21 Oct 2021 01:22:43 +0100 Subject: [PATCH] working on device parser --- user_program/devices.txt | 79 +++++++++++++++++++++++++++++++ user_program/login.sh | 1 + user_program/sync.sh | 1 + user_program/temp.py | 13 +++++ user_program/u2p2_main.py | 24 ++++++++++ user_program/u2p2_scan_devices.py | 29 ++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 user_program/devices.txt create mode 100644 user_program/login.sh create mode 100644 user_program/sync.sh create mode 100644 user_program/temp.py create mode 100644 user_program/u2p2_main.py create mode 100644 user_program/u2p2_scan_devices.py diff --git a/user_program/devices.txt b/user_program/devices.txt new file mode 100644 index 0000000..9e6a3b3 --- /dev/null +++ b/user_program/devices.txt @@ -0,0 +1,79 @@ +I: Bus=0003 Vendor=05ac Product=0250 Version=0111 +N: Name="Apple Inc. Apple Keyboard" +P: Phys=usb-3f980000.usb-1.3.2/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/0003:05AC:0250.0001/input/input0 +U: Uniq= +H: Handlers=sysrq kbd leds event0 +B: PROP=0 +B: EV=120013 +B: KEY=10000 0 0 0 0 0 0 1007b 1007 ff9f207a c14057ff ffbeffdf ffefffff ffffffff fffffffe +B: MSC=10 +B: LED=1f + +I: Bus=0003 Vendor=05ac Product=0250 Version=0111 +N: Name="Apple Inc. Apple Keyboard" +P: Phys=usb-3f980000.usb-1.3.2/input1 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.1/0003:05AC:0250.0002/input/input1 +U: Uniq= +H: Handlers=kbd event1 +B: PROP=0 +B: EV=13 +B: KEY=3a 0 e0000 0 0 0 +B: MSC=10 + +I: Bus=0003 Vendor=17ef Product=6039 Version=0111 +N: Name="Lenovo Laser Wireless Mouse" +P: Phys=usb-3f980000.usb-1.4/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:17EF:6039.0004/input/input3 +U: Uniq= +H: Handlers=mouse0 event3 +B: PROP=0 +B: EV=1f +B: KEY=1f0000 0 0 0 0 0 0 0 0 +B: REL=1943 +B: ABS=100 0 +B: MSC=10 + +I: Bus=0003 Vendor=0483 Product=d11c Version=0111 +N: Name="dekuNukem duckyPad(2020) Keyboard" +P: Phys=usb-3f980000.usb-1.2/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0483:D11C.0006/input/input5 +U: Uniq=DP20_774c6600 +H: Handlers=sysrq kbd event2 +B: PROP=0 +B: EV=100013 +B: KEY=7 ff800000 0 e0b0ffdf 1cfffff ffffffff fffffffe +B: MSC=10 + +I: Bus=0003 Vendor=0483 Product=d11c Version=0111 +N: Name="dekuNukem duckyPad(2020) Consumer Control" +P: Phys=usb-3f980000.usb-1.2/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0483:D11C.0006/input/input6 +U: Uniq=DP20_774c6600 +H: Handlers=kbd event4 +B: PROP=0 +B: EV=13 +B: KEY=7a 0 e0000 0 0 0 +B: MSC=10 + +I: Bus=0003 Vendor=0483 Product=d11c Version=0111 +N: Name="dekuNukem duckyPad(2020) Mouse" +P: Phys=usb-3f980000.usb-1.2/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0483:D11C.0006/input/input7 +U: Uniq=DP20_774c6600 +H: Handlers=mouse1 event5 +B: PROP=0 +B: EV=17 +B: KEY=70000 0 0 0 0 0 0 0 0 +B: REL=903 +B: MSC=10 + +I: Bus=0003 Vendor=0483 Product=d11c Version=0111 +N: Name="dekuNukem duckyPad(2020)" +P: Phys=usb-3f980000.usb-1.2/input0 +S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/0003:0483:D11C.0006/input/input8 +U: Uniq=DP20_774c6600 +H: Handlers=event6 +B: PROP=0 +B: EV=9 +B: ABS=100 0 diff --git a/user_program/login.sh b/user_program/login.sh new file mode 100644 index 0000000..c4928ee --- /dev/null +++ b/user_program/login.sh @@ -0,0 +1 @@ +ssh pi@192.168.1.56 \ No newline at end of file diff --git a/user_program/sync.sh b/user_program/sync.sh new file mode 100644 index 0000000..12c399e --- /dev/null +++ b/user_program/sync.sh @@ -0,0 +1 @@ +scp ./u2p2* pi@192.168.1.56:~/u2p2 \ No newline at end of file diff --git a/user_program/temp.py b/user_program/temp.py new file mode 100644 index 0000000..37ec62a --- /dev/null +++ b/user_program/temp.py @@ -0,0 +1,13 @@ +while current_line_num < max_lines: + this_line = file_content[current_line_num] + + print(current_line_num, len(this_line)) + print(this_line, end='') + + + if this_line.startswith('I: '): + while len(this_line) != 1: + print(this_line) + + + current_line_num += 1 diff --git a/user_program/u2p2_main.py b/user_program/u2p2_main.py new file mode 100644 index 0000000..737d225 --- /dev/null +++ b/user_program/u2p2_main.py @@ -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) + \ No newline at end of file diff --git a/user_program/u2p2_scan_devices.py b/user_program/u2p2_scan_devices.py new file mode 100644 index 0000000..ac4f8a9 --- /dev/null +++ b/user_program/u2p2_scan_devices.py @@ -0,0 +1,29 @@ +import os + +dev_path = '/proc/bus/input/devices' + +if 'nt' in os.name: + dev_path = 'devices.txt' + +dev_file = open(dev_path) +file_content = dev_file.readlines() +dev_file.close() + +current_line_num = 0 +max_lines = len(file_content) + +while current_line_num < max_lines: + this_line = file_content[current_line_num] + + if this_line.startswith('I: '): + print("-------- New block! --------") + while len(this_line) != 1: + current_line_num += 1 + if current_line_num >= max_lines: + print("-------- EOF --------") + break + this_line = file_content[current_line_num] + print(this_line) + print("-------- Block end --------") + + current_line_num += 1