diff --git a/fantemp/statistics.cpp b/fantemp/statistics.cpp index 915fc59..4a4c2c0 100644 --- a/fantemp/statistics.cpp +++ b/fantemp/statistics.cpp @@ -42,7 +42,7 @@ void Statistics::callback() } if (clk::millis() >= m_lastTemperatureWriteback + TEMPERATURE_WRITEBACK_DELAY) { - writeTemperatureHistogram(); + saveTemperatureHistogram(); m_lastTemperatureWriteback = clk::millis(); } } @@ -105,6 +105,13 @@ uint32_t Statistics::getHistogram(const int8_t &temperature) return m_temperatureHistogram[clampTemperature(temperature)]; } +void Statistics::saveTemperatureHistogram() +{ + for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) { + g_eepTemperatureHistogram[i] = m_temperatureHistogram[i]; + } +} + uint8_t Statistics::clampTemperature(const int8_t &temperature) { if (temperature < 0) @@ -113,10 +120,3 @@ uint8_t Statistics::clampTemperature(const int8_t &temperature) return TEMPERATURE_RANGE - 1; return static_cast(temperature); } - -void Statistics::writeTemperatureHistogram() -{ - for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) { - g_eepTemperatureHistogram[i] = m_temperatureHistogram[i]; - } -} diff --git a/fantemp/statistics.hpp b/fantemp/statistics.hpp index e9d19c5..448b652 100644 --- a/fantemp/statistics.hpp +++ b/fantemp/statistics.hpp @@ -17,6 +17,8 @@ class Statistics { static uint32_t getHighestHistogramSamples(); static uint32_t getHistogram(const int8_t &temperature); + static void saveTemperatureHistogram(); + private: static constexpr auto TEMPERATURE_WRITEBACK_DELAY = 1'800'000; static constexpr auto TEMPERATURE_SAMPLE_DELAY = 1'000; @@ -26,5 +28,4 @@ class Statistics { static uint32_t m_temperatureHistogram[TEMPERATURE_RANGE]; static uint8_t clampTemperature(const int8_t &temperature); - static void writeTemperatureHistogram(); }; diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index e9c7550..0a2e916 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -218,6 +218,9 @@ class Terminal { static void handleBootloader() { + m_serial << F("Saving statistics to EEPROM") << detail::ENDL; + Statistics::saveTemperatureHistogram(); + m_serial << F("Entering bootloader...") << detail::ENDL; m_serial.flushTx();