diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index d310b42..29a0eaa 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -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(CURVE_CMD), m_inputSize) == 0) { printCurve(); + } else if (strncmp_P(m_inputBuffer, reinterpret_cast(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::m_inputBuffer[INPUT_BUFFER_SIZE]; template uint16_t Terminal::m_inputSize = 0; + +template +typename Terminal::State Terminal::m_state = State::NONE;