diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index a0c45b4..ae4a22d 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -243,27 +243,50 @@ class Terminal { static void printStatistics() { - m_serial << F("Minimum temperature .: ") << Statistics::getMinTemperature() << F(" C") << detail::ENDL; - m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemperature() << F(" C") << detail::ENDL; + const auto minTemp = Statistics::getMinTemperature(); + const auto maxTemp = Statistics::getMaxTemperature(); + + m_serial << F("Minimum temperature .: "); + if (minTemp != Statistics::TEMPERATURE_RANGE) { + m_serial << minTemp << F(" C"); + } else { + m_serial << F("Not available"); + } + + m_serial << detail::ENDL << F("Maximum temperature .: "); + if (maxTemp != Statistics::TEMPERATURE_RANGE) { + m_serial << maxTemp << F(" C"); + } else { + m_serial << F("Not available"); + } + m_serial << detail::ENDL; } static void printHistogram() { const auto totalSamples = Statistics::getTotalHistogramSamples(); - const auto maximumSamples = Statistics::getHighestHistogramSamples(); - const auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1; - for (uint8_t t = Statistics::getMinTemperature(); t <= Statistics::getMaxTemperature(); ++t) { - const auto histogramSamples = Statistics::getHistogram(t); - m_serial.template txNumber(t); - m_serial << F(" C = "); - m_serial.template txNumber((histogramSamples * 100) / totalSamples); - m_serial << F("%\t"); - const auto normalizedSamples = static_cast(histogramSamples / normalizationFactor); - for (uint8_t i = 0; i < normalizedSamples; ++i) { - m_serial << '#'; + if (totalSamples > 0) { + const auto maximumSamples = Statistics::getHighestHistogramSamples(); + auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1; + + while (maximumSamples / normalizationFactor > 100) + ++normalizationFactor; + + for (uint8_t t = Statistics::getMinTemperature(); t <= Statistics::getMaxTemperature(); ++t) { + const auto histogramSamples = Statistics::getHistogram(t); + m_serial.template txNumber(t); + m_serial << F(" C = "); + m_serial.template txNumber((histogramSamples * 100) / totalSamples); + m_serial << F("%\t"); + const auto normalizedSamples = static_cast(histogramSamples / normalizationFactor); + for (uint8_t i = 0; i < normalizedSamples; ++i) { + m_serial << '#'; + } + m_serial << detail::ENDL; } - m_serial << detail::ENDL; + } else { + m_serial << "There is no data yet!" << detail::ENDL; } }