Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/GamepadPins/GamepadPins.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
#include <XInput.h>

// Setup
const boolean UseLeftJoystick = true; // set to false to disable left joystick
const boolean UseLeftJoystick = false; // set to true to enable left joystick
const boolean InvertLeftYAxis = false; // set to true to use inverted left joy Y

const boolean UseRightJoystick = true; // set to false to disable right joystick
const boolean UseRightJoystick = false; // set to true to enable right joystick
const boolean InvertRightYAxis = false; // set to true to use inverted right joy Y

const boolean UseTriggerButtons = true; // set to false if using analog triggers
Expand Down
16 changes: 8 additions & 8 deletions src/XInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ XInputGamepad::XInputGamepad() :
#endif
}

void XInputGamepad::press(XInputControl button) {
void XInputGamepad::press(uint8_t button) {
setButton(button, true);
}

void XInputGamepad::release(XInputControl button) {
void XInputGamepad::release(uint8_t button) {
setButton(button, false);
}

void XInputGamepad::setButton(XInputControl button, boolean state) {
const XInputMap_Button * buttonData = getButtonFromEnum(button);
void XInputGamepad::setButton(uint8_t button, boolean state) {
const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
if (buttonData != nullptr) {
if (getButton(button) == state) return; // Button hasn't changed

Expand All @@ -222,9 +222,9 @@ void XInputGamepad::setButton(XInputControl button, boolean state) {
autosend();
}
else {
Range * triggerRange = getRangeFromEnum(button);
Range * triggerRange = getRangeFromEnum((XInputControl) button);
if (triggerRange == nullptr) return; // Not a trigger (or joystick, but the trigger function will ignore that)
setTrigger(button, state ? triggerRange->max : triggerRange->min); // Treat trigger like a button
setTrigger((XInputControl) button, state ? triggerRange->max : triggerRange->min); // Treat trigger like a button
}
}

Expand Down Expand Up @@ -291,8 +291,8 @@ void XInputGamepad::setAutoSend(boolean a) {
autoSendOption = a;
}

boolean XInputGamepad::getButton(XInputControl button) const {
const XInputMap_Button * buttonData = getButtonFromEnum(button);
boolean XInputGamepad::getButton(uint8_t button) const {
const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
if (buttonData == nullptr) return 0; // Not a button
return tx[buttonData->index] & buttonData->mask;
}
Expand Down
8 changes: 4 additions & 4 deletions src/XInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class XInputGamepad {
XInputGamepad();

// Set Control Surfaces
void press(XInputControl button);
void release(XInputControl button);
void setButton(XInputControl button, boolean state);
void press(uint8_t button);
void release(uint8_t button);
void setButton(uint8_t button, boolean state);

void setDpad(XInputControl pad, boolean state);
void setDpad(boolean up, boolean down, boolean left, boolean right);
Expand All @@ -96,7 +96,7 @@ class XInputGamepad {
void setAutoSend(boolean a);

// Read Control Surfaces
boolean getButton(XInputControl button) const;
boolean getButton(uint8_t button) const;
boolean getDpad(XInputControl dpad) const;
uint8_t getTrigger(XInputControl trigger) const;
int16_t getJoystickX(XInputControl joy) const;
Expand Down