Add printing of temperature curve

This commit is contained in:
BlackMark 2020-04-01 04:59:11 +02:00
parent c0235bfcf0
commit 7f62961757
3 changed files with 28 additions and 11 deletions

View File

@ -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<uint8_t>(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<uint8_t>(fanSpeed, 0, 100);
}

View File

@ -17,6 +17,8 @@ class Controller {
static void callback();
static uint8_t mapTemperature(double temperature);
private:
using adc_conf = adc::Config<adc::SingleMode>;
static adc::Adc<adc_conf, io::P, io::P::C0> m_adcPin;
@ -34,6 +36,4 @@ class Controller {
return upper;
return static_cast<T>(value);
}
static void mapTemperature();
};

View File

@ -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<const char *>(SHOW_CMD), m_inputSize) == 0) {
showState();
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(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<uint8_t, 10, 3, ' '>(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 \"");