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

Scene selection #72

Merged
merged 4 commits into from
Apr 5, 2024
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/build-platformio-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
python-version: "3.12"

- name: Install SDL2
run: sudo apt install -y libsdl2-dev



run: |
sudo apt update
sudo apt upgrade -y
sudo apt install -y libsdl2-dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ void save_preferences_HAL(void) {
}

std::string get_currentScene_HAL() {
return currentScene;
// if (currentScene == "") {
// // set here something if you need it for a test at startup
// return "Apple TV";
// } else
{return currentScene;}

}
void set_currentScene_HAL(std::string aCurrentScene) {
currentScene = aCurrentScene;
}
std::string get_currentGUIname_HAL(){
return currentGUIname;
// if (currentGUIname == "") {
// // set here something if you need it for a test at startup
// return "IR Receiver"; // "Numpad"; // "Apple TV";
// } else
{return currentGUIname;}
}
void set_currentGUIname_HAL(std::string aCurrentGUIname) {
currentGUIname = aCurrentGUIname;
Expand Down
5 changes: 5 additions & 0 deletions Platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build_flags =
-D ENABLE_KEYBOARD_MQTT=0
-D ENABLE_BLUETOOTH=1
-D ENABLE_KEYBOARD_BLE=1
-D USE_SCENE_SPECIFIC_GUI_LIST=1
-D SCR_WIDTH=${env.custom_screen_width}
-D SCR_HEIGHT=${env.custom_screen_heigth}
;-- lvgl ------------------------------------------------------------------
Expand Down Expand Up @@ -68,6 +69,10 @@ build_flags =
; lvgl variant 2:
; or define where lv_conf.h is, relative to the `lvgl` folder
;-D LV_CONF_PATH=../../../../src/gui_general_and_keys/lv_conf.h
; --- interesting lvgl debug infos (OSD)
;-D LV_USE_PERF_MONITOR=1
;-D LV_USE_MEM_MONITOR=1
;-D LV_USE_REFR_DEBUG=1

[env:esp32]
platform = espressif32
Expand Down
2 changes: 2 additions & 0 deletions Platformio/src/applicationInternal/commandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// show received IR and MQTT messages
#include "guis/gui_irReceiver.h"

uint16_t COMMAND_UNKNOWN;

uint16_t KEYBOARD_DUMMY_UP ; //"Keyboard_dummy_up"
uint16_t KEYBOARD_DUMMY_DOWN ; //"Keyboard_dummy_down"
uint16_t KEYBOARD_DUMMY_RIGHT ; //"Keyboard_dummy_right"
Expand Down
2 changes: 2 additions & 0 deletions Platformio/src/applicationInternal/commandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "devices/keyboard/device_keyboard_mqtt/device_keyboard_mqtt.h"
#include "devices/keyboard/device_keyboard_ble/device_keyboard_ble.h"

extern uint16_t COMMAND_UNKNOWN;

/*
Depending on which keyboard is enabled (BLE or MQTT), we define KEYBOARD_UP, KEYBOARD_DOWN and so on.
These defines are used in keys.cpp, gui*.cpp and commandHandler.cpp
Expand Down
47 changes: 38 additions & 9 deletions Platformio/src/applicationInternal/gui/guiBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "applicationInternal/hardware/hardwarePresenter.h"
#include "applicationInternal/memoryUsage.h"
#include "applicationInternal/gui/guiMemoryOptimizer.h"
// for changing to scene Selection gui
#include "applicationInternal/commandHandler.h"
#include "scenes/scene__default.h"

lv_color_t color_primary = lv_color_hex(0x303030); // gray
lv_obj_t* MemoryUsageLabel = NULL;
Expand All @@ -26,10 +29,26 @@ lv_style_t style_red_border;
#endif

void guis_doTabCreationAtStartup();
void guis_doAfterSliding(int oldTabID, int newTabID);
void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList);

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

// 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");
executeCommand(SCENE_SELECTION);
}

// callback for swipe down event to navigate to the scene selection page
void screen_gesture_event_cb(lv_event_t* e) {
lv_obj_t* screen = lv_event_get_current_target(e);
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
if (dir == LV_DIR_BOTTOM) {
Serial.println("- Scene selection: swipe down received for navigating to scene selection page");
executeCommand(SCENE_SELECTION);
}
}

// Set the page indicator (panel) scroll position relative to the tabview content scroll position
// this is a callback if the CONTENT of the tabview is scrolled (LV_EVENT_SCROLL)
void tabview_content_is_scrolling_event_cb(lv_event_t* e){
Expand Down Expand Up @@ -62,7 +81,7 @@ static void tabview_animation_ready_cb(lv_anim_t* a) {
// We have to wait some more milliseconds or at least one cycle of lv_timer_handler();
// calling lv_timer_handler(); here does not help
// lv_timer_handler();
// guis_doAfterSliding(oldTabID, currentTabID);
// guis_doAfterSliding(oldTabID, currentTabID, false);

waitBeforeActionAfterSlidingAnimationEnded = true;
waitBeforeActionAfterSlidingAnimationEnded_timerStart = millis();
Expand All @@ -77,7 +96,7 @@ void tabview_tab_changed_event_cb(lv_event_t* e) {
oldTabID = currentTabID;
currentTabID = lv_tabview_get_tab_act(lv_event_get_target(e));

// Wait until the animation ended, then call "guis_doAfterSliding(oldTabID, currentTabID);"
// 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* myTabview = lv_event_get_target(e);
lv_obj_t* tabContainer = lv_tabview_get_content(myTabview);
Expand All @@ -91,7 +110,7 @@ void tabview_tab_changed_event_cb(lv_event_t* e) {
} 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);
guis_doAfterSliding(oldTabID, currentTabID, false);
}
}
}
Expand Down Expand Up @@ -131,6 +150,10 @@ void init_gui(void) {
init_gui_memoryUsage_bar();
// status bar
init_gui_status_bar();

// register callback for swipe down event to navigate to the scene selection page
lv_obj_add_event_cb(lv_scr_act(), screen_gesture_event_cb, LV_EVENT_GESTURE, NULL);

}

int panelHeight;
Expand Down Expand Up @@ -205,6 +228,7 @@ void init_gui_memoryUsage_bar() {
void init_gui_status_bar() {
// Create a status bar at the top -------------------------------------------------------------------------
statusbar = lv_btn_create(lv_scr_act());
lv_obj_clear_flag(statusbar, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(statusbar, SCR_WIDTH, statusbarHeight);
lv_obj_set_style_shadow_width(statusbar, 0, LV_PART_MAIN);
lv_obj_set_style_bg_color(statusbar, lv_color_black(), LV_PART_MAIN);
Expand All @@ -231,6 +255,9 @@ void init_gui_status_bar() {
lv_label_set_text(SceneLabel, "");
lv_obj_align(SceneLabel, LV_ALIGN_TOP_MID, 0, labelsPositionTopStatusbar);
lv_obj_set_style_text_font(SceneLabel, &lv_font_montserrat_12, LV_PART_MAIN);
lv_obj_add_flag(SceneLabel, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(SceneLabel, sceneLabel_or_pageIndicator_event_cb, LV_EVENT_CLICKED, NULL);

// Battery ----------------------------------------------------------------------
BattPercentageLabel = lv_label_create(statusbar);
lv_label_set_text(BattPercentageLabel, "");
Expand All @@ -251,12 +278,12 @@ void gui_loop(void) {
waitBeforeActionAfterSlidingAnimationEnded = false;
} else if (waitOneLoop) {
waitOneLoop = false;
guis_doAfterSliding(oldTabID, currentTabID);
guis_doAfterSliding(oldTabID, currentTabID, false);
};
// // as alternative, we could wait some milliseconds. But one cycle of gui_loop() works well.
// if (waitBeforeActionAfterSlidingAnimationEnded) {
// if (millis() - waitBeforeActionAfterSlidingAnimationEnded_timerStart >= 5) {
// guis_doAfterSliding(oldTabID, currentTabID);
// guis_doAfterSliding(oldTabID, currentTabID, false);
// waitBeforeActionAfterSlidingAnimationEnded = false;
// }
// }
Expand All @@ -267,11 +294,13 @@ void gui_loop(void) {
void guis_doTabCreationAtStartup() {
gui_memoryOptimizer_prepare_startup();

guis_doAfterSliding(-1, -1);
guis_doAfterSliding(-1, -1, false);
}

void guis_doAfterSliding(int oldTabID, int newTabID) {
gui_memoryOptimizer_doAfterSliding_deletionAndCreation(&tabview, oldTabID, newTabID, &panel, &img1, &img2);
void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList) {
// With parameter newGuiList it is signaled that we are changing from a scene specific list to the main list or vice versa
// In that case, we have to do special treatment because we are not simply sliding to the left or to the right, but we start newly with a different gui list.
gui_memoryOptimizer_doAfterSliding_deletionAndCreation(&tabview, oldTabID, newTabID, newGuiList, &panel, &img1, &img2);

doLogMemoryUsage();
}
Expand Down
3 changes: 3 additions & 0 deletions Platformio/src/applicationInternal/gui/guiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ 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 sceneLabel_or_pageIndicator_event_cb(lv_event_t* e);
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en);
// used by memoryUsage.cpp
void showMemoryUsageBar(bool showBar);
// used by commandHandler to show WiFi status
void showWiFiConnected(bool connected);

void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList);
Loading