diff --git a/morse.cpp b/morse.cpp index b1d5586..b8c2b20 100644 --- a/morse.cpp +++ b/morse.cpp @@ -1,5 +1,6 @@ #include //tone +#include "encoder.h" #include "morse.h" #include "pin_definitions.h" #include "settings.h" diff --git a/pin_definitions.h b/pin_definitions.h index 18e7dce..a1521ad 100644 --- a/pin_definitions.h +++ b/pin_definitions.h @@ -43,7 +43,3 @@ static const uint8_t PIN_CW_KEY = 2; // Pin goes high during CW keydow // ...key can be up within a tx period //1 is UART RX //0 is UART TX - -int enc_read(void); // returns the number of ticks in a short interval, +ve in clockwise, -ve in anti-clockwise -void enc_setup(void); // Setups up initial values and interrupts. -int btnDown(); //returns true if the encoder button is pressed diff --git a/push_button.cpp b/push_button.cpp new file mode 100644 index 0000000..41f8457 --- /dev/null +++ b/push_button.cpp @@ -0,0 +1,10 @@ +#include +#include "pin_definitions.h" +#include "push_button.h" + +bool IsButtonPressed() +{ + //Button has a pullup, so it reads high normally, + //and reads low when pressed down + return !digitalRead(PIN_ENC_PUSH_BUTTON); +} diff --git a/push_button.h b/push_button.h new file mode 100644 index 0000000..27ff54f --- /dev/null +++ b/push_button.h @@ -0,0 +1,3 @@ +#pragma once + +bool IsButtonPressed(); //returns true if the encoder button is pressed diff --git a/setup.cpp b/setup.cpp index 679f127..6c7a0f4 100644 --- a/setup.cpp +++ b/setup.cpp @@ -1,5 +1,6 @@ #include #include "colors.h" +#include "encoder.h" #include "menu.h" #include "morse.h" #include "nano_gui.h" diff --git a/tmp.cpp b/tmp.cpp index 2c0d556..1adaa49 100644 --- a/tmp.cpp +++ b/tmp.cpp @@ -1,12 +1,3 @@ -#include -#include "pin_definitions.h" - void updateDisplay() {} void redrawVFOs(){} void drawTx(){} -int btnDown() -{ - //Button has a pullup, so it reads high normally, - //and reads low when pressed down - return !digitalRead(PIN_ENC_PUSH_BUTTON); -} \ No newline at end of file diff --git a/ubitxv6.ino b/ubitxv6.ino index 075ef9d..a152ad3 100644 --- a/ubitxv6.ino +++ b/ubitxv6.ino @@ -31,10 +31,12 @@ */ #include #include "button_timing.h" +#include "encoder.h" #include "menu.h" #include "menu_main.h" #include "morse.h" #include "pin_definitions.h" +#include "push_button.h" #include "nano_gui.h" #include "settings.h" #include "setup.h" @@ -86,16 +88,16 @@ void checkPTT(){ //check if the encoder button was pressed ButtonPress_e checkButton(){ - if (!btnDown()){ + if (!IsButtonPressed()){ return ButtonPress_e::NotPressed; } delay(DEBOUNCE_DELAY_MS); - if (!btnDown()){//debounce + if (!IsButtonPressed()){//debounce return ButtonPress_e::NotPressed; } uint16_t down_time = 0; - while(btnDown() && (down_time < LONG_PRESS_TIME_MS)){ + while(IsButtonPressed() && (down_time < LONG_PRESS_TIME_MS)){ delay(LONG_PRESS_POLL_TIME_MS); down_time += LONG_PRESS_POLL_TIME_MS; } @@ -165,7 +167,7 @@ void setup() setFrequency(globalSettings.vfoA.frequency); //Run initial calibration routine if button is pressed during power up - if(btnDown()){ + if(IsButtonPressed()){ LoadDefaultSettings(); setupTouch(); SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);