Reduce code duplication
This commit is contained in:
parent
6ba4a2ce3d
commit
cae18b98e7
@ -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<e_minTemp, true> g_eepMinTemp;
|
||||
Eeprom<e_maxTemp, true> g_eepMaxTemp;
|
||||
|
||||
} // namespace
|
||||
|
||||
void Statistics::init()
|
||||
{
|
||||
m_minTemp = getMinTemp();
|
||||
@ -30,9 +39,6 @@ void Statistics::init()
|
||||
|
||||
void Statistics::callback()
|
||||
{
|
||||
Eeprom<e_minTemp, true> eepromMinTemp;
|
||||
Eeprom<e_maxTemp, true> 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<e_minTemp, true> eepromMinTemp;
|
||||
return eepromMinTemp;
|
||||
return g_eepMinTemp;
|
||||
}
|
||||
|
||||
double Statistics::getMaxTemp()
|
||||
{
|
||||
Eeprom<e_maxTemp, true> eepromMaxTemp;
|
||||
return eepromMaxTemp;
|
||||
return g_eepMaxTemp;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user