Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assist function for MQTT messages #73

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Platformio/src/applicationInternal/gui/guiBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ void tabview_tab_changed_event_cb(lv_event_t* e) {
}
}

void tabview_tab_changed_manually(uint32_t current_tabID) {
oldTabID = currentTabID;
currentTabID = current_tabID;

// Wait until the animation ended, then call "guis_doAfterSliding(oldTabID, currentTabID, false);"
// https://forum.lvgl.io/t/delete-a-tab-after-the-tabview-scroll-animation-is-complete/3155/4
lv_obj_t* tabContainer = lv_tabview_get_content(tabview);
// https://docs.lvgl.io/8.3/overview/animation.html?highlight=lv_anim_get#_CPPv411lv_anim_getPv18lv_anim_exec_xcb_t
// (lv_anim_exec_xcb_t) lv_obj_set_x does not find an animation. NULL is good as well.
lv_anim_t* anim = lv_anim_get(tabContainer, NULL); // (lv_anim_exec_xcb_t) lv_obj_set_x);
if(anim) {
// Swipe is not yet complete. User released the touch screen, an animation will bring it to the end.
// That's the normal (and only?) case for the tft touchscreen
lv_anim_set_ready_cb(anim, tabview_animation_ready_cb);
} else {
// Swipe is complete, no additional animation is needed. Most likely only possible in simulator
Serial.println("Change of tab detected, without animation at the end. Will directly do my job after sliding.");
guis_doAfterSliding(oldTabID, currentTabID, false);
}
}

void setMainWidgetsHeightAndPosition();
void init_gui_status_bar();
void init_gui_memoryUsage_bar();
Expand Down
1 change: 1 addition & 0 deletions Platformio/src/applicationInternal/gui/guiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void gui_loop(void);
// used by guiMemoryOptimizer.cpp
void tabview_content_is_scrolling_event_cb(lv_event_t* e);
void tabview_tab_changed_event_cb(lv_event_t* e);
void tabview_tab_changed_manually(uint32_t current_tabID);
void sceneLabel_or_pageIndicator_event_cb(lv_event_t* e);
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en);
// used by memoryUsage.cpp
Expand Down
34 changes: 34 additions & 0 deletions Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ void getBreadcrumpPosition(uint8_t* breadcrumpPosition, std::string nameOfTab) {
}
}

void sidepanel_click_event_cb(lv_event_t *e) {
lv_obj_t *target = lv_event_get_target(e);
int user_data = (intptr_t)(target->user_data);
if (tabs_in_memory[2].listIndex == -1) {
if (user_data == 2) user_data = 1;
}
Serial.printf(" Sides of bottom bar clicked, swiping left(0) or right(1|2): %d\r\n", user_data);
setActiveTab(user_data, LV_ANIM_ON);
tabview_tab_changed_manually((uint32_t) user_data);
}

void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv_obj_t* img2) {
Serial.printf(" Will fill panel with page indicators\r\n");

Expand Down Expand Up @@ -309,6 +320,14 @@ 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 {
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
if (tabs_in_memory[0].listIndex == -1) {
lv_obj_set_user_data(btn,(void *)(intptr_t)2);
} else {
lv_obj_set_user_data(btn,(void *)(intptr_t)i);
}
lv_obj_add_event_cb(btn, sidepanel_click_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 Expand Up @@ -491,3 +510,18 @@ void gui_memoryOptimizer_doAfterSliding_deletionAndCreation(lv_obj_t** tabview,
Serial.printf("------------ End of tab deletion and creation\r\n");

}

bool checkTabActive(std::string tabName) {
bool tabnameIsActive = false;
if ((tabs_in_memory[1].guiName == tabName) && (tabs_in_memory[2].listIndex > 0)) tabnameIsActive = true;
if ((tabs_in_memory[0].guiName == tabName) && (tabs_in_memory[2].listIndex < 0)) tabnameIsActive = true;
return tabnameIsActive;
}

bool checkTabinMemory(std::string tabName) {
bool tabnameIsActive = false;
for (uint8_t i = 0; i < 3; i++) {
if (tabs_in_memory[i].guiName == tabName) tabnameIsActive = true;
}
return tabnameIsActive;
}
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 checkTabActive(std::string tabName);
bool checkTabinMemory(std::string tabName);