-
Notifications
You must be signed in to change notification settings - Fork 0
/
joystick.sh
47 lines (37 loc) · 1.64 KB
/
joystick.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Create xac_joystick gadget
cd /sys/kernel/config/usb_gadget/
mkdir -p xac_joystick
cd xac_joystick
sudo su
# Define USB specification
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Joystick Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo 0x02 > bDeviceClass
echo 0x00 > bDeviceSubClass
echo 0x00 > bDeviceProtocol
# Device information
mkdir -p strings/0x409
echo "21011970" > strings/0x409/serialnumber
echo "Hazza Industries" > strings/0x409/manufacturer
echo "RaspberryPi Joystick" > strings/0x409/product
# Create configuration file
mkdir -p configs/c.1/strings/0x409
echo 0x80 > configs/c.1/bmAttributes
echo 250 > configs/c.1/MaxPower # 250 mA
echo "Joystick configuration" > configs/c.1/strings/0x409/configuration
# Define the functions of the device
mkdir functions/hid.usb0
echo 0 > functions/hid.usb0/protocol
echo 0 > functions/hid.usb0/subclass
echo 6 > functions/hid.usb0/report_length
# HID descriptor for a joystick with 32 buttons
echo -ne \\x05\\x01\\x09\\x04\\xA1\\x01\\x15\\x81\\x25\\x7F\\x09\\x01\\xA1\\x00\\x09\\x30\\x09\\x31\\x75\\x08\\x95\\x02\\x81\\x02\\xC0\\xA1\\x00\\x05\\x09\\x19\\x01\\x29\\x20\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x20\\x81\\x02\\xC0\\xC0 > functions/hid.usb0/report_desc
#### ^^ Max buttons ^^ Reported buttons
# Link the configuration file
ln -s functions/hid.usb0 configs/c.1
# Activate device
sudo ls /sys/class/udc > UDC
sleep 10