OK, I reply to myself, I find a way to make it work but it’s probably not the best one:
Global var initialisation:
lv_obj_t *State, *Disp;
void setup(void)
{
at the end of the Setup:
lv_buttons();
}
the buttons procedure:
void lv_buttons(void){
lv_obj_t *label;
// Button with counter Temp-
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn1, counter_event_handler, LV_EVENT_ALL, NULL);
//lv_obj_set_pos(btn1, 100, 100); /*Set its position*/
lv_obj_set_pos(btn1, 100, 100); /*Set its position*/
lv_obj_set_size(btn1, 120, 50); /*Set its size*/
label = lv_label_create(btn1);
lv_label_set_text(label, "Temp -");
lv_obj_center(label);
// Button with Temp+
lv_obj_t *btn2 = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn2, counter_event_handlerAdd, LV_EVENT_ALL, NULL);
//lv_obj_set_pos(btn1, 100, 100); //Set its position
lv_obj_set_pos(btn2, 250, 100); //Set its position//
lv_obj_set_size(btn2, 120, 50); //Set its size//
label = lv_label_create(btn2);
lv_label_set_text(label, "Temp +");
lv_obj_center(label);
//create a style for the temperature
static lv_style_t stylTemp;
lv_style_init(&stylTemp);
lv_style_set_text_font(&stylTemp,&lv_font_montserrat_36);
lv_obj_t *Disp = lv_label_create(lv_scr_act()); //create the label
lv_obj_add_style(Disp,&stylTemp,0); //apply the stle
lv_label_set_text(Disp,"00.00"); //temporary value
lv_obj_align(Disp,LV_ALIGN_CENTER, 0,50); // set the position
//Second label, no style on this one
lv_obj_t *State = lv_label_create(lv_scr_act());
char stateOFF[] = "Undefined";
lv_label_set_text(State,stateOFF);
lv_obj_align(State,LV_ALIGN_BOTTOM_MID,0,0);
}
Then, to update the values:
void DspTmp(){
if(Temp<15) Temp=15;//set the min value
if(Temp>32) Temp=32;//set the max value
char tp[6];
snprintf(tp,sizeof tp,"%.2f",Temp); //float to char[]
lv_obj_t *Tst = lv_obj_get_child(lv_scr_act(), 3);//get the address of the Temperature on the display
lv_label_set_text_fmt(Tst, "%s", tp);//update the temperature
char DspState[16];//update the state
if(Temp < RTemp) snprintf(DspState,15,"Compressor OFF"); //check the status
else snprintf(DspState,15,"Compressor ON ");//and define the message
lv_obj_t *Tst1 = lv_obj_get_child(lv_scr_act(), 4); //get the adresse of the status on the display
lv_label_set_text(Tst1, DspState);//update the texte
}
This is working but there no point to get the variable Disp and State as global if I have to address the location on the display by this way… There is probably a better way… I still need your help…
Thank you.