From 1694e3bbabeef1620038188eca104ba809775f69 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Wed, 8 Apr 2020 12:58:59 +0200 Subject: [PATCH] Change histogram to only print from min to max --- fantemp/statistics.cpp | 13 +++++++------ fantemp/statistics.hpp | 7 ++++--- fantemp/terminal.hpp | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fantemp/statistics.cpp b/fantemp/statistics.cpp index 722df05..4af0cb9 100644 --- a/fantemp/statistics.cpp +++ b/fantemp/statistics.cpp @@ -15,7 +15,7 @@ uint32_t Statistics::m_temperatureHistogram[TEMPERATURE_RANGE]; namespace { // Must be in translation unit and cannot be forward declared -EEARRAY(uint32_t, e_temperatureHistogram, 100); +EEARRAY(uint32_t, e_temperatureHistogram, Statistics::TEMPERATURE_RANGE); // Could be declared in every function that uses it, but that would be code duplication EepromArray g_eepTemperatureHistogram; @@ -26,8 +26,7 @@ void Statistics::init() { for (uint8_t i = 0; i < g_eepTemperatureHistogram.size(); ++i) { m_temperatureHistogram[i] = g_eepTemperatureHistogram[i]; - using temperature_t = type::decay_t; - if (m_temperatureHistogram[i] == type::numeric_limits::max()) { + if (m_temperatureHistogram[i] == type::numeric_limits::max()) { m_temperatureHistogram[i] = 0; } } @@ -49,7 +48,7 @@ void Statistics::callback() } } -uint8_t Statistics::getMinTemp() +uint8_t Statistics::getMinTemperature() { for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) { if (m_temperatureHistogram[i] > 0) @@ -59,7 +58,7 @@ uint8_t Statistics::getMinTemp() return TEMPERATURE_RANGE; } -uint8_t Statistics::getMaxTemp() +uint8_t Statistics::getMaxTemperature() { for (int8_t i = TEMPERATURE_RANGE - 1; i >= 0; --i) { if (m_temperatureHistogram[i] > 0) @@ -82,12 +81,14 @@ uint64_t Statistics::getTotalHistogramSamples() uint32_t Statistics::getHighestHistogramSamples() { - uint32_t max = 1; // Avoid division by zero + uint32_t max = 0; + for (uint8_t i = 0; i < TEMPERATURE_RANGE; ++i) { if (m_temperatureHistogram[i] > max) { max = m_temperatureHistogram[i]; } } + return max; } diff --git a/fantemp/statistics.hpp b/fantemp/statistics.hpp index 3405b4f..e27c598 100644 --- a/fantemp/statistics.hpp +++ b/fantemp/statistics.hpp @@ -4,11 +4,13 @@ class Statistics { public: + static constexpr auto TEMPERATURE_RANGE = 100; + static void init(); static void callback(); - static uint8_t getMinTemp(); - static uint8_t getMaxTemp(); + static uint8_t getMinTemperature(); + static uint8_t getMaxTemperature(); static uint64_t getTotalHistogramSamples(); static uint32_t getHighestHistogramSamples(); @@ -17,7 +19,6 @@ class Statistics { private: static constexpr auto TEMPERATURE_WRITEBACK_DELAY = 1'800'000; static constexpr auto TEMPERATURE_SAMPLE_DELAY = 1'000; - static constexpr auto TEMPERATURE_RANGE = 100; static uint64_t m_lastTemperatureWriteback; static uint64_t m_lastTemperatureSample; diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index abdfc9d..a0c45b4 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -243,8 +243,8 @@ class Terminal { static void printStatistics() { - m_serial << F("Minimum temperature .: ") << Statistics::getMinTemp() << F(" C") << detail::ENDL; - m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemp() << F(" C") << detail::ENDL; + m_serial << F("Minimum temperature .: ") << Statistics::getMinTemperature() << F(" C") << detail::ENDL; + m_serial << F("Maximum temperature .: ") << Statistics::getMaxTemperature() << F(" C") << detail::ENDL; } static void printHistogram() @@ -253,7 +253,7 @@ class Terminal { const auto maximumSamples = Statistics::getHighestHistogramSamples(); const auto normalizationFactor = (maximumSamples / 100 > 1) ? (maximumSamples / 100) : 1; - for (uint8_t t = 10; t <= 60; ++t) { + 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 = ");