From c0235bfcf0855badcabc5e0349dc7767c6020e28 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Wed, 1 Apr 2020 04:36:22 +0200 Subject: [PATCH] Refactor magic numbers to have constants --- fantemp/terminal.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index 4cf5c03..a6a20f0 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -14,6 +14,9 @@ GF(ENDL, "\r\n"); GF(HELP_CMD, "help"); GF(SHOW_CMD, "show"); +constexpr auto BACKSPACE = uint8_t{0x7f}; +constexpr auto CTRL_C = uint8_t{0x03}; + template class Terminal { public: @@ -30,11 +33,11 @@ class Terminal { bool handleInput = false; while (m_serial.rxByte(inputByte)) { - if (isprint(inputByte) || inputByte == 0x03) { + if (isprint(inputByte) || inputByte == CTRL_C) { m_inputBuffer[m_inputSize++] = inputByte; // Handle Ctrl + C - if (inputByte == 0x03) { + if (inputByte == CTRL_C) { m_serial << F("^C") << ENDL; handleInput = true; break; @@ -46,8 +49,8 @@ class Terminal { } // Handle backspace - if (inputByte == 0x7f && m_inputSize > 0) { - m_serial << static_cast(0x7f); + if (inputByte == BACKSPACE && m_inputSize > 0) { + m_serial << static_cast(BACKSPACE); --m_inputSize; } // Handle line terminator