Added buttonChanged

This commit is contained in:
Kristian Sloth Lauszus 2013-01-08 08:16:01 +01:00
parent afb87bb457
commit 4c2a97e424
3 changed files with 14 additions and 11 deletions

View file

@ -352,6 +352,7 @@ void XBOXRECV::readReport(uint8_t controller) {
//PrintHex<uint32_t>(ButtonState[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
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;
@ -404,6 +405,11 @@ bool XBOXRECV::getButtonClick(uint8_t controller, Button b) {
int16_t XBOXRECV::getAnalogHat(uint8_t controller, AnalogHat a) {
return hatValue[controller][a];
}
bool XBOXRECV::buttonChanged(uint8_t controller) {
bool state = buttonStateChanged[controller];
buttonStateChanged[controller] = false;
return state;
}
/*
ControllerStatus Breakdown
ControllerStatus[controller] & 0x0001 // 0
@ -424,16 +430,10 @@ ControllerStatus Breakdown
ControllerStatus[controller] & 0x8000 // 0
*/
uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x3)
return 100;
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x2)
return 67;
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x1)
return 33;
else if(((controllerStatus[controller] & 0x00C0) >> 6) == 0x0)
return 0;
else
return -1;
uint8_t batteryLevel = ((controllerStatus[controller] & 0x00C0) >> 6) * 33;
if(batteryLevel == 99)
batteryLevel = 100;
return batteryLevel;
}
void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {

View file

@ -131,7 +131,8 @@ public:
void setLedOn(uint8_t controller, LED l);
void setLedBlink(uint8_t controller, LED l);
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
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];
int16_t hatValue[4][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 R2Clicked[4];

View file

@ -165,6 +165,7 @@ setLedRaw KEYWORD2
setLedBlink KEYWORD2
setLedMode KEYWORD2
getBatteryLevel KEYWORD2
buttonChanged KEYWORD2
XboxReceiverConnected KEYWORD2
Xbox360Connected KEYWORD2