machine : affichage durée depuis départ
This commit is contained in:
parent
a41945bcef
commit
e1640f4ad9
@ -54,6 +54,29 @@ WashingMachineState getEtatMachine(){
|
|||||||
return wms;
|
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)
|
void getEtatMachineStr(WashingMachineState wms, char* etat, size_t etatSize)
|
||||||
{
|
{
|
||||||
char* etatStr;
|
char* etatStr;
|
||||||
@ -73,10 +96,22 @@ void getEtatMachineStr(WashingMachineState wms, char* etat, size_t etatSize)
|
|||||||
etatStr="Etat inconnu";
|
etatStr="Etat inconnu";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char dateStr[30];
|
char dateStr[30];
|
||||||
timestampToDate(wms.depuis,dateStr,30);
|
timestampToDate(wms.depuis,dateStr,30);
|
||||||
|
|
||||||
|
//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);
|
snprintf(etat,etatSize,"%s depuis %s", etatStr, dateStr);
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOGE(TAG,"%s",etat);
|
ESP_LOGE(TAG,"%s",etat);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user