controller-lib
controller-lib copied to clipboard
Detecting if an individual button has been released.
Is there any way to determine if an individual button has been released? The way I understand it you can only handle when no button is being pressed ie the user isn't touching the view.
Cache the old value and check if it changed:
static uint32_t oldButtonValues = 0;
void buttonCallback(uint32_t newButtonValues){
for(uint8_t shift = 0; shift < 32; shift++){
if(oldButtonValues & (1 << shift) && !(newButtonValues & (1 << shift))){
//released
}
else if(!(oldButtonValues & (1 << shift)) && newButtonValues & (1 << shift)){
//pressed
}
}
oldButtonValues = newButtonValues;
}
Convert to Java as needed. The onInputEvent is likely called whenever a finger is pressed released or moved.