Skip to content

Commit fcf3612

Browse files
committed
Fixed some problems in setup instructions and folder structure
1 parent 9337f20 commit fcf3612

File tree

9 files changed

+48
-20
lines changed

9 files changed

+48
-20
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ Sketch for Arduino based taiko game controller circuit
44

55
## Software Setup
66

7+
### Arduino IDE
8+
79
Install the latest version of Arduino IDE from the official website: [https://www.arduino.cc/en/Main/Software](https://www.arduino.cc/en/Main/Software)
810

9-
To enable nintendo switch functionality, replace the following files with the ones provided in "setup" folder:
11+
### Modifications to Arduino IDE
12+
13+
Before starting Arduino IDE, to enable nintendo switch functionality, replace the following files with the ones provided in "setup" folder:
1014

1115
- <your arduino installation path>/hardware/arduino/avr/libraries/HID/src/HID.h
1216
- <your arduino installation path>/hardware/arduino/avr/libraries/HID/src/HID.cpp
@@ -15,15 +19,40 @@ Then copy the text in board.txt in "setup" folder and append it to the following
1519

1620
- <your arduino installation path>/hardware/arduino/avr/boards.txt
1721

22+
If you've successfully done all the modifications above, you should be able to see the board called "Nintendo Switch Controller" next time you start Arduino IDE:
23+
24+
![](https://i.loli.net/2019/03/17/5c8e542c92603.png)
25+
26+
Please select this board before uploading the code as this is essential for your Arduino Leonardo to be recognized by Nintendo Switch.
27+
28+
### Keyboard or Nintendo Switch Controller
29+
1830
To enable or disable keyboard and Nintendo Switch controller functionality, remove or add two charactors "//" before these two lines in taiko_controller.ino:
1931

32+
- To enable Switch controller only
2033
```
2134
//#define ENABLE_KEYBOARD
2235
#define ENABLE_NS_JOYSTICK
2336
```
37+
- To enable keyboard only
38+
```
39+
#define ENABLE_KEYBOARD
40+
//#define ENABLE_NS_JOYSTICK
41+
```
42+
- To enable both (not tested)
43+
```
44+
#define ENABLE_KEYBOARD
45+
#define ENABLE_NS_JOYSTICK
46+
```
2447

2548
## Circuit Setup
2649

50+
### Materials
51+
52+
To setup the circuit, you need an Arduino Leonardo, a set of four piezo sensors, and four 1MΩ resistors for some special cases.
53+
54+
### Connect the Circuit
55+
2756
Connect the sensors to the 3.3v pin and the analog pins according to the diagram below:
2857

2958
![](https://i.loli.net/2019/03/07/5c812d28e0978.png)
@@ -42,7 +71,9 @@ If the controller seems to be generating random inputs, you can fix this by plug
4271

4372
![](https://i.loli.net/2019/03/07/5c812d28e101d.png)
4473

45-
For best performance, the sensors must be piezo sensors (a.k.a. peizo speakers, contact microphones). No guarantee if other types of sensors will simply work, but if analog signals with voltage ranged 0-5V are fed into analog pins, this setup should be good to go.
74+
### Notes
75+
76+
For best performance, the sensors must be piezo sensors (a.k.a. piezo speakers, contact microphones). No guarantee if other types of sensors will simply work, but if analog signals with voltage ranged 0-5V are fed into analog pins, this setup should be good to go.
4677

4778
For further improvements, you can use some diodes to limit the voltage of the piezo sensors, or use a 2.5v power supply, but this won't matter in most cases, at least on my side.
4879

@@ -60,6 +91,8 @@ To deal with four analog inputs, we read the sensor levels one at a time, and on
6091

6192
To deal with Nintendo Switch, I used the HID descriptor for Hori's Pokken fightstick to let Switch trust Arduino as a valid controller device (see the [credits](#credits) section). The default buttons from the four sensors are the analog stick buttons (press the sticks down) and the trigger buttons (ZL and ZR).
6293

94+
As VID and PID of the controller have to be the specific value, the setup to boards.txt is essential. Also, Switch seems also to be judging the device strictly by the first-come HID descriptor of the device, so Arduino's default HID behavior have to be altered to have our customized HID descriptor to work.
95+
6396
## Parameters (with suggested values)
6497

6598
#### min_threshold = 15

setup/HID.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node)
8686
descriptorSize += node->length;
8787
}
8888

89+
void HID_::PrependDescriptor(HIDSubDescriptor *node)
90+
{
91+
node->next = rootNode;
92+
rootNode = node;
93+
descriptorSize += node->length;
94+
}
95+
8996
int HID_::SendReport(uint8_t id, const void* data, int len)
9097
{
9198
auto ret = USB_Send(pluggedEndpoint, &id, 1);
@@ -95,6 +102,11 @@ int HID_::SendReport(uint8_t id, const void* data, int len)
95102
return ret + ret2;
96103
}
97104

105+
int HID_::SendRaw(const void* data, int len)
106+
{
107+
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
108+
}
109+
98110
bool HID_::setup(USBSetup& setup)
99111
{
100112
if (pluggedInterface != setup.wIndex) {

setup/boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Nintendo Switch Controller for Micro/Leonardo #
44
##############################################################
55

6-
ns_con.name=Nintendo Switch Controller (Micro)
6+
ns_con.name=Nintendo Switch Controller (Micro/Leo)
77

88
ns_con.vid.1=0x0F0D
99
ns_con.pid.1=0x0092
File renamed without changes.
File renamed without changes.
File renamed without changes.

Joystick.cpp renamed to taiko_controller/Joystick.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
* https://github.com/progmem/Switch-Fightstick/blob/master/Joystick.h
99
***/
1010

11-
// Functions added to HID_ class
12-
// Don't forget to add definitions in HID.h, which is located at:
13-
// <arduino installation path>\hardware\arduino\avr\libraries\HID\src\
14-
15-
void HID_::PrependDescriptor(HIDSubDescriptor *node)
16-
{
17-
node->next = rootNode;
18-
rootNode = node;
19-
descriptorSize += node->length;
20-
}
21-
22-
int HID_::SendRaw(const void* data, int len)
23-
{
24-
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
25-
}
26-
2711
/***
2812
* Descriptor modified from
2913
* progmem/Switch-Fightstick/Joystick.c
@@ -100,4 +84,3 @@ void Joystick_::sendState()
10084
}
10185

10286
Joystick_ Joystick;
103-
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)