Support library for the ESP8266 Wireless Terminal. Can also be used for communicating with any VT100-compatible terminal.
espterm.hpp@6:7e7550084e5f, 2017-03-19 (annotated)
- Committer:
- MightyPork
- Date:
- Sun Mar 19 19:51:21 2017 +0000
- Revision:
- 6:7e7550084e5f
- Parent:
- 5:7379bd37f3e2
- Child:
- 7:63d903b6ca9b
Commands to enable/disable wrap, scrolling, cursor memory, etc..
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MightyPork | 0:20fb68233f89 | 1 | #ifndef ESPTERM_H |
MightyPork | 0:20fb68233f89 | 2 | #define ESPTERM_H |
MightyPork | 0:20fb68233f89 | 3 | #include "mbed.h" |
MightyPork | 0:20fb68233f89 | 4 | |
MightyPork | 3:1114012184bf | 5 | /* |
MightyPork | 3:1114012184bf | 6 | * ESP8266 Wireless Terminal interfacing library |
MightyPork | 3:1114012184bf | 7 | * --------------------------------------------- |
MightyPork | 3:1114012184bf | 8 | * |
MightyPork | 3:1114012184bf | 9 | * Tested with ESP firmware v0.5.4 |
MightyPork | 3:1114012184bf | 10 | * |
MightyPork | 3:1114012184bf | 11 | * This library provides simplified |
MightyPork | 1:09dfc9fd55f4 | 12 | */ |
MightyPork | 4:294e8f53ebcd | 13 | |
MightyPork | 4:294e8f53ebcd | 14 | // Max nr of CSI parameters |
MightyPork | 4:294e8f53ebcd | 15 | #define CSI_N_MAX 3 |
MightyPork | 4:294e8f53ebcd | 16 | #define OSC_BUF_LEN 16 |
MightyPork | 5:7379bd37f3e2 | 17 | |
MightyPork | 5:7379bd37f3e2 | 18 | |
MightyPork | 5:7379bd37f3e2 | 19 | /** |
MightyPork | 5:7379bd37f3e2 | 20 | * ANSI colors supported by the ESP Terminal |
MightyPork | 5:7379bd37f3e2 | 21 | */ |
MightyPork | 5:7379bd37f3e2 | 22 | enum Color { |
MightyPork | 5:7379bd37f3e2 | 23 | BLACK = 0, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, GRAY_LT, |
MightyPork | 5:7379bd37f3e2 | 24 | GRAY, RED_LT, GREEN_LT, YELLOW_LT, BLUE_LT, PURPLE_LT, CYAN_LT, WHITE, |
MightyPork | 5:7379bd37f3e2 | 25 | |
MightyPork | 5:7379bd37f3e2 | 26 | // aliases |
MightyPork | 5:7379bd37f3e2 | 27 | RED_DK=1, GREEN_DK=2, YELLOW_DK=3, BLUE_DK=4, PURPLE_DK=5, CYAN_DK=6, SILVER=7, |
MightyPork | 5:7379bd37f3e2 | 28 | }; |
MightyPork | 5:7379bd37f3e2 | 29 | |
MightyPork | 5:7379bd37f3e2 | 30 | |
MightyPork | 5:7379bd37f3e2 | 31 | /** |
MightyPork | 5:7379bd37f3e2 | 32 | * Argument for screen or line clear commands |
MightyPork | 5:7379bd37f3e2 | 33 | */ |
MightyPork | 5:7379bd37f3e2 | 34 | enum ClearMode { |
MightyPork | 5:7379bd37f3e2 | 35 | CLEAR_TO_CURSOR = 0, |
MightyPork | 5:7379bd37f3e2 | 36 | CLEAR_FROM_CURSOR = 1, |
MightyPork | 5:7379bd37f3e2 | 37 | CLEAR_ALL = 2, |
MightyPork | 5:7379bd37f3e2 | 38 | }; |
MightyPork | 5:7379bd37f3e2 | 39 | |
MightyPork | 5:7379bd37f3e2 | 40 | |
MightyPork | 5:7379bd37f3e2 | 41 | enum CtlKey { |
MightyPork | 5:7379bd37f3e2 | 42 | KEY_LEFT = 0, |
MightyPork | 5:7379bd37f3e2 | 43 | KEY_RIGHT = 1, |
MightyPork | 5:7379bd37f3e2 | 44 | KEY_UP = 2, |
MightyPork | 5:7379bd37f3e2 | 45 | KEY_DOWN = 3, |
MightyPork | 5:7379bd37f3e2 | 46 | }; |
MightyPork | 5:7379bd37f3e2 | 47 | |
MightyPork | 5:7379bd37f3e2 | 48 | |
MightyPork | 5:7379bd37f3e2 | 49 | /** |
MightyPork | 5:7379bd37f3e2 | 50 | * NOTE: not all may be implemented |
MightyPork | 5:7379bd37f3e2 | 51 | * |
MightyPork | 5:7379bd37f3e2 | 52 | * DOWN (and UP) are fired when the button stays pressed for |
MightyPork | 5:7379bd37f3e2 | 53 | * more than a certain time interval (typ. 200 ms) |
MightyPork | 5:7379bd37f3e2 | 54 | * |
MightyPork | 5:7379bd37f3e2 | 55 | * |
MightyPork | 5:7379bd37f3e2 | 56 | */ |
MightyPork | 5:7379bd37f3e2 | 57 | enum MouseEvent { |
MightyPork | 5:7379bd37f3e2 | 58 | // Left button |
MightyPork | 5:7379bd37f3e2 | 59 | LEFT_CLICK = 0, |
MightyPork | 5:7379bd37f3e2 | 60 | LEFT_DOWN = 1, |
MightyPork | 5:7379bd37f3e2 | 61 | LEFT_UP = 2, |
MightyPork | 5:7379bd37f3e2 | 62 | |
MightyPork | 5:7379bd37f3e2 | 63 | // Right button |
MightyPork | 5:7379bd37f3e2 | 64 | RIGHT_CLICK = 10, |
MightyPork | 5:7379bd37f3e2 | 65 | RIGHT_DOWN = 11, // Probably not working |
MightyPork | 5:7379bd37f3e2 | 66 | RIGHT_UP = 12, // ditto |
MightyPork | 5:7379bd37f3e2 | 67 | |
MightyPork | 5:7379bd37f3e2 | 68 | // Common |
MightyPork | 5:7379bd37f3e2 | 69 | MOUSE_MOVE = 20, // When coords of the cell under mouse changed |
MightyPork | 5:7379bd37f3e2 | 70 | |
MightyPork | 5:7379bd37f3e2 | 71 | // Wheel events |
MightyPork | 5:7379bd37f3e2 | 72 | WHEEL_CLICK = 30, |
MightyPork | 5:7379bd37f3e2 | 73 | WHEEL_DOWN = 31, // This refers to the push button |
MightyPork | 5:7379bd37f3e2 | 74 | WHEEL_UP = 32, |
MightyPork | 5:7379bd37f3e2 | 75 | SCROLL_DOWN = 33, // Here's the scrolling events |
MightyPork | 5:7379bd37f3e2 | 76 | SCROLL_UP = 34, |
MightyPork | 5:7379bd37f3e2 | 77 | }; |
MightyPork | 5:7379bd37f3e2 | 78 | |
MightyPork | 5:7379bd37f3e2 | 79 | |
MightyPork | 1:09dfc9fd55f4 | 80 | |
MightyPork | 1:09dfc9fd55f4 | 81 | /** |
MightyPork | 1:09dfc9fd55f4 | 82 | * ESP8266 Wireless Terminal interface |
MightyPork | 0:20fb68233f89 | 83 | * |
MightyPork | 1:09dfc9fd55f4 | 84 | * Can also be used for sending ANSI sequences to a regular serial terminal |
MightyPork | 0:20fb68233f89 | 85 | */ |
MightyPork | 1:09dfc9fd55f4 | 86 | class ESPTerm |
MightyPork | 1:09dfc9fd55f4 | 87 | { |
MightyPork | 4:294e8f53ebcd | 88 | /** |
MightyPork | 4:294e8f53ebcd | 89 | * Status flag set by the rx handler when device responds with "device OK". |
MightyPork | 4:294e8f53ebcd | 90 | * Cleared before sending Device Status Request. |
MightyPork | 4:294e8f53ebcd | 91 | */ |
MightyPork | 4:294e8f53ebcd | 92 | bool device_ok; |
MightyPork | 4:294e8f53ebcd | 93 | |
MightyPork | 4:294e8f53ebcd | 94 | |
MightyPork | 4:294e8f53ebcd | 95 | /** Serial comm used to talk to the ESP */ |
MightyPork | 0:20fb68233f89 | 96 | Serial* ser; |
MightyPork | 0:20fb68233f89 | 97 | |
MightyPork | 4:294e8f53ebcd | 98 | |
MightyPork | 4:294e8f53ebcd | 99 | /** Internal init func, called from constructor */ |
MightyPork | 4:294e8f53ebcd | 100 | void init(Serial* ser); |
MightyPork | 4:294e8f53ebcd | 101 | |
MightyPork | 4:294e8f53ebcd | 102 | |
MightyPork | 4:294e8f53ebcd | 103 | /** Internal rxchar handler with parser */ |
MightyPork | 4:294e8f53ebcd | 104 | void ser_rx_char(void); |
MightyPork | 4:294e8f53ebcd | 105 | |
MightyPork | 4:294e8f53ebcd | 106 | // ---- Ragel parser variables ---- |
MightyPork | 4:294e8f53ebcd | 107 | int cs; |
MightyPork | 4:294e8f53ebcd | 108 | |
MightyPork | 4:294e8f53ebcd | 109 | // The CSI code is built here |
MightyPork | 4:294e8f53ebcd | 110 | char csi_leading; //!< Leading char, 0 if none |
MightyPork | 4:294e8f53ebcd | 111 | int csi_ni; //!< Number of the active digit |
MightyPork | 4:294e8f53ebcd | 112 | int csi_n[CSI_N_MAX]; //!< Param digits |
MightyPork | 4:294e8f53ebcd | 113 | char csi_char; //!< CSI action char (end) |
MightyPork | 4:294e8f53ebcd | 114 | |
MightyPork | 4:294e8f53ebcd | 115 | char osc_buff[OSC_BUF_LEN]; |
MightyPork | 4:294e8f53ebcd | 116 | int osc_i; |
MightyPork | 4:294e8f53ebcd | 117 | |
MightyPork | 4:294e8f53ebcd | 118 | // Ragel parser funcs |
MightyPork | 4:294e8f53ebcd | 119 | void ansi_parser(const char *newdata, size_t len); |
MightyPork | 4:294e8f53ebcd | 120 | void apars_handle_plainchar(char c); |
MightyPork | 4:294e8f53ebcd | 121 | void apars_handle_csi(char lead, const int* nums, char keychar); |
MightyPork | 4:294e8f53ebcd | 122 | void apars_handle_osc(const char *c); |
MightyPork | 4:294e8f53ebcd | 123 | void apars_handle_badseq(void); |
MightyPork | 4:294e8f53ebcd | 124 | |
MightyPork | 4:294e8f53ebcd | 125 | |
MightyPork | 5:7379bd37f3e2 | 126 | public: |
MightyPork | 4:294e8f53ebcd | 127 | |
MightyPork | 4:294e8f53ebcd | 128 | /** Fired when user taps the screen at the given coords */ |
MightyPork | 5:7379bd37f3e2 | 129 | void (*on_mouse)(int row, int col, MouseEvent event); |
MightyPork | 4:294e8f53ebcd | 130 | |
MightyPork | 4:294e8f53ebcd | 131 | |
MightyPork | 4:294e8f53ebcd | 132 | /** Fired when the user presses one of the blue buttons (index is 1 thru 5) */ |
MightyPork | 4:294e8f53ebcd | 133 | void (*on_button)(int index); |
MightyPork | 4:294e8f53ebcd | 134 | |
MightyPork | 4:294e8f53ebcd | 135 | |
MightyPork | 5:7379bd37f3e2 | 136 | /** Fired on each key press (keyboard arrows etc) */ |
MightyPork | 5:7379bd37f3e2 | 137 | void (*on_key)(CtlKey key); |
MightyPork | 5:7379bd37f3e2 | 138 | |
MightyPork | 5:7379bd37f3e2 | 139 | |
MightyPork | 4:294e8f53ebcd | 140 | /** Fired on rx of the "ESP reset notification" byte */ |
MightyPork | 4:294e8f53ebcd | 141 | void (*on_esp_reset)(void); |
MightyPork | 4:294e8f53ebcd | 142 | |
MightyPork | 4:294e8f53ebcd | 143 | |
MightyPork | 4:294e8f53ebcd | 144 | /** Fired on each received plain character */ |
MightyPork | 4:294e8f53ebcd | 145 | void (*on_char_rx)(char c); |
MightyPork | 4:294e8f53ebcd | 146 | |
MightyPork | 4:294e8f53ebcd | 147 | |
MightyPork | 4:294e8f53ebcd | 148 | /** Handle generic OSC command (may be used in the future) */ |
MightyPork | 4:294e8f53ebcd | 149 | void (*on_osc_rx)(const char *str); |
MightyPork | 4:294e8f53ebcd | 150 | |
MightyPork | 3:1114012184bf | 151 | |
MightyPork | 0:20fb68233f89 | 152 | /** |
MightyPork | 1:09dfc9fd55f4 | 153 | * @brief Create a terminal instance from already initialized serial port |
MightyPork | 0:20fb68233f89 | 154 | * |
MightyPork | 0:20fb68233f89 | 155 | * Example: |
MightyPork | 3:1114012184bf | 156 | * Serial ser(PA_2, PA_3, 115200); // eg. for STM32F042 |
MightyPork | 0:20fb68233f89 | 157 | * ESPTerm term(&ser); |
MightyPork | 0:20fb68233f89 | 158 | */ |
MightyPork | 0:20fb68233f89 | 159 | ESPTerm(Serial *s); |
MightyPork | 1:09dfc9fd55f4 | 160 | |
MightyPork | 4:294e8f53ebcd | 161 | |
MightyPork | 4:294e8f53ebcd | 162 | /** |
MightyPork | 4:294e8f53ebcd | 163 | * @brief Create a terminal instance with given params |
MightyPork | 4:294e8f53ebcd | 164 | */ |
MightyPork | 4:294e8f53ebcd | 165 | ESPTerm(PinName txPin, PinName rxPin, int baud=115200); |
MightyPork | 4:294e8f53ebcd | 166 | |
MightyPork | 4:294e8f53ebcd | 167 | |
MightyPork | 4:294e8f53ebcd | 168 | /** |
MightyPork | 4:294e8f53ebcd | 169 | * @brief Create a terminal instance with given params & 115200 baud |
MightyPork | 4:294e8f53ebcd | 170 | */ |
MightyPork | 4:294e8f53ebcd | 171 | //ESPTerm(PinName txPin, PinName rxPin); |
MightyPork | 4:294e8f53ebcd | 172 | |
MightyPork | 1:09dfc9fd55f4 | 173 | |
MightyPork | 1:09dfc9fd55f4 | 174 | /** |
MightyPork | 1:09dfc9fd55f4 | 175 | * @brief Create with Serial at (PA_2, PA_3, 115200) |
MightyPork | 1:09dfc9fd55f4 | 176 | */ |
MightyPork | 1:09dfc9fd55f4 | 177 | ESPTerm(void); |
MightyPork | 1:09dfc9fd55f4 | 178 | |
MightyPork | 1:09dfc9fd55f4 | 179 | |
MightyPork | 4:294e8f53ebcd | 180 | // ----- Printing ----- |
MightyPork | 4:294e8f53ebcd | 181 | |
MightyPork | 4:294e8f53ebcd | 182 | |
MightyPork | 1:09dfc9fd55f4 | 183 | /** |
MightyPork | 1:09dfc9fd55f4 | 184 | * @brief printf() over the Serial |
MightyPork | 1:09dfc9fd55f4 | 185 | * |
MightyPork | 1:09dfc9fd55f4 | 186 | * Use for raw strings without formatting, or with custom escape sequences. |
MightyPork | 1:09dfc9fd55f4 | 187 | */ |
MightyPork | 1:09dfc9fd55f4 | 188 | int printf(const char *fmt, ...); |
MightyPork | 1:09dfc9fd55f4 | 189 | |
MightyPork | 1:09dfc9fd55f4 | 190 | |
MightyPork | 1:09dfc9fd55f4 | 191 | /** |
MightyPork | 1:09dfc9fd55f4 | 192 | * @brief Alias for printf() |
MightyPork | 1:09dfc9fd55f4 | 193 | */ |
MightyPork | 1:09dfc9fd55f4 | 194 | int print(const char *fmt, ...); |
MightyPork | 1:09dfc9fd55f4 | 195 | |
MightyPork | 1:09dfc9fd55f4 | 196 | |
MightyPork | 1:09dfc9fd55f4 | 197 | /** |
MightyPork | 3:1114012184bf | 198 | * @brief Print with no args |
MightyPork | 3:1114012184bf | 199 | */ |
MightyPork | 4:294e8f53ebcd | 200 | int puts(const char *str) |
MightyPork | 4:294e8f53ebcd | 201 | { |
MightyPork | 4:294e8f53ebcd | 202 | return ser->puts(str); |
MightyPork | 4:294e8f53ebcd | 203 | } |
MightyPork | 4:294e8f53ebcd | 204 | |
MightyPork | 4:294e8f53ebcd | 205 | |
MightyPork | 4:294e8f53ebcd | 206 | /** |
MightyPork | 4:294e8f53ebcd | 207 | * @brief Print a single char |
MightyPork | 4:294e8f53ebcd | 208 | */ |
MightyPork | 4:294e8f53ebcd | 209 | void putc(const char c) |
MightyPork | 4:294e8f53ebcd | 210 | { |
MightyPork | 4:294e8f53ebcd | 211 | ser->putc(c); |
MightyPork | 4:294e8f53ebcd | 212 | } |
MightyPork | 3:1114012184bf | 213 | |
MightyPork | 3:1114012184bf | 214 | |
MightyPork | 3:1114012184bf | 215 | /** |
MightyPork | 2:f9f27e2b64a7 | 216 | * printf() over the Serial, followed by a newline (\\r\\n) |
MightyPork | 1:09dfc9fd55f4 | 217 | * |
MightyPork | 1:09dfc9fd55f4 | 218 | * Use for raw strings without formatting, or with custom escape sequences. |
MightyPork | 1:09dfc9fd55f4 | 219 | * Especially useful for log messages, automatically terminating the line. |
MightyPork | 1:09dfc9fd55f4 | 220 | */ |
MightyPork | 1:09dfc9fd55f4 | 221 | int println(const char *fmt, ...); |
MightyPork | 1:09dfc9fd55f4 | 222 | |
MightyPork | 1:09dfc9fd55f4 | 223 | |
MightyPork | 4:294e8f53ebcd | 224 | // ----- Colors ----- |
MightyPork | 4:294e8f53ebcd | 225 | |
MightyPork | 4:294e8f53ebcd | 226 | |
MightyPork | 1:09dfc9fd55f4 | 227 | /** |
MightyPork | 1:09dfc9fd55f4 | 228 | * @brief Set foreground text color |
MightyPork | 1:09dfc9fd55f4 | 229 | * @param c - color |
MightyPork | 1:09dfc9fd55f4 | 230 | */ |
MightyPork | 3:1114012184bf | 231 | void fg(Color c); |
MightyPork | 1:09dfc9fd55f4 | 232 | |
MightyPork | 1:09dfc9fd55f4 | 233 | |
MightyPork | 1:09dfc9fd55f4 | 234 | /** |
MightyPork | 1:09dfc9fd55f4 | 235 | * @brief Set background text color |
MightyPork | 1:09dfc9fd55f4 | 236 | * @param c - color |
MightyPork | 1:09dfc9fd55f4 | 237 | */ |
MightyPork | 3:1114012184bf | 238 | void bg(Color c); |
MightyPork | 1:09dfc9fd55f4 | 239 | |
MightyPork | 1:09dfc9fd55f4 | 240 | |
MightyPork | 1:09dfc9fd55f4 | 241 | /** |
MightyPork | 1:09dfc9fd55f4 | 242 | * @brief Set both text colors |
MightyPork | 1:09dfc9fd55f4 | 243 | * @param fg - foregorund color |
MightyPork | 1:09dfc9fd55f4 | 244 | * @param bg - background color |
MightyPork | 1:09dfc9fd55f4 | 245 | */ |
MightyPork | 4:294e8f53ebcd | 246 | void colors(Color fg, Color bg) |
MightyPork | 4:294e8f53ebcd | 247 | { |
MightyPork | 4:294e8f53ebcd | 248 | this->fg(fg); |
MightyPork | 4:294e8f53ebcd | 249 | this->bg(bg); |
MightyPork | 4:294e8f53ebcd | 250 | } |
MightyPork | 1:09dfc9fd55f4 | 251 | |
MightyPork | 1:09dfc9fd55f4 | 252 | |
MightyPork | 1:09dfc9fd55f4 | 253 | /** |
MightyPork | 2:f9f27e2b64a7 | 254 | * @brief Send \\e[0m - reset all attributes |
MightyPork | 1:09dfc9fd55f4 | 255 | */ |
MightyPork | 1:09dfc9fd55f4 | 256 | void reset_attribs(void); |
MightyPork | 1:09dfc9fd55f4 | 257 | |
MightyPork | 1:09dfc9fd55f4 | 258 | |
MightyPork | 1:09dfc9fd55f4 | 259 | /** |
MightyPork | 1:09dfc9fd55f4 | 260 | * @brief Reset all attributes (alias) |
MightyPork | 1:09dfc9fd55f4 | 261 | */ |
MightyPork | 4:294e8f53ebcd | 262 | void rst(void) |
MightyPork | 4:294e8f53ebcd | 263 | { |
MightyPork | 4:294e8f53ebcd | 264 | this->reset_attribs(); |
MightyPork | 4:294e8f53ebcd | 265 | } |
MightyPork | 4:294e8f53ebcd | 266 | |
MightyPork | 4:294e8f53ebcd | 267 | |
MightyPork | 4:294e8f53ebcd | 268 | // ----- Cursor & clearing ----- |
MightyPork | 1:09dfc9fd55f4 | 269 | |
MightyPork | 1:09dfc9fd55f4 | 270 | |
MightyPork | 1:09dfc9fd55f4 | 271 | /** |
MightyPork | 1:09dfc9fd55f4 | 272 | * @brief Move cursor to a given position |
MightyPork | 1:09dfc9fd55f4 | 273 | * |
MightyPork | 1:09dfc9fd55f4 | 274 | * Screen coordinates are 1-based, starting left-top, |
MightyPork | 1:09dfc9fd55f4 | 275 | * growing down and right. |
MightyPork | 1:09dfc9fd55f4 | 276 | * |
MightyPork | 1:09dfc9fd55f4 | 277 | * @param y - row |
MightyPork | 1:09dfc9fd55f4 | 278 | * @param x - column |
MightyPork | 1:09dfc9fd55f4 | 279 | */ |
MightyPork | 1:09dfc9fd55f4 | 280 | void go_to(int y, int x); |
MightyPork | 1:09dfc9fd55f4 | 281 | |
MightyPork | 1:09dfc9fd55f4 | 282 | |
MightyPork | 1:09dfc9fd55f4 | 283 | /** |
MightyPork | 6:7e7550084e5f | 284 | * @brief Move cursor relatively to the current position |
MightyPork | 6:7e7550084e5f | 285 | * |
MightyPork | 6:7e7550084e5f | 286 | * @param dy - vertical offset (positive = down) |
MightyPork | 6:7e7550084e5f | 287 | * @param dx - horizontal offset (positive = right) |
MightyPork | 6:7e7550084e5f | 288 | */ |
MightyPork | 6:7e7550084e5f | 289 | void move(int dy, int dx); |
MightyPork | 6:7e7550084e5f | 290 | |
MightyPork | 6:7e7550084e5f | 291 | |
MightyPork | 6:7e7550084e5f | 292 | /** |
MightyPork | 1:09dfc9fd55f4 | 293 | * @brief Clear screen |
MightyPork | 1:09dfc9fd55f4 | 294 | * |
MightyPork | 1:09dfc9fd55f4 | 295 | * Replace part of the screen with spaces (ASCII 32) of the currently |
MightyPork | 1:09dfc9fd55f4 | 296 | * selected foregorund and background colors. |
MightyPork | 1:09dfc9fd55f4 | 297 | * |
MightyPork | 1:09dfc9fd55f4 | 298 | * @param mode - what to clear: part or all |
MightyPork | 1:09dfc9fd55f4 | 299 | */ |
MightyPork | 1:09dfc9fd55f4 | 300 | void clear_screen(ClearMode mode); |
MightyPork | 1:09dfc9fd55f4 | 301 | |
MightyPork | 1:09dfc9fd55f4 | 302 | |
MightyPork | 1:09dfc9fd55f4 | 303 | /** |
MightyPork | 1:09dfc9fd55f4 | 304 | * @brief Clear in line |
MightyPork | 1:09dfc9fd55f4 | 305 | * |
MightyPork | 1:09dfc9fd55f4 | 306 | * Replace part of the current line with spaces (ASCII 32) of the |
MightyPork | 1:09dfc9fd55f4 | 307 | * currently selected foregorund and background colors. |
MightyPork | 1:09dfc9fd55f4 | 308 | * |
MightyPork | 1:09dfc9fd55f4 | 309 | * @param mode - what to clear: part or all |
MightyPork | 1:09dfc9fd55f4 | 310 | */ |
MightyPork | 1:09dfc9fd55f4 | 311 | void clear_line(ClearMode mode); |
MightyPork | 1:09dfc9fd55f4 | 312 | |
MightyPork | 1:09dfc9fd55f4 | 313 | |
MightyPork | 1:09dfc9fd55f4 | 314 | /** |
MightyPork | 1:09dfc9fd55f4 | 315 | * @brief Clear the whole screen and move cursor to 1,1 |
MightyPork | 1:09dfc9fd55f4 | 316 | */ |
MightyPork | 1:09dfc9fd55f4 | 317 | void screen_reset(void); |
MightyPork | 1:09dfc9fd55f4 | 318 | |
MightyPork | 1:09dfc9fd55f4 | 319 | |
MightyPork | 1:09dfc9fd55f4 | 320 | /** |
MightyPork | 6:7e7550084e5f | 321 | * @brief Scroll the screen up or down. |
MightyPork | 6:7e7550084e5f | 322 | * |
MightyPork | 6:7e7550084e5f | 323 | * Moves the screen content in the specified direction, replacing the |
MightyPork | 6:7e7550084e5f | 324 | * vacated lines with spaces (32) of the current colors. |
MightyPork | 6:7e7550084e5f | 325 | * |
MightyPork | 6:7e7550084e5f | 326 | * @param lines - number of lines, positive = down, negative = up. |
MightyPork | 6:7e7550084e5f | 327 | */ |
MightyPork | 6:7e7550084e5f | 328 | void scroll(int lines); |
MightyPork | 6:7e7550084e5f | 329 | |
MightyPork | 6:7e7550084e5f | 330 | |
MightyPork | 6:7e7550084e5f | 331 | /** |
MightyPork | 1:09dfc9fd55f4 | 332 | * @brief Set cursor visibility |
MightyPork | 1:09dfc9fd55f4 | 333 | * |
MightyPork | 1:09dfc9fd55f4 | 334 | * If hidden, there will be no blinking square on the screen, |
MightyPork | 1:09dfc9fd55f4 | 335 | * but the cursor still works (ie. go_to works). |
MightyPork | 1:09dfc9fd55f4 | 336 | * |
MightyPork | 1:09dfc9fd55f4 | 337 | * Hiding the cursor is useful for ASCII-art GUIs (dialog boxes etc) |
MightyPork | 1:09dfc9fd55f4 | 338 | */ |
MightyPork | 1:09dfc9fd55f4 | 339 | void show_cursor(bool yes); |
MightyPork | 1:09dfc9fd55f4 | 340 | |
MightyPork | 1:09dfc9fd55f4 | 341 | |
MightyPork | 6:7e7550084e5f | 342 | /** |
MightyPork | 6:7e7550084e5f | 343 | * @brief Push the cursor (there's only one slot) |
MightyPork | 6:7e7550084e5f | 344 | * |
MightyPork | 6:7e7550084e5f | 345 | * @param with_attribs - store also the colors and attributes |
MightyPork | 6:7e7550084e5f | 346 | */ |
MightyPork | 6:7e7550084e5f | 347 | void cursor_push(bool with_attribs=true); |
MightyPork | 6:7e7550084e5f | 348 | |
MightyPork | 6:7e7550084e5f | 349 | |
MightyPork | 6:7e7550084e5f | 350 | /** |
MightyPork | 6:7e7550084e5f | 351 | * @brief Pop the cursor (if stored) |
MightyPork | 6:7e7550084e5f | 352 | * |
MightyPork | 6:7e7550084e5f | 353 | * @param with_attribs - restore also the colors and attributes |
MightyPork | 6:7e7550084e5f | 354 | */ |
MightyPork | 6:7e7550084e5f | 355 | void cursor_pop(bool with_attribs=true); |
MightyPork | 6:7e7550084e5f | 356 | |
MightyPork | 6:7e7550084e5f | 357 | |
MightyPork | 6:7e7550084e5f | 358 | /** |
MightyPork | 6:7e7550084e5f | 359 | * @brief Enable or disable wrapping at EOL (and automatic scrolling) |
MightyPork | 6:7e7550084e5f | 360 | * |
MightyPork | 6:7e7550084e5f | 361 | * @param yes - enable wrap |
MightyPork | 6:7e7550084e5f | 362 | */ |
MightyPork | 6:7e7550084e5f | 363 | void wrap_enable(bool yes); |
MightyPork | 6:7e7550084e5f | 364 | |
MightyPork | 6:7e7550084e5f | 365 | |
MightyPork | 4:294e8f53ebcd | 366 | // ----- System cmds ----- |
MightyPork | 4:294e8f53ebcd | 367 | |
MightyPork | 4:294e8f53ebcd | 368 | |
MightyPork | 1:09dfc9fd55f4 | 369 | /** |
MightyPork | 1:09dfc9fd55f4 | 370 | * @brief Perform a factory reset of the ESP Terminal |
MightyPork | 1:09dfc9fd55f4 | 371 | * |
MightyPork | 1:09dfc9fd55f4 | 372 | * This clears any saved WiFi config, restores the default AP name |
MightyPork | 1:09dfc9fd55f4 | 373 | * and switches to AP mode. The module will reset itself. |
MightyPork | 1:09dfc9fd55f4 | 374 | * |
MightyPork | 1:09dfc9fd55f4 | 375 | * Expect some ASCII output from the module (and a burst of garbage |
MightyPork | 1:09dfc9fd55f4 | 376 | * during the reset). |
MightyPork | 1:09dfc9fd55f4 | 377 | */ |
MightyPork | 1:09dfc9fd55f4 | 378 | void factory_reset(void); |
MightyPork | 1:09dfc9fd55f4 | 379 | |
MightyPork | 1:09dfc9fd55f4 | 380 | |
MightyPork | 1:09dfc9fd55f4 | 381 | /** |
MightyPork | 1:09dfc9fd55f4 | 382 | * @brief Set screen size |
MightyPork | 1:09dfc9fd55f4 | 383 | * |
MightyPork | 1:09dfc9fd55f4 | 384 | * The total number of characters (rows*cols) is limited by the Terminal |
MightyPork | 1:09dfc9fd55f4 | 385 | * firmware, at v0.5.2 that is 2000 characters (25x80) |
MightyPork | 1:09dfc9fd55f4 | 386 | * |
MightyPork | 1:09dfc9fd55f4 | 387 | * @param rows - number of rows (screen height) |
MightyPork | 1:09dfc9fd55f4 | 388 | * @param cols - number of columns (screen width) |
MightyPork | 1:09dfc9fd55f4 | 389 | */ |
MightyPork | 1:09dfc9fd55f4 | 390 | void set_screen_size(int rows, int cols); |
MightyPork | 4:294e8f53ebcd | 391 | |
MightyPork | 4:294e8f53ebcd | 392 | |
MightyPork | 4:294e8f53ebcd | 393 | /** |
MightyPork | 6:7e7550084e5f | 394 | * @brief Clear the Device OK flag |
MightyPork | 4:294e8f53ebcd | 395 | */ |
MightyPork | 4:294e8f53ebcd | 396 | void clear_status(void) |
MightyPork | 4:294e8f53ebcd | 397 | { |
MightyPork | 4:294e8f53ebcd | 398 | device_ok = false; |
MightyPork | 4:294e8f53ebcd | 399 | } |
MightyPork | 4:294e8f53ebcd | 400 | |
MightyPork | 4:294e8f53ebcd | 401 | |
MightyPork | 4:294e8f53ebcd | 402 | /** |
MightyPork | 6:7e7550084e5f | 403 | * @brief Query device status. |
MightyPork | 4:294e8f53ebcd | 404 | * |
MightyPork | 4:294e8f53ebcd | 405 | * To use the query function, call clear_status() first, and then poll |
MightyPork | 4:294e8f53ebcd | 406 | * query_status() with some delays in between. |
MightyPork | 4:294e8f53ebcd | 407 | * |
MightyPork | 6:7e7550084e5f | 408 | * @return the status flag from a previous query; |
MightyPork | 6:7e7550084e5f | 409 | * if true, does not send another query, and just returns. |
MightyPork | 4:294e8f53ebcd | 410 | */ |
MightyPork | 4:294e8f53ebcd | 411 | bool query_status(void); |
MightyPork | 0:20fb68233f89 | 412 | }; |
MightyPork | 0:20fb68233f89 | 413 | |
MightyPork | 3:1114012184bf | 414 | |
MightyPork | 3:1114012184bf | 415 | /** Convenience alias for using class enums etc */ |
MightyPork | 3:1114012184bf | 416 | typedef ESPTerm VT; |
MightyPork | 3:1114012184bf | 417 | |
MightyPork | 0:20fb68233f89 | 418 | #endif /* ESPTERM_H */ |