2020-02-09 22:10:32 +00:00
|
|
|
#include "menu_main.h"
|
2020-02-10 05:14:43 +00:00
|
|
|
#include "menu_main_buttons.h"
|
2020-02-09 22:10:32 +00:00
|
|
|
|
2020-02-09 23:56:43 +00:00
|
|
|
#include <avr/pgmspace.h>
|
2020-02-10 01:09:46 +00:00
|
|
|
#include <Arduino.h>
|
2020-02-09 23:56:43 +00:00
|
|
|
|
2020-04-26 02:46:36 +00:00
|
|
|
#include "button_grid.h"
|
2020-02-10 05:14:43 +00:00
|
|
|
#include "color_theme.h"
|
2020-02-10 00:17:18 +00:00
|
|
|
#include "menu_utils.h"
|
2020-02-09 22:10:32 +00:00
|
|
|
#include "morse.h"
|
2020-02-10 05:14:43 +00:00
|
|
|
#include "nano_gui.h"
|
2020-04-22 04:14:42 +00:00
|
|
|
#include "scratch_space.h"
|
2020-02-09 22:10:32 +00:00
|
|
|
#include "settings.h"
|
2020-04-22 04:14:42 +00:00
|
|
|
#include "tuner.h"//THRESHOLD_USB_LSB
|
2020-02-09 22:10:32 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
2020-02-10 06:01:19 +00:00
|
|
|
void drawMainMenu(void);
|
2020-02-09 23:30:37 +00:00
|
|
|
MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
|
|
|
|
const ButtonPress_e touch_button,
|
|
|
|
const Point touch_point,
|
|
|
|
const int16_t knob);
|
2020-02-09 22:10:32 +00:00
|
|
|
Menu_t mainMenu = {
|
2020-02-10 06:01:19 +00:00
|
|
|
drawMainMenu,
|
2020-02-09 23:30:37 +00:00
|
|
|
runMainMenu,
|
2020-02-10 06:01:19 +00:00
|
|
|
nullptr
|
2020-02-09 22:10:32 +00:00
|
|
|
};
|
|
|
|
|
2020-02-09 23:30:37 +00:00
|
|
|
Menu_t* const rootMenu = &mainMenu;
|
2020-02-09 22:10:32 +00:00
|
|
|
|
|
|
|
bool mainMenuSelecting = false;//Tracks if we're selecting buttons with knob, or adjusting frequency
|
2020-02-10 01:04:47 +00:00
|
|
|
int16_t mainMenuSelectedItemRaw = 0;//Allow negative only for easier checks on wrap around
|
2020-02-09 22:10:32 +00:00
|
|
|
|
|
|
|
void drawMainMenu(void)
|
|
|
|
{
|
2020-02-10 05:14:43 +00:00
|
|
|
displayClear(COLOR_BACKGROUND);
|
2020-04-26 02:46:36 +00:00
|
|
|
|
|
|
|
drawButtonGrid(&mainMenuGrid);
|
|
|
|
|
2020-02-15 03:28:58 +00:00
|
|
|
ltoa(GetActiveVfoFreq(),b,10);
|
|
|
|
morseText(b);
|
2020-02-10 05:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 22:10:32 +00:00
|
|
|
void mainMenuTune(int16_t knob)
|
|
|
|
{
|
|
|
|
static uint32_t current_freq = 0;
|
|
|
|
|
|
|
|
if((0 == knob) && (GetActiveVfoFreq() == current_freq)){
|
|
|
|
//Nothing to do - we're already set!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_freq = GetActiveVfoFreq();
|
2020-02-12 07:10:06 +00:00
|
|
|
const uint32_t new_freq = current_freq + (50 * knob);
|
2020-02-09 22:10:32 +00:00
|
|
|
|
2020-04-25 19:35:59 +00:00
|
|
|
setFrequency(new_freq);
|
|
|
|
|
|
|
|
if(autoSelectSidebandChanged(current_freq)){
|
2020-04-25 19:10:25 +00:00
|
|
|
updateSidebandButtons();
|
2020-02-09 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 07:10:06 +00:00
|
|
|
const uint32_t old_freq = current_freq;
|
2020-02-09 22:10:32 +00:00
|
|
|
current_freq = new_freq;
|
2020-02-10 05:14:43 +00:00
|
|
|
|
2020-02-12 05:45:26 +00:00
|
|
|
if(Vfo_e::VFO_A == globalSettings.activeVfo){
|
2020-04-26 02:46:36 +00:00
|
|
|
drawButton(&mainMenuVfoGrid,&bVfoA);
|
2020-02-12 05:45:26 +00:00
|
|
|
}
|
|
|
|
else{
|
2020-04-26 02:46:36 +00:00
|
|
|
drawButton(&mainMenuVfoGrid,&bVfoB);
|
2020-02-12 05:45:26 +00:00
|
|
|
}
|
2020-04-26 02:46:36 +00:00
|
|
|
|
2020-02-12 07:10:06 +00:00
|
|
|
updateBandButtons(old_freq);
|
2020-02-09 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 23:30:37 +00:00
|
|
|
MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
|
|
|
|
const ButtonPress_e touch_button,
|
|
|
|
const Point touch_point,
|
|
|
|
const int16_t knob)
|
2020-02-09 22:10:32 +00:00
|
|
|
{
|
|
|
|
//Check tuner_button
|
|
|
|
if(ButtonPress_e::NotPressed != tuner_button){
|
|
|
|
switch(tuner_button){
|
|
|
|
default://Fallthrough intended
|
|
|
|
case ButtonPress_e::NotPressed:
|
|
|
|
{
|
|
|
|
//Nothing to do
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ButtonPress_e::ShortPress:
|
|
|
|
{
|
|
|
|
if(mainMenuSelecting){
|
|
|
|
uint8_t menu_index = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
|
2020-04-26 02:46:36 +00:00
|
|
|
endSelector(mainMenuSelectedItemRaw,&mainMenuGrid);
|
|
|
|
|
2020-02-10 05:59:15 +00:00
|
|
|
Button button;
|
2020-02-12 05:45:26 +00:00
|
|
|
Button* bp;
|
2020-04-26 02:46:36 +00:00
|
|
|
memcpy_P(&bp,&(mainMenuGrid.buttons_P[menu_index]),sizeof(bp));
|
2020-02-12 05:45:26 +00:00
|
|
|
memcpy_P(&button,bp,sizeof(button));
|
2020-02-12 06:17:30 +00:00
|
|
|
button.on_select();
|
2020-02-09 22:10:32 +00:00
|
|
|
}
|
2020-02-09 23:56:43 +00:00
|
|
|
else{
|
2020-02-10 01:04:47 +00:00
|
|
|
initSelector(&mainMenuSelectedItemRaw,
|
2020-04-26 02:46:36 +00:00
|
|
|
&mainMenuGrid,
|
2020-02-10 01:04:47 +00:00
|
|
|
MorsePlaybackType_e::PlayChar);
|
2020-02-09 23:56:43 +00:00
|
|
|
}
|
2020-02-09 22:10:32 +00:00
|
|
|
mainMenuSelecting = !mainMenuSelecting;
|
|
|
|
|
|
|
|
//Don't handle touch or knob on this run
|
|
|
|
return MenuReturn_e::StillActive;//main menu always returns StillActive
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ButtonPress_e::LongPress:
|
|
|
|
{
|
|
|
|
if(!globalSettings.morseMenuOn){
|
|
|
|
globalSettings.morseMenuOn = true;//set before playing
|
|
|
|
morseLetter(2);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
morseLetter(4);
|
|
|
|
globalSettings.morseMenuOn = false;//unset after playing
|
|
|
|
}
|
|
|
|
SaveSettingsToEeprom();
|
|
|
|
//Don't handle touch or knob on this run
|
|
|
|
return MenuReturn_e::StillActive;//main menu always returns StillActive
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}//switch
|
|
|
|
}//tuner_button
|
|
|
|
|
|
|
|
else if(ButtonPress_e::NotPressed != touch_button){
|
|
|
|
//We treat long and short presses the same, so no need to have a switch
|
2020-02-10 00:31:24 +00:00
|
|
|
Button button;
|
2020-04-26 02:46:36 +00:00
|
|
|
if(findPressedButton(&mainMenuGrid,&button,touch_point)){
|
2020-02-12 06:17:30 +00:00
|
|
|
button.on_select();
|
2020-02-09 22:10:32 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
//Touch detected, but not on our buttons, so ignore
|
|
|
|
}
|
|
|
|
}//touch_button
|
|
|
|
|
|
|
|
else{//Neither button input type found, so handle the knob
|
|
|
|
if(mainMenuSelecting){
|
2020-02-10 01:04:47 +00:00
|
|
|
adjustSelector(&mainMenuSelectedItemRaw,
|
|
|
|
knob,
|
2020-04-26 02:46:36 +00:00
|
|
|
&mainMenuGrid,
|
2020-02-10 01:04:47 +00:00
|
|
|
MorsePlaybackType_e::PlayChar);
|
2020-02-09 22:10:32 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
mainMenuTune(knob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
return MenuReturn_e::StillActive;//main menu always returns StillActive
|
|
|
|
}
|