mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Better getButtonClick routine
This commit is contained in:
parent
bf646fdd0e
commit
75a84c5e80
3 changed files with 17 additions and 32 deletions
|
@ -359,9 +359,10 @@ void PS3BT::ACLData(uint8_t* ACLData) {
|
||||||
//Notify(PSTR("\r\nButtonState");
|
//Notify(PSTR("\r\nButtonState");
|
||||||
//PrintHex<uint32_t>(ButtonState);
|
//PrintHex<uint32_t>(ButtonState);
|
||||||
|
|
||||||
if(ButtonState != OldButtonState)
|
if(ButtonState != OldButtonState) {
|
||||||
ButtonClickState = ButtonState;
|
ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
|
||||||
OldButtonState = ButtonState;
|
OldButtonState = ButtonState;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
|
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
|
||||||
for(uint8_t i = 10; i < 58;i++) {
|
for(uint8_t i = 10; i < 58;i++) {
|
||||||
|
|
|
@ -308,10 +308,11 @@ void PS3USB::readReport() {
|
||||||
//Notify(PSTR("\r\nButtonState");
|
//Notify(PSTR("\r\nButtonState");
|
||||||
//PrintHex<uint32_t>(ButtonState);
|
//PrintHex<uint32_t>(ButtonState);
|
||||||
|
|
||||||
if(ButtonState != OldButtonState)
|
if(ButtonState != OldButtonState) {
|
||||||
ButtonClickState = ButtonState; // Update click state variable
|
ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
|
||||||
OldButtonState = ButtonState;
|
OldButtonState = ButtonState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
|
void PS3USB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
|
||||||
if (readBuf == NULL)
|
if (readBuf == NULL)
|
||||||
|
|
29
Wii.cpp
29
Wii.cpp
|
@ -165,11 +165,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
||||||
if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus
|
if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus
|
||||||
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
|
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
|
||||||
else if (nunchuckConnected) // Update if it's a report from the Nunchuck
|
else if (nunchuckConnected) // Update if it's a report from the Nunchuck
|
||||||
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(l2capinbuf[20] & 0x0C) << 14));
|
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14));
|
||||||
//else if(classicControllerConnected) // Update if it's a report from the Classic Controller
|
//else if(classicControllerConnected) // Update if it's a report from the Classic Controller
|
||||||
}
|
}
|
||||||
else if(nunchuckConnected) // The Nunchuck is directly connected
|
else if(nunchuckConnected) // The Nunchuck is directly connected
|
||||||
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(l2capinbuf[20] & 0x03) << 16));
|
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x03) << 16));
|
||||||
//else if(classicControllerConnected) // The Classic Controller is directly connected
|
//else if(classicControllerConnected) // The Classic Controller is directly connected
|
||||||
else if(!unknownExtensionConnected)
|
else if(!unknownExtensionConnected)
|
||||||
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
|
ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
|
||||||
|
@ -178,10 +178,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
||||||
PrintHex<uint32_t>(ButtonState);
|
PrintHex<uint32_t>(ButtonState);
|
||||||
Notify(PSTR("\r\n"));
|
Notify(PSTR("\r\n"));
|
||||||
#endif
|
#endif
|
||||||
if(ButtonState != OldButtonState)
|
if(ButtonState != OldButtonState) {
|
||||||
ButtonClickState = ButtonState; // Update click state variable
|
ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
|
||||||
OldButtonState = ButtonState;
|
OldButtonState = ButtonState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x35) { // Read the accelerometer
|
if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x35) { // Read the accelerometer
|
||||||
accX = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5))-500;
|
accX = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5))-500;
|
||||||
accY = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4))-500;
|
accY = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4))-500;
|
||||||
|
@ -249,11 +250,6 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
||||||
activateNunchuck = false;
|
activateNunchuck = false;
|
||||||
motionPlusConnected = true;
|
motionPlusConnected = true;
|
||||||
nunchuckConnected = true;
|
nunchuckConnected = true;
|
||||||
|
|
||||||
ButtonState |= (Z | C);
|
|
||||||
ButtonState |= ((Z | C)<<2);
|
|
||||||
ButtonClickState = ButtonState;
|
|
||||||
OldButtonState = ButtonState;
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
else {
|
else {
|
||||||
|
@ -570,13 +566,8 @@ void WII::Run() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L2CAP_LED_STATE:
|
case L2CAP_LED_STATE:
|
||||||
if(nunchuck_connected_flag) {
|
if(nunchuck_connected_flag)
|
||||||
nunchuckConnected = true;
|
nunchuckConnected = true;
|
||||||
ButtonState |= (Z | C); // Since the Nunchuck button are cleared when pressed we set the buttonstates like so
|
|
||||||
ButtonState |= ((Z | C)<<2); // And like this when it's connected since the bytes are shifter two to the left
|
|
||||||
ButtonClickState = ButtonState;
|
|
||||||
OldButtonState = ButtonState;
|
|
||||||
}
|
|
||||||
setLedOn(LED1);
|
setLedOn(LED1);
|
||||||
l2cap_state = L2CAP_DONE;
|
l2cap_state = L2CAP_DONE;
|
||||||
break;
|
break;
|
||||||
|
@ -606,10 +597,6 @@ void WII::Run() {
|
||||||
#endif
|
#endif
|
||||||
activateNunchuck = true;
|
activateNunchuck = true;
|
||||||
nunchuckConnected = true;
|
nunchuckConnected = true;
|
||||||
ButtonState |= (Z | C); // Since the Nunchuck button are cleared when pressed we set the buttonstates like so
|
|
||||||
ButtonState |= ((Z | C)<<2); // And like this when it's connected since the bytes are shifter two to the left
|
|
||||||
ButtonClickState = ButtonState;
|
|
||||||
OldButtonState = ButtonState;
|
|
||||||
}
|
}
|
||||||
if(!motionPlusConnected)
|
if(!motionPlusConnected)
|
||||||
stateCounter = 449;
|
stateCounter = 449;
|
||||||
|
@ -792,10 +779,6 @@ bool WII::getButtonPress(Button b) { // Return true when a button is pressed
|
||||||
}
|
}
|
||||||
bool WII::getButtonClick(Button b) { // Only return true when a button is clicked
|
bool WII::getButtonClick(Button b) { // Only return true when a button is clicked
|
||||||
bool click = (ButtonClickState & (uint32_t)b);
|
bool click = (ButtonClickState & (uint32_t)b);
|
||||||
if(b == Z || b == C) {
|
|
||||||
click = !click; // The nunchuck buttons are cleared when pressed
|
|
||||||
ButtonClickState |= (uint32_t)b; // clear "click" event
|
|
||||||
} else
|
|
||||||
ButtonClickState &= ~((uint32_t)b); // clear "click" event
|
ButtonClickState &= ~((uint32_t)b); // clear "click" event
|
||||||
return click;
|
return click;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue