Skip to content

Commit 4ef6741

Browse files
committed
Revert "API Demo: set D-Pad to player number"
On second thought, this requires the send functionality to work *anyways*... It would be better to toggle on an LED, but not all boards have built-in lEDs and even then you need to show 5 states (off/nc, players 1-4) which means 3 LEDs. I'm going to leave this with the 'send' only practical test for now until I can come up with something better. This reverts commit 2e01538.
1 parent 2e01538 commit 4ef6741

1 file changed

Lines changed: 10 additions & 35 deletions

File tree

extras/API-Demo/API-Demo.ino

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,63 +44,38 @@
4444
#else
4545

4646
uint8_t txData[20] = { 0x00, 0x14, 0x00 };
47-
boolean buttonState = false;
47+
uint8_t rxData[8] = { 0x00 };
4848

49-
volatile uint8_t rxData[8] = { 0x00 };
50-
volatile uint8_t playerNum = 0;
49+
boolean buttonState = false;
5150

5251
void setup() {
5352
while (!XInputUSB::connected()) {} // wait for connection
5453
XInputUSB::setRecvCallback(receiveCallback);
5554
}
5655

5756
void loop() {
58-
// Set D-PAD based on player number (test receive)
59-
const uint8_t pNum = playerNum;
60-
if (pNum != 0) {
61-
setPlayerControl(pNum);
62-
playerNum = 0;
63-
}
64-
65-
// Toggle button 'A' (test send)
6657
buttonState = !buttonState;
67-
setButtonA(buttonState);
58+
setButtonA(txData, buttonState);
6859
XInputUSB::send(txData, sizeof(txData));
6960

7061
delay(1000);
7162
}
7263

73-
void setButton(uint8_t index, uint8_t position, uint8_t state) {
64+
void setButtonA(uint8_t * ptr, boolean state) {
65+
const uint8_t ButtonIndex = 3;
66+
const uint8_t ButtonPosition = 4;
67+
7468
if (state == true) {
75-
txData[index] |= (1 << position);
69+
ptr[ButtonIndex] |= (1 << ButtonPosition);
7670
}
7771
else {
78-
txData[index] &= ~(1 << position);
72+
ptr[ButtonIndex] &= ~(1 << ButtonPosition);
7973
}
8074
}
8175

82-
void setButtonA(boolean state) {
83-
setButton(3, 4, state);
84-
}
85-
86-
void setPlayerControl(uint8_t num) {
87-
// Player 1: Dpad Up
88-
// Player 2; Dpad Down
89-
// Player 3: Dpad Left
90-
// Player 4: Dpad Right
91-
setButton(2, num - 1, true);
92-
}
93-
9476
void receiveCallback() {
9577
if (XInputUSB::available() > 0) {
96-
const int success = XInputUSB::recv((uint8_t*) rxData, sizeof(rxData));
97-
98-
if (success > 0 && rxData[0] == 0x01) { // LED Packet
99-
uint8_t ledPattern = rxData[2];
100-
if (ledPattern >= 2 && ledPattern <= 9) { // Player # Pattern
101-
playerNum = ((ledPattern - 2) % 4) + 1; // Player # 1-4
102-
}
103-
}
78+
XInputUSB::recv(rxData, sizeof(rxData));
10479
}
10580
}
10681

0 commit comments

Comments
 (0)