forked from MiyooCFW/buildroot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tunr your handheld into usb gamepad for PC
- Loading branch information
Showing
8 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import keyboard | ||
|
||
## usb hid codes: https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf | ||
hidCodeDict = { | ||
103:82, #up | ||
108:81, #down | ||
105:80, #left | ||
106:79, #right | ||
29:29, #b mapped to z | ||
56:27, #a mapped to x | ||
57:4, #y mapped to a | ||
42:22, #x mapped to s | ||
1:42, #select mapped to backspace | ||
28:40, #start mapped to enter | ||
15:20, #lpad mapped to q | ||
14:26, #rpad mapped to w | ||
97:0, #reset not mapped, used to quit | ||
} | ||
|
||
NULL_CHAR = chr(0) | ||
def write_report(report): | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(report.encode()) | ||
|
||
def translate(code, dictonary): | ||
if code in dictonary: | ||
return dictonary[code] | ||
return 0 | ||
|
||
def write_pressed_keys(e): | ||
line = ''.join(chr(translate(code,hidCodeDict)) for code in keyboard._pressed_events) | ||
if line == '': | ||
write_report(NULL_CHAR*8) | ||
return | ||
print('\r', end='') | ||
write_report(NULL_CHAR*2+line+NULL_CHAR*5) | ||
|
||
print("Press RESET button to quit") | ||
keyboard.hook(write_pressed_keys) | ||
keyboard.wait(97) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/busybox sh | ||
if [ `cat /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode` != "b_peripheral" ]; then | ||
echo -e "\e[31mFirst connect handheld to device!\e[0m"&>$(tty) | ||
sleep 2 | ||
exit | ||
fi | ||
gadget-vid-pid-remove 0x1d6b:0x0104 | ||
gadget-hid | ||
echo -e "\e[32mStarting USB HID mode...\e[0m"&>$(tty) | ||
python /mnt/apps/usb-hid/usb-hid.py&>$(tty) | ||
gadget-vid-pid-remove 0x1d6b:0x0104 | ||
gadget-ms /dev/mmcblk0p1 /dev/mmcblk0p4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
title=USB HID | ||
description=USB HID PC gamepad | ||
exec=/mnt/apps/usb-hid/usb-hid.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
config BR2_PACKAGE_PYTHON_KEYBOARD | ||
select BR2_PACKAGE_KBD | ||
bool "python-keyboard" | ||
help | ||
Hook and simulate keyboard events on Windows and Linux | ||
https://pypi.org/project/keyboard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
################################################################################ | ||
# | ||
# python-keyboard | ||
# | ||
################################################################################ | ||
|
||
PYTHON_KEYBOARD_VERSION = 0.13.5 | ||
PYTHON_KEYBOARD_SOURCE = keyboard-$(PYTHON_KEYBOARD_VERSION).zip | ||
PYTHON_KEYBOARD_SITE = https://files.pythonhosted.org/packages/79/75/c969f2258e908c39aadfc57d1cb78247dc49e6d36371bb3a48c194640c01 | ||
PYTHON_KEYBOARD_LICENSE = MIT | ||
PYTHON_KEYBOARD_LICENSE_FILES = LICENSE | ||
PYTHON_KEYBOARD_SETUP_TYPE = setuptools | ||
define PYTHON_KEYBOARD_EXTRACT_CMDS | ||
$(UNZIP) -d $(@D) $(PYTHON_KEYBOARD_DL_DIR)/$(PYTHON_KEYBOARD_SOURCE) | ||
yes | cp -rf $(@D)/keyboard-0.13.5/* $(@D)/ | ||
endef | ||
$(eval $(python-package)) |