mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Controller is default 0
This will ensure compatible with the other controllers
This commit is contained in:
parent
1a362c5310
commit
216fce8d95
3 changed files with 78 additions and 78 deletions
18
XBOXRECV.cpp
18
XBOXRECV.cpp
|
@ -325,7 +325,7 @@ void XBOXRECV::readReport(uint8_t controller) {
|
|||
case 3: led = LED4;
|
||||
break;
|
||||
}
|
||||
setLedOn(controller, led);
|
||||
setLedOn(led, controller);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
|
@ -381,7 +381,7 @@ void XBOXRECV::printReport(uint8_t controller, uint8_t nBytes) { //Uncomment "#d
|
|||
#endif
|
||||
}
|
||||
|
||||
uint8_t XBOXRECV::getButtonPress(uint8_t controller, Button b) {
|
||||
uint8_t XBOXRECV::getButtonPress(Button b, uint8_t controller) {
|
||||
if (b == L2) // These are analog buttons
|
||||
return (uint8_t)(ButtonState[controller] >> 8);
|
||||
else if (b == R2)
|
||||
|
@ -389,7 +389,7 @@ uint8_t XBOXRECV::getButtonPress(uint8_t controller, Button b) {
|
|||
return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16));
|
||||
}
|
||||
|
||||
bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
|
||||
bool XBOXRECV::getButtonClick(Button b, uint8_t controller) {
|
||||
if (b == L2) {
|
||||
if (L2Clicked[controller]) {
|
||||
L2Clicked[controller] = false;
|
||||
|
@ -409,7 +409,7 @@ bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
|
|||
return click;
|
||||
}
|
||||
|
||||
int16_t XBOXRECV::getAnalogHat(uint8_t controller, AnalogHat a) {
|
||||
int16_t XBOXRECV::getAnalogHat(AnalogHat a, uint8_t controller) {
|
||||
return hatValue[controller][a];
|
||||
}
|
||||
|
||||
|
@ -462,7 +462,7 @@ void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void XBOXRECV::setLedRaw(uint8_t controller, uint8_t value) {
|
||||
void XBOXRECV::setLedRaw(uint8_t value, uint8_t controller) {
|
||||
writeBuf[0] = 0x00;
|
||||
writeBuf[1] = 0x00;
|
||||
writeBuf[2] = 0x08;
|
||||
|
@ -471,16 +471,16 @@ void XBOXRECV::setLedRaw(uint8_t controller, uint8_t value) {
|
|||
XboxCommand(controller, writeBuf, 4);
|
||||
}
|
||||
|
||||
void XBOXRECV::setLedOn(uint8_t controller, LED led) {
|
||||
void XBOXRECV::setLedOn(LED led, uint8_t controller) {
|
||||
if (led != ALL) // All LEDs can't be on a the same time
|
||||
setLedRaw(controller, (pgm_read_byte(&XBOXLEDS[(uint8_t)led])) + 4);
|
||||
}
|
||||
|
||||
void XBOXRECV::setLedBlink(uint8_t controller, LED led) {
|
||||
void XBOXRECV::setLedBlink(LED led, uint8_t controller) {
|
||||
setLedRaw(controller, pgm_read_byte(&XBOXLEDS[(uint8_t)led]));
|
||||
}
|
||||
|
||||
void XBOXRECV::setLedMode(uint8_t controller, LEDMode ledMode) { // This function is used to do some speciel LED stuff the controller supports
|
||||
void XBOXRECV::setLedMode(LEDMode ledMode, uint8_t controller) { // This function is used to do some speciel LED stuff the controller supports
|
||||
setLedRaw(controller, (uint8_t)ledMode);
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ void XBOXRECV::checkStatus() {
|
|||
}
|
||||
}
|
||||
|
||||
void XBOXRECV::setRumbleOn(uint8_t controller, uint8_t lValue, uint8_t rValue) {
|
||||
void XBOXRECV::setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller) {
|
||||
writeBuf[0] = 0x00;
|
||||
writeBuf[1] = 0x01;
|
||||
writeBuf[2] = 0x0f;
|
||||
|
|
66
XBOXRECV.h
66
XBOXRECV.h
|
@ -113,93 +113,93 @@ public:
|
|||
*
|
||||
* So you instance if you need to increase a variable once you would use getButtonClick(uint8_t controller, Button b),
|
||||
* but if you need to drive a robot forward you would use getButtonPress(uint8_t controller, Button b).
|
||||
* @param controller The controller to read from.
|
||||
* @param b ::Button to read.
|
||||
* @param controller The controller to read from. Default to 0.
|
||||
* @return getButtonClick(uint8_t controller, Button b) will return a bool, but getButtonPress(uint8_t controller, Button b)
|
||||
* will return a byte if reading ::L2 or ::R2.
|
||||
*/
|
||||
uint8_t getButtonPress(uint8_t controller, Button b);
|
||||
bool getButtonClick(uint8_t controller, Button b);
|
||||
uint8_t getButtonPress(Button b, uint8_t controller = 0);
|
||||
bool getButtonClick(Button b, uint8_t controller = 0);
|
||||
/**@}*/
|
||||
|
||||
/** @name Xbox Controller functions */
|
||||
/**
|
||||
* Return the analog value from the joysticks on the controller.
|
||||
* @param controller The controller to read from.
|
||||
* Return the analog value from the joysticks on the controller.
|
||||
* @param a Either ::LeftHatX, ::LeftHatY, ::RightHatX or ::RightHatY.
|
||||
* @param controller The controller to read from. Default to 0.
|
||||
* @return Returns a signed 16-bit integer.
|
||||
*/
|
||||
int16_t getAnalogHat(uint8_t controller, AnalogHat a);
|
||||
int16_t getAnalogHat(AnalogHat a, uint8_t controller = 0);
|
||||
|
||||
/**
|
||||
* Turn rumble off and all the LEDs on the specific controller.
|
||||
* @param controller The controller to write to.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setAllOff(uint8_t controller) {
|
||||
setRumbleOn(controller, 0, 0);
|
||||
void setAllOff(uint8_t controller = 0) {
|
||||
setRumbleOn(0, 0, controller);
|
||||
setLedOff(controller);
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn rumble off the specific controller.
|
||||
* @param controller The controller to write to.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setRumbleOff(uint8_t controller) {
|
||||
setRumbleOn(controller, 0, 0);
|
||||
void setRumbleOff(uint8_t controller = 0) {
|
||||
setRumbleOn(0, 0, controller);
|
||||
};
|
||||
/**
|
||||
* Turn rumble on.
|
||||
* @param controller The controller to write to.
|
||||
* Turn rumble on.
|
||||
* @param lValue Left motor (big weight) inside the controller.
|
||||
* @param rValue Right motor (small weight) inside the controller.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setRumbleOn(uint8_t controller, uint8_t lValue, uint8_t rValue);
|
||||
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller = 0);
|
||||
/**
|
||||
* Set LED value. Without using the ::LED or ::LEDMode enum.
|
||||
* @param controller The controller to write to.
|
||||
* @param value See:
|
||||
* setLedOff(uint8_t controller), setLedOn(uint8_t controller, LED l),
|
||||
* setLedBlink(uint8_t controller, LED l), and setLedMode(uint8_t controller, LEDMode lm).
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setLedRaw(uint8_t controller, uint8_t value);
|
||||
void setLedRaw(uint8_t value, uint8_t controller = 0);
|
||||
|
||||
/**
|
||||
* Turn all LEDs off the specific controller.
|
||||
* @param controller The controller to write to.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setLedOff(uint8_t controller) {
|
||||
setLedRaw(controller, 0);
|
||||
void setLedOff(uint8_t controller = 0) {
|
||||
setLedRaw(0, controller);
|
||||
};
|
||||
/**
|
||||
* Turn on a LED by using the ::LED enum.
|
||||
* @param controller The controller to write to.
|
||||
* Turn on a LED by using the ::LED enum.
|
||||
* @param l ::LED1, ::LED2, ::LED3 and ::LED4 is supported by the Xbox controller.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setLedOn(uint8_t controller, LED l);
|
||||
void setLedOn(LED l, uint8_t controller = 0);
|
||||
/**
|
||||
* Turn on a LED by using the ::LED enum.
|
||||
* @param controller The controller to write to.
|
||||
* Turn on a LED by using the ::LED enum.
|
||||
* @param l ::ALL, ::LED1, ::LED2, ::LED3 and ::LED4 is supported by the Xbox controller.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setLedBlink(uint8_t controller, LED l);
|
||||
void setLedBlink(LED l, uint8_t controller = 0);
|
||||
/**
|
||||
* Used to set special LED modes supported by the Xbox controller.
|
||||
* @param controller The controller to write to.
|
||||
* Used to set special LED modes supported by the Xbox controller.
|
||||
* @param lm See ::LEDMode.
|
||||
* @param controller The controller to write to. Default to 0.
|
||||
*/
|
||||
void setLedMode(uint8_t controller, LEDMode lm);
|
||||
void setLedMode(LEDMode lm, uint8_t controller = 0);
|
||||
/**
|
||||
* Used to get the battery level from the controller.
|
||||
* @param controller The controller to read from.
|
||||
* @param controller The controller to read from. Default to 0.
|
||||
* @return Returns the battery level as an integer in the range of 0-3.
|
||||
*/
|
||||
uint8_t getBatteryLevel(uint8_t controller);
|
||||
uint8_t getBatteryLevel(uint8_t controller = 0);
|
||||
/**
|
||||
* Used to check if a button has changed.
|
||||
* @param controller The controller to read from.
|
||||
* @param controller The controller to read from. Default to 0.
|
||||
* @return True if a button has changed.
|
||||
*/
|
||||
bool buttonChanged(uint8_t controller);
|
||||
bool buttonChanged(uint8_t controller = 0);
|
||||
/**@}*/
|
||||
|
||||
/** True if a wireless receiver is connected. */
|
||||
|
|
|
@ -22,86 +22,86 @@ void loop() {
|
|||
if(Xbox.XboxReceiverConnected) {
|
||||
for(uint8_t i=0;i<4;i++) {
|
||||
if(Xbox.Xbox360Connected[i]) {
|
||||
if(Xbox.getButtonPress(i,L2) || Xbox.getButtonPress(i,R2)) {
|
||||
if(Xbox.getButtonPress(L2,i) || Xbox.getButtonPress(R2,i)) {
|
||||
Serial.print("L2: ");
|
||||
Serial.print(Xbox.getButtonPress(i,L2));
|
||||
Serial.print(Xbox.getButtonPress(L2,i));
|
||||
Serial.print("\tR2: ");
|
||||
Serial.println(Xbox.getButtonPress(i,R2));
|
||||
Xbox.setRumbleOn(i,Xbox.getButtonPress(i,L2),Xbox.getButtonPress(i,R2));
|
||||
Serial.println(Xbox.getButtonPress(R2,i));
|
||||
Xbox.setRumbleOn(Xbox.getButtonPress(L2,i),Xbox.getButtonPress(R2,i));
|
||||
}
|
||||
if(Xbox.getAnalogHat(i,LeftHatX) > 7500 || Xbox.getAnalogHat(i,LeftHatX) < -7500 || Xbox.getAnalogHat(i,LeftHatY) > 7500 || Xbox.getAnalogHat(i,LeftHatY) < -7500 || Xbox.getAnalogHat(i,RightHatX) > 7500 || Xbox.getAnalogHat(i,RightHatX) < -7500 || Xbox.getAnalogHat(i,RightHatY) > 7500 || Xbox.getAnalogHat(i,RightHatY) < -7500) {
|
||||
if(Xbox.getAnalogHat(i,LeftHatX) > 7500 || Xbox.getAnalogHat(i,LeftHatX) < -7500) {
|
||||
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500 || Xbox.getAnalogHat(LeftHatY,i) > 7500 || Xbox.getAnalogHat(LeftHatY,i) < -7500 || Xbox.getAnalogHat(RightHatX,i) > 7500 || Xbox.getAnalogHat(RightHatX,i) < -7500 || Xbox.getAnalogHat(RightHatY,i) > 7500 || Xbox.getAnalogHat(RightHatY,i) < -7500) {
|
||||
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500) {
|
||||
Serial.print(F("LeftHatX: "));
|
||||
Serial.print(Xbox.getAnalogHat(i,LeftHatX));
|
||||
Serial.print(Xbox.getAnalogHat(LeftHatX,i));
|
||||
Serial.print("\t");
|
||||
}
|
||||
if(Xbox.getAnalogHat(i,LeftHatY) > 7500 || Xbox.getAnalogHat(i,LeftHatY) < -7500) {
|
||||
if(Xbox.getAnalogHat(LeftHatY,i) > 7500 || Xbox.getAnalogHat(LeftHatY,i) < -7500) {
|
||||
Serial.print(F("LeftHatY: "));
|
||||
Serial.print(Xbox.getAnalogHat(i,LeftHatY));
|
||||
Serial.print(Xbox.getAnalogHat(LeftHatY,i));
|
||||
Serial.print("\t");
|
||||
}
|
||||
if(Xbox.getAnalogHat(i,RightHatX) > 7500 || Xbox.getAnalogHat(i,RightHatX) < -7500) {
|
||||
if(Xbox.getAnalogHat(RightHatX,i) > 7500 || Xbox.getAnalogHat(RightHatX,i) < -7500) {
|
||||
Serial.print(F("RightHatX: "));
|
||||
Serial.print(Xbox.getAnalogHat(i,RightHatX));
|
||||
Serial.print(Xbox.getAnalogHat(RightHatX,i));
|
||||
Serial.print("\t");
|
||||
}
|
||||
if(Xbox.getAnalogHat(i,RightHatY) > 7500 || Xbox.getAnalogHat(i,RightHatY) < -7500) {
|
||||
if(Xbox.getAnalogHat(RightHatY,i) > 7500 || Xbox.getAnalogHat(RightHatY,i) < -7500) {
|
||||
Serial.print(F("RightHatY: "));
|
||||
Serial.print(Xbox.getAnalogHat(i,RightHatY));
|
||||
Serial.print(Xbox.getAnalogHat(RightHatY,i));
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
if(Xbox.getButtonClick(i,UP)) {
|
||||
Xbox.setLedOn(i,LED1);
|
||||
if(Xbox.getButtonClick(UP,i)) {
|
||||
Xbox.setLedOn(LED1,i);
|
||||
Serial.println(F("Up"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,DOWN)) {
|
||||
Xbox.setLedOn(i,LED4);
|
||||
if(Xbox.getButtonClick(DOWN,i)) {
|
||||
Xbox.setLedOn(LED4,i);
|
||||
Serial.println(F("Down"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,LEFT)) {
|
||||
Xbox.setLedOn(i,LED3);
|
||||
if(Xbox.getButtonClick(LEFT,i)) {
|
||||
Xbox.setLedOn(LED3,i);
|
||||
Serial.println(F("Left"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,RIGHT)) {
|
||||
Xbox.setLedOn(i,LED2);
|
||||
if(Xbox.getButtonClick(RIGHT,i)) {
|
||||
Xbox.setLedOn(LED2,i);
|
||||
Serial.println(F("Right"));
|
||||
}
|
||||
|
||||
if(Xbox.getButtonClick(i,START)) {
|
||||
Xbox.setLedMode(i,ALTERNATING);
|
||||
if(Xbox.getButtonClick(START,i)) {
|
||||
Xbox.setLedMode(ALTERNATING,i);
|
||||
Serial.println(F("Start"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,BACK)) {
|
||||
Xbox.setLedBlink(i,ALL);
|
||||
if(Xbox.getButtonClick(BACK,i)) {
|
||||
Xbox.setLedBlink(ALL,i);
|
||||
Serial.println(F("Back"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,L3))
|
||||
if(Xbox.getButtonClick(L3,i))
|
||||
Serial.println(F("L3"));
|
||||
if(Xbox.getButtonClick(i,R3))
|
||||
if(Xbox.getButtonClick(R3,i))
|
||||
Serial.println(F("R3"));
|
||||
|
||||
if(Xbox.getButtonClick(i,L1))
|
||||
if(Xbox.getButtonClick(L1,i))
|
||||
Serial.println(F("L1"));
|
||||
if(Xbox.getButtonClick(i,R1))
|
||||
if(Xbox.getButtonClick(R1,i))
|
||||
Serial.println(F("R1"));
|
||||
if(Xbox.getButtonClick(i,XBOX)) {
|
||||
Xbox.setLedMode(i,ROTATING);
|
||||
if(Xbox.getButtonClick(XBOX,i)) {
|
||||
Xbox.setLedMode(ROTATING,i);
|
||||
Serial.print(F("Xbox (Battery: "));
|
||||
Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
|
||||
Serial.println(F(")"));
|
||||
}
|
||||
if(Xbox.getButtonClick(i,SYNC))
|
||||
if(Xbox.getButtonClick(SYNC,i))
|
||||
Serial.println(F("Sync"));
|
||||
|
||||
if(Xbox.getButtonClick(i,A))
|
||||
if(Xbox.getButtonClick(A,i))
|
||||
Serial.println(F("A"));
|
||||
if(Xbox.getButtonClick(i,B))
|
||||
if(Xbox.getButtonClick(B,i))
|
||||
Serial.println(F("B"));
|
||||
if(Xbox.getButtonClick(i,X))
|
||||
if(Xbox.getButtonClick(X,i))
|
||||
Serial.println(F("X"));
|
||||
if(Xbox.getButtonClick(i,Y))
|
||||
if(Xbox.getButtonClick(Y,i))
|
||||
Serial.println(F("Y"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue