Add check to prevent printing data before it's available
This commit is contained in:
parent
f3cf12db3b
commit
ea6a6bd218
@ -7,6 +7,8 @@ double Controller::m_adcSample;
|
|||||||
double Controller::m_resistance;
|
double Controller::m_resistance;
|
||||||
double Controller::m_temperature;
|
double Controller::m_temperature;
|
||||||
uint8_t Controller::m_fanSpeed;
|
uint8_t Controller::m_fanSpeed;
|
||||||
|
bool Controller::m_dataAvailable = false;
|
||||||
|
|
||||||
volatile uint32_t Controller::m_adcSampleSum;
|
volatile uint32_t Controller::m_adcSampleSum;
|
||||||
volatile bool Controller::m_adcSampleReady = false;
|
volatile bool Controller::m_adcSampleReady = false;
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ void Controller::callback()
|
|||||||
{
|
{
|
||||||
if (m_adcSampleReady) {
|
if (m_adcSampleReady) {
|
||||||
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
|
m_adcSample = static_cast<double>(m_adcSampleSum) / NUM_ADC_SAMPLES;
|
||||||
|
m_dataAvailable = true;
|
||||||
m_adcSampleReady = false;
|
m_adcSampleReady = false;
|
||||||
|
|
||||||
m_resistance = m_thermistor.getResistance(m_adcSample);
|
m_resistance = m_thermistor.getResistance(m_adcSample);
|
||||||
|
@ -12,6 +12,7 @@ class Controller {
|
|||||||
static double m_resistance;
|
static double m_resistance;
|
||||||
static double m_temperature;
|
static double m_temperature;
|
||||||
static uint8_t m_fanSpeed;
|
static uint8_t m_fanSpeed;
|
||||||
|
static bool m_dataAvailable;
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
@ -175,15 +175,19 @@ class Terminal {
|
|||||||
|
|
||||||
static void showState()
|
static void showState()
|
||||||
{
|
{
|
||||||
char floatBuffer[16];
|
if (Controller::m_dataAvailable) {
|
||||||
|
char floatBuffer[16];
|
||||||
|
|
||||||
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
sprintf(floatBuffer, "%.2f", Controller::m_adcSample);
|
||||||
m_serial << F("ADC value ...: ") << floatBuffer << F(" / 1023") << detail::ENDL;
|
m_serial << F("ADC value ...: ") << floatBuffer << F(" / 1023") << detail::ENDL;
|
||||||
sprintf(floatBuffer, "%.2f", Controller::m_resistance);
|
sprintf(floatBuffer, "%.2f", Controller::m_resistance);
|
||||||
m_serial << F("Resistance ..: ") << floatBuffer << F(" Ohm") << detail::ENDL;
|
m_serial << F("Resistance ..: ") << floatBuffer << F(" Ohm") << detail::ENDL;
|
||||||
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
sprintf(floatBuffer, "%.2f", Controller::m_temperature);
|
||||||
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
|
m_serial << F("Temperature .: ") << floatBuffer << F(" C") << detail::ENDL;
|
||||||
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << 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()
|
static void printCurve()
|
||||||
|
Loading…
Reference in New Issue
Block a user