mirror of https://github.com/sqfmi/Watchy.git
Fix button handling in fast menu
parent
c5c83300da
commit
558e0cf209
196
src/Watchy.cpp
196
src/Watchy.cpp
|
@ -113,71 +113,13 @@ void Watchy::_rtcConfig(String datetime){
|
||||||
|
|
||||||
void Watchy::handleButtonPress(){
|
void Watchy::handleButtonPress(){
|
||||||
uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status();
|
uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status();
|
||||||
//Menu Button
|
|
||||||
if (wakeupBit & MENU_BTN_MASK) {
|
|
||||||
if (guiState == WATCHFACE_STATE) {//enter menu state if coming from watch face
|
|
||||||
showMenu(menuIndex, false);
|
|
||||||
} else if (guiState == MAIN_MENU_STATE) {//if already in menu, then select menu item
|
|
||||||
switch(menuIndex) {
|
|
||||||
case 0:
|
|
||||||
showBattery();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
showBuzz();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
showAccelerometer();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
setTime();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
setupWifi();
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
showUpdateFW();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if(guiState == FW_UPDATE_STATE) {
|
|
||||||
updateFWBegin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Back Button
|
|
||||||
else if (wakeupBit & BACK_BTN_MASK) {
|
|
||||||
if (guiState == MAIN_MENU_STATE) {//exit to watch face if already in menu
|
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
|
||||||
RTC.read(currentTime);
|
|
||||||
showWatchFace(false);
|
|
||||||
} else if (guiState == APP_STATE) {
|
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
|
||||||
} else if (guiState == FW_UPDATE_STATE) {
|
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Up Button
|
|
||||||
else if (wakeupBit & UP_BTN_MASK) {
|
|
||||||
if(guiState == MAIN_MENU_STATE) {//increment menu index
|
|
||||||
menuIndex--;
|
|
||||||
if(menuIndex < 0){
|
|
||||||
menuIndex = MENU_LENGTH - 1;
|
|
||||||
}
|
|
||||||
showMenu(menuIndex, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Down Button
|
|
||||||
else if (wakeupBit & DOWN_BTN_MASK) {
|
|
||||||
if(guiState == MAIN_MENU_STATE){//decrement menu index
|
|
||||||
menuIndex++;
|
|
||||||
if(menuIndex > MENU_LENGTH - 1) {
|
|
||||||
menuIndex = 0;
|
|
||||||
}
|
|
||||||
showMenu(menuIndex, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************** fast menu *****************/
|
// Initially button press state is populated by the wakup
|
||||||
|
bool menu_pressed = wakeupBit & MENU_BTN_MASK;
|
||||||
|
bool back_pressed = wakeupBit & BACK_BTN_MASK;
|
||||||
|
bool up_pressed = wakeupBit & UP_BTN_MASK;
|
||||||
|
bool down_pressed = wakeupBit & DOWN_BTN_MASK;
|
||||||
|
|
||||||
bool timeout = false;
|
bool timeout = false;
|
||||||
long lastTimeout = millis();
|
long lastTimeout = millis();
|
||||||
pinMode(MENU_BTN_PIN, INPUT);
|
pinMode(MENU_BTN_PIN, INPUT);
|
||||||
|
@ -185,69 +127,79 @@ void Watchy::handleButtonPress(){
|
||||||
pinMode(UP_BTN_PIN, INPUT);
|
pinMode(UP_BTN_PIN, INPUT);
|
||||||
pinMode(DOWN_BTN_PIN, INPUT);
|
pinMode(DOWN_BTN_PIN, INPUT);
|
||||||
while(!timeout) {
|
while(!timeout) {
|
||||||
if (millis() - lastTimeout > 5000) {
|
if (menu_pressed) {
|
||||||
timeout = true;
|
if (guiState == WATCHFACE_STATE) {
|
||||||
} else {
|
showMenu(menuIndex, false);
|
||||||
if (digitalRead(MENU_BTN_PIN) == 1) {
|
} else if (guiState == MAIN_MENU_STATE) {
|
||||||
lastTimeout = millis();
|
switch(menuIndex) {
|
||||||
if (guiState == MAIN_MENU_STATE) {//if already in menu, then select menu item
|
case 0:
|
||||||
switch(menuIndex) {
|
showBattery();
|
||||||
case 0:
|
break;
|
||||||
showBattery();
|
case 1:
|
||||||
break;
|
showBuzz();
|
||||||
case 1:
|
break;
|
||||||
showBuzz();
|
case 2:
|
||||||
break;
|
showAccelerometer();
|
||||||
case 2:
|
break;
|
||||||
showAccelerometer();
|
case 3:
|
||||||
break;
|
setTime();
|
||||||
case 3:
|
break;
|
||||||
setTime();
|
case 4:
|
||||||
break;
|
setupWifi();
|
||||||
case 4:
|
break;
|
||||||
setupWifi();
|
case 5:
|
||||||
break;
|
showUpdateFW();
|
||||||
case 5:
|
break;
|
||||||
showUpdateFW();
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (guiState == FW_UPDATE_STATE) {
|
|
||||||
updateFWBegin();
|
|
||||||
}
|
}
|
||||||
} else if (digitalRead(BACK_BTN_PIN) == 1) {
|
} else if (guiState == FW_UPDATE_STATE) {
|
||||||
lastTimeout = millis();
|
updateFWBegin();
|
||||||
if (guiState == MAIN_MENU_STATE) {//exit to watch face if already in menu
|
}
|
||||||
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
} else if (back_pressed) {
|
||||||
RTC.read(currentTime);
|
if (guiState == MAIN_MENU_STATE) {//exit to watch face if already in menu
|
||||||
showWatchFace(false);
|
RTC.alarm(ALARM_2); //resets the alarm flag in the RTC
|
||||||
break; //leave loop
|
RTC.read(currentTime);
|
||||||
} else if (guiState == APP_STATE) {
|
showWatchFace(false);
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
break; // leave menu, go back to sleep
|
||||||
} else if (guiState == FW_UPDATE_STATE) {
|
} else if (guiState == APP_STATE) {
|
||||||
showMenu(menuIndex, false);//exit to menu if already in app
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
|
} else if (guiState == FW_UPDATE_STATE) {
|
||||||
|
showMenu(menuIndex, false);//exit to menu if already in app
|
||||||
|
}
|
||||||
|
} else if (up_pressed) {
|
||||||
|
if (guiState == MAIN_MENU_STATE) {//increment menu index
|
||||||
|
menuIndex--;
|
||||||
|
if (menuIndex < 0) {
|
||||||
|
menuIndex = MENU_LENGTH - 1;
|
||||||
}
|
}
|
||||||
} else if (digitalRead(UP_BTN_PIN) == 1) {
|
showMenu(menuIndex, true);
|
||||||
lastTimeout = millis();
|
}
|
||||||
if (guiState == MAIN_MENU_STATE) {//increment menu index
|
} else if (down_pressed) {
|
||||||
menuIndex--;
|
if(guiState == MAIN_MENU_STATE){//decrement menu index
|
||||||
if(menuIndex < 0){
|
menuIndex++;
|
||||||
menuIndex = MENU_LENGTH - 1;
|
if (menuIndex > MENU_LENGTH - 1) {
|
||||||
}
|
menuIndex = 0;
|
||||||
showFastMenu(menuIndex);
|
|
||||||
}
|
|
||||||
} else if (digitalRead(DOWN_BTN_PIN) == 1) {
|
|
||||||
lastTimeout = millis();
|
|
||||||
if (guiState == MAIN_MENU_STATE) {//decrement menu index
|
|
||||||
menuIndex++;
|
|
||||||
if (menuIndex > MENU_LENGTH - 1) {
|
|
||||||
menuIndex = 0;
|
|
||||||
}
|
|
||||||
showFastMenu(menuIndex);
|
|
||||||
}
|
}
|
||||||
|
showMenu(menuIndex, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If any button is pressed, reset the timeout
|
||||||
|
// Go back to sleep after 5 seconds if no button is pressed
|
||||||
|
if (menu_pressed || back_pressed || up_pressed || down_pressed) {
|
||||||
|
lastTimeout = millis();
|
||||||
|
} else {
|
||||||
|
if (millis() - lastTimeout > 5000) {
|
||||||
|
timeout = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query new button state
|
||||||
|
menu_pressed = digitalRead(MENU_BTN_PIN);
|
||||||
|
back_pressed = digitalRead(BACK_BTN_PIN);
|
||||||
|
up_pressed = digitalRead(UP_BTN_PIN);
|
||||||
|
down_pressed = digitalRead(DOWN_BTN_PIN);
|
||||||
}
|
}
|
||||||
display.hibernate();
|
display.hibernate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue