Support library for the ESP8266 Wireless Terminal. Can also be used for communicating with any VT100-compatible terminal.
espterm.cpp
- Committer:
- MightyPork
- Date:
- 2017-03-06
- Revision:
- 1:09dfc9fd55f4
- Parent:
- 0:20fb68233f89
- Child:
- 3:1114012184bf
File content as of revision 1:09dfc9fd55f4:
#include "mbed.h" #include "espterm.hpp" #include <cstdarg> ESPTerm::ESPTerm(Serial *s) { this->ser = s; } ESPTerm::ESPTerm(void) { this->ser = new Serial(PA_2, PA_3, 115200); } int ESPTerm::printf(const char *format, ...) { std::va_list arg; va_start(arg, format); int r = ser->vprintf(format, arg); va_end(arg); return r; } // alias of printf int ESPTerm::print(const char *format, ...) { std::va_list arg; va_start(arg, format); int r = ser->vprintf(format, arg); va_end(arg); return r; } int ESPTerm::println(const char *format, ...) { std::va_list arg; va_start(arg, format); int r = ser->vprintf(format, arg); va_end(arg); r += ser->puts("\r\n"); return r; } void ESPTerm::fg(ANSI_Color c) { int ci = c; if(ci > 7) { ci += (90-8); } else { ci += 30; } ser->printf("\033[%dm", ci); } void ESPTerm::bg(ANSI_Color c) { int ci = c; if(ci > 7) { ci += (100-8); } else { ci += 40; } ser->printf("\033[%dm", ci); } void ESPTerm::colors(ANSI_Color fg, ANSI_Color bg) { this->fg(fg); this->bg(bg); } void ESPTerm::reset_attribs(void) { ser->puts("\033[0m"); } // alias void ESPTerm::rst(void) { this->reset_attribs(); } void ESPTerm::go_to(int y, int x) { ser->printf("\033[%d;%dH", y, x); } void ESPTerm::clear_screen(ClearMode mode) { ser->printf("\033[%dJ", mode); } void ESPTerm::clear_line(ClearMode mode) { ser->printf("\033[%dK", mode); } void ESPTerm::screen_reset(void) { ser->puts("\033c"); } void ESPTerm::show_cursor(bool yes) { if (yes) ser->puts("\033[?25h"); else ser->puts("\033[?25l"); } void ESPTerm::factory_reset(void) { ser->puts("\033]FR\a"); } void ESPTerm::set_screen_size(int rows, int cols) { ser->printf("\033]W%d;%d\a", rows, cols); }