mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added buttonChanged
This commit is contained in:
parent
afb87bb457
commit
4c2a97e424
3 changed files with 14 additions and 11 deletions
20
XBOXRECV.cpp
20
XBOXRECV.cpp
|
@ -352,6 +352,7 @@ void XBOXRECV::readReport(uint8_t controller) {
|
||||||
//PrintHex<uint32_t>(ButtonState[controller]);
|
//PrintHex<uint32_t>(ButtonState[controller]);
|
||||||
|
|
||||||
if(ButtonState[controller] != OldButtonState[controller]) {
|
if(ButtonState[controller] != OldButtonState[controller]) {
|
||||||
|
buttonStateChanged[controller] = true;
|
||||||
ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
|
ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
|
||||||
if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
|
if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
|
||||||
R2Clicked[controller] = true;
|
R2Clicked[controller] = true;
|
||||||
|
@ -404,6 +405,11 @@ bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
|
||||||
int16_t XBOXRECV::getAnalogHat(uint8_t controller, AnalogHat a) {
|
int16_t XBOXRECV::getAnalogHat(uint8_t controller, AnalogHat a) {
|
||||||
return hatValue[controller][a];
|
return hatValue[controller][a];
|
||||||
}
|
}
|
||||||
|
bool XBOXRECV::buttonChanged(uint8_t controller) {
|
||||||
|
bool state = buttonStateChanged[controller];
|
||||||
|
buttonStateChanged[controller] = false;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
ControllerStatus Breakdown
|
ControllerStatus Breakdown
|
||||||
ControllerStatus[controller] & 0x0001 // 0
|
ControllerStatus[controller] & 0x0001 // 0
|
||||||
|
@ -424,16 +430,10 @@ ControllerStatus Breakdown
|
||||||
ControllerStatus[controller] & 0x8000 // 0
|
ControllerStatus[controller] & 0x8000 // 0
|
||||||
*/
|
*/
|
||||||
uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
|
uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
|
||||||
if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x3)
|
uint8_t batteryLevel = ((controllerStatus[controller] & 0x00C0) >> 6) * 33;
|
||||||
return 100;
|
if(batteryLevel == 99)
|
||||||
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x2)
|
batteryLevel = 100;
|
||||||
return 67;
|
return batteryLevel;
|
||||||
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x1)
|
|
||||||
return 33;
|
|
||||||
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x0)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
|
void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
|
||||||
|
|
|
@ -131,7 +131,8 @@ public:
|
||||||
void setLedOn(uint8_t controller, LED l);
|
void setLedOn(uint8_t controller, LED l);
|
||||||
void setLedBlink(uint8_t controller, LED l);
|
void setLedBlink(uint8_t controller, LED l);
|
||||||
void setLedMode(uint8_t controller, LEDMode lm);
|
void setLedMode(uint8_t controller, LEDMode lm);
|
||||||
uint8_t getBatteryLevel(uint8_t controller); // Returns the battery level in percentage in 25% steps
|
uint8_t getBatteryLevel(uint8_t controller); // Returns the battery level in percentage in 33% steps
|
||||||
|
bool buttonChanged(uint8_t controller);
|
||||||
|
|
||||||
bool XboxReceiverConnected; // True if a wireless receiver is connected
|
bool XboxReceiverConnected; // True if a wireless receiver is connected
|
||||||
uint8_t Xbox360Connected[4]; // Variable used to indicate if the XBOX 360 controller is successfully connected
|
uint8_t Xbox360Connected[4]; // Variable used to indicate if the XBOX 360 controller is successfully connected
|
||||||
|
@ -151,6 +152,7 @@ private:
|
||||||
uint16_t ButtonClickState[4];
|
uint16_t ButtonClickState[4];
|
||||||
int16_t hatValue[4][4];
|
int16_t hatValue[4][4];
|
||||||
uint16_t controllerStatus[4];
|
uint16_t controllerStatus[4];
|
||||||
|
bool buttonStateChanged[4]; // True if a button has changed
|
||||||
|
|
||||||
bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
|
bool L2Clicked[4]; // These buttons are analog, so we use we use these bools to check if they where clicked or not
|
||||||
bool R2Clicked[4];
|
bool R2Clicked[4];
|
||||||
|
|
|
@ -165,6 +165,7 @@ setLedRaw KEYWORD2
|
||||||
setLedBlink KEYWORD2
|
setLedBlink KEYWORD2
|
||||||
setLedMode KEYWORD2
|
setLedMode KEYWORD2
|
||||||
getBatteryLevel KEYWORD2
|
getBatteryLevel KEYWORD2
|
||||||
|
buttonChanged KEYWORD2
|
||||||
|
|
||||||
XboxReceiverConnected KEYWORD2
|
XboxReceiverConnected KEYWORD2
|
||||||
Xbox360Connected KEYWORD2
|
Xbox360Connected KEYWORD2
|
||||||
|
|
Loading…
Reference in a new issue