mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-01-28 03:06:24 -05:00
Move selector logic to menu_utils
This commit is contained in:
parent
9e21faa6f1
commit
5e30551bf2
@ -22,7 +22,7 @@ Menu_t mainMenu = {
|
|||||||
Menu_t* const rootMenu = &mainMenu;
|
Menu_t* const rootMenu = &mainMenu;
|
||||||
|
|
||||||
bool mainMenuSelecting = false;//Tracks if we're selecting buttons with knob, or adjusting frequency
|
bool mainMenuSelecting = false;//Tracks if we're selecting buttons with knob, or adjusting frequency
|
||||||
uint8_t mainMenuSelectedItemRaw = 0;
|
int16_t mainMenuSelectedItemRaw = 0;//Allow negative only for easier checks on wrap around
|
||||||
|
|
||||||
const Button mainMenuButtons [] PROGMEM = {};
|
const Button mainMenuButtons [] PROGMEM = {};
|
||||||
static constexpr uint8_t MAIN_MENU_NUM_BUTTONS = sizeof(mainMenuButtons) / sizeof(mainMenuButtons[0]);
|
static constexpr uint8_t MAIN_MENU_NUM_BUTTONS = sizeof(mainMenuButtons) / sizeof(mainMenuButtons[0]);
|
||||||
@ -93,7 +93,10 @@ MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
|
|||||||
//TODO: activate button
|
//TODO: activate button
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
movePuck(nullptr,&mainMenuButtons[0]);
|
initSelector(&mainMenuSelectedItemRaw,
|
||||||
|
mainMenuButtons,
|
||||||
|
MAIN_MENU_NUM_BUTTONS,
|
||||||
|
MorsePlaybackType_e::PlayChar);
|
||||||
}
|
}
|
||||||
mainMenuSelecting = !mainMenuSelecting;
|
mainMenuSelecting = !mainMenuSelecting;
|
||||||
|
|
||||||
@ -132,21 +135,11 @@ MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
|
|||||||
|
|
||||||
else{//Neither button input type found, so handle the knob
|
else{//Neither button input type found, so handle the knob
|
||||||
if(mainMenuSelecting){
|
if(mainMenuSelecting){
|
||||||
const uint8_t prev_select = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
|
adjustSelector(&mainMenuSelectedItemRaw,
|
||||||
mainMenuSelectedItemRaw += LIMIT(mainMenuSelectedItemRaw+knob,0,MAIN_MENU_NUM_BUTTONS*MENU_KNOB_COUNTS_PER_ITEM);
|
knob,
|
||||||
const uint8_t new_select = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
|
mainMenuButtons,
|
||||||
if(prev_select != new_select){
|
MAIN_MENU_NUM_BUTTONS,
|
||||||
movePuck(&mainMenuButtons[prev_select],&mainMenuButtons[new_select]);//TODO
|
MorsePlaybackType_e::PlayChar);
|
||||||
morseLetter(mainMenuButtons[new_select].morse);
|
|
||||||
int8_t morse_status = 0;
|
|
||||||
mainMenuButtons[new_select].morse_status(morse_status);
|
|
||||||
if(morse_status < 0){
|
|
||||||
morseBool(false);
|
|
||||||
}
|
|
||||||
else if(morse_status > 0){
|
|
||||||
morseBool(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
mainMenuTune(knob);
|
mainMenuTune(knob);
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include "menu.h"
|
#include "menu_utils.h"
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "color_theme.h"
|
#include "color_theme.h"
|
||||||
|
#include "morse.h"
|
||||||
#include "nano_gui.h"
|
#include "nano_gui.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
bool runSubmenu(Menu_t* const current_menu,
|
bool runSubmenu(Menu_t* const current_menu,
|
||||||
void(*const redraw_callback)(),
|
void(*const redraw_callback)(),
|
||||||
@ -35,17 +37,6 @@ bool runSubmenu(Menu_t* const current_menu,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool findPressedButton(const Button *const buttons,
|
bool findPressedButton(const Button *const buttons,
|
||||||
const uint8_t num_buttons,
|
const uint8_t num_buttons,
|
||||||
Button *const button_out,
|
Button *const button_out,
|
||||||
@ -63,3 +54,60 @@ bool findPressedButton(const Button *const buttons,
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t morse_status = 0;
|
||||||
|
button->morse_status(&morse_status);
|
||||||
|
if(morse_status < 0){
|
||||||
|
morseBool(false);
|
||||||
|
}
|
||||||
|
else if(morse_status > 0){
|
||||||
|
morseBool(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initSelector(int16_t *const raw_select_val_in_out,
|
||||||
|
const Button *const buttons,
|
||||||
|
const uint8_t num_buttons,
|
||||||
|
const MorsePlaybackType_e play_type)
|
||||||
|
{
|
||||||
|
*raw_select_val_in_out = 0;
|
||||||
|
if(0 < num_buttons){
|
||||||
|
playButtonMorse(&buttons[0],play_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void adjustSelector(int16_t *const raw_select_val_in_out,
|
||||||
|
const int16_t knob,
|
||||||
|
const Button *const buttons,
|
||||||
|
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;
|
||||||
|
*raw_select_val_in_out += LIMIT((*raw_select_val_in_out)+knob,0,num_buttons*MENU_KNOB_COUNTS_PER_ITEM - 1);
|
||||||
|
const uint8_t new_select = (*raw_select_val_in_out)/MENU_KNOB_COUNTS_PER_ITEM;
|
||||||
|
if(prev_select != new_select){
|
||||||
|
movePuck(&buttons[prev_select],&buttons[new_select]);
|
||||||
|
playButtonMorse(&buttons[new_select],play_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
21
menu_utils.h
21
menu_utils.h
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "menu.h"
|
||||||
|
|
||||||
//Returns true if submenu was run, false otherwise
|
//Returns true if submenu was run, false otherwise
|
||||||
bool runSubmenu(Menu_t* current_menu,
|
bool runSubmenu(Menu_t* current_menu,
|
||||||
@ -10,11 +11,23 @@ bool runSubmenu(Menu_t* current_menu,
|
|||||||
const Point touch_point,
|
const Point touch_point,
|
||||||
const int16_t knob);
|
const int16_t knob);
|
||||||
|
|
||||||
void movePuck(const Button *const b_old,
|
|
||||||
const Button *const b_new);
|
|
||||||
|
|
||||||
//Returns true if button was found, false otherwise
|
//Returns true if button was found, false otherwise
|
||||||
bool findPressedButton(const Button *const buttons,
|
bool findPressedButton(const Button *const buttons,
|
||||||
const uint8_t num_buttons,
|
const uint8_t num_buttons,
|
||||||
Button *const button_out,
|
Button *const button_out,
|
||||||
const Point touch_point);
|
const Point touch_point);
|
||||||
|
|
||||||
|
enum MorsePlaybackType_e : uint8_t {
|
||||||
|
PlayChar,
|
||||||
|
PlayText
|
||||||
|
};
|
||||||
|
void initSelector(int16_t *const raw_select_val_in_out,
|
||||||
|
const Button *const buttons,
|
||||||
|
const uint8_t num_buttons,
|
||||||
|
const MorsePlaybackType_e);
|
||||||
|
|
||||||
|
void adjustSelector(int16_t *const raw_select_val_in_out,
|
||||||
|
int16_t knob,
|
||||||
|
const Button *const buttons,
|
||||||
|
const uint8_t num_buttons,
|
||||||
|
const MorsePlaybackType_e);
|
||||||
|
Loading…
Reference in New Issue
Block a user