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_minTemp;
|
||||||
double Statistics::m_maxTemp;
|
double Statistics::m_maxTemp;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Must be in translation unit and cannot be forward declared
|
||||||
EEVAR(double, e_minTemp);
|
EEVAR(double, e_minTemp);
|
||||||
EEVAR(double, e_maxTemp);
|
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()
|
void Statistics::init()
|
||||||
{
|
{
|
||||||
m_minTemp = getMinTemp();
|
m_minTemp = getMinTemp();
|
||||||
@ -30,9 +39,6 @@ void Statistics::init()
|
|||||||
|
|
||||||
void Statistics::callback()
|
void Statistics::callback()
|
||||||
{
|
{
|
||||||
Eeprom<e_minTemp, true> eepromMinTemp;
|
|
||||||
Eeprom<e_maxTemp, true> eepromMaxTemp;
|
|
||||||
|
|
||||||
if (Controller::m_dataAvailable) {
|
if (Controller::m_dataAvailable) {
|
||||||
if (Controller::m_temperature < m_minTemp) {
|
if (Controller::m_temperature < m_minTemp) {
|
||||||
m_minTemp = Controller::m_temperature;
|
m_minTemp = Controller::m_temperature;
|
||||||
@ -42,8 +48,8 @@ void Statistics::callback()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (clk::millis() >= m_lastTempSave + TEMP_SAVE_DELAY) {
|
if (clk::millis() >= m_lastTempSave + TEMP_SAVE_DELAY) {
|
||||||
eepromMinTemp = m_minTemp;
|
g_eepMinTemp = m_minTemp;
|
||||||
eepromMaxTemp = m_maxTemp;
|
g_eepMaxTemp = m_maxTemp;
|
||||||
m_lastTempSave = clk::millis();
|
m_lastTempSave = clk::millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,12 +57,10 @@ void Statistics::callback()
|
|||||||
|
|
||||||
double Statistics::getMinTemp()
|
double Statistics::getMinTemp()
|
||||||
{
|
{
|
||||||
Eeprom<e_minTemp, true> eepromMinTemp;
|
return g_eepMinTemp;
|
||||||
return eepromMinTemp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double Statistics::getMaxTemp()
|
double Statistics::getMaxTemp()
|
||||||
{
|
{
|
||||||
Eeprom<e_maxTemp, true> eepromMaxTemp;
|
return g_eepMaxTemp;
|
||||||
return eepromMaxTemp;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user