From cae18b98e7d0f3bafeeb69b3c258f6302554a92f Mon Sep 17 00:00:00 2001 From: BlackMark Date: Tue, 7 Apr 2020 21:54:15 +0200 Subject: [PATCH] Reduce code duplication --- fantemp/statistics.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fantemp/statistics.cpp b/fantemp/statistics.cpp index 4d7b655..14ede73 100644 --- a/fantemp/statistics.cpp +++ b/fantemp/statistics.cpp @@ -12,9 +12,18 @@ uint64_t Statistics::m_lastTempSave = 0; double Statistics::m_minTemp; double Statistics::m_maxTemp; +namespace { + +// Must be in translation unit and cannot be forward declared EEVAR(double, e_minTemp); EEVAR(double, e_maxTemp); +// Could be declared in every function that uses it, but that would be code duplication +Eeprom g_eepMinTemp; +Eeprom g_eepMaxTemp; + +} // namespace + void Statistics::init() { m_minTemp = getMinTemp(); @@ -30,9 +39,6 @@ void Statistics::init() void Statistics::callback() { - Eeprom eepromMinTemp; - Eeprom eepromMaxTemp; - if (Controller::m_dataAvailable) { if (Controller::m_temperature < m_minTemp) { m_minTemp = Controller::m_temperature; @@ -42,8 +48,8 @@ void Statistics::callback() } if (clk::millis() >= m_lastTempSave + TEMP_SAVE_DELAY) { - eepromMinTemp = m_minTemp; - eepromMaxTemp = m_maxTemp; + g_eepMinTemp = m_minTemp; + g_eepMaxTemp = m_maxTemp; m_lastTempSave = clk::millis(); } } @@ -51,12 +57,10 @@ void Statistics::callback() double Statistics::getMinTemp() { - Eeprom eepromMinTemp; - return eepromMinTemp; + return g_eepMinTemp; } double Statistics::getMaxTemp() { - Eeprom eepromMaxTemp; - return eepromMaxTemp; + return g_eepMaxTemp; }