Move button pressing logic to it's own file
This commit is contained in:
parent
5596c0c8ab
commit
8af59b0a85
7
button_press_e.h
Normal file
7
button_press_e.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum ButtonPress_e : uint8_t {
|
||||||
|
NotPressed,
|
||||||
|
ShortPress,
|
||||||
|
LongPress
|
||||||
|
};
|
7
menu.h
7
menu.h
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "button_press_e.h"
|
||||||
#include "point.h"
|
#include "point.h"
|
||||||
|
|
||||||
enum MenuReturn_e : uint8_t {
|
enum MenuReturn_e : uint8_t {
|
||||||
@ -9,12 +10,6 @@ enum MenuReturn_e : uint8_t {
|
|||||||
ExitedNoRedraw
|
ExitedNoRedraw
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ButtonPress_e : uint8_t {
|
|
||||||
NotPressed,
|
|
||||||
ShortPress,
|
|
||||||
LongPress
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Menu_t {
|
struct Menu_t {
|
||||||
void (*const initMenu)();//Any initial draw routines or state initialization
|
void (*const initMenu)();//Any initial draw routines or state initialization
|
||||||
MenuReturn_e (*const runMenu)(const ButtonPress_e tuner_button,
|
MenuReturn_e (*const runMenu)(const ButtonPress_e tuner_button,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "button_timing.h"
|
||||||
#include "pin_definitions.h"
|
#include "pin_definitions.h"
|
||||||
#include "push_button.h"
|
#include "push_button.h"
|
||||||
|
|
||||||
@ -8,3 +9,26 @@ bool IsButtonPressed()
|
|||||||
//and reads low when pressed down
|
//and reads low when pressed down
|
||||||
return !digitalRead(PIN_ENC_PUSH_BUTTON);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
bool IsButtonPressed(); //returns true if the encoder button is pressed
|
#include "button_press_e.h"
|
||||||
|
|
||||||
|
ButtonPress_e CheckTunerButton();
|
||||||
|
29
ubitxv6.ino
29
ubitxv6.ino
@ -30,7 +30,6 @@
|
|||||||
* Si5351 object to control the clocks.
|
* Si5351 object to control the clocks.
|
||||||
*/
|
*/
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "button_timing.h"
|
|
||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "menu_main.h"
|
#include "menu_main.h"
|
||||||
@ -86,30 +85,6 @@ void checkPTT(){
|
|||||||
stopTx();
|
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
|
* 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
|
* 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);
|
setFrequency(globalSettings.vfoA.frequency);
|
||||||
|
|
||||||
//Run initial calibration routine if button is pressed during power up
|
//Run initial calibration routine if button is pressed during power up
|
||||||
if(IsButtonPressed()){
|
if(ButtonPress_e::NotPressed != CheckTunerButton()){
|
||||||
LoadDefaultSettings();
|
LoadDefaultSettings();
|
||||||
setupTouch();
|
setupTouch();
|
||||||
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
|
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
|
||||||
@ -201,7 +176,7 @@ void loop(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPress_e tuner_button = checkButton();
|
ButtonPress_e tuner_button = CheckTunerButton();
|
||||||
Point touch_point;
|
Point touch_point;
|
||||||
ButtonPress_e touch_button = checkTouch(&touch_point);
|
ButtonPress_e touch_button = checkTouch(&touch_point);
|
||||||
int16_t knob = enc_read();
|
int16_t knob = enc_read();
|
||||||
|
Loading…
Reference in New Issue
Block a user