refonte ihm

This commit is contained in:
Marc PASTEUR 2025-12-16 07:01:03 +01:00
parent 77953a3397
commit 7ff8979051

View File

@ -33,11 +33,11 @@ lv_subject_t forecastH3Subj;
lv_subject_t *tmpHSubj[3] = {&forecastH1Subj, &forecastH2Subj, &forecastH3Subj};
lv_subject_t meteoStatus;
//char dateHeureStr[30];
char dateHeureStr[30];
lv_obj_t *jour;
static lv_style_t no_padding;
//static const char *TAG = "IHM";
static const char *TAG = "IHM";
static lv_subject_t wifiStatus;
LV_IMAGE_DECLARE(wifi_ok);
@ -163,7 +163,7 @@ void drawIhm(void *xIHMEventQueueParam) {
app_main_display();
display_unlock("app_main");
vTaskDelay(pdMS_TO_TICKS(2000));
vTaskDelay(pdMS_TO_TICKS(200));
if (display_lock("draw_ihm")) {
draw_ihm();
@ -372,6 +372,8 @@ void app_main_display()
lv_strcpy(p.desc, "");
d.previsions = p;
d.isValid=false;
ESP_LOGI(TAG, "Init forecastD1Subj");
lv_subject_init_pointer(&forecastD1Subj, &d);
lv_subject_init_pointer(&forecastD2Subj, &d);
lv_subject_init_pointer(&forecastD3Subj, &d);
@ -387,7 +389,7 @@ void app_main_display()
lv_subject_init_pointer(&forecastH3Subj, &d1);
//lv_subject_init_string(&dateHeureSubj, dateHeureStr, NULL, 64, "--");
lv_subject_init_string(&dateHeureSubj, dateHeureStr, NULL, 64, "--");
lv_style_init(&no_padding);
lv_style_set_pad_all(&no_padding, 0);
@ -416,7 +418,7 @@ void app_main_display()
jour = lv_label_create(cont_status);
lv_obj_set_style_text_font(jour,lv_theme_get_font_normal(jour),0);
lv_obj_set_width(jour, LV_SIZE_CONTENT);
//lv_label_bind_text(jour, &dateHeureSubj, NULL);
lv_label_bind_text(jour, &dateHeureSubj, NULL);
lv_obj_refr_size(cont_status);
// lv_obj_align(jour, LV_ALIGN_CENTER,0,0);
@ -429,10 +431,10 @@ void app_main_display()
// lv_label_bind_text(meteoR, &meteoStatus, "Meteo %d");
/*lv_obj_t *wifi =*/ lv_image_create(cont_status);
// lv_obj_set_style_bg_color(wifi, lv_palette_darken(LV_PALETTE_GREY, 3), 0);
// lv_obj_set_style_border_width(wifi,1,0);
// lv_obj_set_style_border_color(wifi,lv_palette_darken(LV_PALETTE_GREY, 3),0);
lv_obj_t *wifi = lv_image_create(cont_status);
lv_obj_set_style_bg_color(wifi, lv_palette_darken(LV_PALETTE_GREY, 3), 0);
//lv_obj_set_style_border_width(wifi,1,0);
//lv_obj_set_style_border_color(wifi,lv_palette_darken(LV_PALETTE_GREY, 3),0);
// lv_label_set_text(wifi,"Wifi Ok");
// lv_label_bind_text(wifi, &wifiStatus, "Wifi %d");
@ -504,23 +506,38 @@ static void weatherdata_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
// Retrieve weatherdata
const struct meteodailyforecast_data *data = subject->value.pointer;
ESP_LOGV(TAG, "CB meteo jour declenché. Meteo valide : %i", data->isValid);
bool isMinimal = observer->user_data;
ESP_LOGI(TAG, "CB meteo jour declenché. Meteo valide : %i - Mode minimal : %d", data->isValid, isMinimal);
// printffd(data);
// char buff[40] = {};
// sprintf(buff,"%s %.1f %.1f", data->previsions.desc, data->previsions.min, data->previsions.max);
if(data->isValid){
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)
{
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 *desc_icon = lv_obj_get_child(parent, 1);
lv_obj_t *temps = lv_obj_get_child(parent, 2);
showMeteoIcon(data->previsions.icon, desc_icon, 0);
char buffer[80];
dtToString(data->datetime, buffer);
if(parent!=NULL){
if(isMinimal){
lv_obj_t *desc_icon = lv_obj_get_child(parent, 0);
showMeteoIcon(data->previsions.icon, desc_icon, 0);
}
else
{
lv_obj_t *datefld = lv_obj_get_child(parent, 0);
lv_obj_t *desc_icon = lv_obj_get_child(parent, 1);
lv_obj_t *temps = lv_obj_get_child(parent, 2);
if (datefld && desc_icon && temps)
{
showMeteoIcon(data->previsions.icon, desc_icon, 0);
char buffer[80];
dtToString(data->datetime, buffer);
lv_label_set_text(datefld, buffer);
lv_label_set_text(lv_obj_get_child(desc_icon, 1), data->previsions.desc);
lv_label_set_text_fmt(lv_obj_get_child(temps, 0), "%.1f°C", data->previsions.max);
lv_label_set_text_fmt(lv_obj_get_child(temps, 1), "%.1f°C", data->previsions.min);
lv_label_set_text(datefld, buffer);
lv_label_set_text(lv_obj_get_child(desc_icon, 1), data->previsions.desc);
lv_label_set_text_fmt(lv_obj_get_child(temps, 0), "%.1f°C", data->previsions.max);
lv_label_set_text_fmt(lv_obj_get_child(temps, 1), "%.1f°C", data->previsions.min);
}
}
}
}
}
@ -559,79 +576,112 @@ static void weatherdataH_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
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:/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);
ESP_LOGV(TAG,"On affiche l'image %s", result);
lv_image_set_src(img, result);
lv_image_set_src(img, "A:/home/marc/domotic/components/domotic_display/images_meteo/p4j.png");
free(result);
}
static lv_style_t tempStyle;
// Ce fragment affiche une prévision journaliere (date,icone, min et max)
static lv_obj_t* weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent)
static void weatherDay_fragment_create_obj(int dayNr, lv_obj_t *parent, bool minimal)
{
lv_obj_t *sup = lv_obj_create(parent);
lv_obj_t *title = lv_label_create(sup);
lv_label_set_text(title, "--");
//lv_obj_remove_style_all(sup);
lv_obj_set_flex_flow(sup, LV_FLEX_FLOW_ROW);
lv_obj_add_style(sup, &style_container, 0);
lv_obj_set_size(sup, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_t *container = lv_obj_create(sup);
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_width(container, 150);
lv_obj_set_height(container, 80);
if(minimal){
lv_obj_remove_style_all(sup);
lv_obj_t *img1 = lv_image_create(container);
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, 32);
lv_image_set_src(img1, LV_SYMBOL_DUMMY);
// 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 *container = lv_obj_create(sup);
lv_obj_remove_style_all(container);
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_width(container, 150);
lv_obj_set_height(container, 80);
lv_obj_t *desc = lv_label_create(container);
lv_label_set_text(desc, "--");
lv_obj_set_style_text_font(desc, lv_theme_get_font_normal(desc),0);
lv_obj_t *img1 = lv_image_create(container);
lv_obj_remove_style_all(img1);
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, 32);
lv_image_set_src(img1, LV_SYMBOL_DUMMY);
// 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 *container2 = lv_obj_create(sup);
lv_obj_set_width(container2, LV_SIZE_CONTENT);
lv_obj_set_height(container2, 80);
lv_obj_add_style(container2, &no_padding, 0);
lv_obj_set_style_pad_top(container2, 5, 0);
lv_obj_set_style_pad_bottom(container2, 5, 0);
lv_obj_set_flex_flow(container2, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(container2, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
// On positionne un observer sur le subjet correspondant au jour du widget
bool isMinimal = true;
lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdata_obs_cb, sup, &isMinimal);
}
else
{
lv_obj_add_style(sup, &style_container, 0);
lv_style_init(&tempStyle);
// lv_style_set_text_font(&tempStyle,&notomedium16);
lv_obj_t *dateField = lv_label_create(sup);
lv_label_set_text(dateField, "--");
lv_obj_t *max = lv_label_create(container2);
lv_label_set_text(max, "--");
lv_obj_add_style(max, &tempStyle, 0);
lv_obj_set_style_text_font(max,lv_theme_get_font_normal(max),0);
lv_obj_set_style_text_color(max, lv_color_hex(0xFF0000), 0);
lv_obj_t *container = lv_obj_create(sup);
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_width(container, 150);
lv_obj_set_height(container, 80);
lv_obj_t *min = lv_label_create(container2);
lv_label_set_text(min, "--");
lv_obj_add_style(min, &tempStyle, 0);
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);
lv_obj_t *img1 = lv_image_create(container);
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, 32);
lv_image_set_src(img1, LV_SYMBOL_DUMMY);
// 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);
// On positionne un observer sur le subjet correspondant au jour du widget
lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdata_obs_cb, sup, NULL);
return container;
lv_obj_t *desc = lv_label_create(container);
lv_label_set_text(desc, "--");
lv_obj_set_style_text_font(desc, lv_theme_get_font_normal(desc), 0);
lv_obj_t *container2 = lv_obj_create(sup);
lv_obj_set_width(container2, LV_SIZE_CONTENT);
lv_obj_set_height(container2, 80);
lv_obj_add_style(container2, &no_padding, 0);
lv_obj_set_style_pad_top(container2, 5, 0);
lv_obj_set_style_pad_bottom(container2, 5, 0);
lv_obj_set_flex_flow(container2, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(container2, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
lv_style_init(&tempStyle);
// lv_style_set_text_font(&tempStyle,&notomedium16);
lv_obj_t *max = lv_label_create(container2);
lv_label_set_text(max, "--");
lv_obj_add_style(max, &tempStyle, 0);
lv_obj_set_style_text_font(max, lv_theme_get_font_normal(max), 0);
lv_obj_set_style_text_color(max, lv_color_hex(0xFF0000), 0);
lv_obj_t *min = lv_label_create(container2);
lv_label_set_text(min, "--");
lv_obj_add_style(min, &tempStyle, 0);
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], weatherdata_obs_cb, sup, NULL);
}
//return container;
}
static lv_style_t tempStyle;
@ -968,9 +1018,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);
weatherH_fragment_create_obj(1, cont_col3);
weatherH_fragment_create_obj(2, cont_col3);
}
void draw_tabCuve(lv_obj_t* parent)
@ -981,9 +1031,9 @@ void draw_tabCuve(lv_obj_t* parent)
void draw_tabMeteo(lv_obj_t * parent)
{
weatherDay_fragment_create_obj(0,parent);
weatherDay_fragment_create_obj(1,parent);
weatherDay_fragment_create_obj(2,parent);
weatherDay_fragment_create_obj(0,parent, false);
weatherDay_fragment_create_obj(1,parent, false);
weatherDay_fragment_create_obj(2,parent, false);
//manager2 = lv_fragment_manager_create(NULL);
//fragment2 = lv_fragment_create(&meteodailyforecast_cls, (void *)1);
//lv_fragment_manager_add(manager2, fragment2, &parent);
@ -1109,7 +1159,7 @@ void coverCardContent(lv_obj_t *cont_colVolets)
{
lv_obj_set_style_pad_all(cont_colVolets, 5, 0);
lv_obj_set_flex_align(cont_colVolets, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_size(cont_colVolets, lv_pct(60), lv_pct(70));
//lv_obj_set_size(cont_colVolets, lv_pct(60), lv_pct(70));
lv_obj_set_flex_flow(cont_colVolets, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(cont_colVolets, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER);
@ -1137,6 +1187,8 @@ void meteoCardContent(lv_obj_t *container)
{
lv_obj_t *txt = lv_label_create(container);
lv_label_set_text(txt, "Meteo");
weatherDay_fragment_create_obj(0,container, true);
//lv_subject_add_observer_obj(&forecastD1Subj, weatherdata_obs_cb, container, NULL);
}
void minuteurCardContent(lv_obj_t *container)
{
@ -1322,6 +1374,7 @@ void create_card(lv_obj_t *parent, char *lbl, void(*contentFct)(lv_obj_t*))
lv_obj_t *app_card = lv_obj_create(parent);
lv_obj_remove_style_all(app_card);
lv_obj_set_size(app_card, 300, 180);
//lv_obj_set_size(app_card, 100, 60);
lv_obj_set_style_radius(app_card, 20, 0);
lv_obj_set_style_bg_opa(app_card, 50, 0);
lv_obj_add_style(app_card, &objstyle, 0);
@ -1343,6 +1396,8 @@ void create_card(lv_obj_t *parent, char *lbl, void(*contentFct)(lv_obj_t*))
lv_obj_add_flag(icon, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_t *content = lv_obj_create(app_card);
lv_obj_set_size(content, LV_PCT(100), LV_PCT(70));
lv_obj_set_style_bg_opa(content, 0, 0);
contentFct(content);
}