From af7942186c7d0567466c25209dcfccb9642d8ed2 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 6 May 2018 22:23:22 +0200 Subject: Fix uart device static_assert, add backspace support other changes: replace strip() with STL functions --- hal/uart.tpp | 8 ++++---- main.cpp | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hal/uart.tpp b/hal/uart.tpp index 359722e..21d7479 100644 --- a/hal/uart.tpp +++ b/hal/uart.tpp @@ -29,28 +29,28 @@ namespace uart template inline std::queue& rx_buffer() { - static_assert(dev <= devices_count, "invalid device number"); + static_assert(dev != 0 && dev <= devices_count, "invalid device number"); return uart::_rx_buffer[dev -1]; } template inline std::queue& tx_buffer() { - static_assert(dev <= devices_count, "invalid device number"); + static_assert(dev != 0 && dev <= devices_count, "invalid device number"); return uart::_tx_buffer[dev -1]; } template inline bool echo(bool enabled) { - static_assert(dev <= devices_count, "invalid device number"); + static_assert(dev != 0 && dev <= devices_count, "invalid device number"); _echo[dev -1] = enabled; } template inline bool echo_enabled() { - static_assert(dev <= devices_count, "invalid device number"); + static_assert(dev != 0 && dev <= devices_count, "invalid device number"); return _echo[dev -1]; } diff --git a/main.cpp b/main.cpp index c48fcae..4fca3db 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ * Created on May 1, 2018, 6:18 PM */ -//#define DEBUG +// #define DEBUG // basic devices #include "hal/confbits.hpp" @@ -46,15 +46,6 @@ std::vector split(const std::string& str, const char sep) return v; } -void strip(std::string &str) -{ - const std::string strip_chars = "\n\r\b\t\f"; - - for (const char &ch : strip_chars) { - str.erase(std::remove_if(str.begin(), str.end(), [ch](const char &c){ return c == ch; }), str.end()); - } -} - int main(int argc, char** argv) { osc::initialize(); @@ -86,22 +77,31 @@ int main(int argc, char** argv) std::string input = ""; // write prompt - uart::write<1>("\n\r> "); + uart::write<1>("> "); do { - input += uart::read_wait<1>(); + input += uart::read_wait<1>(); + + // DEL character + if (input.back() == '\x7f') { + input.pop_back(); + input.pop_back(); + uart::write<1>("\b \b"); + } } while (input.back() != '\r' && input.back() != '\n'); - + + uart::write<1>("\n\r"); + #ifdef DEBUG uart::write<1>("input: "); uart::print<1>(input); #endif - // remove weird symbols - strip(input); + // remove non printable symbols + input.erase(std::remove_if(input.begin(), input.end(), std::iscntrl), input.end()); // set to lowercase - std::transform(input.begin(), input.end(), input.begin(), ::tolower); + std::transform(input.begin(), input.end(), input.begin(), std::tolower); // split const std::vector command = split(input, ' '); -- cgit v1.2.1