Skip to content

Commit

Permalink
Merge branch 'main' into lvgl_9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Apr 11, 2024
2 parents a1ce03d + 3b5e8b5 commit 4e98d74
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 5 deletions.
18 changes: 17 additions & 1 deletion Platformio/src/applicationInternal/gui/guiBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList);

// Helper Functions -----------------------------------------------------------------------------------------------------------------------

// callback when pageIndicator prev or next was clicked
void pageIndicator_navigate_event_cb(lv_event_t* e) {
lv_obj_t* target = lv_event_get_target(e);

int user_data = (intptr_t)(target->user_data);
if (user_data == 0) {
executeCommand(GUI_PREV);
} else if (user_data == 1) {
executeCommand(GUI_NEXT);
}
}

// callback when sceneLabel or pageIndicator was clicked
void sceneLabel_or_pageIndicator_event_cb(lv_event_t* e) {
Serial.println("- Scene selection: sceneLabel or pageIndicator clicked received for navigating to scene selection page");
Expand Down Expand Up @@ -309,7 +321,7 @@ void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList) {
doLogMemoryUsage();
}

void setActiveTab(uint32_t index, lv_anim_enable_t anim_en) {
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en, bool send_tab_changed_event) {
// unsigned long startTime = millis();
if (anim_en == LV_ANIM_ON) {
lv_tabview_set_active(tabview, index, LV_ANIM_ON);
Expand All @@ -322,6 +334,10 @@ void setActiveTab(uint32_t index, lv_anim_enable_t anim_en) {
// lv_timer_handler();
// log_memory();
}

if (send_tab_changed_event) {
lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, NULL);
}
}

