Skip to content

Commit ac7c7ea

Browse files
authored
Merge pull request #35 from dmadison/nxc
WiiClassicController Example Compatibility w/ NintendoExtensionCtrl 0.8.1
2 parents 71b5cd6 + 8090843 commit ac7c7ea

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ before_install:
5050
fi
5151

5252
# Install Libraries
53-
- arduino --install-library "Nintendo Extension Ctrl:0.7.2"
53+
- arduino --install-library "Nintendo Extension Ctrl:0.8.1"
5454

5555
# Sketch Compiling Functions
5656
- CYAN="\033[36m"; NOC="\033[0m";

examples/WiiClassicController/WiiClassicController.ino

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@
3333

3434
ClassicController classic;
3535

36+
const int RangeOffset = 45; // to make sure the values reach min/max outputs
37+
const int RangeMin = 0 + RangeOffset;
38+
const int RangeMax = 255 - RangeOffset;
39+
3640
void setup() {
3741
classic.begin();
3842

39-
XInput.setTriggerRange(4, 26);
43+
XInput.setTriggerRange(RangeMin, RangeMax); // set both left and right
4044

41-
XInput.setRange(JOY_LEFT, 8, 56);
42-
XInput.setRange(JOY_RIGHT, 4, 28);
45+
XInput.setRange(JOY_LEFT, RangeMin, RangeMax);
46+
XInput.setRange(JOY_RIGHT, RangeMin, RangeMax);
4347

4448
XInput.setAutoSend(false); // Wait for all controls before sending
4549

@@ -52,7 +56,7 @@ void setup() {
5256

5357
void loop() {
5458
if(classic.update()) { // Get new data!
55-
XInput.setJoystick(JOY_LEFT, classic.leftJoyX(), classic.leftJoyY());
59+
XInput.setJoystick(JOY_LEFT, classic.leftJoyX(), classic.leftJoyY());
5660
XInput.setJoystick(JOY_RIGHT, classic.rightJoyX(), classic.rightJoyY());
5761

5862
XInput.setButton(BUTTON_A, classic.buttonB());
@@ -61,25 +65,28 @@ void loop() {
6165
XInput.setButton(BUTTON_Y, classic.buttonX());
6266

6367
XInput.setButton(BUTTON_START, classic.buttonPlus());
64-
XInput.setButton(BUTTON_BACK, classic.buttonMinus());
65-
XInput.setButton(BUTTON_LOGO, classic.buttonHome());
68+
XInput.setButton(BUTTON_BACK, classic.buttonMinus());
69+
XInput.setButton(BUTTON_LOGO, classic.buttonHome());
6670

6771
XInput.setDpad(classic.dpadUp(), classic.dpadDown(), classic.dpadLeft(), classic.dpadRight());
6872

69-
XInput.setTrigger(TRIGGER_LEFT, classic.triggerL());
73+
XInput.setTrigger(TRIGGER_LEFT, classic.triggerL());
7074
XInput.setTrigger(TRIGGER_RIGHT, classic.triggerR());
7175

7276
XInput.setButton(BUTTON_LB, classic.buttonZL());
7377
XInput.setButton(BUTTON_RB, classic.buttonZR());
7478

7579
// XInput.setButton(BUTTON_L3, classic.buttonZL()); // The Classic Controller doesn't have L3 and R3
7680
// XInput.setButton(BUTTON_R3, classic.buttonZR()); // but you can uncomment these to check that they work
81+
82+
XInput.send();
7783
}
7884
else { // Data is bad :(
79-
XInput.releaseAll(); // clear set inputs
80-
classic.connect(); // attempt to reconnect
81-
delay(1000);
82-
}
85+
XInput.releaseAll(); // clear set inputs...
86+
XInput.send(); // ...and send that update
8387

84-
XInput.send();
88+
while (!classic.connect()) { // attempt to reconnect
89+
delay(1000);
90+
}
91+
}
8592
}

0 commit comments

Comments
 (0)