Add monitor command to continuously show measurements

This commit is contained in:
BlackMark 2020-04-01 05:21:56 +02:00
parent d6fa78ae5f
commit 6003ea6603

View File

@ -14,6 +14,7 @@ GF(ENDL, "\r\n");
GF(HELP_CMD, "help");
GF(SHOW_CMD, "show");
GF(CURVE_CMD, "curve");
GF(MONITOR_CMD, "monitor");
constexpr auto BACKSPACE = uint8_t{0x7f};
constexpr auto CTRL_C = uint8_t{0x03};
@ -77,14 +78,23 @@ class Terminal {
m_inputSize = 0;
m_serial << F("$ ");
}
if (m_state == State::MONITOR)
showState();
}
private:
static constexpr auto INPUT_BUFFER_SIZE = 128;
enum class State {
NONE,
MONITOR,
};
static Uart m_serial;
static char m_inputBuffer[INPUT_BUFFER_SIZE];
static uint16_t m_inputSize;
static State m_state;
static void parseInput()
{
@ -97,6 +107,8 @@ class Terminal {
showState();
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(CURVE_CMD), m_inputSize) == 0) {
printCurve();
} else if (strncmp_P(m_inputBuffer, reinterpret_cast<const char *>(MONITOR_CMD), m_inputSize) == 0) {
m_state = State::MONITOR;
} else {
printUnknown();
}
@ -106,14 +118,16 @@ class Terminal {
static void handleCtrlC()
{
m_serial << F("Abort!") << ENDL;
m_state = State::NONE;
}
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 << CURVE_CMD << F(" .: shows the curve used to map temperature to 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;
m_serial << MONITOR_CMD << F(" .: loops the show command until Ctrl + C is pressed") << ENDL;
}
static void showState()
@ -156,3 +170,6 @@ char Terminal<Uart>::m_inputBuffer[INPUT_BUFFER_SIZE];
template <class Uart>
uint16_t Terminal<Uart>::m_inputSize = 0;
template <class Uart>
typename Terminal<Uart>::State Terminal<Uart>::m_state = State::NONE;