Support library for the ESP8266 Wireless Terminal. Can also be used for communicating with any VT100-compatible terminal.
espterm.hpp@5:7379bd37f3e2, 2017-03-19 (annotated)
- Committer:
- MightyPork
- Date:
- Sun Mar 19 18:16:17 2017 +0000
- Revision:
- 5:7379bd37f3e2
- Parent:
- 4:294e8f53ebcd
- Child:
- 6:7e7550084e5f
Buncha improvements
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 | 1:09dfc9fd55f4 | 284 | * @brief Clear screen |
MightyPork | 1:09dfc9fd55f4 | 285 | * |
MightyPork | 1:09dfc9fd55f4 | 286 | * Replace part of the screen with spaces (ASCII 32) of the currently |
MightyPork | 1:09dfc9fd55f4 | 287 | * selected foregorund and background colors. |
MightyPork | 1:09dfc9fd55f4 | 288 | * |
MightyPork | 1:09dfc9fd55f4 | 289 | * @param mode - what to clear: part or all |
MightyPork | 1:09dfc9fd55f4 | 290 | */ |
MightyPork | 1:09dfc9fd55f4 | 291 | void clear_screen(ClearMode mode); |
MightyPork | 1:09dfc9fd55f4 | 292 | |
MightyPork | 1:09dfc9fd55f4 | 293 | |
MightyPork | 1:09dfc9fd55f4 | 294 | /** |
MightyPork | 1:09dfc9fd55f4 | 295 | * @brief Clear in line |
MightyPork | 1:09dfc9fd55f4 | 296 | * |
MightyPork | 1:09dfc9fd55f4 | 297 | * Replace part of the current line with spaces (ASCII 32) of the |
MightyPork | 1:09dfc9fd55f4 | 298 | * currently selected foregorund and background colors. |
MightyPork | 1:09dfc9fd55f4 | 299 | * |
MightyPork | 1:09dfc9fd55f4 | 300 | * @param mode - what to clear: part or all |
MightyPork | 1:09dfc9fd55f4 | 301 | */ |
MightyPork | 1:09dfc9fd55f4 | 302 | void clear_line(ClearMode mode); |
MightyPork | 1:09dfc9fd55f4 | 303 | |
MightyPork | 1:09dfc9fd55f4 | 304 | |
MightyPork | 1:09dfc9fd55f4 | 305 | /** |
MightyPork | 1:09dfc9fd55f4 | 306 | * @brief Clear the whole screen and move cursor to 1,1 |
MightyPork | 1:09dfc9fd55f4 | 307 | */ |
MightyPork | 1:09dfc9fd55f4 | 308 | void screen_reset(void); |
MightyPork | 1:09dfc9fd55f4 | 309 | |
MightyPork | 1:09dfc9fd55f4 | 310 | |
MightyPork | 1:09dfc9fd55f4 | 311 | /** |
MightyPork | 1:09dfc9fd55f4 | 312 | * @brief Set cursor visibility |
MightyPork | 1:09dfc9fd55f4 | 313 | * |
MightyPork | 1:09dfc9fd55f4 | 314 | * If hidden, there will be no blinking square on the screen, |
MightyPork | 1:09dfc9fd55f4 | 315 | * but the cursor still works (ie. go_to works). |
MightyPork | 1:09dfc9fd55f4 | 316 | * |
MightyPork | 1:09dfc9fd55f4 | 317 | * Hiding the cursor is useful for ASCII-art GUIs (dialog boxes etc) |
MightyPork | 1:09dfc9fd55f4 | 318 | */ |
MightyPork | 1:09dfc9fd55f4 | 319 | void show_cursor(bool yes); |
MightyPork | 1:09dfc9fd55f4 | 320 | |
MightyPork | 1:09dfc9fd55f4 | 321 | |
MightyPork | 4:294e8f53ebcd | 322 | // ----- System cmds ----- |
MightyPork | 4:294e8f53ebcd | 323 | |
MightyPork | 4:294e8f53ebcd | 324 | |
MightyPork | 1:09dfc9fd55f4 | 325 | /** |
MightyPork | 1:09dfc9fd55f4 | 326 | * @brief Perform a factory reset of the ESP Terminal |
MightyPork | 1:09dfc9fd55f4 | 327 | * |
MightyPork | 1:09dfc9fd55f4 | 328 | * This clears any saved WiFi config, restores the default AP name |
MightyPork | 1:09dfc9fd55f4 | 329 | * and switches to AP mode. The module will reset itself. |
MightyPork | 1:09dfc9fd55f4 | 330 | * |
MightyPork | 1:09dfc9fd55f4 | 331 | * Expect some ASCII output from the module (and a burst of garbage |
MightyPork | 1:09dfc9fd55f4 | 332 | * during the reset). |
MightyPork | 1:09dfc9fd55f4 | 333 | */ |
MightyPork | 1:09dfc9fd55f4 | 334 | void factory_reset(void); |
MightyPork | 1:09dfc9fd55f4 | 335 | |
MightyPork | 1:09dfc9fd55f4 | 336 | |
MightyPork | 1:09dfc9fd55f4 | 337 | /** |
MightyPork | 1:09dfc9fd55f4 | 338 | * @brief Set screen size |
MightyPork | 1:09dfc9fd55f4 | 339 | * |
MightyPork | 1:09dfc9fd55f4 | 340 | * The total number of characters (rows*cols) is limited by the Terminal |
MightyPork | 1:09dfc9fd55f4 | 341 | * firmware, at v0.5.2 that is 2000 characters (25x80) |
MightyPork | 1:09dfc9fd55f4 | 342 | * |
MightyPork | 1:09dfc9fd55f4 | 343 | * @param rows - number of rows (screen height) |
MightyPork | 1:09dfc9fd55f4 | 344 | * @param cols - number of columns (screen width) |
MightyPork | 1:09dfc9fd55f4 | 345 | */ |
MightyPork | 1:09dfc9fd55f4 | 346 | void set_screen_size(int rows, int cols); |
MightyPork | 4:294e8f53ebcd | 347 | |
MightyPork | 4:294e8f53ebcd | 348 | |
MightyPork | 4:294e8f53ebcd | 349 | /** |
MightyPork | 4:294e8f53ebcd | 350 | * Clear the Device OK flag |
MightyPork | 4:294e8f53ebcd | 351 | */ |
MightyPork | 4:294e8f53ebcd | 352 | void clear_status(void) |
MightyPork | 4:294e8f53ebcd | 353 | { |
MightyPork | 4:294e8f53ebcd | 354 | device_ok = false; |
MightyPork | 4:294e8f53ebcd | 355 | } |
MightyPork | 4:294e8f53ebcd | 356 | |
MightyPork | 4:294e8f53ebcd | 357 | |
MightyPork | 4:294e8f53ebcd | 358 | /** |
MightyPork | 4:294e8f53ebcd | 359 | * Query device status, clears "device_ok" and it'll be set by |
MightyPork | 4:294e8f53ebcd | 360 | * the response message. |
MightyPork | 4:294e8f53ebcd | 361 | * |
MightyPork | 4:294e8f53ebcd | 362 | * To use the query function, call clear_status() first, and then poll |
MightyPork | 4:294e8f53ebcd | 363 | * query_status() with some delays in between. |
MightyPork | 4:294e8f53ebcd | 364 | * |
MightyPork | 4:294e8f53ebcd | 365 | * @return the status flag, from a previous query |
MightyPork | 4:294e8f53ebcd | 366 | */ |
MightyPork | 4:294e8f53ebcd | 367 | bool query_status(void); |
MightyPork | 0:20fb68233f89 | 368 | }; |
MightyPork | 0:20fb68233f89 | 369 | |
MightyPork | 3:1114012184bf | 370 | |
MightyPork | 3:1114012184bf | 371 | /** Convenience alias for using class enums etc */ |
MightyPork | 3:1114012184bf | 372 | typedef ESPTerm VT; |
MightyPork | 3:1114012184bf | 373 | |
MightyPork | 0:20fb68233f89 | 374 | #endif /* ESPTERM_H */ |