Update functions to use new button array

This commit is contained in:
Reed Nightingale 2020-02-10 00:53:53 -08:00
parent 55096c9284
commit 4583288bfa
3 changed files with 17 additions and 17 deletions

View File

@ -34,7 +34,7 @@ void drawMainMenu(void)
displayClear(COLOR_BACKGROUND); displayClear(COLOR_BACKGROUND);
Button button; Button button;
for(uint8_t i = 0; i < MAIN_MENU_NUM_BUTTONS; ++i){ for(uint8_t i = 0; i < MAIN_MENU_NUM_BUTTONS; ++i){
memcpy_P(&button, &(mainMenuButtons[i]), sizeof(Button)); memcpy_P(&button, mainMenuButtons[i], sizeof(Button));
displayText(button.text, button.x, button.y, button.w, button.h, COLOR_INACTIVE_TEXT, COLOR_INACTIVE_BACKGROUND, COLOR_INACTIVE_BORDER); displayText(button.text, button.x, button.y, button.w, button.h, COLOR_INACTIVE_TEXT, COLOR_INACTIVE_BACKGROUND, COLOR_INACTIVE_BORDER);
Serial.println(button.text); Serial.println(button.text);
} }
@ -74,7 +74,7 @@ void mainMenuTune(int16_t knob)
current_freq = new_freq; current_freq = new_freq;
Button button; Button button;
memcpy_P(&button, &(mainMenuButtons[0]), sizeof(button)); memcpy_P(&button, mainMenuButtons[0], sizeof(button));
displayText(button.text, button.x, button.y, button.w, button.h, COLOR_INACTIVE_TEXT, COLOR_INACTIVE_BACKGROUND, COLOR_INACTIVE_BORDER); displayText(button.text, button.x, button.y, button.w, button.h, COLOR_INACTIVE_TEXT, COLOR_INACTIVE_BACKGROUND, COLOR_INACTIVE_BORDER);
} }
@ -111,7 +111,7 @@ MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
if(mainMenuSelecting){ if(mainMenuSelecting){
uint8_t menu_index = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM; uint8_t menu_index = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM;
Button button; Button button;
memcpy_P(&button,&mainMenuButtons[menu_index],sizeof(button)); memcpy_P(&button,mainMenuButtons[menu_index],sizeof(button));
endSelector(&button); endSelector(&button);
//TODO: activate button //TODO: activate button

View File

@ -37,17 +37,17 @@ bool runSubmenu(Menu_t* const current_menu,
return false; return false;
} }
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)
{ {
for(uint16_t i = 0; i < num_buttons; ++i){ for(uint16_t i = 0; i < num_buttons; ++i){
if((buttons[i].x <= touch_point.x) if((buttons[i]->x <= touch_point.x)
&&(touch_point.x <= buttons[i].x + buttons[i].w) &&(touch_point.x <= buttons[i]->x + buttons[i]->w)
&&(buttons[i].y <= touch_point.y) &&(buttons[i]->y <= touch_point.y)
&&(touch_point.y <= buttons[i].y + buttons[i].h)){ &&(touch_point.y <= buttons[i]->y + buttons[i]->h)){
memcpy_P(button_out,&buttons[i],sizeof(button_out)); memcpy_P(button_out,buttons[i],sizeof(button_out));
return true; return true;
} }
} }
@ -86,14 +86,14 @@ void playButtonMorse(const Button *const button,
} }
void initSelector(int16_t *const raw_select_val_in_out, void initSelector(int16_t *const raw_select_val_in_out,
const Button *const buttons, const Button* const* buttons,
const uint8_t num_buttons, const uint8_t num_buttons,
const MorsePlaybackType_e play_type) const MorsePlaybackType_e play_type)
{ {
*raw_select_val_in_out = 0; *raw_select_val_in_out = 0;
if(0 < num_buttons){ if(0 < num_buttons){
Button button; Button button;
memcpy_P(&button,&buttons[0],sizeof(button)); memcpy_P(&button,buttons[0],sizeof(button));
movePuck(nullptr,&button); movePuck(nullptr,&button);
playButtonMorse(&button,play_type); playButtonMorse(&button,play_type);
} }
@ -101,7 +101,7 @@ void initSelector(int16_t *const raw_select_val_in_out,
void adjustSelector(int16_t *const raw_select_val_in_out, void adjustSelector(int16_t *const raw_select_val_in_out,
const int16_t knob, const int16_t knob,
const Button *const buttons, const Button* const* buttons,
const uint8_t num_buttons, const uint8_t num_buttons,
const MorsePlaybackType_e play_type) const MorsePlaybackType_e play_type)
{ {
@ -110,9 +110,9 @@ void adjustSelector(int16_t *const raw_select_val_in_out,
const uint8_t new_select = (*raw_select_val_in_out)/MENU_KNOB_COUNTS_PER_ITEM; const uint8_t new_select = (*raw_select_val_in_out)/MENU_KNOB_COUNTS_PER_ITEM;
if(prev_select != new_select){ if(prev_select != new_select){
Button prev_button; Button prev_button;
memcpy_P(&prev_button,&buttons[prev_select],sizeof(prev_button)); memcpy_P(&prev_button,buttons[prev_select],sizeof(prev_button));
Button new_button; Button new_button;
memcpy_P(&new_button,&buttons[new_select],sizeof(new_button)); memcpy_P(&new_button,buttons[new_select],sizeof(new_button));
movePuck(&prev_button,&new_button); movePuck(&prev_button,&new_button);
playButtonMorse(&new_button,play_type); playButtonMorse(&new_button,play_type);

View File

@ -12,7 +12,7 @@ bool runSubmenu(Menu_t* current_menu,
const int16_t knob); const int16_t knob);
//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);
@ -22,13 +22,13 @@ enum MorsePlaybackType_e : uint8_t {
PlayText PlayText
}; };
void initSelector(int16_t *const raw_select_val_in_out, void initSelector(int16_t *const raw_select_val_in_out,
const Button *const buttons, const Button* const* buttons,
const uint8_t num_buttons, const uint8_t num_buttons,
const MorsePlaybackType_e); const MorsePlaybackType_e);
void adjustSelector(int16_t *const raw_select_val_in_out, void adjustSelector(int16_t *const raw_select_val_in_out,
int16_t knob, int16_t knob,
const Button *const buttons, const Button* const* buttons,
const uint8_t num_buttons, const uint8_t num_buttons,
const MorsePlaybackType_e); const MorsePlaybackType_e);