diff --git a/.vscode/launch.json b/.vscode/launch.json index 1349950..ee607c3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -41,12 +41,13 @@ "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, + /* "setupCommands": [ { "description": "Load LVGL GDB helpers", "text": "source /home/marc/domotic/components/domotic_display/test_host/managed_components/lvgl__lvgl/scripts/gdb/gdbinit.py" } - ], + ],*/ "linux": { "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb" diff --git a/.vscode/settings.json b/.vscode/settings.json index ebc0f8c..ecd82d1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,13 @@ { "C_Cpp.intelliSenseEngine": "default", - "idf.espIdfPath": "/home/marc/esp/v5.5.1/esp-idf", + "idf.espIdfPath": "/home/marc/esp/esp-idf", "idf.pythonBinPath": "/home/marc/.espressif/python_env/idf5.5_py3.10_env/bin/python", "idf.toolsPath": "/home/marc/.espressif", "idf.customExtraPaths": "/home/marc/.espressif/tools/xtensa-esp-elf-gdb/14.2_20240403/xtensa-esp-elf-gdb/bin:/home/marc/.espressif/tools/riscv32-esp-elf-gdb/14.2_20240403/riscv32-esp-elf-gdb/bin:/home/marc/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin:/home/marc/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin:/home/marc/.espressif/tools/esp32ulp-elf/2.38_20240113/esp32ulp-elf/bin:/home/marc/.espressif/tools/cmake/3.24.0/bin:/home/marc/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240318/openocd-esp32/bin:/home/marc/.espressif/tools/ninja/1.11.1:/home/marc/.espressif/tools/esp-rom-elfs/20240305", "idf.customExtraVars": { - "OPENOCD_SCRIPTS": "/home/marc/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240318/openocd-esp32/share/openocd/scripts", + "OPENOCD_SCRIPTS": "/home/marc/.espressif/tools/openocd-esp32/v0.12.0-esp32-20251215/openocd-esp32/share/openocd/scripts", "ESP_ROM_ELF_DIR": "/home/marc/.espressif/tools/esp-rom-elfs/20240305/", - "IDF_TARGET": "esp32" + "IDF_TARGET": "linux" }, "idf.gitPath": "git", "idf.adapterTargetName": "esp32s3", @@ -115,5 +115,6 @@ "--background-index", "--query-driver=/home/marc/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20241119/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc", "--compile-commands-dir=/home/marc/domotic/build" - ] + ], + "idf.currentSetup": "/home/marc/.espressif/v5.5.2/esp-idf" } diff --git a/components/domotic_display/ihm.c b/components/domotic_display/ihm.c index ff43808..72dc3d1 100644 --- a/components/domotic_display/ihm.c +++ b/components/domotic_display/ihm.c @@ -47,7 +47,7 @@ lv_obj_t *jour; static lv_style_t no_padding; static const char *TAG = "IHM"; -static lv_subject_t wifiStatus; +lv_subject_t wifiStatus; LV_IMAGE_DECLARE(wifi_ok); LV_IMAGE_DECLARE(wifi_ko); @@ -84,19 +84,18 @@ static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) //lv_obj_t * btn = lv_observer_get_target(observer); } -static void draw_time(struct tm *dateHeure){ - if(display_lock("updateTime")){ +void draw_time(struct tm *dateHeure){ + //if(display_lock("updateTime")){ //lv_label_set_text(jour, dateHeure); - - lv_subject_set_pointer(&timeSubj, dateHeure); - display_unlock("updateTime"); - } + lv_subject_set_pointer(&timeSubj, dateHeure); + //display_unlock("updateTime"); + //} } -static void draw_temp(char * tempHumid){ +void draw_temp(char * tempHumid){ if(display_lock("draw_temp")){ lv_label_set_text(lblTempInt2,tempHumid); - display_unlock("updateTime"); + display_unlock("draw_temp"); } } @@ -123,140 +122,61 @@ void lv_theme_copy(lv_theme_t *dst, const lv_theme_t *src) } lv_memcpy(dst, src, sizeof(*src)); } - - -void drawIhm(void *xIHMEventQueueParam) { - QueueHandle_t xIHMEventQueue = (QueueHandle_t)xIHMEventQueueParam; - - display_lock("app_main"); - init_display_ihm(); - - /* Initialize the new theme with the current theme as its parent - * The user is responsible for freeing the theme when it's no longer needed */ - //lv_theme_t *th_act = lv_display_get_theme(NULL); - //lv_theme_t *th_new = lv_theme_create(); - //lv_theme_copy(th_new, th_act); - //th_new->font_small = &montserrat_medium_12; - //th_new->font_normal = &montserrat_medium_18; - //th_new->font_large = &roboto_medium_36; - // lv_theme_default_deinit(); +static void create_ui(void) +{ + // Initialisation du thème lv_theme_t *th_new = lv_theme_domotic_init(lv_display_get_default()); - //lv_theme_t *th_simple = lv_theme_simple_init(lv_display_get_default()); - - //lv_theme_set_parent(th_simple, NULL); - - //lv_theme_set_parent(th_new, th_simple); - - /*Set the style apply callback for the new theme*/ - //lv_theme_set_apply_cb(th_new, new_theme_apply_cb); - - /*Assign the new theme to the current display*/ lv_display_set_theme(lv_display_get_default(), th_new); + // Initialisation des sujets / observers lv_subject_init_int(&wifiStatus, 0); lv_subject_add_observer_obj(&wifiStatus, wifiStatus_obs_cb, NULL, NULL); + // Création des écrans / widgets + app_main_display(); // ton écran principal + drawHome(); // écran Home + // chart, labels, boutons, etc. + // par exemple : lblEtatMachine, lblHauteurCuve, myChart, ser... +} - //lv_example_style_17(); - app_main_display(); - display_unlock("app_main"); +static void ihm_process_queue(QueueHandle_t xIHMEventQueue) +{ + xIHMEvent_t *xReceivedEvent = NULL; - vTaskDelay(pdMS_TO_TICKS(200)); + while (xQueueReceive(xIHMEventQueue, &xReceivedEvent, 0) == pdTRUE && xReceivedEvent) { - if (display_lock("draw_ihm")) { - drawHome(); - display_unlock("draw_ihm"); } +} - lv_obj_dump_tree(lv_scr_act()); +// draw_ihm.c +#include "ihm_gateway.h" +#include // usleep +#include "platform_detect.h" - while (1) - { - xIHMEvent_t *xReceivedEvent = NULL; +void drawIhm(void *param) { + // Init display + LVGL + init_display_ihm(); + //lv_init(); + lv_theme_t *th_new = lv_theme_domotic_init(lv_display_get_default()); + lv_display_set_theme(lv_display_get_default(), th_new); - if (xQueueReceive(xIHMEventQueue, &xReceivedEvent, portMAX_DELAY) == pdTRUE && xReceivedEvent) { - ESP_LOGE(TAG,"Evt IHM Recu"); - switch (xReceivedEvent->eEventType) { - case IHM_EVT_WIFI_STATUS: - lv_subject_set_int(&wifiStatus, *(bool *)xReceivedEvent->pvData); - break; + // Init queue + //ihm_gateway_init(); - case IHM_EVT_TIME_SETTED: - draw_time(xReceivedEvent->pvData); - break; + create_ui(); - case IHM_EVT_OTA_STARTED: - app_ota_display(); - break; + // Loop unifiée + while (1) { + ihm_gateway_process_queue(); + uint32_t idle_time = lv_timer_handler(); - case IHM_EVT_OTA_PROGRESS: - //setOTAProgress((int)xReceivedEvent->pvData); - break; - - case IHM_EVT_HUMID_TEMP: - draw_temp((char *)xReceivedEvent->pvData); - break; - - case IHM_EVT_PUISSANCE_EMISE: - if (display_lock("updateChart")) { - int val = *(int*)xReceivedEvent->pvData; - ESP_LOGE(TAG, "On a recu %i", val); - if (val == 0) { - lv_chart_set_next_value(myChart, ser, LV_CHART_POINT_NONE); - } else { - lv_chart_set_next_value(myChart, ser, val); - } - display_unlock("updateChart"); - } - break; - case IHM_EVT_ETAT_MACHINE: - if (display_lock("updateChart")) { - char * etatMachine = xReceivedEvent->pvData; - ESP_LOGE(TAG,"Etat Machine : %s", etatMachine); - cJSON *root = cJSON_Parse(etatMachine); - bool enRoute = cJSON_GetObjectItem(root,"state")->valueint; - int depuisQuand= cJSON_GetObjectItem(root,"timestamp")->valueint; - ESP_LOGE(TAG,"Timestamp lu : %i", depuisQuand); - time_t rawtime = (time_t)(depuisQuand); - struct tm *heure_locale = localtime(&rawtime); - char heureFormattee[50]; - strftime(heureFormattee, sizeof(heureFormattee), "%d/%m/%Y %H:%M:%S", heure_locale); - ESP_LOGE(TAG,"Heure: %s", heureFormattee); - char etatFormate[90]; - if(enRoute){ - sprintf(etatFormate,"Machine en route depuis %s", heureFormattee); - }else{ - sprintf(etatFormate,"Machine : Arrêt détecté depuis %s", heureFormattee); - } - ESP_LOGE(TAG,"%s", etatFormate); - lv_label_set_text(lblEtatMachine,etatFormate); - display_unlock("updateChart"); - } - break; - - case IHM_EVT_HAUTEUR_CUVE: - if (display_lock("updateCuve")) { - float hauteur = *(float *)xReceivedEvent->pvData; - lv_label_set_text_fmt(lblHauteurCuve, "%.0f cm", hauteur); - display_unlock("updateCuve"); - } - break; - - default: - ESP_LOGE(TAG, "Evt inconnu"); - break; - } - - ESP_LOGE(TAG,"Evt IHM Traité on nettoie la memoire"); - // Nettoyage mémoire sécurisé - if (xReceivedEvent->bNeedToFreeData && xReceivedEvent->pvData) { - free(xReceivedEvent->pvData); - } - free(xReceivedEvent); - ESP_LOGE(TAG,"Evt IHM Traité !"); + if (platform_is_pc()) { + // SDL backend + usleep(idle_time * 1000); + } else { + // ESP32 : task FreeRTOS + vTaskDelay(pdMS_TO_TICKS(idle_time)); } - - vTaskDelay(pdMS_TO_TICKS(100)); } } @@ -309,6 +229,14 @@ void init_display_ihm(){ bsp_display_brightness_set(50); */ mainState.display_init=true; + + time_t now; + struct tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + + lv_subject_init_pointer(&timeSubj, &timeinfo); + } lv_obj_t * otaStatus; @@ -529,13 +457,17 @@ static void weatherdata_obs_cb(lv_observer_t *observer, lv_subject_t *subject) // Retrieve weatherdata const struct meteodailyforecast_data *data = subject->value.pointer; bool isMinimal = observer->user_data; - ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %i - Mode minimal : %d", data->isValid, isMinimal); + ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %b - Mode minimal : %d", data->isValid, isMinimal); + if(!data->isValid){ + ESP_LOGI(TAG,"Données meteo non valides"); + return; + } // printffd(data); - char buff[40] = {}; - sprintf(buff,"%s %.1f %.1f", data->previsions.desc, data->previsions.min, data->previsions.max); - ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %s", buff); if (data->isValid) { + char buff[40] = {}; + snprintf(buff,sizeof(buff),"%s %.1f %.1f", data->previsions.desc, data->previsions.min, data->previsions.max); + ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %s", buff); lv_obj_t *parent = (lv_obj_t *)(lv_observer_get_target(observer)); lv_obj_dump_tree(parent->parent); ESP_LOGI(TAG, "On accede au parent %p %s", (void*)parent, lv_obj_get_name(parent)); @@ -576,7 +508,7 @@ static void weatherdataH_obs_cb(lv_observer_t *observer, lv_subject_t *subject) //printffd(data); char buff[40] = {}; - sprintf(buff,"%.1f", data->previsions.value); + snprintf(buff,sizeof(buff),"%.1f", data->previsions.value); ESP_LOGV(TAG, "On a recu [%s]", buff); lv_obj_t *parent = (lv_obj_t *)(lv_observer_get_target(observer)); @@ -602,8 +534,10 @@ void showMeteoIcon(const char *icon, lv_obj_t *desc_icon, int childNr) lv_obj_t *img = lv_obj_get_child(desc_icon, childNr); //char *str1 = "A:/littlefs/"; char *str1 = "A:/home/marc/domotic/components/domotic_display/images_meteo"; - char *result = malloc(strlen(str1) + strlen(icon) + 6); - sprintf(result, "%s%s.png", str1, icon); + int sizeOfStr; + sizeOfStr = strlen(str1) + strlen(icon) + 6; + char *result = malloc(sizeOfStr); + snprintf(result,sizeOfStr, "%s%s.png", str1, icon); ESP_LOGV(TAG,"On affiche l'image %s", result); lv_image_set_src(img, "A:/home/marc/domotic/components/domotic_display/images_meteo/p4j.png"); free(result); @@ -1184,7 +1118,7 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) LV_UNUSED(subject); lv_obj_t *dateTimeObj = lv_observer_get_target_obj(observer); - char buf[16]; + //char buf[16]; lv_obj_t *spangroup = lv_obj_find_by_name(dateTimeObj, "date"); //lv_obj_get_child_by_id(dateTimeObj, "date"); @@ -1203,9 +1137,9 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) lv_spangroup_refresh(spangroup); spangroup = lv_obj_find_by_name(dateTimeObj, "time"); - sprintf(buff, "%02" LV_PRId32, dateHeure->tm_hour); + snprintf(buff,sizeof(buff), "%02" LV_PRId32, dateHeure->tm_hour); lv_span_set_text(lv_spangroup_get_child(spangroup, 0), buff); - sprintf(buff, ":%02" LV_PRId32, dateHeure->tm_min); + snprintf(buff,sizeof(buff), ":%02" LV_PRId32, dateHeure->tm_min); lv_span_set_text(lv_spangroup_get_child(spangroup, 1), buff); lv_spangroup_refresh(spangroup); @@ -1662,13 +1596,13 @@ void messageCardContent(lv_obj_t *cont_messages) lv_label_set_text(lblTempExt, LV_SYMBOL_HOME "\xEF\x8B\x8A : 12°C"); lv_obj_set_style_text_font(lblTempExt, lv_theme_get_font_large(lblTempExt),0); - for (size_t i = 0; i < 2; i++) + /*for (size_t i = 0; i < 2; i++) { lv_obj_t *lblNextEvt = lv_label_create(subContent); lv_obj_set_style_margin_top(lblNextEvt, 15, 0); lv_label_set_text(lblNextEvt, events[i].affichage); lv_obj_set_style_text_font(lblNextEvt, &roboto_medium_36, 0); - } + }*/ lv_obj_t *apps = lv_obj_create(bg_cont); lv_obj_set_size(apps, LV_PCT(100), LV_SIZE_CONTENT); diff --git a/components/domotic_display/ihm_gateway.c b/components/domotic_display/ihm_gateway.c new file mode 100644 index 0000000..1cb6f46 --- /dev/null +++ b/components/domotic_display/ihm_gateway.c @@ -0,0 +1,110 @@ +// ihm_gateway.c +#include "ihm_gateway.h" +#include "ihm.h" +#include +#include +#include "platform_detect.h" +#include "cJSON.h" +#include "esp_log.h" + +static const char *TAG = "IHM_GW"; + + +static QueueHandle_t xIHMEventQueue = NULL; + +QueueHandle_t getIHMQueueHandle(void) { + return xIHMEventQueue; +} + +void ihm_gateway_init(void) { + if (!xIHMEventQueue) { + xIHMEventQueue = xQueueCreate(32, sizeof(xIHMEvent_t *)); + } +} + +void ihm_gateway_post_event(xIHMEvent_t *evt) { + if (!xIHMEventQueue) return; + + if (platform_is_pc()) { + xQueueSend(xIHMEventQueue, &evt, 0); // non bloquant sur PC + } else { + xQueueSend(xIHMEventQueue, &evt, portMAX_DELAY); // bloquant ESP32 + } +} + +extern lv_subject_t wifiStatus; + +void ihm_gateway_process_queue(void) { + if (!xIHMEventQueue) return; + + xIHMEvent_t *evt = NULL; + + if (platform_is_pc()) { + if (xQueueReceive(xIHMEventQueue, &evt, 0) != pdTRUE) return; + } else { + if (xQueueReceive(xIHMEventQueue, &evt, pdMS_TO_TICKS(10)) != pdTRUE) return; + } + + if (!evt) return; + + switch (evt->eEventType) { + case IHM_EVT_WIFI_STATUS: + lv_subject_set_int(&wifiStatus, *(bool *)evt->pvData); + break; + + case IHM_EVT_TIME_SETTED: + draw_time(evt->pvData); + break; + + case IHM_EVT_OTA_STARTED: + app_ota_display(); + break; + + case IHM_EVT_HUMID_TEMP: + draw_temp((char *)evt->pvData); + break; + + case IHM_EVT_PUISSANCE_EMISE: { + int val = *(int*)evt->pvData; + //if(val == 0) lv_chart_set_next_value(myChart, ser, LV_CHART_POINT_NONE); + //else lv_chart_set_next_value(myChart, ser, val); + break; + } + + case IHM_EVT_ETAT_MACHINE: { + char *etatMachine = evt->pvData; + cJSON *root = cJSON_Parse(etatMachine); + bool enRoute = cJSON_GetObjectItem(root,"state")->valueint; + int timestamp = cJSON_GetObjectItem(root,"timestamp")->valueint; + + time_t rawtime = (time_t)timestamp; + struct tm *heure_locale = localtime(&rawtime); + char heureFormattee[50]; + strftime(heureFormattee, sizeof(heureFormattee), "%d/%m/%Y %H:%M:%S", heure_locale); + + char etatFormate[90]; + snprintf(etatFormate,sizeof(etatFormate), + enRoute ? "Machine en route depuis %s" : "Machine : Arrêt détecté depuis %s", + heureFormattee); + + //lv_label_set_text(lblEtatMachine, etatFormate); + cJSON_Delete(root); + break; + } + + case IHM_EVT_HAUTEUR_CUVE: { + float hauteur = *(float *)evt->pvData; + //lv_label_set_text_fmt(lblHauteurCuve, "%.0f cm", hauteur); + break; + } + + default: + ESP_LOGE(TAG, "Evt inconnu"); + break; + } + + // Nettoyage mémoire sécurisé + if (evt->bNeedToFreeData && evt->pvData) free(evt->pvData); + free(evt); + +} diff --git a/components/domotic_display/include/bsp/esp-bsp.h b/components/domotic_display/include/bsp/esp-bsp.h index 0f2b209..07be6c0 100644 --- a/components/domotic_display/include/bsp/esp-bsp.h +++ b/components/domotic_display/include/bsp/esp-bsp.h @@ -8,10 +8,10 @@ bool bsp_display_lock(int timeout_ms) // If `timeout_ms` is set to -1, the program will block until the condition is met //const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); //return xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks) == pdTRUE; - lv_lock(); + //lv_lock(); return true; } void bsp_display_unlock() { //xSemaphoreGiveRecursive(lvgl_mux); - lv_unlock(); + //lv_unlock(); } diff --git a/components/domotic_display/include/ihm.h b/components/domotic_display/include/ihm.h index 7af2e9a..2c88e1c 100644 --- a/components/domotic_display/include/ihm.h +++ b/components/domotic_display/include/ihm.h @@ -1,4 +1,5 @@ #pragma once +#include #include "meteofrance.h" #include "lvgl.h" #include "model.h" @@ -20,6 +21,9 @@ void draw_tabVolets(); void meteoCb(lv_obj_t *base_obj); void drawHome(); +void draw_time(struct tm *dateHeure); +void draw_temp(char *tempHumid); + void create_card(); void weather_data_retreived_start(); diff --git a/components/domotic_display/include/ihm_gateway.h b/components/domotic_display/include/ihm_gateway.h new file mode 100644 index 0000000..55cd979 --- /dev/null +++ b/components/domotic_display/include/ihm_gateway.h @@ -0,0 +1,12 @@ +// ihm_gateway.h +#pragma once +#include "lvgl.h" +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include +#include "eventsManager.h" + +QueueHandle_t getIHMQueueHandle(void); +void ihm_gateway_init(void); +void ihm_gateway_post_event(xIHMEvent_t *evt); +void ihm_gateway_process_queue(void); diff --git a/components/domotic_display/include/platform_detect.h b/components/domotic_display/include/platform_detect.h new file mode 100644 index 0000000..896e3ea --- /dev/null +++ b/components/domotic_display/include/platform_detect.h @@ -0,0 +1,13 @@ +// platform_detect.h +#pragma once + +#include "esp_system.h" +#include "sdkconfig.h" + +static inline bool platform_is_pc(void) { +#if CONFIG_IDF_TARGET_LINUX + return true; +#else + return false; +#endif +} diff --git a/components/domotic_display/test_host/dependencies.lock b/components/domotic_display/test_host/dependencies.lock index bb76e7a..5dfd139 100644 --- a/components/domotic_display/test_host/dependencies.lock +++ b/components/domotic_display/test_host/dependencies.lock @@ -2,7 +2,7 @@ dependencies: idf: source: type: idf - version: 5.5.1 + version: 5.5.2 lvgl/lvgl: component_hash: 17e68bfd21f0edf4c3ee838e2273da840bf3930e5dbc3bfa6c1190c3aed41f9f dependencies: [] diff --git a/components/domotic_display/test_host/main/CMakeLists.txt b/components/domotic_display/test_host/main/CMakeLists.txt index 178cec3..e07cd02 100644 --- a/components/domotic_display/test_host/main/CMakeLists.txt +++ b/components/domotic_display/test_host/main/CMakeLists.txt @@ -2,6 +2,7 @@ set(LV_BUILD_USE_KCONFIG ON) idf_component_register(SRCS "test_ihm.c" "../../ihm.c" + "../../ihm_gateway.c" "../../lv_theme_domotic.c" "../../model.c" "driver_backends.c" @@ -29,7 +30,7 @@ idf_component_register(SRCS list(APPEND PKG_CONFIG_LIB ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES}) list(APPEND PKG_CONFIG_INC ${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS}) -target_compile_options(${COMPONENT_LIB} PUBLIC --coverage -DLV_LVGL_H_INCLUDE_SIMPLE) +target_compile_options(${COMPONENT_LIB} PUBLIC --coverage -DLV_LVGL_H_INCLUDE_SIMPLE ) target_link_libraries(${COMPONENT_LIB} PUBLIC ${PKG_CONFIG_LIB} --coverage) target_include_directories(${COMPONENT_LIB} PRIVATE ${CMAKE_SOURCE_DIR}/mock ${PKG_CONFIG_INC}) target_link_libraries(${COMPONENT_LIB} PRIVATE bsd) @@ -38,6 +39,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++20) endif() + # Currently 'main' for IDF_TARGET=linux is defined in freertos component. # Since we are using a freertos mock here, need to let Catch2 provide 'main'. #target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain) diff --git a/components/domotic_display/test_host/main/test_ihm.c b/components/domotic_display/test_host/main/test_ihm.c index 877f7da..6ab3244 100644 --- a/components/domotic_display/test_host/main/test_ihm.c +++ b/components/domotic_display/test_host/main/test_ihm.c @@ -14,6 +14,8 @@ #include "esp_log.h" #include "eventsManager.h" #include "RemindMe.h" +#include "ihm_gateway.h" +#include "platform_detect.h" esp_mqtt_client_handle_t client; SemaphoreHandle_t lvgl_mux; @@ -117,38 +119,65 @@ static void configure_simulator(int argc, char **argv) } } +int app_main(int argc, char *argv[]) { + // Détecte la plateforme + bool isPC = platform_is_pc(); -int app_main(int argc, char *argv[]) + // Init gateway + ihm_gateway_init(); + startEvtManager(); + + if (isPC) { + // PC / SDL : loop dans le thread principal + /* Initialize LVGL. */ + lv_init(); + configure_simulator(argc, argv); + /* Initialize the configured backend */ + if (driver_backends_init_backend(selected_backend) == -1) { + die("Failed to initialize display backend"); + } + lv_sdl_mouse_create(); + lv_sdl_keyboard_create(); + lv_sdl_mousewheel_create(); + lv_sdl_mousewheel_create(); + + time_t now; + struct tm timeinfo; + time(&now); + localtime_r(&now, &timeinfo); + + lv_subject_init_pointer(&timeSubj, &timeinfo); + + drawIhm(NULL); + } else { + // ESP32 : créer task FreeRTOS + xTaskCreate(drawIhm, "LVGL", 256*1024, NULL, 3, NULL); + } + + // Exemple : poster un événement + xIHMEvent_t *evt = malloc(sizeof(*evt)); + evt->eEventType = 1; + evt->pvData = strdup("Hello LVGL"); + evt->bNeedToFreeData = true; + ihm_gateway_post_event(evt); + + return 0; +} + + +int app_main1(int argc, char *argv[]) { /* code */ printf("hello\n"); - lvgl_mux = xSemaphoreCreateRecursiveMutex(); assert(lvgl_mux); init_display_ihm(); - /* Initialize LVGL. */ - lv_init(); - configure_simulator(argc, argv); - /* Initialize the configured backend */ - if (driver_backends_init_backend(selected_backend) == -1) { - die("Failed to initialize display backend"); - } - lv_sdl_mouse_create(); - lv_sdl_keyboard_create(); - lv_sdl_mousewheel_create(); - lv_sdl_mousewheel_create(); //size_t watermark = uxTaskGetStackHighWaterMark(NULL); //ESP_LOGI("STACK", "Remaining stack: %d bytes", watermark); - time_t now; - struct tm timeinfo; - time(&now); - localtime_r(&now, &timeinfo); - - lv_subject_init_pointer(&timeSubj, &timeinfo); /*lv_timer_t *clock_timer = lv_timer_create(clock_timer_cb, 1000, NULL);*/ @@ -160,14 +189,15 @@ int app_main(int argc, char *argv[]) if (!events) { ESP_LOGE("test", "Aucun événement chargé"); - return 0; + //return 0; } // Parcourir tous les événements for (int i = 0; i < count; i++) { ESP_LOGI("test", "%s", events[i].affichage); } - xTaskCreate(drawIhm, "LVGL", 128 * 1024, getIHMQueueHandle(), 3, NULL); + xTaskCreate(drawIhm, "LVGL", 14 * 1024, getIHMQueueHandle(), 3, NULL); + //drawIhm(getIHMQueueHandle()); send_event(EVT_WIFI_CONNECTED,NULL); meteodailyforecast_data dts = { .datetime= time(NULL), @@ -179,6 +209,7 @@ int app_main(int argc, char *argv[]) .min = 3.30f } }; + /* extern lv_subject_t forecastD1Subj; extern lv_subject_t forecastD2Subj; extern lv_subject_t forecastD3Subj; @@ -187,6 +218,7 @@ int app_main(int argc, char *argv[]) lv_subject_set_pointer(&forecastD1Subj, &dts); lv_subject_set_pointer(&forecastD2Subj, &dts); lv_subject_set_pointer(&forecastD3Subj, &dts); + */ /* Enter the run loop of the selected backend */ driver_backends_run_loop(); diff --git a/components/eventsManager/CMakeLists.txt b/components/eventsManager/CMakeLists.txt index bc77982..3c964d0 100644 --- a/components/eventsManager/CMakeLists.txt +++ b/components/eventsManager/CMakeLists.txt @@ -1,3 +1,3 @@ -idf_component_register(SRCS "eventsManager.c" obtain_time.c +idf_component_register(SRCS "obtain_time.c" "eventsManager.c" obtain_time.c INCLUDE_DIRS "include" REQUIRES mqtt) diff --git a/components/eventsManager/eventsManager.c b/components/eventsManager/eventsManager.c index f52788f..75470a8 100644 --- a/components/eventsManager/eventsManager.c +++ b/components/eventsManager/eventsManager.c @@ -14,7 +14,7 @@ static const char *TAG = "evtMgr"; void startEvtManager(){ domotic_event_group = xEventGroupCreate(); - ihm_queue = xQueueCreate(10,sizeof(xIHMEvent_t *)); + ihm_queue = getIHMQueueHandle(); /* Tache updateTime */ BaseType_t ret2 = xTaskCreate(&updateTime, "updateTimeTask", 3 * 1024, NULL, 5, NULL); @@ -25,10 +25,6 @@ void startEvtManager(){ /* Tache updateTime - FIN*/ } -QueueHandle_t getIHMQueueHandle(){ - return ihm_queue; -} - void send_event(domo_events evt, void* pDatas) { ESP_LOGE(TAG,"On est dans l'event handler %i", evt); diff --git a/components/eventsManager/obtain_time.c b/components/eventsManager/obtain_time.c index 92fedc3..e79d385 100644 --- a/components/eventsManager/obtain_time.c +++ b/components/eventsManager/obtain_time.c @@ -25,7 +25,7 @@ void updateTime(void *pvParameter) time(&now); localtime_r(&now, &timeinfo); // strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); - sprintf(strftime_buf, "%s %d %s %02d:%02d", days[timeinfo.tm_wday], timeinfo.tm_mday, months[timeinfo.tm_mon], timeinfo.tm_hour, timeinfo.tm_min); + snprintf(strftime_buf,sizeof(strftime_buf), "%s %d %s %02d:%02d", days[timeinfo.tm_wday], timeinfo.tm_mday, months[timeinfo.tm_mon], timeinfo.tm_hour, timeinfo.tm_min); localtime_r(&now, &timeinfo); ESP_LOGE(TAG, "%s", strftime_buf); send_event(EVT_TIME_SETTED, &timeinfo); diff --git a/components/lvgl__lvgl/idf_component.yml b/components/lvgl__lvgl/idf_component.yml index 41415c4..cb4b4d8 100644 --- a/components/lvgl__lvgl/idf_component.yml +++ b/components/lvgl__lvgl/idf_component.yml @@ -4,6 +4,5 @@ issues: https://github.com/lvgl/lvgl/issues repository: git://github.com/lvgl/lvgl.git repository_info: commit_sha: c016f72d4c125098287be5e83c0f1abed4706ee5 - path: . url: https://lvgl.io/ version: 9.4.0 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c96dfe3..820098f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -5,8 +5,8 @@ set(comps heap nvs_flash esp_netif image_downloader fatfs protocol_examples_comm if(${IDF_TARGET} STREQUAL "esp32p4") message(STATUS "SIMULATION_QEMU = OOF --> main standard") - list(APPEND comps bsp_extra esp32_p4_function_ev_board sdmmc vfs littlefs wifi_logger app_update esp_https_ota espcoredump esp_http_server esp_wifi ) - idf_component_register(SRCS main.c obtain_time.c communication.c + list(APPEND comps esp32_p4_function_ev_board sdmmc vfs littlefs app_update esp_https_ota espcoredump esp_http_server esp_wifi ) + idf_component_register(SRCS main.c communication.c INCLUDE_DIRS "./include" REQUIRES ${comps} EMBED_TXTFILES ${PROJECT_DIR}/main/ca_cert.pem diff --git a/main/idf_component.yml b/main/idf_component.yml index 3a9f8d0..7430317 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -19,14 +19,10 @@ dependencies: esp_lcd_touch_gt911: rules: - if: target in ["esp32p4"] - esp_lvgl_port: - rules: - - if: target in ["esp32p4"] - version: 2.6.0 idf: version: 5.5.* lvgl/lvgl: version: 9.4.0 #espressif/esp32_p4_function_ev_board: # version: "4.1.*" - #espressif/esp32_p4_function_ev_board: '*' + espressif/esp32_p4_function_ev_board: '*' diff --git a/main/main.c b/main/main.c index 8ee878f..05909a8 100644 --- a/main/main.c +++ b/main/main.c @@ -76,6 +76,7 @@ static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject); lv_subject_t mqttStatus; +lv_subject_t wifiStatus; extern lv_subject_t tempIntSubj; extern lv_subject_t tempExtSubj;