diff options
Diffstat (limited to '')
-rw-r--r-- | hal/uart.tpp | 8 | ||||
-rw-r--r-- | 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<unsigned dev> inline std::queue<uint8_t>& 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<unsigned dev> inline std::queue<uint8_t>& 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<unsigned dev> 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<unsigned dev> 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]; } @@ -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<std::string> 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<std::string> command = split(input, ' '); |