Add saving to EEPROM on bootloader entry

This commit is contained in:
BlackMark 2020-04-09 13:21:53 +02:00
parent 6a7213de60
commit d6269952a6
3 changed files with 13 additions and 9 deletions

View File

@ -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<uint8_t>(temperature);
}
void Statistics::writeTemperatureHistogram()
{
for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) {
g_eepTemperatureHistogram[i] = m_temperatureHistogram[i];
}
}

View File

@ -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();
};

View File

@ -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();