2020-02-09 20:04:47 -05:00
|
|
|
#include "menu_utils.h"
|
2020-02-09 18:56:43 -05:00
|
|
|
|
2020-02-09 19:16:57 -05:00
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
|
2020-02-09 18:56:43 -05:00
|
|
|
#include "button.h"
|
|
|
|
#include "color_theme.h"
|
2020-02-09 20:04:47 -05:00
|
|
|
#include "morse.h"
|
2020-02-09 18:42:37 -05:00
|
|
|
#include "nano_gui.h"
|
2020-02-09 20:04:47 -05:00
|
|
|
#include "utils.h"
|
2020-02-09 17:10:08 -05:00
|
|
|
|
2020-02-09 18:30:37 -05:00
|
|
|
bool runSubmenu(Menu_t* const current_menu,
|
|
|
|
void(*const redraw_callback)(),
|
|
|
|
const ButtonPress_e tuner_button,
|
|
|
|
const ButtonPress_e touch_button,
|
|
|
|
const Point touch_point,
|
|
|
|
const int16_t knob){
|
2020-02-09 17:10:08 -05:00
|
|
|
if(nullptr != current_menu->active_submenu){
|
|
|
|
auto ret = current_menu->active_submenu->runMenu(tuner_button,touch_button,touch_point,knob);
|
|
|
|
switch(ret){
|
|
|
|
case MenuReturn_e::StillActive://Fallthrough intended
|
|
|
|
case MenuReturn_e::ExitedNoRedraw:
|
|
|
|
{
|
|
|
|
//Nothing to do here - just return
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default://Fallthrough intended. Default to this menu being active
|
|
|
|
case MenuReturn_e::ExitedRedraw:
|
|
|
|
{
|
|
|
|
//Turn off submenu, redraw, then return
|
|
|
|
current_menu->active_submenu = nullptr;
|
|
|
|
redraw_callback();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}//end switch
|
|
|
|
return true;
|
|
|
|
}//end submenu
|
|
|
|
return false;
|
2020-02-09 18:42:37 -05:00
|
|
|
}
|
|
|
|
|
2020-02-10 03:53:53 -05:00
|
|
|
bool findPressedButton(const Button* const* buttons,
|
2020-02-09 19:16:57 -05:00
|
|
|
const uint8_t num_buttons,
|
|
|
|
Button *const button_out,
|
|
|
|
const Point touch_point)
|
|
|
|
{
|
2020-02-12 00:55:23 -05:00
|
|
|
Button button;
|
|
|
|
Button* bp;
|
2020-02-09 19:16:57 -05:00
|
|
|
for(uint16_t i = 0; i < num_buttons; ++i){
|
2020-02-12 00:55:23 -05:00
|
|
|
memcpy_P(&bp,&(buttons[i]),sizeof(bp));
|
|
|
|
memcpy_P(&button,bp,sizeof(button));
|
|
|
|
if((button.x <= touch_point.x)
|
|
|
|
&&(touch_point.x <= button.x + button.w)
|
|
|
|
&&(button.y <= touch_point.y)
|
|
|
|
&&(touch_point.y <= button.y + button.h)){
|
|
|
|
memcpy_P(button_out,&button,sizeof(button_out));
|
2020-02-09 19:16:57 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-09 20:04:47 -05:00
|
|
|
|
|
|
|
void movePuck(const Button *const b_old,
|
|
|
|
const Button *const b_new)
|
|
|
|
{
|
|
|
|
if(nullptr != b_old){
|
|
|
|
displayRect(b_old->x,b_old->y,b_old->w,b_old->h,COLOR_INACTIVE_BORDER);
|
|
|
|
}
|
|
|
|
if(nullptr != b_new){
|
|
|
|
displayRect(b_new->x,b_new->y,b_new->w,b_new->h,COLOR_ACTIVE_BORDER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void playButtonMorse(const Button *const button,
|
|
|
|
const MorsePlaybackType_e play_type)
|
|
|
|
{
|
|
|
|
if(MorsePlaybackType_e::PlayText == play_type){
|
|
|
|
morseText(button->text);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
morseLetter(button->morse);
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:06:11 -05:00
|
|
|
const ButtonStatus_e bs = button->status();
|
|
|
|
if(ButtonStatus_e::Inactive == bs){
|
2020-02-09 20:04:47 -05:00
|
|
|
morseBool(false);
|
|
|
|
}
|
2020-02-10 03:06:11 -05:00
|
|
|
else if(ButtonStatus_e::Active == bs){
|
2020-02-09 20:04:47 -05:00
|
|
|
morseBool(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void initSelector(int16_t *const raw_select_val_in_out,
|
2020-02-10 03:53:53 -05:00
|
|
|
const Button* const* buttons,
|
2020-02-09 20:04:47 -05:00
|
|
|
const uint8_t num_buttons,
|
|
|
|
const MorsePlaybackType_e play_type)
|
|
|
|
{
|
|
|
|
*raw_select_val_in_out = 0;
|
|
|
|
if(0 < num_buttons){
|
2020-02-10 00:34:30 -05:00
|
|
|
Button button;
|
2020-02-12 00:55:23 -05:00
|
|
|
Button* bp;
|
|
|
|
memcpy_P(&bp,&(buttons[0]),sizeof(bp));
|
|
|
|
memcpy_P(&button,bp,sizeof(button));
|
2020-02-10 00:45:51 -05:00
|
|
|
movePuck(nullptr,&button);
|
2020-02-10 00:34:30 -05:00
|
|
|
playButtonMorse(&button,play_type);
|
2020-02-09 20:04:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void adjustSelector(int16_t *const raw_select_val_in_out,
|
|
|
|
const int16_t knob,
|
2020-02-10 03:53:53 -05:00
|
|
|
const Button* const* buttons,
|
2020-02-09 20:04:47 -05:00
|
|
|
const uint8_t num_buttons,
|
|
|
|
const MorsePlaybackType_e play_type)
|
|
|
|
{
|
|
|
|
const uint8_t prev_select = (*raw_select_val_in_out)/MENU_KNOB_COUNTS_PER_ITEM;
|
2020-02-10 00:34:30 -05:00
|
|
|
*raw_select_val_in_out = LIMIT((*raw_select_val_in_out)+knob,0,num_buttons*MENU_KNOB_COUNTS_PER_ITEM - 1);
|
2020-02-09 20:04:47 -05:00
|
|
|
const uint8_t new_select = (*raw_select_val_in_out)/MENU_KNOB_COUNTS_PER_ITEM;
|
|
|
|
if(prev_select != new_select){
|
2020-02-10 00:34:30 -05:00
|
|
|
Button prev_button;
|
2020-02-12 00:55:23 -05:00
|
|
|
Button* bp;
|
|
|
|
memcpy_P(&bp,&(buttons[prev_select]),sizeof(bp));
|
|
|
|
memcpy_P(&prev_button,bp,sizeof(prev_button));
|
2020-02-10 00:34:30 -05:00
|
|
|
Button new_button;
|
2020-02-12 00:55:23 -05:00
|
|
|
memcpy_P(&bp,&(buttons[new_select]),sizeof(bp));
|
|
|
|
memcpy_P(&new_button,bp,sizeof(new_button));
|
2020-02-10 00:34:30 -05:00
|
|
|
|
|
|
|
movePuck(&prev_button,&new_button);
|
|
|
|
playButtonMorse(&new_button,play_type);
|
2020-02-09 20:04:47 -05:00
|
|
|
}
|
|
|
|
}
|
2020-02-10 00:59:15 -05:00
|
|
|
|
|
|
|
void endSelector(const Button *const button)
|
|
|
|
{
|
|
|
|
movePuck(button,nullptr);
|
|
|
|
}
|