diff --git a/Platformio/hardware/windows_linux/preferencesStorage_hal_windows_linux.cpp b/Platformio/hardware/windows_linux/preferencesStorage_hal_windows_linux.cpp index be907c2..bff2b61 100644 --- a/Platformio/hardware/windows_linux/preferencesStorage_hal_windows_linux.cpp +++ b/Platformio/hardware/windows_linux/preferencesStorage_hal_windows_linux.cpp @@ -24,9 +24,9 @@ int lastActiveGUIlistIndex; void init_preferences_HAL(void) { // set some values for tests - activeScene = ""; // "Off", "TV", "Fire TV", "Chromecast", "Apple TV"; - activeGUIname = ""; // "Scene selection", "Smart Home", "Settings", "IR Receiver" // "Numpad", "Apple TV" - activeGUIlist = MAIN_GUI_LIST; // MAIN_GUI_LIST, SCENE_GUI_LIST; + activeScene = ""; // "Off", "TV", "Fire TV", "Chromecast", "Apple TV"; + activeGUIname = "Scene selection"; // "Scene selection", "Smart Home", "Settings", "IR Receiver" // "Numpad", "Apple TV" + activeGUIlist = MAIN_GUI_LIST; // MAIN_GUI_LIST, SCENE_GUI_LIST; lastActiveGUIlistIndex = 0; } void save_preferences_HAL(void) { diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index 196abb0..643668b 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -26,6 +26,12 @@ build_flags = -D USE_SCENE_SPECIFIC_GUI_LIST=1 -D SCR_WIDTH=${env.custom_screen_width} -D SCR_HEIGHT=${env.custom_screen_heigth} + ;-D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_NONE + ;-D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_ERROR + ;-D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_WARN + -D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_INFO + ;-D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_DEBUG + ;-D OMOTE_LOG_LEVEL=OMOTE_LOG_LEVEL_VERBOSE ;-- lvgl ------------------------------------------------------------------ ; lvgl variant 1: ; Don't use lv_conf.h. Tweak params via platfom.ini. See lv_conf_internal.h line 49. Don't change this line. @@ -46,13 +52,12 @@ build_flags = ; Enable the log module -D LV_USE_LOG=1 -D LV_LOG_PRINTF=1 - ; trace really gives a lot of messages ... - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_WARN - -D LV_LOG_LEVEL=LV_LOG_LEVEL_ERROR - ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_USER ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_NONE + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_USER + -D LV_LOG_LEVEL=LV_LOG_LEVEL_ERROR + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_WARN + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO + ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE ; --- ; Enable asserts if an operation is failed or an invalid data is found. ; If LV_USE_LOG is enabled an error message will be printed on failure*/ diff --git a/Platformio/src/applicationInternal/commandHandler.cpp b/Platformio/src/applicationInternal/commandHandler.cpp index e158343..f3d5439 100644 --- a/Platformio/src/applicationInternal/commandHandler.cpp +++ b/Platformio/src/applicationInternal/commandHandler.cpp @@ -6,6 +6,7 @@ #include "applicationInternal/commandHandler.h" #include "applicationInternal/scenes/sceneHandler.h" #include "applicationInternal/hardware/hardwarePresenter.h" +#include "applicationInternal/omote_log.h" #include "devices/misc/device_specialCommands.h" // show WiFi status #include "applicationInternal/gui/guiBase.h" @@ -179,7 +180,7 @@ std::string convertStringListToString(std::list listOfStrings) { void executeCommandWithData(uint16_t command, commandData commandData, std::string additionalPayload = "") { switch (commandData.commandHandler) { case IR: { - // Serial.printf(" generic IR, payloads %s\r\n", convertStringListToString(commandData.commandPayloads).c_str()); + omote_log_v(" generic IR, payloads %s\r\n", convertStringListToString(commandData.commandPayloads).c_str()); // we received a comma separated list of strings // the first string is the IR protocol, the second is the payload to be sent @@ -187,7 +188,7 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri // get protocol and erase first element in list std::string protocol = *it; it = commandData.commandPayloads.erase(it); - // Serial.printf(" protocol %s, payload %s\r\n", protocol.c_str(), convertStringListToString(commandData.commandPayloads).c_str()); + omote_log_v(" protocol %s, payload %s\r\n", protocol.c_str(), convertStringListToString(commandData.commandPayloads).c_str()); sendIRcode((IRprotocols)std::stoi(protocol), commandData.commandPayloads, additionalPayload); break; @@ -204,7 +205,7 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri } else { payload = additionalPayload; } - Serial.printf("execute: will send MQTT, topic '%s', payload '%s'\r\n", topic.c_str(), payload.c_str()); + omote_log_d("execute: will send MQTT, topic '%s', payload '%s'\r\n", topic.c_str(), payload.c_str()); publishMQTTMessage(topic.c_str(), payload.c_str()); break; } @@ -219,7 +220,7 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri if (additionalPayload != "") { payload = additionalPayload; } - Serial.printf("execute: will send BLE keyboard command, command '%u', payload '%s'\r\n", command, payload.c_str()); + omote_log_d("execute: will send BLE keyboard command, command '%u', payload '%s'\r\n", command, payload.c_str()); keyboard_ble_executeCommand(command, payload); break; } @@ -227,14 +228,14 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri case SCENE: { // let the sceneHandler do the scene stuff - Serial.printf("execute: will send scene command to the sceneHandler\r\n"); + omote_log_d("execute: will send scene command to the sceneHandler\r\n"); handleScene(command, commandData, additionalPayload); break; } case GUI: { // let the sceneHandler find and show the gui - Serial.printf("execute: will send gui command to the sceneHandler\r\n"); + omote_log_d("execute: will send gui command to the sceneHandler\r\n"); handleGUI(command, commandData, additionalPayload); break; } @@ -242,7 +243,7 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri case SPECIAL: { if (command == MY_SPECIAL_COMMAND) { // do your special command here - Serial.printf("execute: could execute a special command here, if you define one\r\n"); + omote_log_d("execute: could execute a special command here, if you define one\r\n"); } break; @@ -253,14 +254,14 @@ void executeCommandWithData(uint16_t command, commandData commandData, std::stri void executeCommand(uint16_t command, std::string additionalPayload) { try { if (commands.count(command) > 0) { - Serial.printf("command: will execute command '%u' with additionalPayload '%s'\r\n", command, additionalPayload.c_str()); + omote_log_d("command: will execute command '%u' with additionalPayload '%s'\r\n", command, additionalPayload.c_str()); executeCommandWithData(command, commands.at(command), additionalPayload); } else { - Serial.printf("command: command '%u' not found\r\n", command); + omote_log_w("command: command '%u' not found\r\n", command); } } catch (const std::out_of_range& oor) { - Serial.printf("executeCommand: internal error, command not registered\r\n"); + omote_log_e("executeCommand: internal error, command not registered\r\n"); } } diff --git a/Platformio/src/applicationInternal/gui/guiBase.cpp b/Platformio/src/applicationInternal/gui/guiBase.cpp index c3948de..217de86 100644 --- a/Platformio/src/applicationInternal/gui/guiBase.cpp +++ b/Platformio/src/applicationInternal/gui/guiBase.cpp @@ -4,6 +4,7 @@ #include "applicationInternal/gui/guiMemoryOptimizer.h" // for changing to scene Selection gui #include "applicationInternal/commandHandler.h" +#include "applicationInternal/omote_log.h" #include "scenes/scene__default.h" lv_color_t color_primary = lv_color_hex(0x303030); // gray @@ -47,7 +48,7 @@ void pageIndicator_navigate_event_cb(lv_event_t* e) { // 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"); + omote_log_d("- Scene selection: sceneLabel or pageIndicator clicked received for navigating to scene selection page\r\n"); executeCommand(SCENE_SELECTION); } @@ -56,7 +57,7 @@ void screen_gesture_event_cb(lv_event_t* e) { lv_obj_t* screen = (lv_obj_t*)lv_event_get_current_target(e); lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_active()); if (dir == LV_DIR_BOTTOM) { - Serial.println("- Scene selection: swipe down received for navigating to scene selection page"); + omote_log_d("- Scene selection: swipe down received for navigating to scene selection page\r\n"); executeCommand(SCENE_SELECTION); } } @@ -79,7 +80,7 @@ void tabview_content_is_scrolling_event_cb(lv_event_t* e){ if ((tabviewX >= 475) && (tabviewX <= 480)) {tabviewX = 480;} // we need 158 more (the size of one page indicator), because we always have one more page indicator at the beginning and at the end (so normally 5 when having 3 tabs) int16_t panelX = tabviewX * bias - offset + 158; - // Serial.printf("scroll %d to %d\r\n", tabviewX, panelX); + omote_log_v("scroll %d to %d\r\n", tabviewX, panelX); lv_obj_scroll_to_x(panel, panelX, LV_ANIM_OFF); // lv_obj_scroll_to_x(panel, lv_obj_get_scroll_x(tabviewContent) * bias - offset, LV_ANIM_OFF); } @@ -120,7 +121,7 @@ void tabview_tab_changed_event_cb(lv_event_t* e) { lv_anim_set_completed_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."); + omote_log_d("Change of tab detected, without animation at the end. Will directly do my job after sliding.\r\n"); guis_doTabCreationAfterSliding(newTabID); } } diff --git a/Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp b/Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp index 278f3e5..295681c 100644 --- a/Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp +++ b/Platformio/src/applicationInternal/gui/guiMemoryOptimizer.cpp @@ -4,6 +4,7 @@ #include "applicationInternal/gui/guiRegistry.h" #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/scenes/sceneRegistry.h" +#include "applicationInternal/omote_log.h" struct t_gui_on_tab { lv_obj_t* tab; @@ -85,11 +86,11 @@ bool gui_memoryOptimizer_isGUInameInMemory(std::string GUIname) { } void notify_active_tabs_before_delete(t_gui_state *gui_state) { - Serial.printf(" Will notify tabs about deletion\r\n"); + omote_log_d(" Will notify tabs about deletion\r\n"); std::string nameOfTab; for (int index=0; index <= 2; index++) { if (gui_state->gui_on_tab[index].gui_list_index == -1) { - Serial.printf(" Will not notify tab %d about deletion because it does not exist\r\n", index); + omote_log_d(" Will not notify tab %d about deletion because it does not exist\r\n", index); continue; } @@ -97,11 +98,11 @@ void notify_active_tabs_before_delete(t_gui_state *gui_state) { // The gui_list might have changed (when switching from a scene specific list to the main list or vice versa), so index could have changed as well. nameOfTab = gui_state->gui_on_tab[index].GUIname; if (nameOfTab == "") { - Serial.printf(" Will not notify tab %d about deletion because it is not set\r\n", index); + omote_log_w(" Will not notify tab %d about deletion because it is not set\r\n", index); } else if (registered_guis_byName_map.count(nameOfTab) == 0) { - Serial.printf(" Can not notify tab %d about deletion because name \"%s\" was not found in registry\r\n", index, nameOfTab.c_str()); + omote_log_w(" Can not notify tab %d about deletion because name \"%s\" was not found in registry\r\n", index, nameOfTab.c_str()); } else { - Serial.printf(" Will notify tab %d with name \"%s\" about deletion\r\n", index, nameOfTab.c_str()); + omote_log_d(" Will notify tab %d with name \"%s\" about deletion\r\n", index, nameOfTab.c_str()); registered_guis_byName_map.at(nameOfTab).this_notify_tab_before_delete(); } } @@ -181,11 +182,11 @@ void create_new_tab(lv_obj_t* tabview, t_gui_on_tab *gui_on_tab) { std::string nameOfTab = get_name_of_gui_to_be_shown(gui_on_tab->gui_list_index); if (nameOfTab == "") { - Serial.printf(" Will not create new tab because no name was provided\r\n"); + omote_log_d(" Will not create new tab because no name was provided\r\n"); } else if (registered_guis_byName_map.count(nameOfTab) == 0) { - Serial.printf(" Will not create new tab because name %s was not found in registry\r\n", nameOfTab.c_str()); + omote_log_w(" Will not create new tab because name %s was not found in registry\r\n", nameOfTab.c_str()); } else { - Serial.printf(" Will create tab with name \"%s\" \r\n", nameOfTab.c_str()); + omote_log_d(" Will create tab with name \"%s\" \r\n", nameOfTab.c_str()); // save name of tab for deletion later gui_on_tab->GUIname = nameOfTab; // create tab and save pointer to tab in gui_on_tab @@ -209,7 +210,7 @@ void setGUIlistIndicesToBeShown_forSpecificGUIlistIndex(int gui_list_index, t_gu // Set the gui_list_indeces to be shown for a specific gui_list_index if (gui_list_index == 0) { // first state - Serial.printf(" GUIlistIndices: will resume at specific index with \"first state\"\r\n"); + omote_log_d(" GUIlistIndices: will resume at specific index with \"first state\"\r\n"); gui_state->gui_on_tab[0] = {NULL, "", 0}; // take care if there is only one gui in list gui_state->gui_on_tab[1] = {NULL, "", get_gui_list_active_withFallback()->size() >= 2 ? 1 : -1}; @@ -217,14 +218,14 @@ void setGUIlistIndicesToBeShown_forSpecificGUIlistIndex(int gui_list_index, t_gu gui_state->activeTabID = 0; } else if (gui_list_index == get_gui_list_active_withFallback()->size() -1) { // last state - Serial.printf(" GUIlistIndices: will resume at specific index with \"last state\"\r\n"); + omote_log_d(" GUIlistIndices: will resume at specific index with \"last state\"\r\n"); gui_state->gui_on_tab[0] = {NULL, "", gui_list_index -1}; gui_state->gui_on_tab[1] = {NULL, "", gui_list_index}; gui_state->gui_on_tab[2] = {NULL, "", -1}; gui_state->activeTabID = 1; } else { // any other state - Serial.printf(" GUIlistIndices: will resume at specific index with \"state between\"\r\n"); + omote_log_d(" GUIlistIndices: will resume at specific index with \"state between\"\r\n"); gui_state->gui_on_tab[0] = {NULL, "", gui_list_index -1}; gui_state->gui_on_tab[1] = {NULL, "", gui_list_index}; gui_state->gui_on_tab[2] = {NULL, "", gui_list_index +1}; @@ -233,7 +234,7 @@ void setGUIlistIndicesToBeShown_forSpecificGUIlistIndex(int gui_list_index, t_gu } void setGUIlistIndicesToBeShown_forFirstGUIinGUIlist(t_gui_state *gui_state) { - Serial.printf(" GUIlistIndices: will show the first gui from \"gui_list\" as initial state\r\n"); + omote_log_d(" GUIlistIndices: will show the first gui from \"gui_list\" as initial state\r\n"); // take care if there is no gui in list gui_state->gui_on_tab[0] = {NULL, "", get_gui_list_active_withFallback()->size() != 0 ? 0 : -1}; // take care if there is only one gui in list @@ -247,7 +248,7 @@ void setGUIlistIndicesToBeShown_afterSlide(t_gui_state *gui_state) { if (gui_state->oldTabID > gui_state->activeTabID) { // swipe to previous item in list - Serial.printf(" Will swipe to previous item in list\r\n"); + omote_log_d(" Will swipe to previous item in list\r\n"); oldListIndex = gui_state->gui_on_tab[1].gui_list_index_previous; if ((oldListIndex == 1)) { // next state is the "first state" @@ -263,7 +264,7 @@ void setGUIlistIndicesToBeShown_afterSlide(t_gui_state *gui_state) { } } else { // swipe to next item in list - Serial.printf(" Will swipe to next item in list\r\n"); + omote_log_d(" Will swipe to next item in list\r\n"); if (gui_state->gui_on_tab[2].gui_list_index_previous == -1) { // last state was the first state oldListIndex = gui_state->gui_on_tab[0].gui_list_index_previous; // is always 0 @@ -289,14 +290,14 @@ void setGUIlistIndicesToBeShown_afterSlide(t_gui_state *gui_state) { void doTabCreation_strategyMax3(lv_obj_t* tabview, t_gui_state *gui_state) { // create the tabs - Serial.printf(" Will create tabs. List indices of the three tabs are %d, %d, %d, tab nr %d will be activated\r\n", gui_state->gui_on_tab[0].gui_list_index, gui_state->gui_on_tab[1].gui_list_index, gui_state->gui_on_tab[2].gui_list_index, gui_state->activeTabID); + omote_log_d(" Will create tabs. List indices of the three tabs are %d, %d, %d, tab nr %d will be activated\r\n", gui_state->gui_on_tab[0].gui_list_index, gui_state->gui_on_tab[1].gui_list_index, gui_state->gui_on_tab[2].gui_list_index, gui_state->activeTabID); for (int i=0; i<3; i++) { create_new_tab(tabview, &gui_state->gui_on_tab[i]); } if (get_gui_list_active_withFallback()->size() > 0) { std::string nameOfNewActiveTab = get_gui_list_active_withFallback()->at(gui_state->gui_on_tab[gui_state->activeTabID].gui_list_index); - Serial.printf(" New visible tab is \"%s\"\r\n", nameOfNewActiveTab.c_str()); + omote_log_d(" New visible tab is \"%s\"\r\n", nameOfNewActiveTab.c_str()); // set active tab setActiveTab(gui_state->activeTabID, LV_ANIM_OFF); @@ -308,10 +309,10 @@ LV_IMAGE_DECLARE(gradientLeft); LV_IMAGE_DECLARE(gradientRight); void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv_obj_t* img2, t_gui_state *gui_state) { - Serial.printf(" Will fill panel with page indicators\r\n"); + omote_log_d(" Will fill panel with page indicators\r\n"); if (get_gui_list_active_withFallback()->size() == 0) { - Serial.printf(" no tab available, so no page indicators\r\n"); + omote_log_d(" no tab available, so no page indicators\r\n"); // at least add the style lv_obj_add_style(panel, &panel_style, 0); #ifdef drawRedBorderAroundMainWidgets @@ -533,7 +534,7 @@ void gui_memoryOptimizer_doContentCreation(lv_obj_t** tabview, lv_obj_t** panel, // find the position of the current GUI in the gui list which was active last (both were automatically saved in the preferences) void gui_memoryOptimizer_onStartup(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_t** img1, lv_obj_t** img2) { - Serial.printf("Startup: try to resume at scene \"%s\" with GUI \"%s\"\r\n", gui_memoryOptimizer_getActiveSceneName().c_str(), gui_memoryOptimizer_getActiveGUIname().c_str()); + omote_log_i("Startup: try to resume at scene \"%s\" with GUI \"%s\"\r\n", gui_memoryOptimizer_getActiveSceneName().c_str(), gui_memoryOptimizer_getActiveGUIname().c_str()); // Get last state from preferences and save it in gui_state // So it is ok to call them without using the return values. @@ -547,7 +548,7 @@ void gui_memoryOptimizer_onStartup(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_ // find index of gui_memoryOptimizer_getActiveGUIname() in gui_list_active for (int i=0; isize(); i++) { if (get_gui_list_active_withFallback()->at(i) == gui_memoryOptimizer_getActiveGUIname()) { - Serial.printf("Startup: found GUI with name \"%s\" in \"gui_list_active\" at position %d\r\n", gui_memoryOptimizer_getActiveGUIname().c_str(), i); + omote_log_i("Startup: found GUI with name \"%s\" in \"gui_list_active\" at position %d\r\n", gui_memoryOptimizer_getActiveGUIname().c_str(), i); gui_list_index = i; break; } @@ -560,7 +561,7 @@ void gui_memoryOptimizer_onStartup(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_ } else { // gui was not found - Serial.printf("Startup: GUI with name \"%s\" was not found. Will start with first GUI of main_gui_list\r\n", gui_memoryOptimizer_getActiveGUIname().c_str()); + omote_log_w("Startup: GUI with name \"%s\" was not found. Will start with first GUI of main_gui_list\r\n", gui_memoryOptimizer_getActiveGUIname().c_str()); gui_memoryOptimizer_setActiveGUIlist(MAIN_GUI_LIST); setGUIlistIndicesToBeShown_forFirstGUIinGUIlist(&gui_state); @@ -580,12 +581,12 @@ void gui_memoryOptimizer_afterSliding(lv_obj_t** tabview, lv_obj_t** panel, lv_o // So we always have 3 tabs. // After the animation, the tabview and hence all tabs are deleted and recreated. - Serial.printf("--- Start of tab deletion and creation\r\n"); + omote_log_d("--- Start of tab deletion and creation\r\n"); gui_state.oldTabID = gui_state.activeTabID; gui_state.activeTabID = newTabID; - Serial.printf("Changing from oldTabID %d \"%s\" to newTabID %d \"%s\"\r\n", + omote_log_d("Changing from oldTabID %d \"%s\" to newTabID %d \"%s\"\r\n", gui_state.oldTabID, gui_state.gui_on_tab[gui_state.oldTabID].GUIname.c_str(), gui_state.activeTabID, gui_state.gui_on_tab[gui_state.activeTabID].GUIname.c_str()); @@ -612,7 +613,7 @@ void gui_memoryOptimizer_afterSliding(lv_obj_t** tabview, lv_obj_t** panel, lv_o // 3. after gui list has changed (called by handleScene()), when switching between main_gui_list and scene specific list. Will show first GUi in list void gui_memoryOptimizer_afterGUIlistChanged(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_t** img1, lv_obj_t** img2, GUIlists newGUIlist) { - Serial.printf("--- Will change to new gui_list\r\n"); + omote_log_d("--- Will change to new gui_list\r\n"); if (gui_state.last_active_gui_list != newGUIlist) { // we are changing the gui_list, so save the last_active_gui_list_index @@ -634,10 +635,10 @@ void gui_memoryOptimizer_afterGUIlistChanged(lv_obj_t** tabview, lv_obj_t** pane // 4. navigate to a specific GUI in gui_list void gui_memoryOptimizer_navigateToGUI(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_t** img1, lv_obj_t** img2, GUIlists GUIlist, int gui_list_index) { - Serial.printf("--- Will navigate to specific GUI\r\n"); + omote_log_d("--- Will navigate to specific GUI\r\n"); if ( !((gui_list_index >= 0) && (gui_list_index < get_gui_list_withFallback(GUIlist)->size()))) { - Serial.printf(" cannot navigate to GUI because gui_list_index \"%d\" is out of range\r\n", gui_list_index); + omote_log_w(" cannot navigate to GUI because gui_list_index \"%d\" is out of range\r\n", gui_list_index); return; } @@ -662,15 +663,15 @@ void gui_memoryOptimizer_navigateToGUI(lv_obj_t** tabview, lv_obj_t** panel, lv_ void gui_memoryOptimizer_navigateToLastActiveGUIofPreviousGUIlist(lv_obj_t** tabview, lv_obj_t** panel, lv_obj_t** img1, lv_obj_t** img2) { #if (USE_SCENE_SPECIFIC_GUI_LIST == 0) - Serial.printf("--- Cannot navigate to last GUI from scene, because scene specific gui lists are not enabled\r\n"); + omote_log_w("--- Cannot navigate to last GUI from scene, because scene specific gui lists are not enabled\r\n"); return; #endif if (gui_memoryOptimizer_getLastActiveGUIlistIndex() == -1) { - Serial.printf("--- Cannot navigate to last GUI from scene, because it is not set\r\n"); + omote_log_w("--- Cannot navigate to last GUI from scene, because it is not set\r\n"); return; } else { - Serial.printf("--- Will navigate to last GUI from scene\r\n"); + omote_log_d("--- Will navigate to last GUI from scene\r\n"); } // navigate to the other gui_list @@ -710,6 +711,6 @@ void gui_memoryOptimizer_doContentCreation(lv_obj_t** tabview, lv_obj_t** panel, // so that we can use SCENE_BACK_TO_PREVIOUS_GUI_LIST gui_state->last_active_gui_list = gui_memoryOptimizer_getActiveGUIlist(); - Serial.printf("------------ End of tab deletion and creation\r\n"); + omote_log_d("------------ End of tab deletion and creation\r\n"); } diff --git a/Platformio/src/applicationInternal/gui/guiRegistry.cpp b/Platformio/src/applicationInternal/gui/guiRegistry.cpp index ed628a4..51b06db 100644 --- a/Platformio/src/applicationInternal/gui/guiRegistry.cpp +++ b/Platformio/src/applicationInternal/gui/guiRegistry.cpp @@ -7,6 +7,7 @@ #include "applicationInternal/gui/guiBase.h" #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/scenes/sceneRegistry.h" +#include "applicationInternal/omote_log.h" #include "scenes/scene__default.h" // ------------------------------------------------------------------------------------ @@ -27,7 +28,7 @@ void register_gui( ) { if (registered_guis_byName_map.count(a_name) > 0) { - Serial.printf("ERROR!!!: you cannot register two guis having the same name '%s'\r\n", a_name.c_str()); + omote_log_e("ERROR!!!: you cannot register two guis having the same name '%s'\r\n", a_name.c_str()); return; } diff --git a/Platformio/src/applicationInternal/keys.cpp b/Platformio/src/applicationInternal/keys.cpp index f46cdcb..422a271 100644 --- a/Platformio/src/applicationInternal/keys.cpp +++ b/Platformio/src/applicationInternal/keys.cpp @@ -3,6 +3,7 @@ #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/scenes/sceneRegistry.h" #include "applicationInternal/commandHandler.h" +#include "applicationInternal/omote_log.h" const uint8_t ROWS = 5; //five rows const uint8_t COLS = 5; //five columns @@ -36,10 +37,10 @@ void doShortPress(char keyChar, int keyCode){ uint16_t command = get_command_short(gui_memoryOptimizer_getActiveSceneName(), keyChar); if (command != COMMAND_UNKNOWN) { - Serial.printf("key: key '%c', will use command '%u'\r\n", keyChar, command); + omote_log_d("key: key '%c', will use command '%u'\r\n", keyChar, command); executeCommand(command); } else { - Serial.printf("key: key '%c', but no command defined\r\n", keyChar); + omote_log_w("key: key '%c', but no command defined\r\n", keyChar); } } } @@ -47,10 +48,10 @@ void doShortPress(char keyChar, int keyCode){ void doLongPress(char keyChar, int keyCode){ uint16_t command = get_command_long(gui_memoryOptimizer_getActiveSceneName(), keyChar); if (command != COMMAND_UNKNOWN) { - Serial.printf("key: key '%c' (long press), will use command '%u'\r\n", keyChar, command); + omote_log_d("key: key '%c' (long press), will use command '%u'\r\n", keyChar, command); executeCommand(command); } else { - Serial.printf("key: key '%c' (long press), but no command defined\r\n", keyChar); + omote_log_w("key: key '%c' (long press), but no command defined\r\n", keyChar); } } @@ -69,52 +70,52 @@ void keypad_loop(void) { int keyCode = keypad_keys[i].kcode; if (keypad_keys[i].kstate == PRESSED) { - // Serial.println("pressed"); + omote_log_v("pressed\r\n"); if ((get_key_repeatMode(gui_memoryOptimizer_getActiveSceneName(), keyChar) == SHORT) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) { - // Serial.printf("key: PRESSED of SHORT key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("key: PRESSED of SHORT key %c (%d)\r\n", keyChar, keyCode); doShortPress(keyChar, keyCode); } else if ((get_key_repeatMode(gui_memoryOptimizer_getActiveSceneName(), keyChar) == SHORT_REPEATED) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) { // here do not repeat it too early, do the repeat only in HOLD - // Serial.printf("key: PRESSED of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("key: PRESSED of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode); doShortPress(keyChar, keyCode); } lastKeyState[keyCode/ROWS][keyCode%ROWS] = PRESSED; } else if (keypad_keys[i].kstate == HOLD) { - // Serial.println("hold"); + omote_log_v("hold\r\n"); if ((get_key_repeatMode(gui_memoryOptimizer_getActiveSceneName(), keyChar) == SHORTorLONG) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != HOLD)) { - // Serial.printf("key: HOLD of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode); - // Serial.printf("will set keyIsHold to TRUE for keycode %d\r\n", keyCode); + omote_log_v("key: HOLD of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("will set keyIsHold to TRUE for keycode %d\r\n", keyCode); keyIsHold[keyCode/ROWS][keyCode%ROWS] = true; doLongPress(keyChar, keyCode); } else if (get_key_repeatMode(gui_memoryOptimizer_getActiveSceneName(), keyChar) == SHORT_REPEATED) { // this is the only case where we do not check the lastKeyState, because here it is intended to repeat the action - // Serial.printf("key: HOLD of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("key: HOLD of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode); doShortPress(keyChar, keyCode); } lastKeyState[keyCode/ROWS][keyCode%ROWS] = HOLD; } else if (keypad_keys[i].kstate == RELEASED) { - // Serial.println("released"); + omote_log_v("released\r\n"); if ((get_key_repeatMode(gui_memoryOptimizer_getActiveSceneName(), keyChar) == SHORTorLONG) && !keyIsHold[keyCode/ROWS][keyCode%ROWS] && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != RELEASED)) { - // Serial.printf("value of keyIsHold for keycode %d is %d\r\n", keyCode, keyIsHold[keyCode/ROWS][keyCode%ROWS]); - // Serial.printf("key: RELEASED of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("value of keyIsHold for keycode %d is %d\r\n", keyCode, keyIsHold[keyCode/ROWS][keyCode%ROWS]); + omote_log_v("key: RELEASED of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode); doShortPress(keyChar, keyCode); } - // Serial.printf("will set keyIsHold to FALSE for keycode %d\r\n", keyCode); + omote_log_v("will set keyIsHold to FALSE for keycode %d\r\n", keyCode); keyIsHold[keyCode/ROWS][keyCode%ROWS] = false; - // Serial.printf("key: press of key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("key: press of key %c (%d)\r\n", keyChar, keyCode); lastKeyState[keyCode/ROWS][keyCode%ROWS] = RELEASED; } else if (keypad_keys[i].kstate == IDLE) { - // Serial.println("idle"); + omote_log_v("idle\r\n"); - // Serial.printf("key: idle of key %c (%d)\r\n", keyChar, keyCode); + omote_log_v("key: idle of key %c (%d)\r\n", keyChar, keyCode); lastKeyState[keyCode/ROWS][keyCode%ROWS] = IDLE; } diff --git a/Platformio/src/applicationInternal/memoryUsage.cpp b/Platformio/src/applicationInternal/memoryUsage.cpp index 04634ca..402e753 100644 --- a/Platformio/src/applicationInternal/memoryUsage.cpp +++ b/Platformio/src/applicationInternal/memoryUsage.cpp @@ -1,6 +1,7 @@ #include #include "applicationInternal/gui/guiBase.h" #include "applicationInternal/hardware/hardwarePresenter.h" +#include "applicationInternal/omote_log.h" bool showMemoryUsage = 0; @@ -22,7 +23,7 @@ void setShowMemoryUsage(bool aShowMemoryUsage) { } void doLogMemoryUsage() { - // Serial.println("inside doLogMemoryUsage"); + omote_log_v("inside doLogMemoryUsage\r\n"); unsigned long systemHeapSize; unsigned long freeSystemHeap; unsigned long maxAllocSystemHeap; @@ -51,13 +52,13 @@ void doLogMemoryUsage() { #if defined(SHOW_LOG_ON_SERIAL) // Serial log every 5 sec if(millis() - updateSerialLogTimer >= 5000) { - // Serial.println("inside doLogMemoryUsage: will do serial log"); + omote_log_v("inside doLogMemoryUsage: will do serial log\r\n"); updateSerialLogTimer = millis(); if (doESPHeapWarning) { - Serial.println("WARNING: ESP heap is getting low. You might encounter weird behaviour of your OMOTE, especially when using WiFi and/or BLE."); + omote_log_w("WARNING: ESP heap is getting low. You might encounter weird behaviour of your OMOTE, especially when using WiFi and/or BLE.\r\n"); } - Serial.printf( + omote_log_d( "ESP32 heap: size: %6lu, used: %6lu (%2.0f%%), free: %6lu (%2.0f%%), heapMax: %6lu, heapMin: %6lu\r\n", systemHeapSize, systemHeapSize - freeSystemHeap, float(systemHeapSize - freeSystemHeap) / systemHeapSize * 100, @@ -66,9 +67,9 @@ void doLogMemoryUsage() { #if (LV_USE_STDLIB_MALLOC == 0) if (doLVGLMemoryWarning) { - Serial.println("WARNING: LVGL memory is getting low. You GUI might stop working. In that case, increase \"-D LV_MEM_SIZE\" in platformio.ini"); + omote_log_w("WARNING: LVGL memory is getting low. You GUI might stop working. In that case, increase \"-D LV_MEM_SIZE\" in platformio.ini\r\n"); } - Serial.printf( + omote_log_d( "lvgl memory: size: %6lu, used: %6lu (%2d%%), free: %6lu (%2d%%), max_used: %6lu, free_biggest: %6lu, frag_pct: %2d%%\r\n", mon.total_size, mon.total_size - mon.free_size, mon.used_pct, @@ -76,7 +77,7 @@ void doLogMemoryUsage() { mon.max_used, mon.free_biggest_size, mon.frag_pct); #endif } else { - // Serial.println("inside doLogMemoryUsage: serial log skipped"); + omote_log_v("inside doLogMemoryUsage: serial log skipped\r\n"); } #endif diff --git a/Platformio/src/applicationInternal/omote_log.h b/Platformio/src/applicationInternal/omote_log.h new file mode 100644 index 0000000..9c57d5d --- /dev/null +++ b/Platformio/src/applicationInternal/omote_log.h @@ -0,0 +1,66 @@ +#ifndef __OMOTE_LOG_H__ +#define __OMOTE_LOG_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define OMOTE_LOG_LEVEL_NONE (0) +#define OMOTE_LOG_LEVEL_ERROR (1) +#define OMOTE_LOG_LEVEL_WARN (2) +#define OMOTE_LOG_LEVEL_INFO (3) +#define OMOTE_LOG_LEVEL_DEBUG (4) +#define OMOTE_LOG_LEVEL_VERBOSE (5) + +#ifndef CONFIG_OMOTE_LOG_DEFAULT_LEVEL +#define CONFIG_OMOTE_LOG_DEFAULT_LEVEL OMOTE_LOG_LEVEL_NONE +#endif + +#ifndef OMOTE_LOG_LEVEL +#define OMOTE_LOG_LEVEL CONFIG_OMOTE_LOG_DEFAULT_LEVEL +#endif + +#define OMOTE_LOG_FORMAT(letter, format) "[OMOTE " #letter "][%8lu]: " format , (unsigned long) millis() + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_VERBOSE +#define omote_log_v(format, ...) Serial.printf(OMOTE_LOG_FORMAT(V, format), ##__VA_ARGS__) +#else +#define omote_log_v(format, ...) do {} while(0) +#endif + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_DEBUG +#define omote_log_d(format, ...) Serial.printf(OMOTE_LOG_FORMAT(D, format), ##__VA_ARGS__) +#else +#define omote_log_d(format, ...) do {} while(0) +#endif + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_INFO +#define omote_log_i(format, ...) Serial.printf(OMOTE_LOG_FORMAT(I, format), ##__VA_ARGS__) +#else +#define omote_log_i(format, ...) do {} while(0) +#endif + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_WARN +#define omote_log_w(format, ...) Serial.printf(OMOTE_LOG_FORMAT(W, format), ##__VA_ARGS__) +#else +#define omote_log_w(format, ...) do {} while(0) +#endif + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_ERROR +#define omote_log_e(format, ...) Serial.printf(OMOTE_LOG_FORMAT(E, format), ##__VA_ARGS__) +#else +#define omote_log_e(format, ...) do {} while(0) +#endif + +#if OMOTE_LOG_LEVEL >= OMOTE_LOG_LEVEL_NONE +#define omote_log_n(format, ...) Serial.printf(OMOTE_LOG_FORMAT(E, format), ##__VA_ARGS__) +#else +#define omote_log_n(format, ...) do {} while(0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __OMOTE_LOG_H__ */ diff --git a/Platformio/src/applicationInternal/scenes/sceneHandler.cpp b/Platformio/src/applicationInternal/scenes/sceneHandler.cpp index 3e77910..64f468f 100644 --- a/Platformio/src/applicationInternal/scenes/sceneHandler.cpp +++ b/Platformio/src/applicationInternal/scenes/sceneHandler.cpp @@ -5,6 +5,7 @@ #include "applicationInternal/scenes/sceneRegistry.h" #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/commandHandler.h" +#include "applicationInternal/omote_log.h" #include "guis/gui_sceneSelection.h" #include "scenes/scene__default.h" @@ -23,7 +24,7 @@ void handleScene(uint16_t command, commandData commandData, std::string addition // --- do not switch scene, but show scene selection gui. From that on, we are in the main_gui_list. ---------------- if (scene_name == scene_name_selection) { - Serial.println("scene: will show scene selection gui"); + omote_log_d("scene: will show scene selection gui\r\n"); showSpecificGUI(MAIN_GUI_LIST, tabName_sceneSelection); return; } @@ -32,17 +33,17 @@ void handleScene(uint16_t command, commandData commandData, std::string addition if ((scene_name == scene_gui_next) || (scene_name == scene_gui_prev)) { if (scene_name == scene_gui_prev) { if (gui_memoryOptimizer_getActiveTabID() == 0) { - Serial.println("scene: cannot navigate to prev gui, because there is none"); + omote_log_d("scene: cannot navigate to prev gui, because there is none\r\n"); } else { - Serial.println("scene: will navigate to prev gui"); + omote_log_d("scene: will navigate to prev gui\r\n"); setActiveTab(gui_memoryOptimizer_getActiveTabID() -1, LV_ANIM_ON, true); } } else if (scene_name == scene_gui_next) { if (!gui_memoryOptimizer_isTabIDInMemory(gui_memoryOptimizer_getActiveTabID() +1)) { - Serial.println("scene: cannot navigate to next gui, because there is none"); + omote_log_d("scene: cannot navigate to next gui, because there is none\r\n"); } else { - Serial.println("scene: will navigate to next gui"); + omote_log_d("scene: will navigate to next gui\r\n"); setActiveTab(gui_memoryOptimizer_getActiveTabID() +1, LV_ANIM_ON, true); } @@ -54,10 +55,10 @@ void handleScene(uint16_t command, commandData commandData, std::string addition if (scene_name == scene_back_to_previous_gui_list) { if (get_scene_has_gui_list(gui_memoryOptimizer_getActiveSceneName())) { - Serial.println("scene: will navigate back to last active gui from previous gui list"); + omote_log_d("scene: will navigate back to last active gui from previous gui list\r\n"); guis_doTabCreationForNavigateToLastActiveGUIofPreviousGUIlist(); } else { - Serial.println("scene: cannot navigate back to last active gui from previous gui list, because no scene specific gui list was defined"); + omote_log_d("scene: cannot navigate back to last active gui from previous gui list, because no scene specific gui list was defined\r\n"); } return; @@ -79,19 +80,19 @@ void handleScene(uint16_t command, commandData commandData, std::string addition // 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()); + omote_log_w("scene: cannot start scene %s, because it is unknown\r\n", scene_name.c_str()); return; } else { - Serial.printf("scene: will switch from old scene %s to new scene %s\r\n", gui_memoryOptimizer_getActiveSceneName().c_str(), scene_name.c_str()); + omote_log_d("scene: will switch from old scene %s to new scene %s\r\n", gui_memoryOptimizer_getActiveSceneName().c_str(), scene_name.c_str()); } // do not activate the same scene again, only when forced to do so (e.g. by long press on the gui or when selected by hardware key) bool callEndAndStartSequences; if ((scene_name == gui_memoryOptimizer_getActiveSceneName()) && ((isForcePayload != "FORCE") && (additionalPayload != "FORCE"))) { - Serial.printf("scene: will not start scene again, because it is already active\r\n"); + omote_log_d("scene: will not start scene again, because it is already active\r\n"); callEndAndStartSequences = false; } else if ((scene_name == gui_memoryOptimizer_getActiveSceneName()) && ((isForcePayload == "FORCE") || (additionalPayload == "FORCE"))) { - Serial.printf("scene: scene is already active, but FORCE was set, so start scene again\r\n"); + omote_log_d("scene: scene is already active, but FORCE was set, so start scene again\r\n"); callEndAndStartSequences = true; } else { // this is the default when switching to a different scene @@ -104,18 +105,18 @@ void handleScene(uint16_t command, commandData commandData, std::string addition if (callEndAndStartSequences) { // end old scene if (!sceneExists(gui_memoryOptimizer_getActiveSceneName()) && (gui_memoryOptimizer_getActiveSceneName() != "")) { - Serial.printf("scene: WARNING: cannot end scene %s, because it is unknown\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); + omote_log_w("scene: WARNING: cannot end scene %s, because it is unknown\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); } else { if (gui_memoryOptimizer_getActiveSceneName() != "") { - Serial.printf("scene: will call end sequence for scene %s\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); + omote_log_d("scene: will call end sequence for scene %s\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); scene_end_sequence_from_registry(gui_memoryOptimizer_getActiveSceneName()); } } // start new scene - Serial.printf("scene: will call start sequence for scene %s\r\n", scene_name.c_str()); + omote_log_d("scene: will call start sequence for scene %s\r\n", scene_name.c_str()); scene_start_sequence_from_registry(scene_name); } @@ -123,7 +124,7 @@ void handleScene(uint16_t command, commandData commandData, std::string addition if (SceneLabel != NULL) {lv_label_set_text(SceneLabel, gui_memoryOptimizer_getActiveSceneName().c_str());} - Serial.printf("scene: scene handling finished, new scene %s is active\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); + omote_log_d("scene: scene handling finished, new scene %s is active\r\n", gui_memoryOptimizer_getActiveSceneName().c_str()); guis_doTabCreationAfterGUIlistChanged(SCENE_GUI_LIST); } @@ -135,7 +136,7 @@ void showSpecificGUI(GUIlists GUIlist, std::string GUIname) { int gui_list_index = -1; for (int i=0; i < gui_list_for_search->size(); i++) { if (gui_list_for_search->at(i) == GUIname) { - Serial.printf("showSpecificGUI: found GUI with name \"%s\" in %s at position %d\r\n", GUIname.c_str(), GUIlist == MAIN_GUI_LIST ? "\"main_gui_list\"" : "\"scene gui list\"", i); + omote_log_d("showSpecificGUI: found GUI with name \"%s\" in %s at position %d\r\n", GUIname.c_str(), GUIlist == MAIN_GUI_LIST ? "\"main_gui_list\"" : "\"scene gui list\"", i); gui_list_index = i; break; } @@ -147,7 +148,7 @@ void showSpecificGUI(GUIlists GUIlist, std::string GUIname) { } else { // gui was not found - Serial.printf("showSpecificGUI: GUI with name \"%s\" was not found in gui list %s. Cannot navigate to that GUI\r\n", GUIname.c_str(), GUIlist == MAIN_GUI_LIST ? "\"main_gui_list\"" : "\"scene gui list\""); + omote_log_w("showSpecificGUI: GUI with name \"%s\" was not found in gui list %s. Cannot navigate to that GUI\r\n", GUIname.c_str(), GUIlist == MAIN_GUI_LIST ? "\"main_gui_list\"" : "\"scene gui list\""); return; } } diff --git a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp index 81df397..7fecf66 100644 --- a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp +++ b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp @@ -5,6 +5,7 @@ #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/scenes/sceneRegistry.h" #include "applicationInternal/commandHandler.h" +#include "applicationInternal/omote_log.h" // scenes #include "scenes/scene__default.h" @@ -52,7 +53,7 @@ void scene_start_sequence_from_registry(std::string sceneName) { registered_scenes.at(sceneName).this_scene_start_sequence(); } catch (const std::out_of_range& oor) { - Serial.printf("scene_start_sequence_from_registry: internal error, sceneName not registered\r\n"); + omote_log_e("scene_start_sequence_from_registry: internal error, sceneName not registered\r\n"); } } @@ -61,7 +62,7 @@ void scene_end_sequence_from_registry(std::string sceneName) { registered_scenes.at(sceneName).this_scene_end_sequence(); } catch (const std::out_of_range& oor) { - Serial.printf("scene_end_sequence_from_registry: internal error, sceneName not registered\r\n"); + omote_log_e("scene_end_sequence_from_registry: internal error, sceneName not registered\r\n"); } } @@ -70,27 +71,27 @@ repeatModes get_key_repeatMode(std::string sceneName, char keyChar) { // look if the map of the active gui has a definition for it std::string GUIname = gui_memoryOptimizer_getActiveGUIname(); if ((registered_guis_byName_map.count(GUIname) > 0) && (registered_guis_byName_map.at(GUIname).this_key_repeatModes != NULL) && (registered_guis_byName_map.at(GUIname).this_key_repeatModes->count(keyChar) > 0)) { - // Serial.printf("get_key_repeatMode: will use key from gui %s\r\n", GUIname.c_str()); + omote_log_v("get_key_repeatMode: will use key from gui %s\r\n", GUIname.c_str()); return registered_guis_byName_map.at(GUIname).this_key_repeatModes->at(keyChar); // look if the map of the active scene has a definition for it } else if ((registered_scenes.count(sceneName) > 0) && (registered_scenes.at(sceneName).this_key_repeatModes->count(keyChar) > 0)) { - // Serial.printf("get_key_repeatMode: will use key from scene %s\r\n", sceneName.c_str()); + omote_log_v("get_key_repeatMode: will use key from scene %s\r\n", sceneName.c_str()); return registered_scenes.at(sceneName).this_key_repeatModes->at(keyChar); // look if there is a default definition } else if (key_repeatModes_default.count(keyChar) > 0) { - // Serial.printf("get_key_repeatMode: will use default key\r\n"); + omote_log_v("get_key_repeatMode: will use default key\r\n"); return key_repeatModes_default.at(keyChar); // no key definition found } else { - // Serial.printf("get_key_repeatMode: WARNING no key definition found\r\n"); + omote_log_v("get_key_repeatMode: WARNING no key definition found\r\n"); return REPEAT_MODE_UNKNOWN; } } catch (const std::out_of_range& oor) { - Serial.printf("get_key_repeatMode: internal error, sceneName not registered\r\n"); + omote_log_e("get_key_repeatMode: internal error, sceneName not registered\r\n"); return REPEAT_MODE_UNKNOWN; } } @@ -100,27 +101,27 @@ uint16_t get_command_short(std::string sceneName, char keyChar) { // look if the map of the active gui has a definition for it std::string GUIname = gui_memoryOptimizer_getActiveGUIname(); if ((registered_guis_byName_map.count(GUIname) > 0) && (registered_guis_byName_map.at(GUIname).this_key_commands_short != NULL) && (registered_guis_byName_map.at(GUIname).this_key_commands_short->count(keyChar) > 0)) { - // Serial.printf("get_command_short: will use key from gui %s\r\n", GUIname.c_str()); + omote_log_v("get_command_short: will use key from gui %s\r\n", GUIname.c_str()); return registered_guis_byName_map.at(GUIname).this_key_commands_short->at(keyChar); // look if the map of the active scene has a definition for it } else if ((registered_scenes.count(sceneName) > 0) && (registered_scenes.at(sceneName).this_key_commands_short->count(keyChar) > 0)) { - // Serial.printf("get_command_short: will use key from scene %s\r\n", sceneName.c_str()); + omote_log_v("get_command_short: will use key from scene %s\r\n", sceneName.c_str()); return registered_scenes.at(sceneName).this_key_commands_short->at(keyChar); // look if there is a default definition } else if (key_commands_short_default.count(keyChar) > 0) { - // Serial.printf("get_command_short: will use default key\r\n"); + omote_log_v("get_command_short: will use default key\r\n"); return key_commands_short_default.at(keyChar); // no key definition found } else { - // Serial.printf("get_command_short: WARNING no key definition found\r\n"); + omote_log_v("get_command_short: WARNING no key definition found\r\n"); return COMMAND_UNKNOWN; } } catch (const std::out_of_range& oor) { - Serial.printf("get_command_short: internal error, sceneName not registered\r\n"); + omote_log_e("get_command_short: internal error, sceneName not registered\r\n"); return COMMAND_UNKNOWN; } @@ -131,27 +132,27 @@ uint16_t get_command_long(std::string sceneName, char keyChar) { // look if the map of the active gui has a definition for it std::string GUIname = gui_memoryOptimizer_getActiveGUIname(); if ((registered_guis_byName_map.count(GUIname) > 0) && (registered_guis_byName_map.at(GUIname).this_key_commands_long != NULL) && (registered_guis_byName_map.at(GUIname).this_key_commands_long->count(keyChar) > 0)) { - // Serial.printf("get_command_long: will use key from gui %s\r\n", GUIname.c_str()); + omote_log_v("get_command_long: will use key from gui %s\r\n", GUIname.c_str()); return registered_guis_byName_map.at(GUIname).this_key_commands_long->at(keyChar); // look if the map of the active scene has a definition for it } else if ((registered_scenes.count(sceneName) > 0) && (registered_scenes.at(sceneName).this_key_commands_long->count(keyChar) > 0)) { - // Serial.printf("get_command_long: will use key from scene %s\r\n", sceneName.c_str()); + omote_log_v("get_command_long: will use key from scene %s\r\n", sceneName.c_str()); return registered_scenes.at(sceneName).this_key_commands_long->at(keyChar); // look if there is a default definition } else if (key_commands_long_default.count(keyChar) > 0) { - // Serial.printf("get_command_long: will use default key\r\n"); + omote_log_v("get_command_long: will use default key\r\n"); return key_commands_long_default.at(keyChar); // no key definition found } else { - // Serial.printf("get_command_long: WARNING no key definition found\r\n"); + omote_log_v("get_command_long: WARNING no key definition found\r\n"); return COMMAND_UNKNOWN; } } catch (const std::out_of_range& oor) { - Serial.printf("get_command_long: internal error, sceneName not registered\r\n"); + omote_log_e("get_command_long: internal error, sceneName not registered\r\n"); return COMMAND_UNKNOWN; } @@ -169,7 +170,7 @@ gui_list get_gui_list_withFallback(GUIlists gui_list) { #if (USE_SCENE_SPECIFIC_GUI_LIST != 0) // look if the active scene has a definition for a gui list if ((registered_scenes.count(gui_memoryOptimizer_getActiveSceneName()) > 0) && (registered_scenes.at(gui_memoryOptimizer_getActiveSceneName()).this_gui_list != NULL)) { - // Serial.printf("get_gui_list: will use gui_list from scene %s\r\n", sceneName.c_str()); + omote_log_v("get_gui_list: will use gui_list from scene %s\r\n", sceneName.c_str()); return registered_scenes.at(gui_memoryOptimizer_getActiveSceneName()).this_gui_list; } else { // no scene specific gui list was defined @@ -182,7 +183,7 @@ gui_list get_gui_list_withFallback(GUIlists gui_list) { } } catch (const std::out_of_range& oor) { - Serial.printf("get_gui_list: internal error, sceneName not registered\r\n"); + omote_log_e("get_gui_list: internal error, sceneName not registered\r\n"); return NULL; } } @@ -201,7 +202,7 @@ bool get_scene_has_gui_list(std::string sceneName) { } } catch (const std::out_of_range& oor) { - Serial.printf("get_scene_has_gui_list: internal error, sceneName not registered\r\n"); + omote_log_e("get_scene_has_gui_list: internal error, sceneName not registered\r\n"); return false; } } @@ -210,18 +211,18 @@ uint16_t get_activate_scene_command(std::string sceneName) { try { // look if the scene is known if ((registered_scenes.count(sceneName) > 0)) { - // Serial.printf("get_activate_scene_command: will use activate_scene_command from scene %s\r\n", sceneName.c_str()); + omote_log_v("get_activate_scene_command: will use activate_scene_command from scene %s\r\n", sceneName.c_str()); return registered_scenes.at(sceneName).this_activate_scene_command; // if the scene is not know, simply return 0 } else { - // Serial.printf("get_activate_scene_command: will return 0\r\n"); + omote_log_v("get_activate_scene_command: will return 0\r\n"); return 0; } } catch (const std::out_of_range& oor) { - Serial.printf("get_activate_scene_command: internal error, sceneName not registered\r\n"); + omote_log_e("get_activate_scene_command: internal error, sceneName not registered\r\n"); return 0; } diff --git a/Platformio/src/devices/keyboard/device_keyboard_ble/device_keyboard_ble.cpp b/Platformio/src/devices/keyboard/device_keyboard_ble/device_keyboard_ble.cpp index e95affe..7e2739b 100644 --- a/Platformio/src/devices/keyboard/device_keyboard_ble/device_keyboard_ble.cpp +++ b/Platformio/src/devices/keyboard/device_keyboard_ble/device_keyboard_ble.cpp @@ -1,4 +1,5 @@ #include "applicationInternal/commandHandler.h" +#include "applicationInternal/omote_log.h" #include "device_keyboard_ble.h" #include "applicationInternal/hardware/hardwarePresenter.h" @@ -72,34 +73,34 @@ void keyboard_ble_executeCommand(uint16_t command, std::string additionalPayload if (doLog) { if (keyboardBLE_isConnected()) { - Serial.println("BLE keyboard connected, could send key"); + omote_log_d("BLE keyboard connected, can send key\r\n"); } else { - Serial.println("BLE keyboard NOT connected, cannot send key"); + omote_log_d("BLE keyboard NOT connected, cannot send key\r\n"); } } if (command == KEYBOARD_BLE_UP) { - if (doLog) {Serial.printf("UP received\r\n");} + if (doLog) {omote_log_d("UP received\r\n");} keyboardBLE_write(BLE_KEY_UP_ARROW); } else if (command == KEYBOARD_BLE_DOWN) { - if (doLog) {Serial.printf("DOWN received\r\n");} + if (doLog) {omote_log_d("DOWN received\r\n");} keyboardBLE_write(BLE_KEY_DOWN_ARROW); } else if (command == KEYBOARD_BLE_RIGHT) { - if (doLog) {Serial.printf("RIGHT received\r\n");} + if (doLog) {omote_log_d("RIGHT received\r\n");} keyboardBLE_write(BLE_KEY_RIGHT_ARROW); } else if (command == KEYBOARD_BLE_LEFT) { - if (doLog) {Serial.printf("LEFT received\r\n");} + if (doLog) {omote_log_d("LEFT received\r\n");} keyboardBLE_write(BLE_KEY_LEFT_ARROW); } else if (command == KEYBOARD_BLE_SELECT) { - if (doLog) {Serial.printf("SELECT received\r\n");} + if (doLog) {omote_log_d("SELECT received\r\n");} keyboardBLE_write(BLE_KEY_RETURN); } else if (command == KEYBOARD_BLE_SENDSTRING) { - if (doLog) {Serial.printf("SENDSTRING received\r\n");} + if (doLog) {omote_log_d("SENDSTRING received\r\n");} if (additionalPayload != "") { keyboardBLE_sendString(additionalPayload.c_str()); } @@ -107,19 +108,19 @@ void keyboard_ble_executeCommand(uint16_t command, std::string additionalPayload } else if (command == KEYBOARD_BLE_BACK) { - if (doLog) {Serial.printf("BACK received\r\n");} + if (doLog) {omote_log_d("BACK received\r\n");} // test which one works best for your device // keyboardBLE_write(KEY_ESC); consumerControlBLE_write(BLE_KEY_MEDIA_WWW_BACK); } else if (command == KEYBOARD_BLE_HOME) { - if (doLog) {Serial.printf("HOME received\r\n");} + if (doLog) {omote_log_d("HOME received\r\n");} // test which one works best for your device // keyboardBLE_home(); consumerControlBLE_write(BLE_KEY_MEDIA_WWW_HOME); } else if (command == KEYBOARD_BLE_MENU) { - if (doLog) {Serial.printf("MENU received\r\n");} + if (doLog) {omote_log_d("MENU received\r\n");} keyboardBLE_write(0xED); // 0xDA + 13 = 0xED @@ -128,49 +129,49 @@ void keyboard_ble_executeCommand(uint16_t command, std::string additionalPayload // https://github.com/espressif/arduino-esp32/blob/master/libraries/USB/src/USBHIDConsumerControl.h // https://github.com/adafruit/Adafruit_CircuitPython_HID/blob/main/adafruit_hid/consumer_control_code.py } else if (command == KEYBOARD_BLE_SCAN_PREVIOUS_TRACK) { - if (doLog) {Serial.printf("SCAN_PREVIOUS_TRACK received\r\n");} + if (doLog) {omote_log_d("SCAN_PREVIOUS_TRACK received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_PREVIOUS_TRACK); } else if (command == KEYBOARD_BLE_REWIND_LONG) { - if (doLog) {Serial.printf("REWIND_LONG received\r\n");} + if (doLog) {omote_log_d("REWIND_LONG received\r\n");} //keyboardBLE_longpress(KEY_LEFT_ARROW); consumerControlBLE_longpress(BLE_KEY_MEDIA_REWIND); } else if (command == KEYBOARD_BLE_REWIND) { - if (doLog) {Serial.printf("REWIND received\r\n");} + if (doLog) {omote_log_d("REWIND received\r\n");} //keyboardBLE_write(KEY_LEFT_ARROW); consumerControlBLE_write(BLE_KEY_MEDIA_REWIND); } else if (command == KEYBOARD_BLE_PLAYPAUSE) { - if (doLog) {Serial.printf("PLAYPAUSE received\r\n");} + if (doLog) {omote_log_d("PLAYPAUSE received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_PLAY_PAUSE); } else if (command == KEYBOARD_BLE_FASTFORWARD) { - if (doLog) {Serial.printf("FASTFORWARD received\r\n");} + if (doLog) {omote_log_d("FASTFORWARD received\r\n");} //keyboardBLE_write(KEY_RIGHT_ARROW); consumerControlBLE_write(BLE_KEY_MEDIA_FASTFORWARD); } else if (command == KEYBOARD_BLE_FASTFORWARD_LONG) { - if (doLog) {Serial.printf("FASTFORWARD_LONG received\r\n");} + if (doLog) {omote_log_d("FASTFORWARD_LONG received\r\n");} //keyboardBLE_longpress(KEY_RIGHT_ARROW); consumerControlBLE_longpress(BLE_KEY_MEDIA_FASTFORWARD); } else if (command == KEYBOARD_BLE_SCAN_NEXT_TRACK) { - if (doLog) {Serial.printf("SCAN_NEXT_TRACK received\r\n");} + if (doLog) {omote_log_d("SCAN_NEXT_TRACK received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_NEXT_TRACK); } else if (command == KEYBOARD_BLE_MUTE) { - if (doLog) {Serial.printf("MUTE received\r\n");} + if (doLog) {omote_log_d("MUTE received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_MUTE); } else if (command == KEYBOARD_BLE_VOLUME_INCREMENT) { - if (doLog) {Serial.printf("VOLUME_INCREMENT received\r\n");} + if (doLog) {omote_log_d("VOLUME_INCREMENT received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_VOLUME_UP); } else if (command == KEYBOARD_BLE_VOLUME_DECREMENT) { - if (doLog) {Serial.printf("VOLUME_DECREMENT received\r\n");} + if (doLog) {omote_log_d("VOLUME_DECREMENT received\r\n");} consumerControlBLE_write(BLE_KEY_MEDIA_VOLUME_DOWN); } diff --git a/Platformio/src/devices/mediaPlayer/device_appleTV/gui_appleTV.cpp b/Platformio/src/devices/mediaPlayer/device_appleTV/gui_appleTV.cpp index 8fdec12..cd65c34 100644 --- a/Platformio/src/devices/mediaPlayer/device_appleTV/gui_appleTV.cpp +++ b/Platformio/src/devices/mediaPlayer/device_appleTV/gui_appleTV.cpp @@ -2,6 +2,7 @@ #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/gui/guiBase.h" #include "applicationInternal/gui/guiRegistry.h" +#include "applicationInternal/omote_log.h" #include "devices/mediaPlayer/device_appleTV/gui_appleTV.h" #include "applicationInternal/commandHandler.h" @@ -17,7 +18,7 @@ static void appleKey_event_cb(lv_event_t* e) { // Send IR command based on the event user data int user_data = *((int*)(&(e->user_data))); executeCommand(APPLETV_GUI_EVENT_USER_DATA, std::to_string(50 + user_data)); - // Serial.println(50 + user_data); + omote_log_v("%d\r\n", 50 + user_data); } void create_tab_content_appleTV(lv_obj_t* tab) { diff --git a/Platformio/src/guis/gui_irReceiver.cpp b/Platformio/src/guis/gui_irReceiver.cpp index d83e8a3..abf505d 100644 --- a/Platformio/src/guis/gui_irReceiver.cpp +++ b/Platformio/src/guis/gui_irReceiver.cpp @@ -3,6 +3,7 @@ #include "applicationInternal/hardware/hardwarePresenter.h" #include "applicationInternal/gui/guiBase.h" #include "applicationInternal/gui/guiRegistry.h" +#include "applicationInternal/omote_log.h" #include "guis/gui_irReceiver.h" lv_obj_t* menuBoxToggle; @@ -40,7 +41,7 @@ void showMQTTmessage(std::string topic, std::string payload) { void printIRMessages(bool clearMessages = false) { if (!tabIsInMemory) {return;} - //Serial.println(""); + omote_log_v("\r\n"); int messagePosLoop; if (messageCount < maxCountMessages) { messagePosLoop = 0; @@ -48,12 +49,12 @@ void printIRMessages(bool clearMessages = false) { messagePosLoop = messagePos; } - //Serial.printf("will start printing messages, beginning at position %d\r\n", messagePosLoop); + omote_log_v("will start printing messages, beginning at position %d\r\n", messagePosLoop); for (int i=0; i