Swap loop logic for new menu logic

This commit is contained in:
Reed Nightingale 2020-02-09 17:59:58 -08:00
parent e50857f181
commit b29bd955ca

View File

@ -30,6 +30,8 @@
* Si5351 object to control the clocks. * Si5351 object to control the clocks.
*/ */
#include <Wire.h> #include <Wire.h>
#include "menu.h"
#include "menu_main.h"
#include "morse.h" #include "morse.h"
#include "nano_gui.h" #include "nano_gui.h"
#include "settings.h" #include "settings.h"
@ -302,41 +304,30 @@ void checkPTT(){
} }
//check if the encoder button was pressed //check if the encoder button was pressed
void checkButton(){ static const uint8_t DEBOUNCE_DELAY_MS = 50;
//only if the button is pressed static const uint16_t LONG_PRESS_TIME_MS = 3000;
if (!btnDown()) static const uint8_t LONG_PRESS_POLL_TIME_MS = 10;
return; ButtonPress_e checkButton(){
active_delay(50); if (!btnDown()){
if (!btnDown()) //debounce return ButtonPress_e::NotPressed;
return; }
delay(DEBOUNCE_DELAY_MS);
//disengage any CAT work if (!btnDown()){//debounce
doingCAT = 0; return ButtonPress_e::NotPressed;
int downTime = 0;
while(btnDown()){
active_delay(10);
downTime++;
if (downTime > 300){
if(!globalSettings.morseMenuOn){
globalSettings.morseMenuOn = true;//set before playing
morseLetter(2);
}
else{
morseLetter(4);
globalSettings.morseMenuOn = false;//unset after playing
}
SaveSettingsToEeprom();
return;
}
} }
active_delay(100);
doCommands(); uint16_t down_time = 0;
//wait for the button to go up again while(btnDown() && (down_time < LONG_PRESS_TIME_MS)){
while(btnDown()) delay(LONG_PRESS_POLL_TIME_MS);
active_delay(10); down_time += LONG_PRESS_POLL_TIME_MS;
active_delay(50);//debounce }
if(down_time < LONG_PRESS_TIME_MS){
return ButtonPress_e::ShortPress;
}
else{
return ButtonPress_e::LongPress;
}
} }
void switchVFO(Vfo_e new_vfo){ void switchVFO(Vfo_e new_vfo){
@ -502,18 +493,17 @@ void loop(){
else if(!globalSettings.txCatActive){ else if(!globalSettings.txCatActive){
checkPTT(); checkPTT();
} }
checkButton();
//tune only when not tranmsitting
if(!globalSettings.txActive){
if(globalSettings.ritOn){
doRIT();
}
else{
doTuning();
}
checkTouch();
}
checkCAT(); checkCAT();
if(globalSettings.txActive){
//Don't run menus when transmitting
return;
}
ButtonPress_e tuner_button = checkButton();
Point touch_point;
ButtonPress_e touch_button = checkTouch(&touch_point);
int16_t knob = enc_read();
rootMenu->runMenu(tuner_button,touch_button,touch_point,knob);
} }