Refactor magic numbers to have constants
This commit is contained in:
parent
45eafd9fc3
commit
c0235bfcf0
@ -14,6 +14,9 @@ GF(ENDL, "\r\n");
|
|||||||
GF(HELP_CMD, "help");
|
GF(HELP_CMD, "help");
|
||||||
GF(SHOW_CMD, "show");
|
GF(SHOW_CMD, "show");
|
||||||
|
|
||||||
|
constexpr auto BACKSPACE = uint8_t{0x7f};
|
||||||
|
constexpr auto CTRL_C = uint8_t{0x03};
|
||||||
|
|
||||||
template <class Uart>
|
template <class Uart>
|
||||||
class Terminal {
|
class Terminal {
|
||||||
public:
|
public:
|
||||||
@ -30,11 +33,11 @@ class Terminal {
|
|||||||
bool handleInput = false;
|
bool handleInput = false;
|
||||||
|
|
||||||
while (m_serial.rxByte(inputByte)) {
|
while (m_serial.rxByte(inputByte)) {
|
||||||
if (isprint(inputByte) || inputByte == 0x03) {
|
if (isprint(inputByte) || inputByte == CTRL_C) {
|
||||||
m_inputBuffer[m_inputSize++] = inputByte;
|
m_inputBuffer[m_inputSize++] = inputByte;
|
||||||
|
|
||||||
// Handle Ctrl + C
|
// Handle Ctrl + C
|
||||||
if (inputByte == 0x03) {
|
if (inputByte == CTRL_C) {
|
||||||
m_serial << F("^C") << ENDL;
|
m_serial << F("^C") << ENDL;
|
||||||
handleInput = true;
|
handleInput = true;
|
||||||
break;
|
break;
|
||||||
@ -46,8 +49,8 @@ class Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle backspace
|
// Handle backspace
|
||||||
if (inputByte == 0x7f && m_inputSize > 0) {
|
if (inputByte == BACKSPACE && m_inputSize > 0) {
|
||||||
m_serial << static_cast<char>(0x7f);
|
m_serial << static_cast<char>(BACKSPACE);
|
||||||
--m_inputSize;
|
--m_inputSize;
|
||||||
}
|
}
|
||||||
// Handle line terminator
|
// Handle line terminator
|
||||||
|
Loading…
Reference in New Issue
Block a user