23 int8_t SwitchProParser::getButtonIndexSwitchPro(
ButtonEnum b) {
30 const int8_t index = getButtonIndexSwitchPro(b);
if (index < 0)
return 0;
35 const int8_t index = getButtonIndexSwitchPro(b);
if (index < 0)
return 0;
37 bool click = buttonClickState.
val & mask;
38 buttonClickState.
val &= ~mask;
45 return switchProData.
leftHatX - 2048;
47 return 2048 - switchProData.
leftHatY;
60 for (uint8_t i = 0; i < len; i++) {
61 D_PrintHex<uint8_t > (buf[i], 0x80);
73 else if (buf[0] == 0x30) {
76 Notify(
PSTR(
"\r\nReport is too short: "), 0x80);
77 D_PrintHex<uint8_t > (len, 0x80);
81 memcpy(&switchProData, buf + 2, min((uint8_t)(len - 2),
MFK_CASTUINT8T sizeof(switchProData)));
83 if (switchProData.
btn.
val != oldButtonState.
val) {
84 buttonClickState.
val = switchProData.
btn.
val & ~oldButtonState.
val;
85 oldButtonState.
val = switchProData.
btn.
val;
89 }
else if (buf[0] == 0x21) {
91 }
else if (buf[0] == 0x81) {
96 D_PrintHex<uint8_t > (buf[0], 0x80);
98 D_PrintHex<uint8_t > (len, 0x80);
112 uint32_t now = millis();
113 if (now - rumble_on_timer > 1000) {
114 rumble_on_timer = now;
115 sendRumbleOutputReport();
120 void SwitchProParser::sendOutputCmd() {
124 uint8_t buf[14] = { 0 };
126 buf[0x01] = output_sequence_counter++;
130 buf[0x02 + 0] = 0x28;
131 buf[0x02 + 1] = 0x88;
132 buf[0x02 + 2] = 0x60;
133 buf[0x02 + 3] = 0x61;
135 buf[0x02 + 0] = 0x00;
136 buf[0x02 + 1] = 0x01;
137 buf[0x02 + 2] = 0x40;
138 buf[0x02 + 3] = 0x40;
143 buf[0x02 + 4] = 0x28;
144 buf[0x02 + 5] = 0x88;
145 buf[0x02 + 6] = 0x60;
146 buf[0x02 + 7] = 0x61;
148 buf[0x02 + 4] = 0x00;
149 buf[0x02 + 5] = 0x01;
150 buf[0x02 + 6] = 0x40;
151 buf[0x02 + 7] = 0x40;
159 buf[0x0A + 0] = 0x30;
169 buf[0x0A + 0] = 0x38;
172 buf[0x0A + 2] = (0xF << 4) | 0x0 ;
173 buf[0x0A + 3] = (0xF << 4) | 0x0 ;
180 buf[0x0A + 0] = 0x03;
181 buf[0x0A + 1] = 0x30;
186 buf[0x0A + 0] = 0x40;
194 void SwitchProParser::sendRumbleOutputReport() {
198 uint8_t buf[10] = { 0 };
200 buf[0x01] = output_sequence_counter++;
204 buf[0x02 + 0] = 0x28;
205 buf[0x02 + 1] = 0x88;
206 buf[0x02 + 2] = 0x60;
207 buf[0x02 + 3] = 0x61;
209 buf[0x02 + 0] = 0x00;
210 buf[0x02 + 1] = 0x01;
211 buf[0x02 + 2] = 0x40;
212 buf[0x02 + 3] = 0x40;
217 buf[0x02 + 4] = 0x28;
218 buf[0x02 + 5] = 0x88;
219 buf[0x02 + 6] = 0x60;
220 buf[0x02 + 7] = 0x61;
222 buf[0x02 + 4] = 0x00;
223 buf[0x02 + 5] = 0x01;
224 buf[0x02 + 6] = 0x40;
225 buf[0x02 + 7] = 0x40;
236 switchProData.
btn.
val = 0;
237 oldButtonState.
val = 0;
238 buttonClickState.
val = 0;
240 output_sequence_counter = 0;
const uint8_t SWITCH_PRO_BUTTONS[]
virtual void sendOutputReport(uint8_t *data, uint8_t len)=0
int16_t getAnalogHat(AnalogHatEnum a)
bool getButtonClick(ButtonEnum b)
bool getButtonPress(ButtonEnum b)
virtual void disableTimeout()
virtual void sendHandshake()
void Parse(uint8_t len, uint8_t *buf)
SwitchProOutput switchProOutput
constexpr int8_t ButtonIndex(ButtonEnum key)
bool enableFullReportMode
bool ledHomeReportChanged
#define pgm_read_byte(addr)