remise cuve
This commit is contained in:
parent
c690ac01e1
commit
de8d9ede17
@ -83,7 +83,13 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicTest, 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0);
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicdomoticCommand, 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicEtatMachine, 0);
|
||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||
|
||||
msg_id = esp_mqtt_client_subscribe(client, topicConsoElec, 0);
|
||||
|
||||
139
main/ihm.c
139
main/ihm.c
@ -92,78 +92,92 @@ static void draw_temp(char * tempHumid){
|
||||
|
||||
lv_obj_t* myChart;
|
||||
lv_chart_series_t * ser;
|
||||
lv_obj_t *lblHauteurCuve;
|
||||
|
||||
void drawIhm(void *xIHMEventQueue){
|
||||
void drawIhm(void *xIHMEventQueueParam) {
|
||||
QueueHandle_t xIHMEventQueue = (QueueHandle_t)xIHMEventQueueParam;
|
||||
|
||||
init_display();
|
||||
|
||||
lv_subject_init_int(&wifiStatus,0);
|
||||
lv_subject_init_int(&wifiStatus, 0);
|
||||
lv_subject_add_observer_obj(&wifiStatus, wifiStatus_obs_cb, NULL, NULL);
|
||||
|
||||
display_lock("app_main");
|
||||
app_main_display();
|
||||
display_unlock("app_main");
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
// Show LVGL objects
|
||||
if(display_lock("draw_ihm")){
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
|
||||
if (display_lock("draw_ihm")) {
|
||||
draw_ihm();
|
||||
display_unlock("draw_ihm");
|
||||
}
|
||||
while (1){
|
||||
xIPStackEvent_t xReceivedEvent;
|
||||
// On cree une queue qui va permettre de recevoir les informations a afficher
|
||||
xQueueReceive(xIHMEventQueue,&xReceivedEvent, portMAX_DELAY );
|
||||
switch (xReceivedEvent.eEventType)
|
||||
{
|
||||
case IHM_EVT_WIFI_STATUS:
|
||||
ESP_LOGV(TAG, "evt wifi -- begin");
|
||||
lv_subject_set_int(&wifiStatus, (int)xReceivedEvent.pvData);
|
||||
ESP_LOGV(TAG, "evt wifi -- end");
|
||||
break;
|
||||
case IHM_EVT_TIME_SETTED:
|
||||
ESP_LOGV(TAG, "evt timesetted -- begin");
|
||||
draw_time(xReceivedEvent.pvData);
|
||||
ESP_LOGV(TAG, "evt timesetted -- end");
|
||||
break;
|
||||
case IHM_EVT_OTA_STARTED:
|
||||
ESP_LOGV(TAG, "evt OTA_STARTED -- begin");
|
||||
app_ota_display();
|
||||
ESP_LOGV(TAG, "evt OTA_STARTED -- end");
|
||||
break;
|
||||
case IHM_EVT_OTA_PROGRESS:
|
||||
//ESP_LOGE(TAG, "evt OTA_PROGRESS -- begin");
|
||||
setOTAProgress((int)xReceivedEvent.pvData);
|
||||
//ESP_LOGE(TAG, "evt OTA_PROGRESS -- end");
|
||||
break;
|
||||
case IHM_EVT_HUMID_TEMP:
|
||||
ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- begin");
|
||||
draw_temp((char *)xReceivedEvent.pvData);
|
||||
ESP_LOGV(TAG, "evt IHM_EVT_HUMID_TEMP -- end");
|
||||
break;
|
||||
case IHM_EVT_PUISSANCE_EMISE:
|
||||
if(display_lock("updateChart")){
|
||||
ESP_LOGE(TAG,"On a recu %i",(int)xReceivedEvent.pvData);
|
||||
if((int)xReceivedEvent.pvData==0){
|
||||
lv_chart_set_next_value(myChart,ser,LV_CHART_POINT_NONE);
|
||||
}else{
|
||||
lv_chart_set_next_value(myChart,ser,(int)xReceivedEvent.pvData);
|
||||
}
|
||||
//lv_chart_refresh(myChart);
|
||||
display_unlock("updateChart");
|
||||
|
||||
while (1) {
|
||||
xIHMEvent_t *xReceivedEvent = NULL;
|
||||
|
||||
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;
|
||||
|
||||
case IHM_EVT_TIME_SETTED:
|
||||
draw_time(xReceivedEvent->pvData);
|
||||
break;
|
||||
|
||||
case IHM_EVT_OTA_STARTED:
|
||||
app_ota_display();
|
||||
break;
|
||||
|
||||
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:
|
||||
case IHM_EVT_ETAT_MACHINE:
|
||||
if (display_lock("updateChart")) {
|
||||
int val = (int)xReceivedEvent->pvData;
|
||||
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_HAUTEUR_CUVE:
|
||||
if (display_lock("updateCuve")) {
|
||||
float hauteur = *(float *)xReceivedEvent->pvData;
|
||||
lv_label_set_text_fmt(lblHauteurCuve, "%.2f cm", hauteur);
|
||||
display_unlock("updateCuve");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Evt inconnu");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Evt inconnu");
|
||||
break;
|
||||
};
|
||||
ESP_LOGV(TAG,"IHM delay");
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
|
||||
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é !");
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void event_handler(lv_event_t *e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
@ -695,13 +709,16 @@ static void draw_event_cb(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_t* lblEtatMachine;
|
||||
void draw_tabMinuteur(lv_obj_t * parent)
|
||||
{
|
||||
lblEtatMachine = lv_label_create(parent);
|
||||
lv_label_set_text(lblEtatMachine,"Machine: ");
|
||||
myChart = lv_chart_create(parent);
|
||||
lv_chart_set_type(myChart, LV_CHART_TYPE_BAR);
|
||||
lv_chart_set_point_count(myChart, 30);
|
||||
lv_obj_set_style_pad_column(myChart, 2, 0);
|
||||
lv_obj_set_size(myChart, 600, 500);
|
||||
lv_obj_set_size(myChart, 600, 400);
|
||||
lv_chart_set_range(myChart, LV_CHART_AXIS_PRIMARY_Y, 0, 1500);
|
||||
lv_obj_center(myChart);
|
||||
|
||||
@ -811,6 +828,7 @@ void draw_tabHome(lv_obj_t* parent){
|
||||
lv_label_bind_text(lblTempExt, &tempExtSubj, "%s °C");
|
||||
|
||||
//Create a container with COLUMN flex direction
|
||||
/*
|
||||
lv_obj_t *cont_tempInt = lv_obj_create(cont_colTemp);
|
||||
lv_obj_add_style(cont_tempInt, &style_container, 0);
|
||||
// lv_obj_set_height(cont_tempInt,50);
|
||||
@ -821,13 +839,14 @@ void draw_tabHome(lv_obj_t* parent){
|
||||
lv_obj_add_style(lblTempInt, &style_lbvValue, 0);
|
||||
lv_label_set_text(lblTempInt, "");
|
||||
lv_label_bind_text(lblTempInt, &tempIntSubj, "%s °C");
|
||||
*/
|
||||
|
||||
//Create a container with COLUMN flex direction
|
||||
lv_obj_t *cont_tempInt2 = lv_obj_create(cont_colTemp);
|
||||
lv_obj_add_style(cont_tempInt2, &style_container, 0);
|
||||
// lv_obj_set_height(cont_tempInt,50);
|
||||
lv_obj_set_flex_flow(cont_tempInt2, LV_FLEX_FLOW_ROW);
|
||||
lblInt = lv_label_create(cont_tempInt2);
|
||||
lv_obj_t * lblInt = lv_label_create(cont_tempInt2);
|
||||
lv_label_set_text(lblInt, "int.");
|
||||
lblTempInt2 = lv_label_create(cont_tempInt2);
|
||||
lv_obj_add_style(lblTempInt2, &style_lbvValue, 0);
|
||||
@ -844,9 +863,9 @@ void draw_tabHome(lv_obj_t* parent){
|
||||
|
||||
lv_obj_t *lblHauteurEau = lv_label_create(cont_Cuve);
|
||||
lv_label_set_text(lblHauteurEau, "Cuve: ");
|
||||
lv_obj_t *lblHauteurCuve = lv_label_create(cont_Cuve);
|
||||
lblHauteurCuve = lv_label_create(cont_Cuve);
|
||||
lv_obj_add_style(lblHauteurCuve, &style_lbvValue, 0);
|
||||
lv_label_bind_text(lblHauteurCuve, &hauteurCuveSubj, "%s cm");
|
||||
//lv_label_bind_text(lblHauteurCuve, &hauteurCuveSubj, "%s cm");
|
||||
|
||||
lv_obj_t *btnUp = lv_button_create(cont_colVolets);
|
||||
lv_obj_add_style(btnUp, &style_btn, 0);
|
||||
|
||||
@ -37,14 +37,17 @@ typedef enum eIHMEvent_t{
|
||||
IHM_EVT_OTA_STARTED,
|
||||
IHM_EVT_OTA_PROGRESS,
|
||||
IHM_EVT_HUMID_TEMP,
|
||||
IHM_EVT_PUISSANCE_EMISE
|
||||
IHM_EVT_PUISSANCE_EMISE,
|
||||
IHM_EVT_ETAT_MACHINE,
|
||||
IHM_EVT_HAUTEUR_CUVE,
|
||||
} eIHMEvent_t;
|
||||
|
||||
typedef struct IP_TASK_COMMANDS
|
||||
typedef struct IHM_EVENT
|
||||
{
|
||||
eIHMEvent_t eEventType; /* Tells the receiving task what the event is. */
|
||||
void *pvData; /* Holds or points to any data associated with the event. */
|
||||
} xIPStackEvent_t;
|
||||
bool bNeedToFreeData; // ← Important !
|
||||
} xIHMEvent_t;
|
||||
|
||||
|
||||
void drawIhm(void *pvParameter);
|
||||
|
||||
@ -23,6 +23,7 @@ void mqtt_app_start(mqtt_callback cb, EventGroupHandle_t evtGroup);
|
||||
#define topicTempInt "house/temp/287DCF1E00008020"
|
||||
#define topicHauteurCuveEvol "house/cuve/hauteurEvol"
|
||||
#define topicConsoElec "energy/puissance_5mn"
|
||||
#define topicEtatMachine "energy/machine_en_route"
|
||||
#define topicdomoticCommand "domotic/cmd"
|
||||
#define topicTest "test"
|
||||
|
||||
|
||||
127
main/main.c
127
main/main.c
@ -121,9 +121,9 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
}
|
||||
else if (strncmp(event->topic, topicHauteurCuveEvol, event->topic_len) == 0)
|
||||
/*else if (strncmp(event->topic, topicHauteurCuveEvol, event->topic_len) == 0)
|
||||
{
|
||||
/* float datas[4] = {};
|
||||
float datas[4] = {};
|
||||
splitIt(event->data, event->data_len, datas);
|
||||
ser1->y_points[0] = 130 - (int)datas[0];
|
||||
ser1->y_points[1] = 130 - (int)datas[1];
|
||||
@ -132,12 +132,16 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
|
||||
lvgl_port_lock(0);
|
||||
lv_chart_refresh(chart);
|
||||
lvgl_port_unlock();
|
||||
*/
|
||||
|
||||
|
||||
// lv_subject_copy_string(&hauteurCuveEvolSubj, event->data);
|
||||
}
|
||||
}*/
|
||||
else if (strncmp(event->topic, topicHauteurCuve, event->topic_len) == 0)
|
||||
{
|
||||
float f = strtof(event->data, NULL);
|
||||
ESP_LOGE(TAG,"%f recu mqtt", f);
|
||||
send_event(EVT_HAUTEUR_CUVE,&f);
|
||||
/*
|
||||
if (lvgl_port_lock(50)){
|
||||
float temp = strtof(event->data, NULL);
|
||||
char buff[5];
|
||||
@ -145,6 +149,7 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
|
||||
lv_subject_copy_string(&hauteurCuveSubj, buff);
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
*/
|
||||
}else if (strncmp(event->topic, topicTest, event->topic_len) == 0){
|
||||
ESP_LOGD(TAG,"Msg reecu sur test");
|
||||
}else if (strncmp(event->topic, topicConsoElec, event->topic_len) == 0){
|
||||
@ -153,6 +158,12 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
|
||||
|
||||
send_event(EVT_PUISSANCE_RECUE,(int*)atoi(datas));
|
||||
|
||||
}else if (strncmp(event->topic, topicEtatMachine, event->topic_len) == 0){
|
||||
char* datas = malloc(event->data_len+1);
|
||||
strncpy(datas, event->data, event->data_len);
|
||||
|
||||
send_event(EVT_ETAT_MACHINE,(int*)atoi(datas));
|
||||
|
||||
}else if (strncmp(event->topic, topicdomoticCommand, event->topic_len) == 0){
|
||||
if(strncmp(event->data,"restart",7)==0){
|
||||
ESP_LOGI(TAG," Commande 'restart' recue");
|
||||
@ -175,37 +186,93 @@ void mqtt_cb(mqtt_evt evt, esp_mqtt_event_handle_t event){
|
||||
}
|
||||
|
||||
|
||||
void send_event(domo_events evt, void* pDatas){
|
||||
void send_event(domo_events evt, void* pDatas) {
|
||||
ESP_LOGE(TAG,"On est dans l'event handler %i", evt);
|
||||
switch(evt){
|
||||
case EVT_WIFI_CONNECTED:
|
||||
|
||||
xIHMEvent_t *ihmEvt = malloc(sizeof(xIHMEvent_t));
|
||||
if (!ihmEvt) {
|
||||
ESP_LOGE(TAG, "malloc failed for event struct");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt) {
|
||||
case EVT_WIFI_CONNECTED: {
|
||||
xEventGroupSetBits(domotic_event_group, WIFI_CONNECTED_BIT);
|
||||
ESP_LOGI(TAG, "connected to ap SSID");
|
||||
xIPStackEvent_t evt = {
|
||||
.eEventType = IHM_EVT_WIFI_STATUS,
|
||||
.pvData = (void *)true
|
||||
};
|
||||
if(xQueueSendToFront( ihm_queue, ( void * ) &evt, ( TickType_t ) 10 ) != pdPASS){
|
||||
ESP_LOGE(TAG, "La queue est pleine");
|
||||
};
|
||||
ESP_LOGI(TAG, "connected to AP SSID");
|
||||
|
||||
bool *wifiStatus = malloc(sizeof(bool));
|
||||
if (!wifiStatus) {
|
||||
ESP_LOGE(TAG, "malloc failed for wifiStatus");
|
||||
free(ihmEvt);
|
||||
return;
|
||||
}
|
||||
*wifiStatus = true;
|
||||
|
||||
ihmEvt->eEventType = IHM_EVT_WIFI_STATUS;
|
||||
ihmEvt->pvData = wifiStatus;
|
||||
ihmEvt->bNeedToFreeData = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case EVT_TIME_SETTED:
|
||||
xIPStackEvent_t m = {
|
||||
.eEventType = IHM_EVT_TIME_SETTED,
|
||||
.pvData = pDatas
|
||||
};
|
||||
xQueueSendToFront(ihm_queue,&m,5);
|
||||
const char *msg = (const char *)pDatas;
|
||||
char *msg_copy = malloc(strlen(msg) + 1);
|
||||
if (!msg_copy) {
|
||||
ESP_LOGE(TAG, "malloc failed for message string");
|
||||
free(ihmEvt);
|
||||
return;
|
||||
}
|
||||
strcpy(msg_copy, msg);
|
||||
ihmEvt->eEventType = IHM_EVT_TIME_SETTED;
|
||||
ihmEvt->pvData = msg_copy;
|
||||
ihmEvt->bNeedToFreeData = true;
|
||||
break;
|
||||
|
||||
case EVT_BTN_VOLET:
|
||||
esp_mqtt_client_publish(client, "volets", pDatas, 0, 0, 0);
|
||||
break;
|
||||
free(ihmEvt); // rien à envoyer à l'IHM
|
||||
return;
|
||||
|
||||
case EVT_PUISSANCE_RECUE:
|
||||
xIPStackEvent_t m1 = {
|
||||
.eEventType = IHM_EVT_PUISSANCE_EMISE,
|
||||
.pvData = pDatas
|
||||
};
|
||||
xQueueSendToFront(ihm_queue,&m1,5);
|
||||
ihmEvt->eEventType = IHM_EVT_PUISSANCE_EMISE;
|
||||
ihmEvt->pvData = pDatas;
|
||||
ihmEvt->bNeedToFreeData = false;
|
||||
break;
|
||||
|
||||
case EVT_ETAT_MACHINE:
|
||||
ihmEvt->eEventType = IHM_EVT_ETAT_MACHINE;
|
||||
ihmEvt->pvData = pDatas;
|
||||
ihmEvt->bNeedToFreeData = false;
|
||||
break;
|
||||
|
||||
case EVT_HAUTEUR_CUVE: {
|
||||
float *data = malloc(sizeof(float));
|
||||
if (!data) {
|
||||
ESP_LOGE(TAG, "malloc failed for hauteur_cuve");
|
||||
free(ihmEvt);
|
||||
return;
|
||||
}
|
||||
*data = *(float *)pDatas;
|
||||
ESP_LOGE(TAG, "EVENT_HANDLER -> On a recu %f", *data);
|
||||
|
||||
ihmEvt->eEventType = IHM_EVT_HAUTEUR_CUVE;
|
||||
ihmEvt->pvData = data;
|
||||
ihmEvt->bNeedToFreeData = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unhandled event type");
|
||||
free(ihmEvt);
|
||||
return;
|
||||
}
|
||||
ESP_LOGE(TAG, "Envoi d'un evt %i a l'IHM", ihmEvt->eEventType);
|
||||
if (xQueueSendToFront(ihm_queue, &ihmEvt, pdMS_TO_TICKS(10)) != pdPASS) {
|
||||
ESP_LOGE(TAG, "La queue est pleine");
|
||||
if (ihmEvt->bNeedToFreeData && ihmEvt->pvData) {
|
||||
free(ihmEvt->pvData);
|
||||
}
|
||||
free(ihmEvt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,7 +479,7 @@ void simple_ota_example_task(void *pvParameter)
|
||||
ESP_LOGE(TAG, "image header verification failed");
|
||||
goto ota_end;
|
||||
}
|
||||
xIPStackEvent_t m = {
|
||||
xIHMEvent_t m = {
|
||||
.eEventType = IHM_EVT_OTA_STARTED,
|
||||
.pvData = NULL
|
||||
};
|
||||
@ -477,11 +544,11 @@ void readTempHumid(void *pvParameter)
|
||||
char buff[40];
|
||||
ESP_LOGI(TAG, "Temperature: %.1f °C, Humidity: %.1f %%", temperature, humidity);
|
||||
sprintf(buff,"%.1f °C, %.1f %%", temperature, humidity);
|
||||
xIPStackEvent_t m = {
|
||||
xIHMEvent_t m = {
|
||||
.eEventType = IHM_EVT_HUMID_TEMP,
|
||||
.pvData = buff
|
||||
};
|
||||
xQueueSendToFront(ihm_queue,&m,5);
|
||||
//xQueueSendToFront(ihm_queue,&m,5);
|
||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
@ -788,7 +855,7 @@ void app_main(void)
|
||||
{
|
||||
|
||||
domotic_event_group = xEventGroupCreate();
|
||||
ihm_queue = xQueueCreate(10,sizeof(xIPStackEvent_t));
|
||||
ihm_queue = xQueueCreate(10,sizeof(xIHMEvent_t *));
|
||||
//init_display();
|
||||
const esp_timer_create_args_t periodic_timer_args = {
|
||||
.callback = &presence_timer_callback,
|
||||
|
||||
@ -4,6 +4,8 @@ typedef enum domo_events{
|
||||
EVT_WIFI_CONNECTED,
|
||||
EVT_TIME_SETTED,
|
||||
EVT_BTN_VOLET,
|
||||
EVT_PUISSANCE_RECUE
|
||||
EVT_PUISSANCE_RECUE,
|
||||
EVT_ETAT_MACHINE,
|
||||
EVT_HAUTEUR_CUVE
|
||||
} domo_events;
|
||||
void send_event(domo_events evt, void* pDatas);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user