Skip to content

Commit 5811d4b

Browse files
committed
Update WiiClassic example with auto-range
1 parent 89c22a1 commit 5811d4b

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

examples/WiiClassicController/WiiClassicController.ino

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ ClassicController classic;
3636
void setup() {
3737
classic.begin();
3838

39+
XInput.setTriggerRange(2, 28);
40+
41+
XInput.setRange(JOY_LEFT, 8, 56);
42+
XInput.setRange(JOY_RIGHT, 4, 28);
43+
3944
while (!classic.connect()) {
4045
delay(1000); // Controller not connected
4146
}
4247
}
4348

4449
void loop() {
4550
if(classic.update()) { // Get new data!
46-
XInput.setJoystick(JOY_LEFT, map((classic.leftJoyX() << 2), 0, 255, -32768, 32767), map((classic.leftJoyY() << 2), 0, 255, -32768, 32767));
47-
XInput.setJoystick(JOY_RIGHT, map((classic.rightJoyX() << 3), 0, 255, -32768, 32767), map((classic.rightJoyY() << 3), 0, 255, -32768, 32767));
51+
XInput.setJoystick(JOY_LEFT, classic.leftJoyX(), classic.leftJoyY());
52+
XInput.setJoystick(JOY_RIGHT, classic.rightJoyX(), classic.rightJoyY());
4853

4954
XInput.setButton(BUTTON_A, classic.buttonB());
5055
XInput.setButton(BUTTON_B, classic.buttonA());
@@ -57,19 +62,20 @@ void loop() {
5762

5863
XInput.setDpad(classic.dpadUp(), classic.dpadDown(), classic.dpadLeft(), classic.dpadRight());
5964

60-
XInput.setTrigger(TRIGGER_LEFT, classic.triggerL() << 3);
61-
XInput.setTrigger(TRIGGER_RIGHT, classic.triggerR() << 3);
65+
XInput.setTrigger(TRIGGER_LEFT, classic.triggerL());
66+
XInput.setTrigger(TRIGGER_RIGHT, classic.triggerR());
6267

6368
XInput.setButton(BUTTON_LB, classic.buttonZL());
6469
XInput.setButton(BUTTON_RB, classic.buttonZR());
6570

6671
// XInput.setButton(BUTTON_L3, classic.buttonZL()); // The Classic Controller doesn't have L3 and R3
6772
// XInput.setButton(BUTTON_R3, classic.buttonZR()); // but you can uncomment these to check that they work
68-
69-
XInput.send();
70-
XInput.receive();
7173
}
7274
else { // Data is bad :(
75+
XInput.releaseAll();
7376
classic.reconnect();
7477
}
78+
79+
XInput.send();
80+
XInput.receive();
7581
}

0 commit comments

Comments
 (0)