diff --git a/CMakeLists.txt b/CMakeLists.txt index 0272a4b..e0067a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ if(SIMULATION_QEMU) components/domotic_display managed_components/lvgl_lvgl main + esp-timer $ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs ) @@ -29,7 +30,7 @@ else() # $ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs # ) endif() -list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/esp_timer") +#list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/esp_timer") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(rgb_lcd) @@ -50,5 +51,13 @@ if(CONFIG_SIMULATION_QEMU) #) else() message(STATUS "Compilation standard") - add_link_options("-Wl,--disable-non-contiguous-regions -lSDL2") + #add_link_options("-Wl,--disable-non-contiguous-regions") + add_compile_options( + -fsanitize=address + -fno-omit-frame-pointer + -O0 + -g + ) + + add_link_options(-fsanitize=address) endif() diff --git a/components/domotic_display/CMakeLists.txt b/components/domotic_display/CMakeLists.txt index 2c3aabd..c71a176 100644 --- a/components/domotic_display/CMakeLists.txt +++ b/components/domotic_display/CMakeLists.txt @@ -24,7 +24,7 @@ if(${IDF_TARGET} STREQUAL "esp32p4" OR ${IDF_TARGET} STREQUAL "esp32s3") #esp32_p4_function_ev_board idf_component_register(SRC_DIRS . fonts INCLUDE_DIRS "include" - REQUIRES ${comps} esp_lvgl_port) + REQUIRES ${comps} esp_lvgl_port esp32_p4_function_ev_board ) target_compile_options(${COMPONENT_LIB} PUBLIC -DLV_LVGL_H_INCLUDE_SIMPLE) lvgl_port_create_c_image("images/wifi_ok.png" "images/" "ARGB8888" "NONE") diff --git a/components/domotic_display/ihm.c b/components/domotic_display/ihm.c index c6d60dc..77c9ea2 100644 --- a/components/domotic_display/ihm.c +++ b/components/domotic_display/ihm.c @@ -5,10 +5,20 @@ #include "meteofrance.h" #include "cJSON.h" #include "eventsManager.h" + +#ifndef CONFIG_IDF_TARGET_LINUX #include "bsp/esp-bsp.h" +#include "bsp/esp32_p4_function_ev_board.h" +#include "esp_lvgl_port.h" +#else +#include "esp-bsp-mock.h" +#endif + #include "lvgl_private.h" #include "lv_examples.h" + + #include "lv_theme_domotic.h" @@ -22,6 +32,9 @@ LV_FONT_DECLARE(roboto_medium_36); LV_FONT_DECLARE(roboto_medium_72); LV_FONT_DECLARE(super_malibu_80); +LV_IMAGE_DECLARE(mqtt_ok); +LV_IMAGE_DECLARE(mqtt_ko); + lv_subject_t dateHeureSubj; lv_obj_t *lblTempInt2; char tempExtStr[6]; @@ -55,7 +68,10 @@ LV_IMAGE_DECLARE(wifi_ko); static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) { ESP_LOGV(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); + + #ifndef CONFIG_IDF_TARGET_LINUX bsp_display_lock(0); + #endif if(lv_layer_top()!=NULL && lv_obj_get_child_cnt(lv_layer_top())){ lv_obj_t * wifiSt = lv_obj_get_child(lv_obj_get_child(lv_layer_top(), 0),2); if(lv_obj_check_type(wifiSt, &lv_image_class)){ @@ -76,8 +92,9 @@ static void wifiStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) }else{ ESP_LOGI(TAG,"Pour le moment l'icone de statut n'existe pas"); } - + #ifndef CONFIG_IDF_TARGET_LINUX bsp_display_unlock(); + #endif //int32_t prev_v = lv_subject_get_previous_int(subject); //int32_t cur_v = lv_subject_get_int(subject); @@ -122,7 +139,7 @@ void lv_theme_copy(lv_theme_t *dst, const lv_theme_t *src) } lv_memcpy(dst, src, sizeof(*src)); } -static void create_ui(void) +static void create_ui(void*) { // Initialisation du thème lv_theme_t *th_new = lv_theme_domotic_init(lv_display_get_default()); @@ -139,15 +156,6 @@ static void create_ui(void) // par exemple : lblEtatMachine, lblHauteurCuve, myChart, ser... } -static void ihm_process_queue(QueueHandle_t xIHMEventQueue) -{ - xIHMEvent_t *xReceivedEvent = NULL; - - while (xQueueReceive(xIHMEventQueue, &xReceivedEvent, 0) == pdTRUE && xReceivedEvent) { - - } -} - // draw_ihm.c #include "ihm_gateway.h" #include // usleep @@ -157,26 +165,19 @@ 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); // Init queue //ihm_gateway_init(); - create_ui(); + lv_async_call(create_ui,NULL); // Loop unifiée while (1) { ihm_gateway_process_queue(); uint32_t idle_time = lv_timer_handler(); - if (platform_is_pc()) { - // SDL backend - usleep(idle_time * 1000); - } else { - // ESP32 : task FreeRTOS - vTaskDelay(pdMS_TO_TICKS(idle_time)); - } + // ESP32 : task FreeRTOS + vTaskDelay(500 / portTICK_PERIOD_MS); } } @@ -215,8 +216,8 @@ static void event_handler(lv_event_t *e) void init_display_ihm(){ - lv_init(); #if CONFIG_IDF_TARGET_LINUX + lv_init(); printf("Hello from sim\n"); display = lv_sdl_window_create(1024, 600); mouse = lv_sdl_mouse_create(); @@ -224,11 +225,14 @@ void init_display_ihm(){ keyboard = lv_sdl_keyboard_create(); #else lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG(); - lvgl_cfg.task_priority=15; + lvgl_cfg.task_priority=4; bsp_display_cfg_t cfg = { .lvgl_port_cfg = lvgl_cfg, .buffer_size = 1024*600,//BSP_LCD_DRAW_BUFF_SIZE, .double_buffer = 1, + .hw_cfg = { + .dsi_bus.lane_bit_rate_mbps= 1000 + }, .flags = { .buff_dma = false, .buff_spiram = false, @@ -236,7 +240,8 @@ void init_display_ihm(){ } }; ESP_LOGE(TAG,"On demarre le display"); - lv_display_t *dsp = bsp_display_start_with_config(&cfg); + bsp_display_start(); + //lv_display_t *dsp = bsp_display_start_with_config(&cfg); //bsp_display_rotate(dsp,LV_DISP_ROTATION_180); bsp_display_backlight_on(); @@ -1129,41 +1134,94 @@ void draw_tabVolets(lv_obj_t* parent) } } +typedef struct { + lv_obj_t *date_group; + lv_span_t *date_day; + lv_span_t *date_month; + + lv_obj_t *time_group; + lv_span_t *time_hour; + lv_span_t *time_min; + + int last_day; + int last_month; + int last_hour; + int last_min; +} datetime_ctx_t; + +static inline void u8_to_2digits(char *buf, uint8_t v) +{ + buf[0] = '0' + (v / 10); + buf[1] = '0' + (v % 10); + buf[2] = '\0'; +} + static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) { - LV_UNUSED(subject); + LV_UNUSED(observer); + lv_obj_t *dateTimeObj = lv_observer_get_target_obj(observer); + datetime_ctx_t *ctx = lv_obj_get_user_data(dateTimeObj); + if (!ctx) return; - //char buf[16]; + struct tm *t = (struct tm *)lv_subject_get_pointer(subject); + if (!t) return; + ESP_LOGE(TAG,"%d %d %d %02d:%02d", t->tm_wday, t->tm_mday, t->tm_mon, t->tm_hour, t->tm_min); - lv_obj_t *spangroup = lv_obj_find_by_name(dateTimeObj, "date"); //lv_obj_get_child_by_id(dateTimeObj, "date"); + char buf[4]; + bool refresh_date = false; + bool refresh_time = false; - // lv_span_set_text(lv_spangroup_get_child(spangroup, 2), lv_subject_get_string(lv_subject_get_group_element(subject, 0))); - - if (display_lock("updateTime")) - { - struct tm *dateHeure = (struct tm *)lv_subject_get_pointer(subject); - char buff[13]; - - snprintf(buff, 8, "%02" LV_PRIu32 "/", (uint32_t)dateHeure->tm_mday); - ESP_LOGE(TAG, "%s", buff); - lv_span_set_text(lv_spangroup_get_child(spangroup, 0), buff); - snprintf(buff, 4, "%02" LV_PRIu32, (uint32_t)((dateHeure->tm_mon) + 1)); - lv_span_set_text(lv_spangroup_get_child(spangroup, 1), buff); - lv_spangroup_refresh(spangroup); - - spangroup = lv_obj_find_by_name(dateTimeObj, "time"); - snprintf(buff,sizeof(buff), "%02" LV_PRId32, (uint32_t)dateHeure->tm_hour); - lv_span_set_text(lv_spangroup_get_child(spangroup, 0), buff); - snprintf(buff,sizeof(buff), ":%02" LV_PRId32, (uint32_t)dateHeure->tm_min); - lv_span_set_text(lv_spangroup_get_child(spangroup, 1), buff); - lv_spangroup_refresh(spangroup); - - display_unlock("updateTime"); + // ---- DATE ---- + if (t->tm_mday != ctx->last_day) { + ctx->last_day = t->tm_mday; + u8_to_2digits(buf, t->tm_mday); + buf[2] = '/'; + buf[3] = '\0'; + ESP_LOGE(TAG,"Jour %s",buf); + lv_span_set_text(ctx->date_day, buf); + refresh_date = true; } + + if ((t->tm_mon + 1) != ctx->last_month) { + ctx->last_month = t->tm_mon + 1; + u8_to_2digits(buf, ctx->last_month); + ESP_LOGE(TAG,"Mois %s",buf); + lv_span_set_text(ctx->date_month, buf); + refresh_date = true; } + if (refresh_date) { + lv_spangroup_refresh(ctx->date_group); + } + + // ---- TIME ---- + if (t->tm_hour != ctx->last_hour) { + ctx->last_hour = t->tm_hour; + u8_to_2digits(buf, t->tm_hour); + ESP_LOGE(TAG,"Heure %s",buf); + lv_span_set_text(ctx->time_hour, buf); + refresh_time = true; + } + + if (t->tm_min != ctx->last_min) { + ctx->last_min = t->tm_min; + buf[0] = ':'; + buf[1] = '0' + (t->tm_min / 10); + buf[2] = '0' + (t->tm_min % 10); + buf[3] = '\0'; + ESP_LOGE(TAG,"Minutes %s",buf); + lv_span_set_text(ctx->time_min, buf); + refresh_time = true; + } + + if (refresh_time) { + lv_spangroup_refresh(ctx->time_group); + } + +} + /* ------------------------------------------------------------ */ /* Dessin IHM */ /* ------------------------------------------------------------ */ @@ -1293,11 +1351,11 @@ void blink_start(lv_obj_t *obj, uint32_t period_ms) } static void anim_opa_cb(void *obj, int32_t v) { - if (display_lock_logChoose("msg fade", false)) - { + //if (display_lock_logChoose("msg fade", false)) + //{ lv_obj_set_style_opa(obj, v, 0); - display_unlock_logChoose("msg fade",false); - } + // display_unlock_logChoose("msg fade",false); + //} } void blink_fade(lv_obj_t *obj) { @@ -1520,6 +1578,25 @@ void messageCardContent(lv_obj_t *cont_messages) drawMeteo(base_obj); } + void datetime_ctx_init(lv_obj_t *dateTimeObj) +{ + datetime_ctx_t *ctx = lv_malloc(sizeof(datetime_ctx_t)); + LV_ASSERT_MALLOC(ctx); + memset(ctx, -1, sizeof(datetime_ctx_t)); // force 1ère mise à jour + + ctx->date_group = lv_obj_find_by_name(dateTimeObj, "date"); + ctx->time_group = lv_obj_find_by_name(dateTimeObj, "time"); + + ctx->date_day = lv_spangroup_get_child(ctx->date_group, 0); + ctx->date_month = lv_spangroup_get_child(ctx->date_group, 1); + + ctx->time_hour = lv_spangroup_get_child(ctx->time_group, 0); + ctx->time_min = lv_spangroup_get_child(ctx->time_group, 1); + + lv_obj_set_user_data(dateTimeObj, ctx); +} + + void drawHome() { @@ -1602,7 +1679,7 @@ void messageCardContent(lv_obj_t *cont_messages) //lv_subject_add_observer_obj(&c->th, theme_observer_accent_span_cb, time, minute); lv_subject_add_observer_obj(&timeSubj, time_observer_cb, date_and_time, NULL); - + datetime_ctx_init(date_and_time); lv_obj_t * subContent = lv_obj_create(info_area); lv_obj_set_flex_flow(subContent, LV_FLEX_FLOW_COLUMN); lv_obj_set_size(subContent, LV_PCT(70), LV_PCT(100)); diff --git a/components/domotic_display/ihm_gateway.c b/components/domotic_display/ihm_gateway.c index 1cb6f46..5711ee1 100644 --- a/components/domotic_display/ihm_gateway.c +++ b/components/domotic_display/ihm_gateway.c @@ -39,72 +39,86 @@ void ihm_gateway_process_queue(void) { 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 CONFIG_IDF_TARGET_LINUX + while (xQueueReceive(xIHMEventQueue, &evt, pdMS_TO_TICKS(0)) == pdTRUE) +#else + while (xQueueReceive(xIHMEventQueue, &evt, pdMS_TO_TICKS(10)) == pdTRUE) +#endif + { 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); - + UBaseType_t pending = uxQueueMessagesWaiting(xIHMEventQueue); + ESP_LOGV(TAG,"Evt recu %d. La queue comporte %d éléments à traiter", evt->eEventType, pending); + + lv_async_call(traiteEvt, evt); + } +} + +void traiteEvt(void *arg) +{ + xIHMEvent_t *evt = (xIHMEvent_t *)arg; + 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); + ESP_LOGV(TAG, "Evt traité"); } diff --git a/components/domotic_display/include/bsp/esp-bsp.h b/components/domotic_display/include/bsp/esp-bsp.h deleted file mode 100644 index 07be6c0..0000000 --- a/components/domotic_display/include/bsp/esp-bsp.h +++ /dev/null @@ -1,17 +0,0 @@ -#include "lvgl.h" -extern SemaphoreHandle_t lvgl_mux; -static const char* TAG_BSP="bsp"; -bool bsp_display_lock(int timeout_ms) -{ - //ESP_LOGI(TAG_BSP, "Obtention mutex"); - // Convert timeout in milliseconds to FreeRTOS ticks - // 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(); - return true; -} -void bsp_display_unlock() { - //xSemaphoreGiveRecursive(lvgl_mux); - //lv_unlock(); -} diff --git a/components/domotic_display/include/esp-bsp-mock.h b/components/domotic_display/include/esp-bsp-mock.h new file mode 100644 index 0000000..8ab1270 --- /dev/null +++ b/components/domotic_display/include/esp-bsp-mock.h @@ -0,0 +1,2 @@ +bool bsp_display_lock(int timeout_ms){return true;}; +void bsp_display_unlock(){}; \ No newline at end of file diff --git a/components/domotic_display/include/ihm_gateway.h b/components/domotic_display/include/ihm_gateway.h index 55cd979..f6b5795 100644 --- a/components/domotic_display/include/ihm_gateway.h +++ b/components/domotic_display/include/ihm_gateway.h @@ -10,3 +10,5 @@ QueueHandle_t getIHMQueueHandle(void); void ihm_gateway_init(void); void ihm_gateway_post_event(xIHMEvent_t *evt); void ihm_gateway_process_queue(void); + +void traiteEvt(void * evt); diff --git a/components/domotic_display/include/platform_detect.h b/components/domotic_display/include/platform_detect.h index 896e3ea..5002ce8 100644 --- a/components/domotic_display/include/platform_detect.h +++ b/components/domotic_display/include/platform_detect.h @@ -6,7 +6,7 @@ static inline bool platform_is_pc(void) { #if CONFIG_IDF_TARGET_LINUX - return true; + return false; #else return false; #endif diff --git a/components/eventsManager/eventsManager.c b/components/eventsManager/eventsManager.c index 75470a8..135634c 100644 --- a/components/eventsManager/eventsManager.c +++ b/components/eventsManager/eventsManager.c @@ -26,7 +26,7 @@ void startEvtManager(){ } void send_event(domo_events evt, void* pDatas) { - ESP_LOGE(TAG,"On est dans l'event handler %i", evt); + ESP_LOGV(TAG,"On est dans l'event handler %i", evt); xIHMEvent_t *ihmEvt = malloc(sizeof(xIHMEvent_t)); if (!ihmEvt) { @@ -70,6 +70,7 @@ void send_event(domo_events evt, void* pDatas) { return; } + *msg_copy = *msg; ihmEvt->eEventType = IHM_EVT_TIME_SETTED; ihmEvt->pvData = msg_copy; @@ -130,8 +131,8 @@ void send_event(domo_events evt, void* pDatas) { return; } ESP_LOGE(TAG, "Envoi d'un evt %i a l'IHM", ihmEvt->eEventType); - if( ihm_queue != NULL ){ - if (ihmEvt && xQueueSendToFront(ihm_queue, &ihmEvt, pdMS_TO_TICKS(10)) != pdPASS) + if( ihm_queue != NULL && ihmEvt){ + if (xQueueSendToFront(ihm_queue, &ihmEvt, pdMS_TO_TICKS(10)) != pdPASS) { ESP_LOGE(TAG, "La queue est pleine"); if (ihmEvt->bNeedToFreeData && ihmEvt->pvData) diff --git a/components/eventsManager/obtain_time.c b/components/eventsManager/obtain_time.c index e79d385..bbbd102 100644 --- a/components/eventsManager/obtain_time.c +++ b/components/eventsManager/obtain_time.c @@ -27,9 +27,9 @@ void updateTime(void *pvParameter) // strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); 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); + //ESP_LOGE(TAG, "%s", strftime_buf); send_event(EVT_TIME_SETTED, &timeinfo); - vTaskDelay(10000 / portTICK_PERIOD_MS); + vTaskDelay(1000 / portTICK_PERIOD_MS); } } #else @@ -45,8 +45,9 @@ void time_sync_notification_cb(struct timeval *tv) 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); + ESP_LOGE(TAG, "%s", strftime_buf); localtime_r(&now, &timeinfo); - send_event(EVT_TIME_SETTED, &strftime_buf); + send_event(EVT_TIME_SETTED, &timeinfo); } void updateTime(void *pvParameter) @@ -77,7 +78,8 @@ void updateTime(void *pvParameter) struct tm timeinfo = {0}; localtime_r(&now, &timeinfo); sprintf(strftime_buf, "%s %d %s %02d:%02d (%lli mn depuis reboot)", days[timeinfo.tm_wday], timeinfo.tm_mday, months[timeinfo.tm_mon], timeinfo.tm_hour, timeinfo.tm_min, (esp_timer_get_time() / 1000 / 1000 / 60)); - send_event(EVT_TIME_SETTED, &strftime_buf); + ESP_LOGE(TAG, "%s", strftime_buf); + send_event(EVT_TIME_SETTED, &timeinfo); vTaskDelay(60000 / portTICK_PERIOD_MS); } } diff --git a/components/image_downloader/CMakeLists.txt b/components/image_downloader/CMakeLists.txt index 2596e40..79ea867 100644 --- a/components/image_downloader/CMakeLists.txt +++ b/components/image_downloader/CMakeLists.txt @@ -1,11 +1,5 @@ set(requires json esp_http_client esp-tls esp_timer) -idf_build_get_property(target IDF_TARGET) -if(${target} STREQUAL "linux") - list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/esp_timer" ) -else() - list(APPEND requires esp_timer) -endif() idf_component_register(SRCS "image_downloader.c" INCLUDE_DIRS "include" - REQUIRES ${requires} ) + REQUIRES ${requires}) diff --git a/components/meteofrance/meteofrance.c b/components/meteofrance/meteofrance.c index 5b8005c..e04c74b 100644 --- a/components/meteofrance/meteofrance.c +++ b/components/meteofrance/meteofrance.c @@ -320,7 +320,7 @@ static bool process_response_body(const char *body) return true; } -static void http_request_task(void* domotic_event_group) +static void meteo_task(void* domotic_event_group) { while (1) { @@ -385,7 +385,7 @@ static void http_request_task(void* domotic_event_group) }else{ //Ca a échoué on recommence dans 30 secondes ESP_LOGI(TAG, "Données non valides on attend avant de retenter"); - vTaskDelay(30000 / portTICK_PERIOD_MS); + vTaskDelay(10000 / portTICK_PERIOD_MS); } }else{ @@ -412,7 +412,7 @@ void initialise_weather_data_retrieval(unsigned long retreival_period, void* dom // http_client_on_process_chunk(&http_client, process_chunk); // http_client_on_disconnected(&http_client, disconnected); TaskHandle_t xHandle = NULL; - BaseType_t ret1 = xTaskCreatePinnedToCore(&http_request_task, "http_meteof", 5 * 1024, domotic_event_group, 5, &xHandle, 0); + BaseType_t ret1 = xTaskCreate(&meteo_task, "http_meteof", 20 * 1024, domotic_event_group, configMAX_PRIORITIES-2, &xHandle); if(ret1!=pdPASS ){ ESP_LOGE(TAG, "Impossible de creer la tache %"PRIi16, ret1); } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c2c7679..f492c69 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,7 +1,7 @@ idf_build_get_property(python SIMULATION_QEMU) message(STATUS "The Python interpreter is: ${python}") -set(comps heap nvs_flash esp_netif image_downloader fatfs protocol_examples_common mqtt meteofrance domotic_display RemindMe) +set(comps heap nvs_flash esp_netif image_downloader fatfs protocol_examples_common mqtt meteofrance domotic_display RemindMe esp_timer) if(${IDF_TARGET} STREQUAL "esp32p4") message(STATUS "SIMULATION_QEMU = OOF --> main standard") diff --git a/main/idf_component.yml b/main/idf_component.yml index 9f9c9f7..5a0a2ac 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -21,8 +21,6 @@ dependencies: - if: target in ["esp32p4"] 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: diff --git a/main/main.c b/main/main.c index c1d14b0..688ee54 100644 --- a/main/main.c +++ b/main/main.c @@ -768,7 +768,7 @@ void weather_data_retreived(struct meteodailyforecast_data dailyDatas[3], struct //display_unlock("weather_data_retreived"); ESP_LOGV(TAG, "------------------------------------- Fin Set des subjects --------------------------------"); //}else{ - ESP_LOGE(TAG, "Impossible d'obtenir le mutex dans weather_data_retreived"); + //ESP_LOGE(TAG, "Impossible d'obtenir le mutex dans weather_data_retreived"); //} } @@ -785,9 +785,6 @@ void weather_data_retreived_start() //} } -LV_IMAGE_DECLARE(mqtt_ok); -LV_IMAGE_DECLARE(mqtt_ko); - /* static void mqttStatus_obs_cb(lv_observer_t * observer, lv_subject_t * subject) { ESP_LOGV(TAG, "On passe dans le callback de chgt de statut; %li", lv_subject_get_int(subject)); @@ -904,27 +901,30 @@ void app_main(void) ihm_gateway_init(); startEvtManager(); - boucleMeteo(); - #if CONFIG_IDF_TARGET_LINUX + //boucleMeteo(); + +#if CONFIG_IDF_TARGET_LINUX // en mode linux on simule l'obtention de la connexion wifi xEventGroupSetBits(domotic_event_group, WIFI_CONNECTED_BIT); - - drawIhm(NULL); - #else - xTaskCreatePinnedToCore(&drawIhm,"ihm_task",10000,getIHMQueueHandle(),10,NULL,0); - #endif + xTaskCreate(&drawIhm,"ihm_task",10000,getIHMQueueHandle(),10,NULL); + //drawIhm(getIHMQueueHandle()); + +#else + xTaskCreate(&drawIhm,"ihm_task",10000,getIHMQueueHandle(),10,NULL); + //et sinon on se connecte + ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); + wifi_init_sta(wifi_cb); + //start_wifi_logger(); +#endif TaskHandle_t xHandle = NULL; BaseType_t ret1; - ret1 = xTaskCreate(&imgdwn, "imageDownload_task", 3 * 1024, domotic_event_group, 5, &xHandle); + /*ret1 = xTaskCreate(&imgdwn, "imageDownload_task", 3 * 1024, domotic_event_group, 5, &xHandle); if (ret1 != pdPASS) { ESP_LOGE(TAG, "Impossiblke de creer la tache imageDownload_task %i", ret1); - } + }*/ - - /* Create widgets on the screen */ - //lv_demo_widgets(); } void boucleMeteo() @@ -1012,9 +1012,6 @@ void app_main1(void) } ESP_ERROR_CHECK(ret); - ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); - //wifi_init_sta(wifi_cb); - //start_wifi_logger(); //wifi_log_e("test", "%s %d %f", "hello world wifi logger", 43, 45.341223242); // write log over wifi with log level -> ERROR esp_log_level_set("tcp_handler", ESP_LOG_NONE); printf("8b - Free heap after buffers allocation: %zu\n", xPortGetFreeHeapSize());