void showWiFiConnected(bool connected) {
Expand Down
3 changes: 2 additions & 1 deletion Platformio/src/applicationInternal/gui/guiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void gui_loop(void);
void tabview_content_is_scrolling_event_cb(lv_event_t* e);
void tabview_tab_changed_event_cb(lv_event_t* e);
void sceneLabel_or_pageIndicator_event_cb(lv_event_t* e);
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en);
void pageIndicator_navigate_event_cb(lv_event_t* e);
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en, bool send_tab_changed_event = false);
// used by memoryUsage.cpp
void showMemoryUsageBar(bool showBar);
// used by commandHandler to show WiFi status
Expand Down
32 changes: 32 additions & 0 deletions Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ tab_in_memory tabs_in_memory[3] = {{NULL, -1, ""}, {NULL, -1, ""}, {NULL, -1, ""
// holds the ids of the tabs we had in memory before, so that we can determine the next or previous id
int tabs_in_memory_previous_listIndex[3]= {-1 , -1, -1};

bool gui_memoryOptimizer_isTabIDInMemory(int tabID) {
// range check
if ((tabID < 0) || (tabID >= 3)) {
return false;
}
return (tabs_in_memory[tabID].listIndex != -1);
}

bool gui_memoryOptimizer_isGUInameInMemory(std::string guiName) {
for (uint8_t index=0; index <= 2; index++) {
if (tabs_in_memory[index].guiName == guiName) {
return true;
}
}
return false;
}

void notify_active_tabs_before_delete() {
Serial.printf(" Will notify tabs about deletion\r\n");
std::string nameOfTab;
Expand Down Expand Up @@ -311,6 +328,21 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
if (nameOfTab == get_currentGUIname()) {
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(btn, sceneLabel_or_pageIndicator_event_cb, LV_EVENT_CLICKED, NULL);

} else if ((i==0 || i==1) && (tabs_in_memory[i+1].listIndex != -1)) {
// this is the button on the previous tab, which can be seen on the active tab
// activate click to prev tab
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_user_data(btn,(void *)(intptr_t)0);
lv_obj_add_event_cb(btn, pageIndicator_navigate_event_cb, LV_EVENT_CLICKED, NULL);

} else if (i==1 || i==2) {
// this is the button on the next tab, which can be seen on the active tab
// activate click to next tab
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_user_data(btn,(void *)(intptr_t)1);
lv_obj_add_event_cb(btn, pageIndicator_navigate_event_cb, LV_EVENT_CLICKED, NULL);

}
lv_obj_set_size(btn, 150, lv_pct(100));
lv_obj_remove_style(btn, NULL, LV_STATE_PRESSED);
Expand Down
2 changes: 2 additions & 0 deletions Platformio/src/applicationInternal/gui/guiMemoryOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

void gui_memoryOptimizer_prepare_startup();
void gui_memoryOptimizer_doAfterSliding_deletionAndCreation(lv_obj_t** tabview, int oldTabID, int newTabID, bool newGuiList, lv_obj_t** panel, lv_obj_t** img1, lv_obj_t** img2);
bool gui_memoryOptimizer_isTabIDInMemory(int tabID);
bool gui_memoryOptimizer_isGUInameInMemory(std::string guiName);
23 changes: 23 additions & 0 deletions Platformio/src/applicationInternal/scenes/sceneHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string>
#include <lvgl.h>
#include "applicationInternal/gui/guiBase.h"
#include "applicationInternal/gui/guiMemoryOptimizer.h"
#include "applicationInternal/scenes/sceneRegistry.h"
#include "applicationInternal/hardware/hardwarePresenter.h"
#include "applicationInternal/commandHandler.h"
Expand Down Expand Up @@ -29,6 +30,28 @@ void handleScene(uint16_t command, commandData commandData, std::string addition
return;
}

// do not switch scene, but navigate to the prev or next gui in the currently active list of guis
if ((scene_name == scene_gui_next) || (scene_name == scene_gui_prev)) {
if (scene_name == scene_gui_prev) {
if (currentTabID == 0) {
Serial.println("scene: cannot navigate to prev gui, because there is none");
} else {
Serial.println("scene: will navigate to prev gui");
setActiveTab(currentTabID -1, LV_ANIM_ON, true);
}

} else if (scene_name == scene_gui_next) {
if (!gui_memoryOptimizer_isTabIDInMemory(currentTabID +1)) {
Serial.println("scene: cannot navigate to next gui, because there is none");
} else {
Serial.println("scene: will navigate to next gui");
setActiveTab(currentTabID +1, LV_ANIM_ON, true);
}

}
return;
}

// check if we know the new scene
if (!sceneExists(scene_name)) {
Serial.printf("scene: cannot start scene %s, because it is unknown\r\n", scene_name.c_str());
Expand Down
10 changes: 8 additions & 2 deletions Platformio/src/scenes/scene__default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

uint16_t SCENE_SELECTION;
std::string scene_name_selection = "sceneSelection";
uint16_t GUI_PREV;
uint16_t GUI_NEXT;
std::string scene_gui_prev = "GUI_prev";
std::string scene_gui_next = "GUI_next";

std::map<char, repeatModes> key_repeatModes_default;
std::map<char, uint16_t> key_commands_short_default;
Expand Down Expand Up @@ -44,7 +48,7 @@ void register_scene_defaultKeys(void) {
/*{KEY_STOP, COMMAND_UNKNOWN }, {KEY_REWI, COMMAND_UNKNOWN }, {KEY_PLAY, COMMAND_UNKNOWN }, {KEY_FORW, COMMAND_UNKNOWN },*/
/*{KEY_CONF, COMMAND_UNKNOWN }, {KEY_INFO, COMMAND_UNKNOWN },*/
/* {KEY_UP, COMMAND_UNKNOWN },*/
/* {KEY_LEFT, COMMAND_UNKNOWN }, {KEY_OK, COMMAND_UNKNOWN }, {KEY_RIGHT, COMMAND_UNKNOWN },*/
{KEY_LEFT, GUI_PREV }, /* {KEY_OK, COMMAND_UNKNOWN },*/ {KEY_RIGHT, GUI_NEXT },
/* {KEY_DOWN, COMMAND_UNKNOWN },*/
{KEY_BACK, SCENE_SELECTION }, /*{KEY_SRC, COMMAND_UNKNOWN },*/
{KEY_VOLUP, YAMAHA_VOL_PLUS }, {KEY_MUTE, YAMAHA_MUTE_TOGGLE}, /*{KEY_CHUP, COMMAND_UNKNOWN },*/
Expand All @@ -57,6 +61,8 @@ void register_scene_defaultKeys(void) {

};

register_command(&SCENE_SELECTION , makeCommandData(SCENE, {scene_name_selection}));
register_command(&SCENE_SELECTION, makeCommandData(SCENE, {scene_name_selection}));
register_command(&GUI_PREV , makeCommandData(SCENE, {scene_gui_prev}));
register_command(&GUI_NEXT , makeCommandData(SCENE, {scene_gui_next}));

}
6 changes: 5 additions & 1 deletion Platformio/src/scenes/scene__default.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include "applicationInternal/scenes/sceneRegistry.h"

extern uint16_t SCENE_SELECTION; // command
extern std::string scene_name_selection; // name of this fake default scene
extern std::string scene_name_selection; // payload: name of this fake default scene
extern uint16_t GUI_PREV; // command
extern uint16_t GUI_NEXT; // command
extern std::string scene_gui_prev; // payload: name of this fake scene
extern std::string scene_gui_next; // payload: name of this fake scene

extern std::map<char, repeatModes> key_repeatModes_default;
extern std::map<char, uint16_t> key_commands_short_default;
Expand Down

0 comments on commit 4e98d74

Please sign in to comment.