diff --git a/button_press_e.h b/button_press_e.h new file mode 100644 index 0000000..9147d4b --- /dev/null +++ b/button_press_e.h @@ -0,0 +1,7 @@ +#pragma once + +enum ButtonPress_e : uint8_t { + NotPressed, + ShortPress, + LongPress +}; diff --git a/menu.h b/menu.h index 82a755e..ef46054 100644 --- a/menu.h +++ b/menu.h @@ -1,6 +1,7 @@ #pragma once #include +#include "button_press_e.h" #include "point.h" enum MenuReturn_e : uint8_t { @@ -9,12 +10,6 @@ enum MenuReturn_e : uint8_t { ExitedNoRedraw }; -enum ButtonPress_e : uint8_t { - NotPressed, - ShortPress, - LongPress -}; - struct Menu_t { void (*const initMenu)();//Any initial draw routines or state initialization MenuReturn_e (*const runMenu)(const ButtonPress_e tuner_button, diff --git a/push_button.cpp b/push_button.cpp index 41f8457..fb34813 100644 --- a/push_button.cpp +++ b/push_button.cpp @@ -1,4 +1,5 @@ #include +#include "button_timing.h" #include "pin_definitions.h" #include "push_button.h" @@ -8,3 +9,26 @@ bool IsButtonPressed() //and reads low when pressed down return !digitalRead(PIN_ENC_PUSH_BUTTON); } + +ButtonPress_e CheckTunerButton(){ + if (!IsButtonPressed()){ + return ButtonPress_e::NotPressed; + } + delay(DEBOUNCE_DELAY_MS); + if (!IsButtonPressed()){//debounce + return ButtonPress_e::NotPressed; + } + + uint16_t down_time = 0; + while(IsButtonPressed() && (down_time < LONG_PRESS_TIME_MS)){ + delay(LONG_PRESS_POLL_TIME_MS); + down_time += LONG_PRESS_POLL_TIME_MS; + } + + if(down_time < LONG_PRESS_TIME_MS){ + return ButtonPress_e::ShortPress; + } + else{ + return ButtonPress_e::LongPress; + } +} diff --git a/push_button.h b/push_button.h index 27ff54f..c83a173 100644 --- a/push_button.h +++ b/push_button.h @@ -1,3 +1,5 @@ #pragma once -bool IsButtonPressed(); //returns true if the encoder button is pressed +#include "button_press_e.h" + +ButtonPress_e CheckTunerButton(); diff --git a/ubitxv6.ino b/ubitxv6.ino index a152ad3..f3d1594 100644 --- a/ubitxv6.ino +++ b/ubitxv6.ino @@ -30,7 +30,6 @@ * Si5351 object to control the clocks. */ #include -#include "button_timing.h" #include "encoder.h" #include "menu.h" #include "menu_main.h" @@ -86,30 +85,6 @@ void checkPTT(){ stopTx(); } -//check if the encoder button was pressed -ButtonPress_e checkButton(){ - if (!IsButtonPressed()){ - return ButtonPress_e::NotPressed; - } - delay(DEBOUNCE_DELAY_MS); - if (!IsButtonPressed()){//debounce - return ButtonPress_e::NotPressed; - } - - uint16_t down_time = 0; - while(IsButtonPressed() && (down_time < LONG_PRESS_TIME_MS)){ - delay(LONG_PRESS_POLL_TIME_MS); - down_time += LONG_PRESS_POLL_TIME_MS; - } - - if(down_time < LONG_PRESS_TIME_MS){ - return ButtonPress_e::ShortPress; - } - else{ - return ButtonPress_e::LongPress; - } -} - /** * The settings are read from EEPROM. The first time around, the values may not be * present or out of range, in this case, some intelligent defaults are copied into the @@ -167,7 +142,7 @@ void setup() setFrequency(globalSettings.vfoA.frequency); //Run initial calibration routine if button is pressed during power up - if(IsButtonPressed()){ + if(ButtonPress_e::NotPressed != CheckTunerButton()){ LoadDefaultSettings(); setupTouch(); SetActiveVfoMode(VfoMode_e::VFO_MODE_USB); @@ -201,7 +176,7 @@ void loop(){ return; } - ButtonPress_e tuner_button = checkButton(); + ButtonPress_e tuner_button = CheckTunerButton(); Point touch_point; ButtonPress_e touch_button = checkTouch(&touch_point); int16_t knob = enc_read();