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

Committer:
MightyPork
Date:
Sun Mar 19 19:51:21 2017 +0000
Revision:
6:7e7550084e5f
Parent:
5:7379bd37f3e2
Commands to enable/disable wrap, scrolling, cursor memory, etc..

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MightyPork 0:20fb68233f89 1 #include "mbed.h"
MightyPork 0:20fb68233f89 2 #include "espterm.hpp"
MightyPork 0:20fb68233f89 3
MightyPork 1:09dfc9fd55f4 4 #include <cstdarg>
MightyPork 1:09dfc9fd55f4 5
MightyPork 1:09dfc9fd55f4 6
MightyPork 4:294e8f53ebcd 7 void ESPTerm::init(Serial *s)
MightyPork 4:294e8f53ebcd 8 {
MightyPork 4:294e8f53ebcd 9 cs = -1;
MightyPork 4:294e8f53ebcd 10 device_ok = false;
MightyPork 4:294e8f53ebcd 11
MightyPork 5:7379bd37f3e2 12 on_mouse = NULL;
MightyPork 4:294e8f53ebcd 13 on_button = NULL;
MightyPork 5:7379bd37f3e2 14 on_key = NULL;
MightyPork 4:294e8f53ebcd 15 on_esp_reset = NULL;
MightyPork 4:294e8f53ebcd 16 on_char_rx = NULL;
MightyPork 4:294e8f53ebcd 17 on_osc_rx = NULL;
MightyPork 4:294e8f53ebcd 18
MightyPork 4:294e8f53ebcd 19 ser = s;
MightyPork 4:294e8f53ebcd 20 ser->attach(callback(this, &ESPTerm::ser_rx_char), Serial::RxIrq);
MightyPork 4:294e8f53ebcd 21 }
MightyPork 4:294e8f53ebcd 22
MightyPork 4:294e8f53ebcd 23
MightyPork 1:09dfc9fd55f4 24 ESPTerm::ESPTerm(Serial *s)
MightyPork 1:09dfc9fd55f4 25 {
MightyPork 4:294e8f53ebcd 26 init(s);
MightyPork 0:20fb68233f89 27 }
MightyPork 1:09dfc9fd55f4 28
MightyPork 1:09dfc9fd55f4 29
MightyPork 1:09dfc9fd55f4 30 ESPTerm::ESPTerm(void)
MightyPork 1:09dfc9fd55f4 31 {
MightyPork 4:294e8f53ebcd 32 // Defaults
MightyPork 4:294e8f53ebcd 33 init(new Serial(PA_2, PA_3, 115200));
MightyPork 1:09dfc9fd55f4 34 }
MightyPork 1:09dfc9fd55f4 35
MightyPork 4:294e8f53ebcd 36
MightyPork 4:294e8f53ebcd 37 ESPTerm::ESPTerm(PinName txPin, PinName rxPin, int baud)
MightyPork 4:294e8f53ebcd 38 {
MightyPork 4:294e8f53ebcd 39 init(new Serial(txPin, rxPin, baud));
MightyPork 4:294e8f53ebcd 40 }
MightyPork 4:294e8f53ebcd 41
MightyPork 4:294e8f53ebcd 42
MightyPork 3:1114012184bf 43 // ----- Printing -----
MightyPork 3:1114012184bf 44
MightyPork 1:09dfc9fd55f4 45
MightyPork 1:09dfc9fd55f4 46 int ESPTerm::printf(const char *format, ...)
MightyPork 1:09dfc9fd55f4 47 {
MightyPork 1:09dfc9fd55f4 48 std::va_list arg;
MightyPork 1:09dfc9fd55f4 49 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 50 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 51 va_end(arg);
MightyPork 1:09dfc9fd55f4 52
MightyPork 1:09dfc9fd55f4 53 return r;
MightyPork 1:09dfc9fd55f4 54 }
MightyPork 1:09dfc9fd55f4 55
MightyPork 4:294e8f53ebcd 56
MightyPork 1:09dfc9fd55f4 57 // alias of printf
MightyPork 1:09dfc9fd55f4 58 int ESPTerm::print(const char *format, ...)
MightyPork 1:09dfc9fd55f4 59 {
MightyPork 1:09dfc9fd55f4 60 std::va_list arg;
MightyPork 1:09dfc9fd55f4 61 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 62 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 63 va_end(arg);
MightyPork 1:09dfc9fd55f4 64
MightyPork 1:09dfc9fd55f4 65 return r;
MightyPork 1:09dfc9fd55f4 66 }
MightyPork 1:09dfc9fd55f4 67
MightyPork 1:09dfc9fd55f4 68
MightyPork 1:09dfc9fd55f4 69 int ESPTerm::println(const char *format, ...) {
MightyPork 1:09dfc9fd55f4 70 std::va_list arg;
MightyPork 1:09dfc9fd55f4 71 va_start(arg, format);
MightyPork 1:09dfc9fd55f4 72 int r = ser->vprintf(format, arg);
MightyPork 1:09dfc9fd55f4 73 va_end(arg);
MightyPork 1:09dfc9fd55f4 74
MightyPork 1:09dfc9fd55f4 75 r += ser->puts("\r\n");
MightyPork 1:09dfc9fd55f4 76 return r;
MightyPork 1:09dfc9fd55f4 77 }
MightyPork 1:09dfc9fd55f4 78
MightyPork 1:09dfc9fd55f4 79
MightyPork 3:1114012184bf 80 // ----- Colors -----
MightyPork 3:1114012184bf 81
MightyPork 3:1114012184bf 82
MightyPork 3:1114012184bf 83 void ESPTerm::fg(Color c)
MightyPork 1:09dfc9fd55f4 84 {
MightyPork 1:09dfc9fd55f4 85 int ci = c;
MightyPork 1:09dfc9fd55f4 86 if(ci > 7) {
MightyPork 1:09dfc9fd55f4 87 ci += (90-8);
MightyPork 1:09dfc9fd55f4 88 } else {
MightyPork 1:09dfc9fd55f4 89 ci += 30;
MightyPork 1:09dfc9fd55f4 90 }
MightyPork 1:09dfc9fd55f4 91 ser->printf("\033[%dm", ci);
MightyPork 1:09dfc9fd55f4 92 }
MightyPork 1:09dfc9fd55f4 93
MightyPork 1:09dfc9fd55f4 94
MightyPork 3:1114012184bf 95 void ESPTerm::bg(Color c)
MightyPork 1:09dfc9fd55f4 96 {
MightyPork 1:09dfc9fd55f4 97 int ci = c;
MightyPork 1:09dfc9fd55f4 98 if(ci > 7) {
MightyPork 1:09dfc9fd55f4 99 ci += (100-8);
MightyPork 1:09dfc9fd55f4 100 } else {
MightyPork 1:09dfc9fd55f4 101 ci += 40;
MightyPork 1:09dfc9fd55f4 102 }
MightyPork 1:09dfc9fd55f4 103 ser->printf("\033[%dm", ci);
MightyPork 1:09dfc9fd55f4 104 }
MightyPork 1:09dfc9fd55f4 105
MightyPork 1:09dfc9fd55f4 106
MightyPork 1:09dfc9fd55f4 107 void ESPTerm::reset_attribs(void)
MightyPork 1:09dfc9fd55f4 108 {
MightyPork 1:09dfc9fd55f4 109 ser->puts("\033[0m");
MightyPork 1:09dfc9fd55f4 110 }
MightyPork 1:09dfc9fd55f4 111
MightyPork 1:09dfc9fd55f4 112
MightyPork 3:1114012184bf 113 // ----- Cursor control & erasing -----
MightyPork 3:1114012184bf 114
MightyPork 3:1114012184bf 115
MightyPork 1:09dfc9fd55f4 116 void ESPTerm::go_to(int y, int x)
MightyPork 1:09dfc9fd55f4 117 {
MightyPork 1:09dfc9fd55f4 118 ser->printf("\033[%d;%dH", y, x);
MightyPork 1:09dfc9fd55f4 119 }
MightyPork 1:09dfc9fd55f4 120
MightyPork 1:09dfc9fd55f4 121
MightyPork 6:7e7550084e5f 122 void ESPTerm::move(int dy, int dx)
MightyPork 6:7e7550084e5f 123 {
MightyPork 6:7e7550084e5f 124 if (dy != 0) {
MightyPork 6:7e7550084e5f 125 if (dy > 0) {
MightyPork 6:7e7550084e5f 126 // Down
MightyPork 6:7e7550084e5f 127 ser->printf("\033[%dB", dy);
MightyPork 6:7e7550084e5f 128 }
MightyPork 6:7e7550084e5f 129 else {
MightyPork 6:7e7550084e5f 130 // Up
MightyPork 6:7e7550084e5f 131 ser->printf("\033[%dA", -dy);
MightyPork 6:7e7550084e5f 132 }
MightyPork 6:7e7550084e5f 133 }
MightyPork 6:7e7550084e5f 134
MightyPork 6:7e7550084e5f 135 if (dx != 0) {
MightyPork 6:7e7550084e5f 136 if (dx > 0) {
MightyPork 6:7e7550084e5f 137 // Forward
MightyPork 6:7e7550084e5f 138 ser->printf("\033[%dC", dx);
MightyPork 6:7e7550084e5f 139 }
MightyPork 6:7e7550084e5f 140 else {
MightyPork 6:7e7550084e5f 141 // Backward
MightyPork 6:7e7550084e5f 142 ser->printf("\033[%dD", -dx);
MightyPork 6:7e7550084e5f 143 }
MightyPork 6:7e7550084e5f 144 }
MightyPork 6:7e7550084e5f 145 }
MightyPork 6:7e7550084e5f 146
MightyPork 6:7e7550084e5f 147
MightyPork 1:09dfc9fd55f4 148 void ESPTerm::clear_screen(ClearMode mode)
MightyPork 1:09dfc9fd55f4 149 {
MightyPork 1:09dfc9fd55f4 150 ser->printf("\033[%dJ", mode);
MightyPork 1:09dfc9fd55f4 151 }
MightyPork 1:09dfc9fd55f4 152
MightyPork 1:09dfc9fd55f4 153
MightyPork 1:09dfc9fd55f4 154 void ESPTerm::clear_line(ClearMode mode)
MightyPork 1:09dfc9fd55f4 155 {
MightyPork 1:09dfc9fd55f4 156 ser->printf("\033[%dK", mode);
MightyPork 1:09dfc9fd55f4 157 }
MightyPork 1:09dfc9fd55f4 158
MightyPork 1:09dfc9fd55f4 159
MightyPork 1:09dfc9fd55f4 160 void ESPTerm::screen_reset(void)
MightyPork 1:09dfc9fd55f4 161 {
MightyPork 1:09dfc9fd55f4 162 ser->puts("\033c");
MightyPork 1:09dfc9fd55f4 163 }
MightyPork 1:09dfc9fd55f4 164
MightyPork 1:09dfc9fd55f4 165
MightyPork 1:09dfc9fd55f4 166 void ESPTerm::show_cursor(bool yes)
MightyPork 1:09dfc9fd55f4 167 {
MightyPork 6:7e7550084e5f 168 if (yes) {
MightyPork 1:09dfc9fd55f4 169 ser->puts("\033[?25h");
MightyPork 6:7e7550084e5f 170 }
MightyPork 6:7e7550084e5f 171 else {
MightyPork 1:09dfc9fd55f4 172 ser->puts("\033[?25l");
MightyPork 6:7e7550084e5f 173 }
MightyPork 6:7e7550084e5f 174 }
MightyPork 6:7e7550084e5f 175
MightyPork 6:7e7550084e5f 176
MightyPork 6:7e7550084e5f 177 void ESPTerm::scroll(int lines)
MightyPork 6:7e7550084e5f 178 {
MightyPork 6:7e7550084e5f 179 if (lines > 0) {
MightyPork 6:7e7550084e5f 180 ser->printf("\033[%dT", lines);
MightyPork 6:7e7550084e5f 181 }
MightyPork 6:7e7550084e5f 182 else {
MightyPork 6:7e7550084e5f 183 ser->printf("\033[%dS", -lines);
MightyPork 6:7e7550084e5f 184 }
MightyPork 6:7e7550084e5f 185 }
MightyPork 6:7e7550084e5f 186
MightyPork 6:7e7550084e5f 187
MightyPork 6:7e7550084e5f 188 void ESPTerm::cursor_push(bool with_attribs)
MightyPork 6:7e7550084e5f 189 {
MightyPork 6:7e7550084e5f 190 if (with_attribs) {
MightyPork 6:7e7550084e5f 191 ser->puts("\0337");
MightyPork 6:7e7550084e5f 192 }
MightyPork 6:7e7550084e5f 193 else {
MightyPork 6:7e7550084e5f 194 ser->puts("\033[s");
MightyPork 6:7e7550084e5f 195 }
MightyPork 6:7e7550084e5f 196 }
MightyPork 6:7e7550084e5f 197
MightyPork 6:7e7550084e5f 198
MightyPork 6:7e7550084e5f 199 void ESPTerm::cursor_pop(bool with_attribs)
MightyPork 6:7e7550084e5f 200 {
MightyPork 6:7e7550084e5f 201 if (with_attribs) {
MightyPork 6:7e7550084e5f 202 ser->puts("\0338");
MightyPork 6:7e7550084e5f 203 }
MightyPork 6:7e7550084e5f 204 else {
MightyPork 6:7e7550084e5f 205 ser->puts("\033[u");
MightyPork 6:7e7550084e5f 206 }
MightyPork 6:7e7550084e5f 207 }
MightyPork 6:7e7550084e5f 208
MightyPork 6:7e7550084e5f 209
MightyPork 6:7e7550084e5f 210 void ESPTerm::wrap_enable(bool yes)
MightyPork 6:7e7550084e5f 211 {
MightyPork 6:7e7550084e5f 212 if (yes) {
MightyPork 6:7e7550084e5f 213 ser->puts("\033[?7h");
MightyPork 6:7e7550084e5f 214 }
MightyPork 6:7e7550084e5f 215 else {
MightyPork 6:7e7550084e5f 216 ser->puts("\033[?7l");
MightyPork 6:7e7550084e5f 217 }
MightyPork 1:09dfc9fd55f4 218 }
MightyPork 1:09dfc9fd55f4 219
MightyPork 1:09dfc9fd55f4 220
MightyPork 3:1114012184bf 221 // ----- System commands -----
MightyPork 3:1114012184bf 222
MightyPork 3:1114012184bf 223
MightyPork 1:09dfc9fd55f4 224 void ESPTerm::factory_reset(void)
MightyPork 1:09dfc9fd55f4 225 {
MightyPork 1:09dfc9fd55f4 226 ser->puts("\033]FR\a");
MightyPork 1:09dfc9fd55f4 227 }
MightyPork 1:09dfc9fd55f4 228
MightyPork 1:09dfc9fd55f4 229
MightyPork 1:09dfc9fd55f4 230 void ESPTerm::set_screen_size(int rows, int cols)
MightyPork 1:09dfc9fd55f4 231 {
MightyPork 1:09dfc9fd55f4 232 ser->printf("\033]W%d;%d\a", rows, cols);
MightyPork 1:09dfc9fd55f4 233 }
MightyPork 4:294e8f53ebcd 234
MightyPork 4:294e8f53ebcd 235
MightyPork 4:294e8f53ebcd 236 bool ESPTerm::query_status(void)
MightyPork 4:294e8f53ebcd 237 {
MightyPork 4:294e8f53ebcd 238 if (device_ok) return true;
MightyPork 4:294e8f53ebcd 239
MightyPork 4:294e8f53ebcd 240 ser->puts("\033[5n");
MightyPork 4:294e8f53ebcd 241 return false;
MightyPork 4:294e8f53ebcd 242 }
MightyPork 4:294e8f53ebcd 243
MightyPork 4:294e8f53ebcd 244
MightyPork 4:294e8f53ebcd 245 // ----- Rx command parsing -----
MightyPork 4:294e8f53ebcd 246
MightyPork 4:294e8f53ebcd 247
MightyPork 4:294e8f53ebcd 248 void ESPTerm::ser_rx_char(void)
MightyPork 4:294e8f53ebcd 249 {
MightyPork 4:294e8f53ebcd 250 while (ser->readable()) {
MightyPork 4:294e8f53ebcd 251 char c = ser->getc();
MightyPork 4:294e8f53ebcd 252 ansi_parser(&c, 1); // pretend as if it was a string, this is safe
MightyPork 4:294e8f53ebcd 253 }
MightyPork 4:294e8f53ebcd 254 }
MightyPork 4:294e8f53ebcd 255
MightyPork 4:294e8f53ebcd 256
MightyPork 4:294e8f53ebcd 257 void ESPTerm::apars_handle_plainchar(char c)
MightyPork 4:294e8f53ebcd 258 {
MightyPork 4:294e8f53ebcd 259 if (c == 24) {
MightyPork 4:294e8f53ebcd 260 if (on_esp_reset) on_esp_reset();
MightyPork 4:294e8f53ebcd 261 }
MightyPork 4:294e8f53ebcd 262 else if (c >= 1 && c <= 5) {
MightyPork 4:294e8f53ebcd 263 if (on_button) on_button((int)c);
MightyPork 4:294e8f53ebcd 264 }
MightyPork 4:294e8f53ebcd 265 else {
MightyPork 4:294e8f53ebcd 266 if (on_char_rx) on_char_rx(c);
MightyPork 4:294e8f53ebcd 267 }
MightyPork 4:294e8f53ebcd 268 }
MightyPork 4:294e8f53ebcd 269
MightyPork 4:294e8f53ebcd 270
MightyPork 4:294e8f53ebcd 271 void ESPTerm::apars_handle_csi(char lead, const int* nums, char keychar)
MightyPork 4:294e8f53ebcd 272 {
MightyPork 4:294e8f53ebcd 273 // Keyboard events
MightyPork 5:7379bd37f3e2 274 if (on_key) {
MightyPork 5:7379bd37f3e2 275 if (keychar == 'A') on_key(KEY_UP);
MightyPork 5:7379bd37f3e2 276 else if (keychar == 'B') on_key(KEY_DOWN);
MightyPork 5:7379bd37f3e2 277 else if (keychar == 'C') on_key(KEY_RIGHT);
MightyPork 5:7379bd37f3e2 278 else if (keychar == 'D') on_key(KEY_LEFT);
MightyPork 4:294e8f53ebcd 279 }
MightyPork 4:294e8f53ebcd 280
MightyPork 4:294e8f53ebcd 281 // Screen tapped / clicked
MightyPork 5:7379bd37f3e2 282 if (on_mouse && keychar == 'M') {
MightyPork 5:7379bd37f3e2 283 on_mouse(nums[0], nums[1], (MouseEvent) nums[2]);
MightyPork 4:294e8f53ebcd 284 }
MightyPork 4:294e8f53ebcd 285
MightyPork 4:294e8f53ebcd 286 // "Device OK" response to "Device Status Query"
MightyPork 4:294e8f53ebcd 287 if (keychar == 'n' && nums[0] == 0) {
MightyPork 4:294e8f53ebcd 288 device_ok = true;
MightyPork 4:294e8f53ebcd 289 }
MightyPork 4:294e8f53ebcd 290
MightyPork 4:294e8f53ebcd 291 // ... other commands when added
MightyPork 4:294e8f53ebcd 292 }
MightyPork 4:294e8f53ebcd 293
MightyPork 4:294e8f53ebcd 294
MightyPork 4:294e8f53ebcd 295 void ESPTerm::apars_handle_osc(const char *str)
MightyPork 4:294e8f53ebcd 296 {
MightyPork 4:294e8f53ebcd 297 // ... additional parsing when needed in later esp term versions
MightyPork 4:294e8f53ebcd 298 if (on_osc_rx) on_osc_rx(str);
MightyPork 4:294e8f53ebcd 299 }
MightyPork 4:294e8f53ebcd 300
MightyPork 4:294e8f53ebcd 301
MightyPork 4:294e8f53ebcd 302 void ESPTerm::apars_handle_badseq(void)
MightyPork 4:294e8f53ebcd 303 {
MightyPork 4:294e8f53ebcd 304 // Do nothing
MightyPork 4:294e8f53ebcd 305 }
MightyPork 4:294e8f53ebcd 306
MightyPork 4:294e8f53ebcd 307
MightyPork 4:294e8f53ebcd 308
MightyPork 4:294e8f53ebcd 309 /* ----- Ragel constants block ------ */
MightyPork 4:294e8f53ebcd 310
MightyPork 4:294e8f53ebcd 311 /* #line 38 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 312 static const int ansi_start = 1;
MightyPork 4:294e8f53ebcd 313 //static const int ansi_first_final = 7;
MightyPork 4:294e8f53ebcd 314 //static const int ansi_error = 0;
MightyPork 4:294e8f53ebcd 315
MightyPork 4:294e8f53ebcd 316 //static const int ansi_en_CSI_body = 3;
MightyPork 4:294e8f53ebcd 317 //static const int ansi_en_OSC_body = 5;
MightyPork 4:294e8f53ebcd 318 //static const int ansi_en_main = 1;
MightyPork 4:294e8f53ebcd 319
MightyPork 4:294e8f53ebcd 320
MightyPork 4:294e8f53ebcd 321
MightyPork 4:294e8f53ebcd 322 /* Ragel generated parser */
MightyPork 4:294e8f53ebcd 323
MightyPork 4:294e8f53ebcd 324 /**
MightyPork 4:294e8f53ebcd 325 * \brief Linear ANSI chars stream parser (Rage generated)
MightyPork 4:294e8f53ebcd 326 *
MightyPork 4:294e8f53ebcd 327 * Parses a stream of bytes using a Ragel parser. The defined
MightyPork 4:294e8f53ebcd 328 * grammar does not use 'unget', so the entire buffer is
MightyPork 4:294e8f53ebcd 329 * always processed in a linear manner.
MightyPork 4:294e8f53ebcd 330 *
MightyPork 4:294e8f53ebcd 331 * \attention -> but always check the Ragel output for 'p--'
MightyPork 4:294e8f53ebcd 332 * or 'p -=', that means trouble.
MightyPork 4:294e8f53ebcd 333 *
MightyPork 4:294e8f53ebcd 334 * \param newdata - array of new chars to process
MightyPork 4:294e8f53ebcd 335 * \param len - length of the newdata buffer
MightyPork 4:294e8f53ebcd 336 */
MightyPork 4:294e8f53ebcd 337 void ESPTerm::ansi_parser(const char *newdata, size_t len)
MightyPork 4:294e8f53ebcd 338 {
MightyPork 4:294e8f53ebcd 339 if (len == 0) len = strlen(newdata);
MightyPork 4:294e8f53ebcd 340
MightyPork 4:294e8f53ebcd 341 // Load new data to Ragel vars
MightyPork 4:294e8f53ebcd 342 const char *p = newdata;
MightyPork 4:294e8f53ebcd 343 const char *eof = NULL;
MightyPork 4:294e8f53ebcd 344 const char *pe = newdata + len;
MightyPork 4:294e8f53ebcd 345
MightyPork 4:294e8f53ebcd 346 // Init Ragel on the first run
MightyPork 4:294e8f53ebcd 347 if (cs == -1) {
MightyPork 4:294e8f53ebcd 348
MightyPork 4:294e8f53ebcd 349 /* #line 77 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 350 {
MightyPork 4:294e8f53ebcd 351 cs = ansi_start;
MightyPork 4:294e8f53ebcd 352 }
MightyPork 4:294e8f53ebcd 353
MightyPork 4:294e8f53ebcd 354 /* #line 65 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 355 }
MightyPork 4:294e8f53ebcd 356
MightyPork 4:294e8f53ebcd 357 // The parser
MightyPork 4:294e8f53ebcd 358
MightyPork 4:294e8f53ebcd 359 /* #line 87 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 360 {
MightyPork 4:294e8f53ebcd 361 if ( p == pe )
MightyPork 4:294e8f53ebcd 362 goto _test_eof;
MightyPork 4:294e8f53ebcd 363 switch ( cs )
MightyPork 4:294e8f53ebcd 364 {
MightyPork 4:294e8f53ebcd 365 tr0:
MightyPork 4:294e8f53ebcd 366 /* #line 75 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 367 {
MightyPork 4:294e8f53ebcd 368 apars_handle_plainchar((*p));
MightyPork 4:294e8f53ebcd 369 }
MightyPork 4:294e8f53ebcd 370 goto st1;
MightyPork 4:294e8f53ebcd 371 st1:
MightyPork 4:294e8f53ebcd 372 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 373 goto _test_eof1;
MightyPork 4:294e8f53ebcd 374 case 1:
MightyPork 4:294e8f53ebcd 375 /* #line 103 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 376 if ( (*p) == 27 )
MightyPork 4:294e8f53ebcd 377 goto st2;
MightyPork 4:294e8f53ebcd 378 goto tr0;
MightyPork 4:294e8f53ebcd 379 st2:
MightyPork 4:294e8f53ebcd 380 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 381 goto _test_eof2;
MightyPork 4:294e8f53ebcd 382 case 2:
MightyPork 4:294e8f53ebcd 383 switch( (*p) ) {
MightyPork 4:294e8f53ebcd 384 case 91: goto tr3;
MightyPork 4:294e8f53ebcd 385 case 93: goto tr4;
MightyPork 4:294e8f53ebcd 386 }
MightyPork 4:294e8f53ebcd 387 goto tr2;
MightyPork 4:294e8f53ebcd 388 tr2:
MightyPork 4:294e8f53ebcd 389 /* #line 116 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 390 {
MightyPork 4:294e8f53ebcd 391 apars_handle_badseq();
MightyPork 4:294e8f53ebcd 392 {goto st1;}
MightyPork 4:294e8f53ebcd 393 }
MightyPork 4:294e8f53ebcd 394 // goto st0;
MightyPork 4:294e8f53ebcd 395 /* #line 123 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 396 //st0:
MightyPork 4:294e8f53ebcd 397 //cs = 0;
MightyPork 4:294e8f53ebcd 398 // goto _out;
MightyPork 4:294e8f53ebcd 399 tr3:
MightyPork 4:294e8f53ebcd 400 /* #line 82 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 401 {
MightyPork 4:294e8f53ebcd 402 /* Reset the CSI builder */
MightyPork 4:294e8f53ebcd 403 csi_leading = csi_char = 0;
MightyPork 4:294e8f53ebcd 404 csi_ni = 0;
MightyPork 4:294e8f53ebcd 405
MightyPork 4:294e8f53ebcd 406 /* Zero out digits */
MightyPork 4:294e8f53ebcd 407 for(int i = 0; i < CSI_N_MAX; i++) {
MightyPork 4:294e8f53ebcd 408 csi_n[i] = 0;
MightyPork 4:294e8f53ebcd 409 }
MightyPork 4:294e8f53ebcd 410
MightyPork 4:294e8f53ebcd 411 {goto st3;}
MightyPork 4:294e8f53ebcd 412 }
MightyPork 4:294e8f53ebcd 413 //goto st7;
MightyPork 4:294e8f53ebcd 414 tr4:
MightyPork 4:294e8f53ebcd 415 /* #line 129 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 416 {
MightyPork 4:294e8f53ebcd 417 /* Reset the OSC buffer */
MightyPork 4:294e8f53ebcd 418 osc_i = 0;
MightyPork 4:294e8f53ebcd 419 {goto st5;}
MightyPork 4:294e8f53ebcd 420 }
MightyPork 4:294e8f53ebcd 421 //goto st7;
MightyPork 4:294e8f53ebcd 422 //st7:
MightyPork 4:294e8f53ebcd 423 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 424 // goto _test_eof7;
MightyPork 4:294e8f53ebcd 425 case 7:
MightyPork 4:294e8f53ebcd 426 /* #line 154 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 427 if ( (*p) == 27 )
MightyPork 4:294e8f53ebcd 428 goto st2;
MightyPork 4:294e8f53ebcd 429 goto tr0;
MightyPork 4:294e8f53ebcd 430 st3:
MightyPork 4:294e8f53ebcd 431 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 432 goto _test_eof3;
MightyPork 4:294e8f53ebcd 433 case 3:
MightyPork 4:294e8f53ebcd 434 if ( (*p) == 59 )
MightyPork 4:294e8f53ebcd 435 goto tr7;
MightyPork 4:294e8f53ebcd 436 if ( (*p) < 60 ) {
MightyPork 4:294e8f53ebcd 437 if ( (*p) > 47 ) {
MightyPork 4:294e8f53ebcd 438 if ( 48 <= (*p) && (*p) <= 57 )
MightyPork 4:294e8f53ebcd 439 goto tr6;
MightyPork 4:294e8f53ebcd 440 } else if ( (*p) >= 32 )
MightyPork 4:294e8f53ebcd 441 goto tr5;
MightyPork 4:294e8f53ebcd 442 } else if ( (*p) > 64 ) {
MightyPork 4:294e8f53ebcd 443 if ( (*p) > 90 ) {
MightyPork 4:294e8f53ebcd 444 if ( 97 <= (*p) && (*p) <= 122 )
MightyPork 4:294e8f53ebcd 445 goto tr8;
MightyPork 4:294e8f53ebcd 446 } else if ( (*p) >= 65 )
MightyPork 4:294e8f53ebcd 447 goto tr8;
MightyPork 4:294e8f53ebcd 448 } else
MightyPork 4:294e8f53ebcd 449 goto tr5;
MightyPork 4:294e8f53ebcd 450 goto tr2;
MightyPork 4:294e8f53ebcd 451 tr5:
MightyPork 4:294e8f53ebcd 452 /* #line 95 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 453 {
MightyPork 4:294e8f53ebcd 454 csi_leading = (*p);
MightyPork 4:294e8f53ebcd 455 }
MightyPork 4:294e8f53ebcd 456 goto st4;
MightyPork 4:294e8f53ebcd 457 tr6:
MightyPork 4:294e8f53ebcd 458 /* #line 99 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 459 {
MightyPork 4:294e8f53ebcd 460 /* x10 + digit */
MightyPork 4:294e8f53ebcd 461 if (csi_ni < CSI_N_MAX) {
MightyPork 4:294e8f53ebcd 462 csi_n[csi_ni] = csi_n[csi_ni]*10 + ((*p) - '0');
MightyPork 4:294e8f53ebcd 463 }
MightyPork 4:294e8f53ebcd 464 }
MightyPork 4:294e8f53ebcd 465 goto st4;
MightyPork 4:294e8f53ebcd 466 tr7:
MightyPork 4:294e8f53ebcd 467 /* #line 106 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 468 {
MightyPork 4:294e8f53ebcd 469 csi_ni++;
MightyPork 4:294e8f53ebcd 470 }
MightyPork 4:294e8f53ebcd 471 goto st4;
MightyPork 4:294e8f53ebcd 472 st4:
MightyPork 4:294e8f53ebcd 473 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 474 goto _test_eof4;
MightyPork 4:294e8f53ebcd 475 case 4:
MightyPork 4:294e8f53ebcd 476 /* #line 204 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 477 if ( (*p) == 59 )
MightyPork 4:294e8f53ebcd 478 goto tr7;
MightyPork 4:294e8f53ebcd 479 if ( (*p) < 65 ) {
MightyPork 4:294e8f53ebcd 480 if ( 48 <= (*p) && (*p) <= 57 )
MightyPork 4:294e8f53ebcd 481 goto tr6;
MightyPork 4:294e8f53ebcd 482 } else if ( (*p) > 90 ) {
MightyPork 4:294e8f53ebcd 483 if ( 97 <= (*p) && (*p) <= 122 )
MightyPork 4:294e8f53ebcd 484 goto tr8;
MightyPork 4:294e8f53ebcd 485 } else
MightyPork 4:294e8f53ebcd 486 goto tr8;
MightyPork 4:294e8f53ebcd 487 goto tr2;
MightyPork 4:294e8f53ebcd 488 tr8:
MightyPork 4:294e8f53ebcd 489 /* #line 110 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 490 {
MightyPork 4:294e8f53ebcd 491 csi_char = (*p);
MightyPork 4:294e8f53ebcd 492 apars_handle_csi(csi_leading, csi_n, csi_char);
MightyPork 4:294e8f53ebcd 493 {goto st1;}
MightyPork 4:294e8f53ebcd 494 }
MightyPork 4:294e8f53ebcd 495 // goto st8;
MightyPork 4:294e8f53ebcd 496 //st8:
MightyPork 4:294e8f53ebcd 497 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 498 // goto _test_eof8;
MightyPork 4:294e8f53ebcd 499 case 8:
MightyPork 4:294e8f53ebcd 500 /* #line 228 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 501 goto tr2;
MightyPork 4:294e8f53ebcd 502 tr9:
MightyPork 4:294e8f53ebcd 503 /* #line 135 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 504 {
MightyPork 4:294e8f53ebcd 505 if (osc_i < OSC_BUF_LEN-1) {
MightyPork 4:294e8f53ebcd 506 osc_buff[osc_i++] = (*p);
MightyPork 4:294e8f53ebcd 507 }
MightyPork 4:294e8f53ebcd 508 }
MightyPork 4:294e8f53ebcd 509 goto st5;
MightyPork 4:294e8f53ebcd 510 st5:
MightyPork 4:294e8f53ebcd 511 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 512 goto _test_eof5;
MightyPork 4:294e8f53ebcd 513 case 5:
MightyPork 4:294e8f53ebcd 514 /* #line 242 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 515 switch( (*p) ) {
MightyPork 4:294e8f53ebcd 516 case 7: goto tr10;
MightyPork 4:294e8f53ebcd 517 case 27: goto st6;
MightyPork 4:294e8f53ebcd 518 }
MightyPork 4:294e8f53ebcd 519 goto tr9;
MightyPork 4:294e8f53ebcd 520 tr10:
MightyPork 4:294e8f53ebcd 521 /* #line 141 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 522 {
MightyPork 4:294e8f53ebcd 523 /** Terminate the buffer */
MightyPork 4:294e8f53ebcd 524 osc_buff[osc_i] = '\0';
MightyPork 4:294e8f53ebcd 525 apars_handle_osc(osc_buff);
MightyPork 4:294e8f53ebcd 526
MightyPork 4:294e8f53ebcd 527 {goto st1;}
MightyPork 4:294e8f53ebcd 528 }
MightyPork 4:294e8f53ebcd 529 // goto st9;
MightyPork 4:294e8f53ebcd 530 //st9:
MightyPork 4:294e8f53ebcd 531 // if ( ++p == pe )
MightyPork 4:294e8f53ebcd 532 // goto _test_eof9;
MightyPork 4:294e8f53ebcd 533 case 9:
MightyPork 4:294e8f53ebcd 534 /* #line 262 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 535 goto tr2;
MightyPork 4:294e8f53ebcd 536 st6:
MightyPork 4:294e8f53ebcd 537 if ( ++p == pe )
MightyPork 4:294e8f53ebcd 538 goto _test_eof6;
MightyPork 4:294e8f53ebcd 539 case 6:
MightyPork 4:294e8f53ebcd 540 if ( (*p) == 92 )
MightyPork 4:294e8f53ebcd 541 goto tr10;
MightyPork 4:294e8f53ebcd 542 goto tr2;
MightyPork 4:294e8f53ebcd 543 }
MightyPork 4:294e8f53ebcd 544 _test_eof1: cs = 1; goto _test_eof;
MightyPork 4:294e8f53ebcd 545 _test_eof2: cs = 2; goto _test_eof;
MightyPork 4:294e8f53ebcd 546 //_test_eof7: cs = 7; goto _test_eof;
MightyPork 4:294e8f53ebcd 547 _test_eof3: cs = 3; goto _test_eof;
MightyPork 4:294e8f53ebcd 548 _test_eof4: cs = 4; goto _test_eof;
MightyPork 4:294e8f53ebcd 549 //_test_eof8: cs = 8; goto _test_eof;
MightyPork 4:294e8f53ebcd 550 _test_eof5: cs = 5; goto _test_eof;
MightyPork 4:294e8f53ebcd 551 //_test_eof9: cs = 9; goto _test_eof;
MightyPork 4:294e8f53ebcd 552 _test_eof6: cs = 6; goto _test_eof;
MightyPork 4:294e8f53ebcd 553
MightyPork 4:294e8f53ebcd 554 _test_eof: {}
MightyPork 4:294e8f53ebcd 555 if ( p == eof )
MightyPork 4:294e8f53ebcd 556 {
MightyPork 4:294e8f53ebcd 557 switch ( cs ) {
MightyPork 4:294e8f53ebcd 558 case 1:
MightyPork 4:294e8f53ebcd 559 case 2:
MightyPork 4:294e8f53ebcd 560 case 3:
MightyPork 4:294e8f53ebcd 561 case 4:
MightyPork 4:294e8f53ebcd 562 case 5:
MightyPork 4:294e8f53ebcd 563 case 6:
MightyPork 4:294e8f53ebcd 564 /* #line 116 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 565 {
MightyPork 4:294e8f53ebcd 566 apars_handle_badseq();
MightyPork 4:294e8f53ebcd 567 {goto st1;}
MightyPork 4:294e8f53ebcd 568 }
MightyPork 4:294e8f53ebcd 569 // break;
MightyPork 4:294e8f53ebcd 570 /* #line 298 "ansi_parser_cpp.c" */
MightyPork 4:294e8f53ebcd 571 }
MightyPork 4:294e8f53ebcd 572 }
MightyPork 4:294e8f53ebcd 573
MightyPork 4:294e8f53ebcd 574 //_out: {}
MightyPork 4:294e8f53ebcd 575 }
MightyPork 4:294e8f53ebcd 576
MightyPork 4:294e8f53ebcd 577 /* #line 162 "ansi_parser_cpp.rl" */
MightyPork 4:294e8f53ebcd 578
MightyPork 4:294e8f53ebcd 579 }
MightyPork 4:294e8f53ebcd 580
MightyPork 4:294e8f53ebcd 581
MightyPork 4:294e8f53ebcd 582
MightyPork 4:294e8f53ebcd 583
MightyPork 4:294e8f53ebcd 584
MightyPork 4:294e8f53ebcd 585
MightyPork 4:294e8f53ebcd 586
MightyPork 4:294e8f53ebcd 587
MightyPork 4:294e8f53ebcd 588
MightyPork 4:294e8f53ebcd 589
MightyPork 4:294e8f53ebcd 590
MightyPork 4:294e8f53ebcd 591
MightyPork 4:294e8f53ebcd 592
MightyPork 4:294e8f53ebcd 593
MightyPork 4:294e8f53ebcd 594
MightyPork 4:294e8f53ebcd 595
MightyPork 4:294e8f53ebcd 596
MightyPork 4:294e8f53ebcd 597
MightyPork 4:294e8f53ebcd 598
MightyPork 4:294e8f53ebcd 599