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(SHOW_CMD, "show");
|
||||
|
||||
constexpr auto BACKSPACE = uint8_t{0x7f};
|
||||
constexpr auto CTRL_C = uint8_t{0x03};
|
||||
|
||||
template <class Uart>
|
||||
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<char>(0x7f);
|
||||
if (inputByte == BACKSPACE && m_inputSize > 0) {
|
||||
m_serial << static_cast<char>(BACKSPACE);
|
||||
--m_inputSize;
|
||||
}
|
||||
// Handle line terminator
|
||||
|
Loading…
Reference in New Issue
Block a user