Add check to prevent printing data before it's available

This commit is contained in:
BlackMark 2020-04-07 21:05:40 +02:00
parent f3cf12db3b
commit ea6a6bd218
3 changed files with 16 additions and 8 deletions

View File

@ -7,6 +7,8 @@ double Controller::m_adcSample;
double Controller::m_resistance;
double Controller::m_temperature;
uint8_t Controller::m_fanSpeed;
bool Controller::m_dataAvailable = false;
volatile uint32_t Controller::m_adcSampleSum;
volatile bool Controller::m_adcSampleReady = false;
@ -21,6 +23,7 @@ void Controller::callback()
{
if (m_adcSampleReady) {
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
m_dataAvailable = true;
m_adcSampleReady = false;
m_resistance = m_thermistor.getResistance(m_adcSample);

View File

@ -12,6 +12,7 @@ class Controller {
static double m_resistance;
static double m_temperature;
static uint8_t m_fanSpeed;
static bool m_dataAvailable;
static void init();

View File

@ -175,6 +175,7 @@ class Terminal {
static void showState()
{
if (Controller::m_dataAvailable) {
char floatBuffer[16];
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
@ -184,6 +185,9 @@ class Terminal {
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << detail::ENDL;
} else {
m_serial << F("No data available yet!") << detail::ENDL;
}
}
static void printCurve()