meilleure gestion meteo
This commit is contained in:
parent
f29fee752f
commit
28c5870ca6
@ -116,6 +116,20 @@ void draw_temp(char * tempHumid){
|
||||
}
|
||||
}
|
||||
|
||||
void draw_meteo(meteo_event_payload_t *meteo){
|
||||
//if(display_lock("updateTime")){
|
||||
//lv_label_set_text(jour, dateHeure);
|
||||
lv_subject_set_pointer(&forecastH1Subj, &meteo->daily[0]);
|
||||
lv_subject_set_pointer(&forecastH2Subj, &meteo->daily[1]);
|
||||
lv_subject_set_pointer(&forecastH3Subj, &meteo->daily[2]);
|
||||
lv_subject_set_pointer(&forecastD1Subj, &meteo->forecast[0]);
|
||||
lv_subject_set_pointer(&forecastD2Subj, &meteo->forecast[1]);
|
||||
lv_subject_set_pointer(&forecastD3Subj, &meteo->forecast[2]);
|
||||
|
||||
//display_unlock("updateTime");
|
||||
//}
|
||||
}
|
||||
|
||||
lv_obj_t* myChart;
|
||||
lv_chart_series_t * ser;
|
||||
lv_obj_t *lblHauteurCuve;
|
||||
@ -177,7 +191,9 @@ void drawIhm(void *param) {
|
||||
// Loop unifiée
|
||||
while (1) {
|
||||
ihm_gateway_process_queue();
|
||||
//uint32_t idle_time = lv_timer_handler();
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
uint32_t idle_time = lv_timer_handler();
|
||||
#endif
|
||||
|
||||
// ESP32 : task FreeRTOS
|
||||
//vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
@ -479,7 +495,7 @@ static lv_style_t style_container;
|
||||
|
||||
// Callback pour mettre à jour une météo journaliere
|
||||
// On pointe sur un tableau de meteodailyforecast_data
|
||||
static void weatherdata_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
|
||||
static void weatherdataJour_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
|
||||
{
|
||||
|
||||
// Retrieve weatherdata
|
||||
@ -527,7 +543,7 @@ static void weatherdata_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
|
||||
|
||||
// Callback pour mettre à jour une météo horaire
|
||||
// On pointe sur un tableau de meteoforecast_data
|
||||
static void weatherdataH_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
|
||||
static void weatherdataHeure_obs_cb(lv_observer_t *observer, lv_subject_t *subject)
|
||||
{
|
||||
ESP_LOGV("MeteoFrance", "CB meteo horaire declenché");
|
||||
// Retrieve weatherdata
|
||||
@ -628,7 +644,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], weatherdata_obs_cb, parent, &isMinimal);
|
||||
lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdataJour_obs_cb, parent, &isMinimal);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -694,7 +710,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], weatherdata_obs_cb, sup, NULL);
|
||||
lv_subject_add_observer_obj(tmpSubj[dayNr], weatherdataJour_obs_cb, sup, NULL);
|
||||
}
|
||||
|
||||
//return container;
|
||||
@ -749,7 +765,7 @@ static lv_obj_t* weatherH_fragment_create_obj(int horaireNr, lv_obj_t *parent)
|
||||
|
||||
// On positionne un observer sur le subjet correspondant a l'horaire du widget
|
||||
ESP_LOGV(TAG, "on positionne obs sur horaire %d", horaireNr);
|
||||
lv_subject_add_observer_obj(tmpHSubj[horaireNr], weatherdataH_obs_cb, sup, NULL);
|
||||
lv_subject_add_observer_obj(tmpHSubj[horaireNr], weatherdataHeure_obs_cb, sup, NULL);
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
@ -112,6 +112,30 @@ void traiteEvt(void *arg)
|
||||
break;
|
||||
}
|
||||
|
||||
case IHM_EVT_METEO_RECUE:{
|
||||
//(void *)evt->pvData; // Pointeur sur tableau
|
||||
//(void *)evt->pvData
|
||||
ESP_LOGE("MeteoFrance", "------------------------------------- Set des subjects J --------------------------------");
|
||||
meteo_event_payload_t *datas = (meteo_event_payload_t *) evt->pvData;
|
||||
draw_meteo(datas);
|
||||
// Prévisions des 3 prochains jours
|
||||
//lv_subject_set_pointer(&forecastD1Subj, &dailyDatas[0]);
|
||||
//lv_subject_set_pointer(&forecastD2Subj, &dailyDatas[1]);
|
||||
//lv_subject_set_pointer(&forecastD3Subj, &dailyDatas[2]);
|
||||
|
||||
ESP_LOGE("MeteoFrance", "------------------------------------- Set des subjects H--------------------------------");
|
||||
// Prévisions des 3 prochains jours
|
||||
//ESP_LOGV("MeteoFrance", "Pointeur %lli", datas[0].datetime);
|
||||
//lv_subject_set_pointer(&forecastH1Subj, &datas[0]);
|
||||
//lv_subject_set_pointer(&forecastH2Subj, &datas[1]);
|
||||
// lv_subject_set_pointer(&forecastH3Subj, &datas[2]);
|
||||
|
||||
//lv_subject_set_int(&meteoStatus, 0);
|
||||
//display_unlock("weather_data_retreived");
|
||||
ESP_LOGE(TAG, "------------------------------------- Fin Set des subjects --------------------------------");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Evt inconnu");
|
||||
break;
|
||||
|
||||
@ -24,11 +24,13 @@ void drawHome();
|
||||
void draw_time(struct tm *dateHeure);
|
||||
void draw_temp(char *tempHumid);
|
||||
|
||||
void draw_meteo(meteo_event_payload_t *meteo);
|
||||
|
||||
void create_card();
|
||||
|
||||
void weather_data_retreived_start();
|
||||
|
||||
void weather_data_retreived(meteodailyforecast_data dailyDatas[3], meteoforecast_data datas[3]);
|
||||
void weather_data_retreived(meteo_event_payload_t *datas);
|
||||
|
||||
void draw_tabMeteo(lv_obj_t * parent);
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "obtain_time.c" "eventsManager.c" obtain_time.c
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES mqtt esp_netif)
|
||||
REQUIRES mqtt esp_netif meteofrance)
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "mqtt_client.h"
|
||||
#include "obtain_time.h"
|
||||
#include <time.h>
|
||||
#include "meteofrance.h"
|
||||
|
||||
EventGroupHandle_t domotic_event_group;
|
||||
QueueHandle_t ihm_queue;
|
||||
@ -125,6 +126,22 @@ void send_event(domo_events evt, void* pDatas) {
|
||||
break;
|
||||
}
|
||||
|
||||
case EVT_METEO_RECUE:{
|
||||
meteo_event_payload_t *incoming = (meteo_event_payload_t *) pDatas;
|
||||
meteo_event_payload_t *payload = malloc(sizeof(meteo_event_payload_t));
|
||||
if (payload == NULL) {
|
||||
// gérer l’erreur
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(payload->daily, incoming->daily, sizeof(incoming->daily));
|
||||
memcpy(payload->forecast, incoming->daily, sizeof(incoming->forecast));
|
||||
ihmEvt->eEventType = IHM_EVT_METEO_RECUE;
|
||||
ihmEvt->pvData = payload;
|
||||
ihmEvt->bNeedToFreeData = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unhandled event type");
|
||||
free(ihmEvt);
|
||||
|
||||
@ -14,6 +14,7 @@ typedef enum eIHMEvent_t{
|
||||
IHM_EVT_PUISSANCE_EMISE,
|
||||
IHM_EVT_ETAT_MACHINE,
|
||||
IHM_EVT_HAUTEUR_CUVE,
|
||||
IHM_EVT_METEO_RECUE
|
||||
} eIHMEvent_t;
|
||||
|
||||
typedef struct IHM_EVENT
|
||||
@ -29,7 +30,8 @@ typedef enum domo_events{
|
||||
EVT_BTN_VOLET,
|
||||
EVT_PUISSANCE_RECUE,
|
||||
EVT_ETAT_MACHINE,
|
||||
EVT_HAUTEUR_CUVE
|
||||
EVT_HAUTEUR_CUVE,
|
||||
EVT_METEO_RECUE
|
||||
} domo_events;
|
||||
void startEvtManager();
|
||||
QueueHandle_t getIHMQueueHandle();
|
||||
|
||||
@ -29,21 +29,26 @@
|
||||
char icon[9];
|
||||
};
|
||||
|
||||
typedef struct meteodailyforecast_data
|
||||
typedef struct meteodailyforecast_data // Meteo "par jour"
|
||||
{
|
||||
time_t datetime;
|
||||
bool isValid;
|
||||
struct dailyforecast_prev previsions;
|
||||
} meteodailyforecast_data;
|
||||
|
||||
typedef struct meteoforecast_data
|
||||
typedef struct meteoforecast_data // Meteo "par heure"
|
||||
{
|
||||
time_t datetime;
|
||||
bool isValid;
|
||||
struct forecast_prev previsions;
|
||||
} meteoforecast_data;
|
||||
|
||||
typedef void (*weather_data_callback)(struct meteodailyforecast_data *datas, struct meteoforecast_data *datasf);
|
||||
typedef struct {
|
||||
meteodailyforecast_data daily[3];
|
||||
meteoforecast_data forecast[3];
|
||||
} meteo_event_payload_t;
|
||||
|
||||
typedef void (*weather_data_callback)(meteo_event_payload_t *datas);
|
||||
typedef void (*weather_data_start_callback)();
|
||||
|
||||
typedef struct
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_tls.h"
|
||||
#include "stateManagement.h"
|
||||
#include "eventsManager.h"
|
||||
static const char *TAG = "MeteoFrance";
|
||||
|
||||
/* Constants that aren't configurable in menuconfig
|
||||
@ -39,8 +40,8 @@ static const char *TAG = "MeteoFrance";
|
||||
#define MAX_HTTP_OUTPUT_BUFFER 32000
|
||||
|
||||
static weather_data weather;
|
||||
static struct meteodailyforecast_data dailydatas[5];
|
||||
static struct meteoforecast_data forecastdatas[5];
|
||||
static struct meteodailyforecast_data dailydatas[3];
|
||||
static struct meteoforecast_data forecastdatas[3];
|
||||
|
||||
void printdftemp(struct dailyforecast_prev *tmp)
|
||||
{
|
||||
@ -379,8 +380,13 @@ static void meteo_task(void* domotic_event_group)
|
||||
heap_caps_free(local_response_buffer);
|
||||
esp_http_client_cleanup(client);
|
||||
if(dailydatas->isValid){
|
||||
ESP_LOGV(TAG, "Données valides on appelle le cb");
|
||||
weather.data_retreived_cb(dailydatas, forecastdatas);
|
||||
ESP_LOGE(TAG, "Données valides on appelle le cb");
|
||||
meteo_event_payload_t *payload = malloc(sizeof(*payload));
|
||||
memcpy(payload->daily, dailydatas, sizeof(payload->daily));
|
||||
memcpy(payload->forecast, forecastdatas, sizeof(payload->forecast));
|
||||
send_event(EVT_METEO_RECUE, payload);
|
||||
//weather.data_retreived_cb(payload);
|
||||
free(payload);
|
||||
vTaskDelay(weather.retreival_period / portTICK_PERIOD_MS);
|
||||
}else{
|
||||
//Ca a échoué on recommence dans 30 secondes
|
||||
|
||||
20
main/main.c
20
main/main.c
@ -711,9 +711,9 @@ extern lv_subject_t forecastH2Subj;
|
||||
extern lv_subject_t forecastH3Subj;
|
||||
extern lv_subject_t meteoStatus;
|
||||
|
||||
void weather_data_retreived(struct meteodailyforecast_data dailyDatas[3], struct meteoforecast_data datas[3])
|
||||
void weather_data_retreived(meteo_event_payload_t *datas)
|
||||
{
|
||||
|
||||
send_event(EVT_METEO_RECUE, datas);
|
||||
/* ESP_LOGE(TAG, "debut debug");
|
||||
printf("%lld\n", datas[0].datetime);
|
||||
printf("%s\n", datas[0].previsions.desc);
|
||||
@ -728,22 +728,6 @@ void weather_data_retreived(struct meteodailyforecast_data dailyDatas[3], struct
|
||||
*/
|
||||
//if (display_lock("weather_data_retreived"))
|
||||
//{
|
||||
ESP_LOGV("MeteoFrance", "------------------------------------- Set des subjects J --------------------------------");
|
||||
// Prévisions des 3 prochains jours
|
||||
//lv_subject_set_pointer(&forecastD1Subj, &dailyDatas[0]);
|
||||
//lv_subject_set_pointer(&forecastD2Subj, &dailyDatas[1]);
|
||||
//lv_subject_set_pointer(&forecastD3Subj, &dailyDatas[2]);
|
||||
|
||||
ESP_LOGV("MeteoFrance", "------------------------------------- Set des subjects H--------------------------------");
|
||||
// Prévisions des 3 prochains jours
|
||||
ESP_LOGV("MeteoFrance", "Pointeur %lli", datas[0].datetime);
|
||||
//lv_subject_set_pointer(&forecastH1Subj, &datas[0]);
|
||||
//lv_subject_set_pointer(&forecastH2Subj, &datas[1]);
|
||||
// lv_subject_set_pointer(&forecastH3Subj, &datas[2]);
|
||||
|
||||
//lv_subject_set_int(&meteoStatus, 0);
|
||||
//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");
|
||||
//}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user