diff --git a/lib/SimuGaz/SimuGaz.cpp b/lib/SimuGaz/SimuGaz.cpp index 22880d2..36e698f 100644 --- a/lib/SimuGaz/SimuGaz.cpp +++ b/lib/SimuGaz/SimuGaz.cpp @@ -1,4 +1,5 @@ #include +#include #define INITIAL_CONSUMPTION 1594.87f #define INITIAL_SECONDS 11462400 // date initiale = 13/05/2026 16:00 @@ -21,15 +22,32 @@ static const float GRDF_MONTHLY_COEFF[12] = { 2.11f, // Décembre }; +Preferences prefs; + // Base annuelle : 972 m³/an pour 100m² (CRE) // - base mensuelle moyenne = 81 m³/mois // - base journalière moyenne = 2.66 m³/j -RTC_DATA_ATTR float consumptionM3 = INITIAL_CONSUMPTION; -RTC_DATA_ATTR uint32_t totalSeconds = INITIAL_SECONDS; +float consumptionM3; +uint32_t totalSeconds; + +void get_stored_values(){ + prefs.begin("simugaz"); + consumptionM3 = prefs.getFloat("consumption_m3", INITIAL_CONSUMPTION); + totalSeconds = prefs.getUInt("seconds", INITIAL_SECONDS); + prefs.end(); +} + +void store_values(){ + prefs.begin("simugaz"); + prefs.putFloat("consumption_m3", consumptionM3); + prefs.putUInt("seconds", totalSeconds); + prefs.end(); +} uint32_t simulateGasPulses(uint32_t intervalSeconds) { + get_stored_values(); totalSeconds += intervalSeconds; uint32_t month = (totalSeconds / (86400UL * 30UL)) % 12; @@ -45,6 +63,8 @@ uint32_t simulateGasPulses(uint32_t intervalSeconds) uint32_t pulseCount = (uint32_t)(consumptionM3 / 0.010f); uint32_t incrementPulses = (uint32_t)(incrementM3 / 0.010f); + store_values(); + Serial.printf("[GAZ] Incrément de %lu impulsions - Total : %lu impulsions (%.3f m³)\n", incrementPulses, pulseCount, pulseCount * 0.010f); return pulseCount; } \ No newline at end of file diff --git a/lib/SimuGaz/SimuGaz.h b/lib/SimuGaz/SimuGaz.h index c183478..a7ca631 100644 --- a/lib/SimuGaz/SimuGaz.h +++ b/lib/SimuGaz/SimuGaz.h @@ -2,4 +2,6 @@ #include -uint32_t simulateGasPulses(uint32_t intervalSeconds = 86400); \ No newline at end of file +uint32_t simulateGasPulses(uint32_t intervalSeconds = 86400); +void get_stored_values(); +void store_values(); \ No newline at end of file