MCPcopy Create free account
hub / github.com/dmadison/ArduinoXInput / setButton

Method setButton

src/XInput.cpp:221–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221void XInputController::setButton(uint8_t button, boolean state) {
222 const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
223 if (buttonData != nullptr) {
224 if (getButton(button) == state) return; // Button hasn't changed
225
226 if (state) { tx[buttonData->index] |= buttonData->mask; } // Press
227 else { tx[buttonData->index] &= ~(buttonData->mask); } // Release
228 newData = true;
229 autosend();
230 }
231 else {
232 Range * triggerRange = getRangeFromEnum((XInputControl) button);
233 if (triggerRange == nullptr) return; // Not a trigger (or joystick, but the trigger function will ignore that)
234 setTrigger((XInputControl) button, state ? triggerRange->max : triggerRange->min); // Treat trigger like a button
235 }
236}
237
238void XInputController::setDpad(XInputControl pad, boolean state) {
239 setButton(pad, state);

Callers

nothing calls this directly

Calls 1

getButtonFromEnumFunction · 0.85

Tested by

no test coverage detected