Support library for the ESP8266 Wireless Terminal. Can also be used for communicating with any VT100-compatible terminal.

Committer:
MightyPork
Date:
Tue Mar 21 21:27:10 2017 +0000
Revision:
7:63d903b6ca9b
Parent:
6:7e7550084e5f
updated docs

Who changed what in which revision?

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