Add printing of temperature curve
This commit is contained in:
parent
c0235bfcf0
commit
7f62961757
@ -18,19 +18,19 @@ void Controller::init()
|
|||||||
void Controller::callback()
|
void Controller::callback()
|
||||||
{
|
{
|
||||||
sample();
|
sample();
|
||||||
mapTemperature();
|
m_fanSpeed = mapTemperature(m_temperature);
|
||||||
pwm::setDuty(m_fanSpeed);
|
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()
|
void Controller::sample()
|
||||||
{
|
{
|
||||||
m_adcSample = m_thermistor.sampleAdc(m_adcPin, 1000);
|
m_adcSample = m_thermistor.sampleAdc(m_adcPin, 1000);
|
||||||
m_resistance = m_thermistor.getResistance(m_adcSample);
|
m_resistance = m_thermistor.getResistance(m_adcSample);
|
||||||
m_temperature = m_thermistor.getTemperature(m_resistance);
|
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);
|
|
||||||
}
|
|
||||||
|
@ -17,6 +17,8 @@ class Controller {
|
|||||||
|
|
||||||
static void callback();
|
static void callback();
|
||||||
|
|
||||||
|
static uint8_t mapTemperature(double temperature);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using adc_conf = adc::Config<adc::SingleMode>;
|
using adc_conf = adc::Config<adc::SingleMode>;
|
||||||
static adc::Adc<adc_conf, io::P, io::P::C0> m_adcPin;
|
static adc::Adc<adc_conf, io::P, io::P::C0> m_adcPin;
|
||||||
@ -34,6 +36,4 @@ class Controller {
|
|||||||
return upper;
|
return upper;
|
||||||
return static_cast<T>(value);
|
return static_cast<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapTemperature();
|
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
GF(ENDL, "\r\n");
|
GF(ENDL, "\r\n");
|
||||||
GF(HELP_CMD, "help");
|
GF(HELP_CMD, "help");
|
||||||
GF(SHOW_CMD, "show");
|
GF(SHOW_CMD, "show");
|
||||||
|
GF(CURVE_CMD, "curve");
|
||||||
|
|
||||||
constexpr auto BACKSPACE = uint8_t{0x7f};
|
constexpr auto BACKSPACE = uint8_t{0x7f};
|
||||||
constexpr auto CTRL_C = uint8_t{0x03};
|
constexpr auto CTRL_C = uint8_t{0x03};
|
||||||
@ -92,6 +93,8 @@ class Terminal {
|
|||||||
printHelp();
|
printHelp();
|
||||||
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(SHOW_CMD), m_inputSize) == 0) {
|
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(SHOW_CMD), m_inputSize) == 0) {
|
||||||
showState();
|
showState();
|
||||||
|
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(CURVE_CMD), m_inputSize) == 0) {
|
||||||
|
printCurve();
|
||||||
} else {
|
} else {
|
||||||
printUnknown();
|
printUnknown();
|
||||||
}
|
}
|
||||||
@ -101,8 +104,9 @@ class Terminal {
|
|||||||
static void printHelp()
|
static void printHelp()
|
||||||
{
|
{
|
||||||
m_serial << F("FanTemp command overview: ") << ENDL;
|
m_serial << F("FanTemp command overview: ") << ENDL;
|
||||||
m_serial << HELP_CMD << F(" .: print this help message") << 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 << 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()
|
static void showState()
|
||||||
@ -118,6 +122,19 @@ class Terminal {
|
|||||||
m_serial << F("Fan speed ...: ") << Controller::m_fanSpeed << F("%") << ENDL;
|
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()
|
static void printUnknown()
|
||||||
{
|
{
|
||||||
m_serial << F("Unknown command \"");
|
m_serial << F("Unknown command \"");
|
||||||
|
Loading…
Reference in New Issue
Block a user