Add uptime command

This commit is contained in:
BlackMark 2020-04-06 22:12:11 +02:00
parent 9ef4d2a737
commit 34428b76dd
2 changed files with 26 additions and 2 deletions

View File

@ -19,8 +19,10 @@ GF(SHOW_CMD, "show");
GF(CURVE_CMD, "curve");
GF(MONITOR_CMD, "monitor");
GF(BOOTLOADER_CMD, "bootloader");
GF(UPTIME_CMD, "uptime");
GF(VERSION_CMD, "version");
GF(VERSION, "1.2");
GF(VERSION, "1.3");
static inline bool substringEquals(const char *str, const ::detail::FlashString *flashStr, const size_t &size)
{
@ -137,6 +139,8 @@ class Terminal {
m_state = State::MONITOR;
} else if (substringEquals(m_inputBuffer, detail::BOOTLOADER_CMD, m_inputSize)) {
handleBootloader();
} else if (substringEquals(m_inputBuffer, detail::UPTIME_CMD, m_inputSize)) {
printUptime();
} else if (substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
printVersion();
} else {
@ -164,6 +168,7 @@ class Terminal {
m_serial << detail::CURVE_CMD << F(" ......: shows mapping from temperature to fan speed") << detail::ENDL;
m_serial << detail::MONITOR_CMD << F(" ....: loops the show command until Ctrl + C is pressed") << detail::ENDL;
m_serial << detail::BOOTLOADER_CMD << F(" .: enters the bootloader after 3 seconds") << detail::ENDL;
m_serial << detail::UPTIME_CMD << F(" .....: show system uptime") << detail::ENDL;
m_serial << detail::VERSION_CMD << F(" ....: displays firmware version") << detail::ENDL;
}
@ -203,6 +208,25 @@ class Terminal {
Bootloader::enter();
}
static void printUptime()
{
constexpr auto delimiter = ':';
const auto uptime = clk::millis();
const auto hours = static_cast<uint16_t>(uptime / 1000 / 60 / 60);
const auto minutes = static_cast<uint8_t>((uptime / 1000 / 60) % 60);
const auto seconds = static_cast<uint8_t>((uptime / 1000) % 60);
m_serial << F("System uptime: ");
m_serial.template txNumber<uint16_t, 10, 2>(hours);
m_serial << delimiter;
m_serial.template txNumber<uint8_t, 10, 2>(minutes);
m_serial << delimiter;
m_serial.template txNumber<uint8_t, 10, 2>(seconds);
m_serial << detail::ENDL;
}
static void printVersion()
{
m_serial << F("FanTemp v") << detail::VERSION << detail::ENDL;

@ -1 +1 @@
Subproject commit cb436b11a8428c2c40a11b51fedb4d2c7d38ece7
Subproject commit 6f592dd0987cae4f7f826056e5ff358ad26d3127