diff --git a/fantemp/controller.cpp b/fantemp/controller.cpp index 40b4f83..5f3c931 100644 --- a/fantemp/controller.cpp +++ b/fantemp/controller.cpp @@ -18,19 +18,19 @@ void Controller::init() void Controller::callback() { sample(); - mapTemperature(); + m_fanSpeed = mapTemperature(m_temperature); pwm::setDuty(m_fanSpeed); } +uint8_t Controller::mapTemperature(double temperature) +{ + double fanSpeed = (10 * temperature - 200) / 3; + return clamp(fanSpeed, 0, 100); +} + void Controller::sample() { m_adcSample = m_thermistor.sampleAdc(m_adcPin, 1000); m_resistance = m_thermistor.getResistance(m_adcSample); m_temperature = m_thermistor.getTemperature(m_resistance); } - -void Controller::mapTemperature() -{ - double fanSpeed = (10 * m_temperature - 200) / 3; - m_fanSpeed = clamp(fanSpeed, 0, 100); -} diff --git a/fantemp/controller.hpp b/fantemp/controller.hpp index 74dd7db..a4bb661 100644 --- a/fantemp/controller.hpp +++ b/fantemp/controller.hpp @@ -17,6 +17,8 @@ class Controller { static void callback(); + static uint8_t mapTemperature(double temperature); + private: using adc_conf = adc::Config; static adc::Adc m_adcPin; @@ -34,6 +36,4 @@ class Controller { return upper; return static_cast(value); } - - static void mapTemperature(); }; diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index a6a20f0..280f39e 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -13,6 +13,7 @@ GF(ENDL, "\r\n"); GF(HELP_CMD, "help"); GF(SHOW_CMD, "show"); +GF(CURVE_CMD, "curve"); constexpr auto BACKSPACE = uint8_t{0x7f}; constexpr auto CTRL_C = uint8_t{0x03}; @@ -92,6 +93,8 @@ class Terminal { printHelp(); } else if (strncmp_P(m_inputBuffer, reinterpret_cast(SHOW_CMD), m_inputSize) == 0) { showState(); + } else if (strncmp_P(m_inputBuffer, reinterpret_cast(CURVE_CMD), m_inputSize) == 0) { + printCurve(); } else { printUnknown(); } @@ -101,8 +104,9 @@ class Terminal { static void printHelp() { m_serial << F("FanTemp command overview: ") << ENDL; - m_serial << HELP_CMD << F(" .: print this help message") << ENDL; - m_serial << SHOW_CMD << F(" .: shows current temperature and fan speed") << ENDL; + m_serial << HELP_CMD << F(" ..: print this help message") << ENDL; + m_serial << SHOW_CMD << F(" ..: shows current temperature and fan speed") << ENDL; + m_serial << CURVE_CMD << F(" .: shows the curve used to map temperature to fan speed") << ENDL; } static void showState() @@ -118,6 +122,19 @@ class Terminal { m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << ENDL; } + static void printCurve() + { + for (uint8_t i = 10; i <= 60; ++i) { + m_serial << i << F(" C = "); + m_serial.template txNumber(Controller::mapTemperature(i)); + m_serial << F("%\t"); + for (uint8_t s = 0; s < Controller::mapTemperature(i); ++s) { + m_serial << "#"; + } + m_serial << ENDL; + } + } + static void printUnknown() { m_serial << F("Unknown command \"");