From 4583288bfae8e0e354b881f733a0542ce1ffed86 Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Mon, 10 Feb 2020 00:53:53 -0800 Subject: [PATCH] Update functions to use new button array --- menu_main.cpp | 6 +++--- menu_utils.cpp | 22 +++++++++++----------- menu_utils.h | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/menu_main.cpp b/menu_main.cpp index 2a12ced..d5652d9 100644 --- a/menu_main.cpp +++ b/menu_main.cpp @@ -34,7 +34,7 @@ void drawMainMenu(void) displayClear(COLOR_BACKGROUND); Button button; 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); Serial.println(button.text); } @@ -74,7 +74,7 @@ void mainMenuTune(int16_t knob) current_freq = new_freq; 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); } @@ -111,7 +111,7 @@ MenuReturn_e runMainMenu(const ButtonPress_e tuner_button, if(mainMenuSelecting){ uint8_t menu_index = mainMenuSelectedItemRaw/MENU_KNOB_COUNTS_PER_ITEM; Button button; - memcpy_P(&button,&mainMenuButtons[menu_index],sizeof(button)); + memcpy_P(&button,mainMenuButtons[menu_index],sizeof(button)); endSelector(&button); //TODO: activate button diff --git a/menu_utils.cpp b/menu_utils.cpp index 2063294..8e5ca20 100644 --- a/menu_utils.cpp +++ b/menu_utils.cpp @@ -37,17 +37,17 @@ bool runSubmenu(Menu_t* const current_menu, return false; } -bool findPressedButton(const Button *const buttons, +bool findPressedButton(const Button* const* buttons, const uint8_t num_buttons, Button *const button_out, const Point touch_point) { for(uint16_t i = 0; i < num_buttons; ++i){ - if((buttons[i].x <= touch_point.x) - &&(touch_point.x <= buttons[i].x + buttons[i].w) - &&(buttons[i].y <= touch_point.y) - &&(touch_point.y <= buttons[i].y + buttons[i].h)){ - memcpy_P(button_out,&buttons[i],sizeof(button_out)); + if((buttons[i]->x <= touch_point.x) + &&(touch_point.x <= buttons[i]->x + buttons[i]->w) + &&(buttons[i]->y <= touch_point.y) + &&(touch_point.y <= buttons[i]->y + buttons[i]->h)){ + memcpy_P(button_out,buttons[i],sizeof(button_out)); return true; } } @@ -86,14 +86,14 @@ void playButtonMorse(const Button *const button, } void initSelector(int16_t *const raw_select_val_in_out, - const Button *const buttons, + const Button* const* buttons, const uint8_t num_buttons, const MorsePlaybackType_e play_type) { *raw_select_val_in_out = 0; if(0 < num_buttons){ Button button; - memcpy_P(&button,&buttons[0],sizeof(button)); + memcpy_P(&button,buttons[0],sizeof(button)); movePuck(nullptr,&button); 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, const int16_t knob, - const Button *const buttons, + const Button* const* buttons, const uint8_t num_buttons, 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; if(prev_select != new_select){ 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; - 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); playButtonMorse(&new_button,play_type); diff --git a/menu_utils.h b/menu_utils.h index 2787213..05f43d2 100644 --- a/menu_utils.h +++ b/menu_utils.h @@ -12,7 +12,7 @@ bool runSubmenu(Menu_t* current_menu, const int16_t knob); //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, Button *const button_out, const Point touch_point); @@ -22,13 +22,13 @@ enum MorsePlaybackType_e : uint8_t { PlayText }; void initSelector(int16_t *const raw_select_val_in_out, - const Button *const buttons, + 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 Button* const* buttons, const uint8_t num_buttons, const MorsePlaybackType_e);