mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Merge branch 'dev' into ticktype
This commit is contained in:
@@ -23,6 +23,7 @@ ButtonState getButtonState() {
|
|||||||
* (downtime>filter)
|
* (downtime>filter)
|
||||||
*/
|
*/
|
||||||
static uint8_t previousState = 0;
|
static uint8_t previousState = 0;
|
||||||
|
static bool longPressed = false;
|
||||||
static TickType_t previousStateChange = 0;
|
static TickType_t previousStateChange = 0;
|
||||||
const TickType_t timeout = TICKS_100MS * 4;
|
const TickType_t timeout = TICKS_100MS * 4;
|
||||||
uint8_t currentState;
|
uint8_t currentState;
|
||||||
@@ -34,9 +35,10 @@ ButtonState getButtonState() {
|
|||||||
if (currentState == previousState) {
|
if (currentState == previousState) {
|
||||||
if (currentState == 0)
|
if (currentState == 0)
|
||||||
return BUTTON_NONE;
|
return BUTTON_NONE;
|
||||||
if ((xTaskGetTickCount() - previousStateChange) > timeout) {
|
if ((xTaskGetTickCount() - previousStateChange) >= timeout) {
|
||||||
// User has been holding the button down
|
// User has been holding the button down
|
||||||
// We want to send a button is held message
|
// We want to send a button is held message
|
||||||
|
longPressed = true;
|
||||||
if (currentState == 0x01)
|
if (currentState == 0x01)
|
||||||
return BUTTON_F_LONG;
|
return BUTTON_F_LONG;
|
||||||
else if (currentState == 0x02)
|
else if (currentState == 0x02)
|
||||||
@@ -50,19 +52,15 @@ ButtonState getButtonState() {
|
|||||||
ButtonState retVal = BUTTON_NONE;
|
ButtonState retVal = BUTTON_NONE;
|
||||||
if (currentState) {
|
if (currentState) {
|
||||||
// User has pressed a button down (nothing done on down)
|
// User has pressed a button down (nothing done on down)
|
||||||
if (currentState != previousState) {
|
// If there is a rising edge on one of the buttons from double press we
|
||||||
// There has been a change in the button states
|
// want to mask that out As users are having issues with not release
|
||||||
// If there is a rising edge on one of the buttons from double press we
|
// both at once
|
||||||
// want to mask that out As users are having issues with not release
|
previousState |= currentState;
|
||||||
// both at once
|
|
||||||
if (previousState == 0x03)
|
|
||||||
currentState = 0x03;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// User has released buttons
|
// User has released buttons
|
||||||
// If they previously had the buttons down we want to check if they were <
|
// If they previously had the buttons down we want to check if they were <
|
||||||
// long hold and trigger a press
|
// long hold and trigger a press
|
||||||
if ((xTaskGetTickCount() - previousStateChange) < timeout) {
|
if (!longPressed) {
|
||||||
// The user didn't hold the button for long
|
// The user didn't hold the button for long
|
||||||
// So we send button press
|
// So we send button press
|
||||||
|
|
||||||
@@ -73,8 +71,9 @@ ButtonState getButtonState() {
|
|||||||
else
|
else
|
||||||
retVal = BUTTON_BOTH; // Both being held case
|
retVal = BUTTON_BOTH; // Both being held case
|
||||||
}
|
}
|
||||||
|
previousState = 0;
|
||||||
|
longPressed = false;
|
||||||
}
|
}
|
||||||
previousState = currentState;
|
|
||||||
previousStateChange = xTaskGetTickCount();
|
previousStateChange = xTaskGetTickCount();
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user