Change histogram to only print from min to max
This commit is contained in:
parent
02565c9396
commit
1694e3bbab
@ -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<e_temperatureHistogram, EEARRAY_SIZE(e_temperatureHistogram), true> 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<decltype(m_temperatureHistogram[0])>;
|
||||
if (m_temperatureHistogram[i] == type::numeric_limits<temperature_t>::max()) {
|
||||
if (m_temperatureHistogram[i] == type::numeric_limits<uint32_t>::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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<uint8_t, 10, 2>(t);
|
||||
m_serial << F(" C = ");
|
||||
|
Loading…
Reference in New Issue
Block a user