Reuse menu running code between quicklist and numpad

This commit is contained in:
Reed Nightingale 2020-04-26 22:43:47 -07:00
parent 61c22474e9
commit ab8ba66067
6 changed files with 90 additions and 73 deletions

52
menu_np_ql_shared.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "menu_np_ql_shared.h"
#include <avr/pgmspace.h>
#include "button.h"
#include "menu_utils.h"
MenuReturn_e runNpQlShared(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob,
int16_t *const menuSelectedItemRaw,
const Button *const *const menu_buttons,
const uint8_t menu_num_buttons,
ButtonPress_e *const selection_mode)
{
if(ButtonPress_e::NotPressed != tuner_button){
uint8_t menu_index = *menuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
Button button;
Button* bp;
memcpy_P(&bp,&(menu_buttons[menu_index]),sizeof(bp));
memcpy_P(&button,bp,sizeof(button));
*selection_mode = tuner_button;
button.on_select();
}//tuner_button
else if(ButtonPress_e::NotPressed != touch_button){
Button button;
if(findPressedButton(menu_buttons,menu_num_buttons,&button,touch_point)){
*selection_mode = touch_button;
button.on_select();
}
else{
//Touch detected, but not on our buttons, so ignore
}
}//touch_button
else{//Neither button input type found, so handle the knob
adjustSelector(menuSelectedItemRaw,
knob,
menu_buttons,
menu_num_buttons,
MorsePlaybackType_e::PlayChar);
}
if(ButtonPress_e::NotPressed == *selection_mode){
return MenuReturn_e::ExitedRedraw;
}
else{
return MenuReturn_e::StillActive;
}
}

14
menu_np_ql_shared.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "button.h"
#include "menu.h"
MenuReturn_e runNpQlShared(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob,
int16_t *const menuSelectedItemRaw,
const Button *const *const menu_buttons,
const uint8_t menu_num_buttons,
ButtonPress_e *const selection_mode);

View File

@ -4,6 +4,7 @@
#include <avr/pgmspace.h>
#include "color_theme.h"
#include "menu_np_ql_shared.h"
#include "menu_utils.h"
#include "nano_gui.h"
@ -36,6 +37,7 @@ void drawNumpad(void)
void initNumpad(void)
{
numpadMenuFrequency = 0;
numpadSelectionMode = ButtonPress_e::LongPress;//Anything except NotPressed
drawNumpad();
initSelector(&numpadMenuSelectedItemRaw,
numpadMenuButtons,
@ -48,39 +50,12 @@ MenuReturn_e runNumpad(const ButtonPress_e tuner_button,
const Point touch_point,
const int16_t knob)
{
if(ButtonPress_e::NotPressed != tuner_button){
//We treat long and short presses the same, so no need to have a switch
uint8_t menu_index = numpadMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
Button button;
Button* bp;
memcpy_P(&bp,&(numpadMenuButtons[menu_index]),sizeof(bp));
memcpy_P(&button,bp,sizeof(button));
button.on_select();
}//tuner_button
else if(ButtonPress_e::NotPressed != touch_button){
//We treat long and short presses the same, so no need to have a switch
Button button;
if(findPressedButton(numpadMenuButtons,NUMPAD_MENU_NUM_BUTTONS,&button,touch_point)){
button.on_select();
}
else{
//Touch detected, but not on our buttons, so ignore
}
}//touch_button
else{//Neither button input type found, so handle the knob
adjustSelector(&numpadMenuSelectedItemRaw,
return runNpQlShared(tuner_button,
touch_button,
touch_point,
knob,
&numpadMenuSelectedItemRaw,
numpadMenuButtons,
NUMPAD_MENU_NUM_BUTTONS,
MorsePlaybackType_e::PlayChar);
}
if(NUMPAD_MENU_EXIT_FREQ == numpadMenuFrequency){
return MenuReturn_e::ExitedRedraw;
}
else{
return MenuReturn_e::StillActive;
}
&numpadSelectionMode);
}

View File

@ -22,8 +22,8 @@ static const unsigned int LAYOUT_BUTTON_HEIGHT = 36;
static const unsigned int LAYOUT_BUTTON_PITCH_X = 64;
static const unsigned int LAYOUT_BUTTON_PITCH_Y = 40;
const uint32_t NUMPAD_MENU_EXIT_FREQ = -1;
uint32_t numpadMenuFrequency;
ButtonPress_e numpadSelectionMode;
#define D_STRINGIFY(x) #x
#define D_STRING(x) D_STRINGIFY(x)
@ -152,10 +152,10 @@ void osOk(void)
SetActiveVfoFreq(numpadMenuFrequency);
SaveSettingsToEeprom();
setFrequency(numpadMenuFrequency);
numpadMenuFrequency = NUMPAD_MENU_EXIT_FREQ;
numpadSelectionMode = ButtonPress_e::NotPressed;
}
void osCancel(void)
{
numpadMenuFrequency = NUMPAD_MENU_EXIT_FREQ;
numpadSelectionMode = ButtonPress_e::NotPressed;
}

View File

@ -3,9 +3,11 @@
#include <stdint.h>
#include "button.h"
#include "button_press_e.h"
extern const Button* const numpadMenuButtons[];
extern const uint8_t NUMPAD_MENU_NUM_BUTTONS;
extern const uint32_t NUMPAD_MENU_EXIT_FREQ;
extern uint32_t numpadMenuFrequency;
extern ButtonPress_e numpadSelectionMode;//NotPressed means exit menu. Other press types are consumed by selectors

View File

@ -5,6 +5,7 @@
#include <WString.h>//F()
#include "color_theme.h"
#include "menu_np_ql_shared.h"
#include "menu_utils.h"
#include "nano_gui.h"
#include "scratch_space.h"
@ -52,39 +53,12 @@ MenuReturn_e runQuickList(const ButtonPress_e tuner_button,
const Point touch_point,
const int16_t knob)
{
if(ButtonPress_e::NotPressed != tuner_button){
uint8_t menu_index = quickListMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
Button button;
Button* bp;
memcpy_P(&bp,&(quickListMenuButtons[menu_index]),sizeof(bp));
memcpy_P(&button,bp,sizeof(button));
quickListSelectionMode = tuner_button;
button.on_select();
}//tuner_button
else if(ButtonPress_e::NotPressed != touch_button){
Button button;
if(findPressedButton(quickListMenuButtons,QUICKLIST_MENU_NUM_BUTTONS,&button,touch_point)){
quickListSelectionMode = touch_button;
button.on_select();
}
else{
//Touch detected, but not on our buttons, so ignore
}
}//touch_button
else{//Neither button input type found, so handle the knob
adjustSelector(&quickListMenuSelectedItemRaw,
return runNpQlShared(tuner_button,
touch_button,
touch_point,
knob,
&quickListMenuSelectedItemRaw,
quickListMenuButtons,
QUICKLIST_MENU_NUM_BUTTONS,
MorsePlaybackType_e::PlayChar);
}
if(ButtonPress_e::NotPressed == quickListSelectionMode){
return MenuReturn_e::ExitedRedraw;
}
else{
return MenuReturn_e::StillActive;
}
&quickListSelectionMode);
}