diff --git a/components/domotic_display/ihm.c b/components/domotic_display/ihm.c index 0b2a788..7ab50a6 100644 --- a/components/domotic_display/ihm.c +++ b/components/domotic_display/ihm.c @@ -48,7 +48,7 @@ lv_subject_t hauteurCuveEvolSubj; lv_subject_t forecastD1Subj; lv_subject_t forecastD2Subj; lv_subject_t forecastD3Subj; -lv_subject_t *tmpSubj[3] = {&forecastD1Subj, &forecastD2Subj, &forecastD3Subj}; +lv_subject_t *tmpDSubj[3] = {&forecastD1Subj, &forecastD2Subj, &forecastD3Subj}; lv_subject_t forecastH1Subj; lv_subject_t forecastH2Subj; lv_subject_t forecastH3Subj; @@ -165,6 +165,7 @@ static void create_ui(void*) // Création des écrans / widgets app_main_display(); // ton écran principal + initHome(); // écran Home drawHome(); // écran Home // chart, labels, boutons, etc. // par exemple : lblEtatMachine, lblHauteurCuve, myChart, ser... @@ -499,7 +500,7 @@ static void weatherdataJour_obs_cb(lv_observer_t *observer, lv_subject_t *subjec { // Retrieve weatherdata - struct meteodailyforecast_data *data = subject->value.pointer; + const struct meteodailyforecast_data *data = subject->value.pointer; bool isMinimal = observer->user_data; ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %d - Mode minimal : %d", data->isValid, isMinimal); @@ -548,27 +549,42 @@ static void weatherdataJour_obs_cb(lv_observer_t *observer, lv_subject_t *subjec // On pointe sur un tableau de meteoforecast_data static void weatherdataHeure_obs_cb(lv_observer_t *observer, lv_subject_t *subject) { - ESP_LOGV("MeteoFrance", "CB meteo horaire declenché"); + // Retrieve weatherdata - struct meteoforecast_data *data = subject->value.pointer; + const struct meteoforecast_data *data = subject->value.pointer; + bool isMinimal = observer->user_data; + //ESP_LOGE(TAG, "CB meteo horaire declenché. Meteo valide : %d - Mode minimal : %d", data->isValid, isMinimal); + if(data->isValid){ //printffd(data); char buff[40] = {}; snprintf(buff,sizeof(buff),"%.1f", data->previsions.value); - ESP_LOGV(TAG, "On a recu [%s]", buff); + //ESP_LOGE(TAG, "On a recu %s - [%s] - %s", data->type, buff, data->previsions.icon); - lv_obj_t *parent = (lv_obj_t *)(lv_observer_get_target(observer)); - lv_obj_t *datefld = lv_obj_get_child(parent, 0); - lv_obj_t *temp_desc_icon = lv_obj_get_child(parent, 1); - showMeteoIcon(data->previsions.icon, temp_desc_icon, 1); + if(isMinimal){ + lv_obj_t *parent = (lv_obj_t *)(lv_observer_get_target(observer)); + //lv_obj_dump_tree(parent); + lv_obj_t *descfld = lv_obj_get_child(parent, 1); + showMeteoIcon(data->previsions.icon, parent, 0); + lv_label_set_text(descfld, data->previsions.desc); + lv_obj_t *valuefld = lv_obj_get_child(parent, 2); + lv_label_set_text_fmt(valuefld, "%.1f°C", data->previsions.value); - char buffer[80]; - dtHToString(data->datetime, buffer); + }else{ + lv_obj_t *parent = (lv_obj_t *)(lv_observer_get_target(observer)); + lv_obj_dump_tree(parent); + lv_obj_t *datefld = lv_obj_get_child(parent, 0); + lv_obj_t *temp_desc_icon = lv_obj_get_child(parent, 1); + showMeteoIcon(data->previsions.icon, temp_desc_icon, 1); - lv_label_set_text(datefld, buffer); - lv_label_set_text(lv_obj_get_child(temp_desc_icon, 2), data->previsions.desc); - lv_label_set_text_fmt(lv_obj_get_child(temp_desc_icon, 0), "%.1f°C", data->previsions.value); + char buffer[80]; + dtHToString(data->datetime, buffer); + + lv_label_set_text(datefld, buffer); + lv_label_set_text(lv_obj_get_child(temp_desc_icon, 2), data->previsions.desc); + lv_label_set_text_fmt(lv_obj_get_child(temp_desc_icon, 0), "%.1f°C", data->previsions.value); + } //free(data); }else{ @@ -600,7 +616,6 @@ static lv_style_t tempStyle; static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool minimal) { - if (minimal) { //lv_obj_set_flex_flow(sup, LV_FLEX_FLOW_COLUMN); @@ -609,6 +624,7 @@ static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool min //lv_obj_set_style_border_width(sup, 1, 0); //lv_obj_set_style_border_color(sup, lv_color_white(), 0); + lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN); lv_obj_t *container = lv_obj_create(parent); lv_obj_set_align(container, LV_ALIGN_CENTER); lv_obj_set_name(container, "container_meteo"); @@ -651,7 +667,7 @@ static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool min // On positionne un observer sur le subjet correspondant au jour du widget bool isMinimal = true; - lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdataJour_obs_cb, parent, &isMinimal); + lv_subject_add_observer_obj(tmpDSubj[dayNr], weatherdataJour_obs_cb, parent, &isMinimal); } else { @@ -717,7 +733,7 @@ static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool min lv_obj_set_style_text_font(min, lv_theme_get_font_normal(max), 0); //lv_obj_set_style_text_color(min, lv_color_hex(0x3000FF), 0); // On positionne un observer sur le subjet correspondant au jour du widget - lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdataJour_obs_cb, sup, NULL); + lv_subject_add_observer_obj(tmpDSubj[dayNr], weatherdataJour_obs_cb, sup, NULL); } //return container; @@ -726,10 +742,72 @@ static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool min static lv_style_t tempStyle; // Ce fragment affiche une prévision horaire (date,icone, temp moyenne) -static lv_obj_t* weatherH_fragment_create_obj(int horaireNr, lv_obj_t *parent) +static lv_obj_t* weatherH_fragment_create_obj(int horaireNr, lv_obj_t *parent, bool minimal) { - lv_obj_t *sup = lv_obj_create(parent); + lv_obj_t *container = lv_obj_create(parent); + if (minimal) + { + lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_ROW); + //lv_obj_set_flex_flow(sup, LV_FLEX_FLOW_COLUMN); + lv_obj_set_size(parent, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + //lv_obj_set_flex_align(sup, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + //lv_obj_set_style_border_width(sup, 1, 0); + //lv_obj_set_style_border_color(sup, lv_color_white(), 0); + + lv_obj_set_align(container, LV_ALIGN_CENTER); + char name[17]; + snprintf(name, 17,"%s%d","container_meteo", horaireNr); + lv_obj_set_name(container, name); + // lv_obj_remove_style_all(container); + // lv_obj_set_style_border_width(container, 1, 0); + // lv_obj_set_style_border_color(container, lv_color_make(0, 255, 0), 0); + lv_obj_set_flex_flow(container, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_add_style(container, &no_padding, 0); + lv_obj_set_size(container, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_add_flag(container, LV_OBJ_FLAG_EVENT_BUBBLE); + + lv_obj_t *img1 = lv_image_create(container); + lv_obj_set_name(img1, "meteo_img"); + lv_obj_add_flag(img1, LV_OBJ_FLAG_EVENT_BUBBLE); + + lv_obj_remove_style_all(img1); + //lv_obj_set_style_bg_color(img1, lv_color_white(),0); + //lv_obj_set_style_border_width(img1,1,0); + lv_obj_add_style(img1, &no_padding, 0); + lv_obj_set_style_bg_color(img1, lv_palette_lighten(LV_PALETTE_BLUE_GREY, 4), 0); + lv_image_set_inner_align(img1, LV_IMAGE_ALIGN_TOP_LEFT); + lv_image_set_offset_y(img1, -8); + lv_image_set_offset_x(img1, -5); + lv_obj_set_size(img1, 40, 35); + lv_image_set_src(img1, LV_SYMBOL_DUMMY); + //lv_obj_set_style_image_recolor_opa(img1, 100, 0); + //lv_obj_set_style_image_recolor(img1, lv_color_black(), 0); + // lv_obj_set_style_border_width(img1,2,0); + // lv_obj_set_style_border_color(img1, lv_palette_main(LV_PALETTE_BLUE_GREY), 0); + lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t *desc = lv_label_create(container); + lv_obj_set_name(desc, "meteo_desc"); + lv_label_set_long_mode(desc, LV_LABEL_LONG_MODE_WRAP); + lv_obj_set_size(desc, 85, LV_SIZE_CONTENT); + //lv_obj_set_style_text_color(desc, lv_color_white(), 0); + lv_label_set_text(desc, name); + lv_obj_set_style_text_align(desc, LV_TEXT_ALIGN_CENTER, 0); + + lv_obj_t *temp = lv_label_create(container); + lv_label_set_text(temp, "--"); + lv_obj_add_style(temp, &tempStyle, 0); + lv_obj_set_style_text_font(temp,lv_theme_get_font_normal(temp),0); + + + // On positionne un observer sur le subjet correspondant a l'horaire du widget + bool isMinimal = true; + //ESP_LOGE(TAG, "on positionne obs sur horaire %d", horaireNr); + lv_subject_add_observer_obj(tmpHSubj[horaireNr], weatherdataHeure_obs_cb, container, &isMinimal); + }else{ + lv_obj_t *sup = lv_obj_create(parent); lv_obj_t *title = lv_label_create(sup); lv_label_set_text(title, "--"); @@ -771,8 +849,9 @@ static lv_obj_t* weatherH_fragment_create_obj(int horaireNr, lv_obj_t *parent) lv_obj_set_style_text_font(desc, lv_theme_get_font_normal(desc), 0); // On positionne un observer sur le subjet correspondant a l'horaire du widget - ESP_LOGV(TAG, "on positionne obs sur horaire %d", horaireNr); + //ESP_LOGV(TAG, "on positionne obs sur horaire %d", horaireNr); lv_subject_add_observer_obj(tmpHSubj[horaireNr], weatherdataHeure_obs_cb, sup, NULL); + } return container; } @@ -1058,9 +1137,9 @@ void draw_tabHome(lv_obj_t* parent){ lv_label_set_text(label, LV_SYMBOL_DOWN); lv_obj_center(label); - weatherH_fragment_create_obj(0, cont_col3); - weatherH_fragment_create_obj(1, cont_col3); - weatherH_fragment_create_obj(2, cont_col3); + weatherH_fragment_create_obj(0, cont_col3,false); + weatherH_fragment_create_obj(1, cont_col3,false); + weatherH_fragment_create_obj(2, cont_col3,false); } void draw_tabCuve(lv_obj_t* parent) @@ -1190,13 +1269,21 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) { LV_UNUSED(observer); + ESP_LOGE(TAG,"################### On passe dans le cb time"); + lv_obj_t *dateTimeObj = lv_observer_get_target_obj(observer); datetime_ctx_t *ctx = lv_obj_get_user_data(dateTimeObj); - if (!ctx) return; + if (!ctx){ + ESP_LOGE(TAG,"################### Contexte non positionné"); + return; + } 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); + if (!t){ + ESP_LOGE(TAG,"################### Pas de struct tm"); + return; + } + ESP_LOGE(TAG,"################################# %d %d %d %02d:%02d", t->tm_wday, t->tm_mday, t->tm_mon, t->tm_hour, t->tm_min); char buf[4]; bool refresh_date = false; @@ -1208,20 +1295,22 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) u8_to_2digits(buf, t->tm_mday); buf[2] = '/'; buf[3] = '\0'; - ESP_LOGE(TAG,"Jour %s",buf); + //ESP_LOGE(TAG,"Jour %s",buf); lv_span_set_text(ctx->date_day, buf); refresh_date = true; + }else{ + ESP_LOGE(TAG, "########################### Meme date !"); } 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); + //ESP_LOGE(TAG,"Mois %s",buf); lv_span_set_text(ctx->date_month, buf); refresh_date = true; } - if (refresh_date) { + if (true || refresh_date) { lv_spangroup_refresh(ctx->date_group); } @@ -1229,7 +1318,7 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) 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); + //ESP_LOGE(TAG,"Heure %s",buf); lv_span_set_text(ctx->time_hour, buf); refresh_time = true; } @@ -1240,7 +1329,7 @@ static void time_observer_cb(lv_observer_t *observer, lv_subject_t *subject) buf[1] = '0' + (t->tm_min / 10); buf[2] = '0' + (t->tm_min % 10); buf[3] = '\0'; - ESP_LOGE(TAG,"Minutes %s",buf); + //ESP_LOGE(TAG,"Minutes %s",buf); lv_span_set_text(ctx->time_min, buf); refresh_time = true; } @@ -1446,7 +1535,9 @@ void messageCardContent(lv_obj_t *cont_messages) { // lv_obj_t *txt = lv_label_create(container); // lv_label_set_text(txt, "Meteo"); - weatherDay_fragment_create_obj(0, container, true); + weatherH_fragment_create_obj(0, container,true); + weatherH_fragment_create_obj(1, container,true); + weatherH_fragment_create_obj(2, container,true); // lv_subject_add_observer_obj(&forecastD1Subj, weatherdata_obs_cb, container, NULL); } void minuteurCardContent(lv_obj_t * container) @@ -1625,21 +1716,29 @@ void messageCardContent(lv_obj_t *cont_messages) lv_obj_set_user_data(dateTimeObj, ctx); } - - void drawHome() - { - - /*Initialize the styles*/ + void initHome(){ + /*Initialize the styles*/ lv_style_init(&style_btn); // lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_GREEN)); // lv_style_set_border_color(&style_btn, lv_palette_darken(LV_PALETTE_GREEN, 3)); // lv_style_set_border_width(&style_btn, 3); + lv_style_init(&objstyle); + lv_style_set_bg_color(&objstyle, accent); + lv_style_set_outline_color(&objstyle, accent); + + lv_subject_init_string(&tempExtSubj, tempExtStr, NULL, 6, "--"); lv_subject_init_string(&tempIntSubj, tempIntStr, NULL, 6, "--"); lv_subject_init_string(&hauteurCuveSubj, hauteurCuveStr, NULL, 9, "--"); lv_subject_init_string(&hauteurCuveEvolSubj, hauteurCuveEvolStr, NULL, 9, "--"); + } + + void drawHome() + { + + // keys.clear(); lv_obj_clean(lv_scr_act()); @@ -1654,9 +1753,6 @@ void messageCardContent(lv_obj_t *cont_messages) lv_obj_set_style_pad_top(bg_cont, 5, 0); lv_obj_set_style_bg_color(bg_cont, bgColor, 0); - lv_style_init(&objstyle); - lv_style_set_bg_color(&objstyle, accent); - lv_style_set_outline_color(&objstyle, accent); /* info area */ @@ -1706,9 +1802,10 @@ void messageCardContent(lv_obj_t *cont_messages) lv_style_set_line_color(lv_span_get_style(minute), accent); lv_style_set_text_font(lv_span_get_style(minute), &super_malibu_80); //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_subject_add_observer_obj(&timeSubj, time_observer_cb, date_and_time, NULL); + + 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 1c76ab6..fa05423 100644 --- a/components/domotic_display/ihm_gateway.c +++ b/components/domotic_display/ihm_gateway.c @@ -65,7 +65,7 @@ void traiteEvt(void *arg) case IHM_EVT_TIME_SETTED: draw_time(evt->pvData); - break; + break; case IHM_EVT_OTA_STARTED: app_ota_display(); @@ -120,12 +120,15 @@ void traiteEvt(void *arg) // On ne veut liberer la memoire que lorsque l'evenement aura été traité! evt->bNeedToFreeData=false; meteo_event_payload_t *datas = (meteo_event_payload_t *) evt->pvData; - ESP_LOGE(TAG,"Est valide : %d - %s", datas->daily[0].isValid, datas->daily[0].previsions.desc); - ESP_LOGE(TAG,"Est valide : %d - %s", datas->daily[1].isValid, datas->daily[1].previsions.desc); - ESP_LOGE(TAG,"Est valide : %d - %s", datas->daily[2].isValid, datas->daily[2].previsions.desc); - ESP_LOGE(TAG,"Est valide : %d - %s", datas->forecast[0].isValid, datas->forecast[0].previsions.desc); - ESP_LOGE(TAG,"Est valide : %d - %s", datas->forecast[1].isValid, datas->forecast[1].previsions.desc); - ESP_LOGE(TAG,"Est valide : %d - %s", datas->forecast[2].isValid, datas->forecast[2].previsions.desc); + for (size_t i = 0; i < 3; i++) + { + ESP_LOGE(TAG,"Type: %s - Valide : %d - %s", datas->daily[i].type, datas->daily[i].isValid, datas->daily[i].previsions.desc); + } + for (size_t i = 0; i < 3; i++) + { + ESP_LOGE(TAG,"Type: %s - Valide : %d - %s - %s - %f", datas->forecast[i].type, datas->forecast[i].isValid, datas->forecast[i].previsions.desc, datas->forecast[i].previsions.icon, datas->forecast[i].previsions.value); + } + draw_meteo(datas); //lv_subject_set_int(&meteoStatus, 0); //display_unlock("weather_data_retreived"); diff --git a/components/domotic_display/include/ihm.h b/components/domotic_display/include/ihm.h index 7ea4e36..5b64e55 100644 --- a/components/domotic_display/include/ihm.h +++ b/components/domotic_display/include/ihm.h @@ -19,6 +19,7 @@ void showMeteoIcon(const char *icon, lv_obj_t *desc_icon, int childNr); void draw_tabVolets(); void meteoCb(lv_obj_t *base_obj); +void initHome(); void drawHome(); void draw_time(struct tm *dateHeure); diff --git a/components/meteofrance/include/meteofrance.h b/components/meteofrance/include/meteofrance.h index a303ed9..b1c6846 100644 --- a/components/meteofrance/include/meteofrance.h +++ b/components/meteofrance/include/meteofrance.h @@ -31,6 +31,7 @@ typedef struct meteodailyforecast_data // Meteo "par jour" { + char *type; time_t datetime; bool isValid; struct dailyforecast_prev previsions; @@ -38,6 +39,7 @@ typedef struct meteoforecast_data // Meteo "par heure" { + char *type; time_t datetime; bool isValid; struct forecast_prev previsions; diff --git a/components/meteofrance/meteofrance.c b/components/meteofrance/meteofrance.c index 83714b6..629b97e 100644 --- a/components/meteofrance/meteofrance.c +++ b/components/meteofrance/meteofrance.c @@ -248,6 +248,7 @@ void JSON_Parse(const cJSON *const root) cJSON *dt = cJSON_GetObjectItem(current_element, "dt"); if (cJSON_IsNumber(dt)) { + datasT.type="Daily"; datasT.datetime = dt->valueint; cJSON *temps = cJSON_GetObjectItem(current_element, "T"); datasT.previsions.min = cJSON_GetObjectItem(temps, "min")->valuedouble; @@ -279,6 +280,7 @@ void JSON_Parse(const cJSON *const root) cJSON *dt = cJSON_GetObjectItem(current_element, "dt"); if (cJSON_IsNumber(dt)) { + datasT.type="Hourly"; datasT.datetime = dt->valueint; struct tm timeinfo = {0}; localtime_r(&(datasT.datetime), &timeinfo);