Implement setting fan speed manually
This commit is contained in:
parent
7aa98a8ebd
commit
5ec4a5441a
@ -8,6 +8,7 @@ double Controller::m_resistance;
|
|||||||
double Controller::m_temperature;
|
double Controller::m_temperature;
|
||||||
uint8_t Controller::m_fanSpeed;
|
uint8_t Controller::m_fanSpeed;
|
||||||
bool Controller::m_dataAvailable = false;
|
bool Controller::m_dataAvailable = false;
|
||||||
|
bool Controller::m_autoMode = true;
|
||||||
|
|
||||||
volatile uint32_t Controller::m_adcSampleSum;
|
volatile uint32_t Controller::m_adcSampleSum;
|
||||||
volatile bool Controller::m_adcSampleReady = false;
|
volatile bool Controller::m_adcSampleReady = false;
|
||||||
@ -28,6 +29,8 @@ void Controller::callback()
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
if (m_autoMode)
|
||||||
m_fanSpeed = mapTemperature(m_temperature);
|
m_fanSpeed = mapTemperature(m_temperature);
|
||||||
|
|
||||||
pwm::setDuty(m_fanSpeed);
|
pwm::setDuty(m_fanSpeed);
|
||||||
|
@ -13,6 +13,7 @@ class Controller {
|
|||||||
static double m_temperature;
|
static double m_temperature;
|
||||||
static uint8_t m_fanSpeed;
|
static uint8_t m_fanSpeed;
|
||||||
static bool m_dataAvailable;
|
static bool m_dataAvailable;
|
||||||
|
static bool m_autoMode;
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
@ -22,11 +22,13 @@ GF(MONITOR_CMD, "monitor");
|
|||||||
GF(BOOTLOADER_CMD, "bootloader");
|
GF(BOOTLOADER_CMD, "bootloader");
|
||||||
GF(UPTIME_CMD, "uptime");
|
GF(UPTIME_CMD, "uptime");
|
||||||
GF(STATISTICS_CMD, "statistics");
|
GF(STATISTICS_CMD, "statistics");
|
||||||
GF(RESET_CMD, "reset");
|
|
||||||
GF(HISTOGRAM_CMD, "histogram");
|
GF(HISTOGRAM_CMD, "histogram");
|
||||||
|
GF(RESET_CMD, "reset");
|
||||||
|
GF(SET_CMD, "set");
|
||||||
|
GF(AUTO_CMD, "auto");
|
||||||
|
|
||||||
GF(VERSION_CMD, "version");
|
GF(VERSION_CMD, "version");
|
||||||
GF(VERSION, "1.7");
|
GF(VERSION, "1.8");
|
||||||
|
|
||||||
static inline bool substringEquals(const char *str, const ::detail::FlashString *flashStr, const size_t &size)
|
static inline bool substringEquals(const char *str, const ::detail::FlashString *flashStr, const size_t &size)
|
||||||
{
|
{
|
||||||
@ -128,6 +130,26 @@ class Terminal {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t parseFanSpeed()
|
||||||
|
{
|
||||||
|
const auto setCmdLen = strlen_P(reinterpret_cast<const char *>(detail::SET_CMD));
|
||||||
|
|
||||||
|
if (m_inputSize > setCmdLen && substringEquals(m_inputBuffer, detail::SET_CMD, setCmdLen) &&
|
||||||
|
m_inputSize < INPUT_BUFFER_SIZE) {
|
||||||
|
m_inputBuffer[m_inputSize] = '\0'; // Null terminate to be parsable by stdlib
|
||||||
|
const auto *fanSpeedStr = m_inputBuffer + setCmdLen;
|
||||||
|
auto *fanSpeedStrEnd = m_inputBuffer + setCmdLen;
|
||||||
|
const auto fanSpeed = strtol(fanSpeedStr, &fanSpeedStrEnd, 10);
|
||||||
|
|
||||||
|
if (fanSpeedStrEnd != fanSpeedStr && *fanSpeedStr != '\0' && *fanSpeedStrEnd == '\0') {
|
||||||
|
if (fanSpeed >= 0 && fanSpeed <= 100)
|
||||||
|
return static_cast<uint8_t>(fanSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
static void parseInput()
|
static void parseInput()
|
||||||
{
|
{
|
||||||
if (m_inputSize) {
|
if (m_inputSize) {
|
||||||
@ -152,6 +174,10 @@ class Terminal {
|
|||||||
printHistogram();
|
printHistogram();
|
||||||
} else if (stringEquals(m_inputBuffer, detail::RESET_CMD, m_inputSize)) {
|
} else if (stringEquals(m_inputBuffer, detail::RESET_CMD, m_inputSize)) {
|
||||||
handleReset();
|
handleReset();
|
||||||
|
} else if (uint8_t targetFanSpeed = parseFanSpeed(); targetFanSpeed <= 100) {
|
||||||
|
handleSet(targetFanSpeed);
|
||||||
|
} else if (substringEquals(m_inputBuffer, detail::AUTO_CMD, m_inputSize)) {
|
||||||
|
handleAuto();
|
||||||
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
|
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
|
||||||
printVersion();
|
printVersion();
|
||||||
} else {
|
} else {
|
||||||
@ -183,6 +209,8 @@ class Terminal {
|
|||||||
m_serial << detail::STATISTICS_CMD << F(" .: prints overall statistics like min and max temp") << detail::ENDL;
|
m_serial << detail::STATISTICS_CMD << F(" .: prints overall statistics like min and max temp") << detail::ENDL;
|
||||||
m_serial << detail::HISTOGRAM_CMD << F(" ..: prints a histogram of the temperature") << detail::ENDL;
|
m_serial << detail::HISTOGRAM_CMD << F(" ..: prints a histogram of the temperature") << detail::ENDL;
|
||||||
m_serial << detail::RESET_CMD << F(" ......: resets statistics to 0 in EEPROM and RAM") << detail::ENDL;
|
m_serial << detail::RESET_CMD << F(" ......: resets statistics to 0 in EEPROM and RAM") << detail::ENDL;
|
||||||
|
m_serial << detail::SET_CMD << F(" ........: sets the fan speed to the provided value") << detail::ENDL;
|
||||||
|
m_serial << detail::AUTO_CMD << F(" .......: turns on automatic fan control") << detail::ENDL;
|
||||||
m_serial << detail::VERSION_CMD << F(" ....: displays firmware version") << detail::ENDL;
|
m_serial << detail::VERSION_CMD << F(" ....: displays firmware version") << detail::ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,6 +334,21 @@ class Terminal {
|
|||||||
m_serial << F("Reset statistics") << detail::ENDL;
|
m_serial << F("Reset statistics") << detail::ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleSet(uint8_t targetFanSpeed)
|
||||||
|
{
|
||||||
|
m_serial << F("Setting fan speed to ");
|
||||||
|
m_serial.txNumber(targetFanSpeed);
|
||||||
|
m_serial << detail::ENDL;
|
||||||
|
Controller::m_autoMode = false;
|
||||||
|
Controller::m_fanSpeed = targetFanSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handleAuto()
|
||||||
|
{
|
||||||
|
m_serial << F("Turning on automatic fan control") << detail::ENDL;
|
||||||
|
Controller::m_autoMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
static void printVersion()
|
static void printVersion()
|
||||||
{
|
{
|
||||||
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;
|
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;
|
||||||
|
Loading…
Reference in New Issue
Block a user