From e1640f4ad97a489014f93f3a278a58fbb5ffe3b9 Mon Sep 17 00:00:00 2001 From: Marc Pasteur Date: Thu, 26 Feb 2026 23:20:05 +0100 Subject: [PATCH] =?UTF-8?q?machine=20:=20affichage=20dur=C3=A9e=20depuis?= =?UTF-8?q?=20d=C3=A9part?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../washingMachineState/washingMachineState.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/components/washingMachineState/washingMachineState.c b/components/washingMachineState/washingMachineState.c index ce07549..5abd47c 100644 --- a/components/washingMachineState/washingMachineState.c +++ b/components/washingMachineState/washingMachineState.c @@ -54,6 +54,29 @@ WashingMachineState getEtatMachine(){ return wms; } +char *duree_depuis_timestamp_formatee(time_t timestamp) +{ + time_t maintenant = time(NULL); + long diff_minutes = (maintenant - timestamp) / 60; + + if (diff_minutes < 0) + diff_minutes = 0; // sécurité si timestamp futur + + char *resultat = malloc(32); + if (!resultat) + return NULL; + + if (diff_minutes < 60) { + snprintf(resultat, 32, "%ldmn", diff_minutes); + } else { + long heures = diff_minutes / 60; + long minutes = diff_minutes % 60; + snprintf(resultat, 32, "%ldh%02ld", heures, minutes); + } + + return resultat; +} + void getEtatMachineStr(WashingMachineState wms, char* etat, size_t etatSize) { char* etatStr; @@ -73,10 +96,22 @@ void getEtatMachineStr(WashingMachineState wms, char* etat, size_t etatSize) etatStr="Etat inconnu"; break; } + char dateStr[30]; timestampToDate(wms.depuis,dateStr,30); - snprintf(etat,etatSize,"%s depuis %s", etatStr, dateStr); + //Si la machine est en route on ajoute la durée en heures/minutes depuis le départ + if(wms.etat==LAVEUSE_LAVAGE){ + char *duree = duree_depuis_timestamp_formatee(wms.depuis); + if (duree) { + printf("Durée : %s\n", duree); + snprintf(etat,etatSize,"%s depuis %s\n (%s)", etatStr, duree, dateStr); + free(duree); + } + }else{ + snprintf(etat,etatSize,"%s depuis %s", etatStr, dateStr); + } + ESP_LOGE(TAG,"%s",etat); }