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

Committer:
MightyPork
Date:
Sun Mar 19 10:34:48 2017 +0000
Revision:
3:1114012184bf
Parent:
2:f9f27e2b64a7
Child:
4:294e8f53ebcd
some code cleaning

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 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 1:09dfc9fd55f4 13
MightyPork 1:09dfc9fd55f4 14
MightyPork 1:09dfc9fd55f4 15 /**
MightyPork 1:09dfc9fd55f4 16 * ESP8266 Wireless Terminal interface
MightyPork 0:20fb68233f89 17 *
MightyPork 1:09dfc9fd55f4 18 * Can also be used for sending ANSI sequences to a regular serial terminal
MightyPork 0:20fb68233f89 19 */
MightyPork 1:09dfc9fd55f4 20 class ESPTerm
MightyPork 1:09dfc9fd55f4 21 {
MightyPork 0:20fb68233f89 22 Serial* ser;
MightyPork 0:20fb68233f89 23
MightyPork 0:20fb68233f89 24 public:
MightyPork 3:1114012184bf 25 /**
MightyPork 3:1114012184bf 26 * ANSI colors supported by the ESP Terminal
MightyPork 3:1114012184bf 27 */
MightyPork 3:1114012184bf 28 enum Color {
MightyPork 3:1114012184bf 29 BLACK = 0, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, GRAY_LT,
MightyPork 3:1114012184bf 30 GRAY, RED_LT, GREEN_LT, YELLOW_LT, BLUE_LT, PURPLE_LT, CYAN_LT, WHITE,
MightyPork 3:1114012184bf 31
MightyPork 3:1114012184bf 32 // aliases
MightyPork 3:1114012184bf 33 RED_DK=1, GREEN_DK=2, YELLOW_DK=3, BLUE_DK=4, PURPLE_DK=5, CYAN_DK=6, SILVER=7,
MightyPork 3:1114012184bf 34 };
MightyPork 3:1114012184bf 35
MightyPork 3:1114012184bf 36
MightyPork 3:1114012184bf 37 /**
MightyPork 3:1114012184bf 38 * Argument for screen or line clear commands
MightyPork 3:1114012184bf 39 */
MightyPork 3:1114012184bf 40 enum ClearMode {
MightyPork 3:1114012184bf 41 CLEAR_TO_CURSOR = 0,
MightyPork 3:1114012184bf 42 CLEAR_FROM_CURSOR = 1,
MightyPork 3:1114012184bf 43 CLEAR_ALL = 2,
MightyPork 3:1114012184bf 44 };
MightyPork 3:1114012184bf 45
MightyPork 3:1114012184bf 46
MightyPork 0:20fb68233f89 47 /**
MightyPork 1:09dfc9fd55f4 48 * @brief Create a terminal instance from already initialized serial port
MightyPork 0:20fb68233f89 49 *
MightyPork 0:20fb68233f89 50 * Example:
MightyPork 3:1114012184bf 51 * Serial ser(PA_2, PA_3, 115200); // eg. for STM32F042
MightyPork 0:20fb68233f89 52 * ESPTerm term(&ser);
MightyPork 0:20fb68233f89 53 */
MightyPork 0:20fb68233f89 54 ESPTerm(Serial *s);
MightyPork 1:09dfc9fd55f4 55
MightyPork 1:09dfc9fd55f4 56
MightyPork 1:09dfc9fd55f4 57 /**
MightyPork 1:09dfc9fd55f4 58 * @brief Create with Serial at (PA_2, PA_3, 115200)
MightyPork 1:09dfc9fd55f4 59 */
MightyPork 1:09dfc9fd55f4 60 ESPTerm(void);
MightyPork 1:09dfc9fd55f4 61
MightyPork 1:09dfc9fd55f4 62
MightyPork 1:09dfc9fd55f4 63 /**
MightyPork 1:09dfc9fd55f4 64 * @brief printf() over the Serial
MightyPork 1:09dfc9fd55f4 65 *
MightyPork 1:09dfc9fd55f4 66 * Use for raw strings without formatting, or with custom escape sequences.
MightyPork 1:09dfc9fd55f4 67 */
MightyPork 1:09dfc9fd55f4 68 int printf(const char *fmt, ...);
MightyPork 1:09dfc9fd55f4 69
MightyPork 1:09dfc9fd55f4 70
MightyPork 1:09dfc9fd55f4 71 /**
MightyPork 1:09dfc9fd55f4 72 * @brief Alias for printf()
MightyPork 1:09dfc9fd55f4 73 */
MightyPork 1:09dfc9fd55f4 74 int print(const char *fmt, ...);
MightyPork 1:09dfc9fd55f4 75
MightyPork 1:09dfc9fd55f4 76
MightyPork 1:09dfc9fd55f4 77 /**
MightyPork 3:1114012184bf 78 * @brief Print with no args
MightyPork 3:1114012184bf 79 */
MightyPork 3:1114012184bf 80 int puts(const char *str);
MightyPork 3:1114012184bf 81
MightyPork 3:1114012184bf 82
MightyPork 3:1114012184bf 83 /**
MightyPork 2:f9f27e2b64a7 84 * printf() over the Serial, followed by a newline (\\r\\n)
MightyPork 1:09dfc9fd55f4 85 *
MightyPork 1:09dfc9fd55f4 86 * Use for raw strings without formatting, or with custom escape sequences.
MightyPork 1:09dfc9fd55f4 87 * Especially useful for log messages, automatically terminating the line.
MightyPork 1:09dfc9fd55f4 88 */
MightyPork 1:09dfc9fd55f4 89 int println(const char *fmt, ...);
MightyPork 1:09dfc9fd55f4 90
MightyPork 1:09dfc9fd55f4 91
MightyPork 1:09dfc9fd55f4 92 /**
MightyPork 1:09dfc9fd55f4 93 * @brief Set foreground text color
MightyPork 1:09dfc9fd55f4 94 * @param c - color
MightyPork 1:09dfc9fd55f4 95 */
MightyPork 3:1114012184bf 96 void fg(Color c);
MightyPork 1:09dfc9fd55f4 97
MightyPork 1:09dfc9fd55f4 98
MightyPork 1:09dfc9fd55f4 99 /**
MightyPork 1:09dfc9fd55f4 100 * @brief Set background text color
MightyPork 1:09dfc9fd55f4 101 * @param c - color
MightyPork 1:09dfc9fd55f4 102 */
MightyPork 3:1114012184bf 103 void bg(Color c);
MightyPork 1:09dfc9fd55f4 104
MightyPork 1:09dfc9fd55f4 105
MightyPork 1:09dfc9fd55f4 106 /**
MightyPork 1:09dfc9fd55f4 107 * @brief Set both text colors
MightyPork 1:09dfc9fd55f4 108 * @param fg - foregorund color
MightyPork 1:09dfc9fd55f4 109 * @param bg - background color
MightyPork 1:09dfc9fd55f4 110 */
MightyPork 3:1114012184bf 111 void colors(Color fg, Color bg);
MightyPork 1:09dfc9fd55f4 112
MightyPork 1:09dfc9fd55f4 113
MightyPork 1:09dfc9fd55f4 114 /**
MightyPork 2:f9f27e2b64a7 115 * @brief Send \\e[0m - reset all attributes
MightyPork 1:09dfc9fd55f4 116 */
MightyPork 1:09dfc9fd55f4 117 void reset_attribs(void);
MightyPork 1:09dfc9fd55f4 118
MightyPork 1:09dfc9fd55f4 119
MightyPork 1:09dfc9fd55f4 120 /**
MightyPork 1:09dfc9fd55f4 121 * @brief Reset all attributes (alias)
MightyPork 1:09dfc9fd55f4 122 */
MightyPork 1:09dfc9fd55f4 123 void rst(void);
MightyPork 1:09dfc9fd55f4 124
MightyPork 1:09dfc9fd55f4 125
MightyPork 1:09dfc9fd55f4 126 /**
MightyPork 1:09dfc9fd55f4 127 * @brief Move cursor to a given position
MightyPork 1:09dfc9fd55f4 128 *
MightyPork 1:09dfc9fd55f4 129 * Screen coordinates are 1-based, starting left-top,
MightyPork 1:09dfc9fd55f4 130 * growing down and right.
MightyPork 1:09dfc9fd55f4 131 *
MightyPork 1:09dfc9fd55f4 132 * @param y - row
MightyPork 1:09dfc9fd55f4 133 * @param x - column
MightyPork 1:09dfc9fd55f4 134 */
MightyPork 1:09dfc9fd55f4 135 void go_to(int y, int x);
MightyPork 1:09dfc9fd55f4 136
MightyPork 1:09dfc9fd55f4 137
MightyPork 1:09dfc9fd55f4 138 /**
MightyPork 1:09dfc9fd55f4 139 * @brief Clear screen
MightyPork 1:09dfc9fd55f4 140 *
MightyPork 1:09dfc9fd55f4 141 * Replace part of the screen with spaces (ASCII 32) of the currently
MightyPork 1:09dfc9fd55f4 142 * selected foregorund and background colors.
MightyPork 1:09dfc9fd55f4 143 *
MightyPork 1:09dfc9fd55f4 144 * @param mode - what to clear: part or all
MightyPork 1:09dfc9fd55f4 145 */
MightyPork 1:09dfc9fd55f4 146 void clear_screen(ClearMode mode);
MightyPork 1:09dfc9fd55f4 147
MightyPork 1:09dfc9fd55f4 148
MightyPork 1:09dfc9fd55f4 149 /**
MightyPork 1:09dfc9fd55f4 150 * @brief Clear in line
MightyPork 1:09dfc9fd55f4 151 *
MightyPork 1:09dfc9fd55f4 152 * Replace part of the current line with spaces (ASCII 32) of the
MightyPork 1:09dfc9fd55f4 153 * currently selected foregorund and background colors.
MightyPork 1:09dfc9fd55f4 154 *
MightyPork 1:09dfc9fd55f4 155 * @param mode - what to clear: part or all
MightyPork 1:09dfc9fd55f4 156 */
MightyPork 1:09dfc9fd55f4 157 void clear_line(ClearMode mode);
MightyPork 1:09dfc9fd55f4 158
MightyPork 1:09dfc9fd55f4 159
MightyPork 1:09dfc9fd55f4 160 /**
MightyPork 1:09dfc9fd55f4 161 * @brief Clear the whole screen and move cursor to 1,1
MightyPork 1:09dfc9fd55f4 162 */
MightyPork 1:09dfc9fd55f4 163 void screen_reset(void);
MightyPork 1:09dfc9fd55f4 164
MightyPork 1:09dfc9fd55f4 165
MightyPork 1:09dfc9fd55f4 166 /**
MightyPork 1:09dfc9fd55f4 167 * @brief Set cursor visibility
MightyPork 1:09dfc9fd55f4 168 *
MightyPork 1:09dfc9fd55f4 169 * If hidden, there will be no blinking square on the screen,
MightyPork 1:09dfc9fd55f4 170 * but the cursor still works (ie. go_to works).
MightyPork 1:09dfc9fd55f4 171 *
MightyPork 1:09dfc9fd55f4 172 * Hiding the cursor is useful for ASCII-art GUIs (dialog boxes etc)
MightyPork 1:09dfc9fd55f4 173 */
MightyPork 1:09dfc9fd55f4 174 void show_cursor(bool yes);
MightyPork 1:09dfc9fd55f4 175
MightyPork 1:09dfc9fd55f4 176
MightyPork 1:09dfc9fd55f4 177 /**
MightyPork 1:09dfc9fd55f4 178 * @brief Perform a factory reset of the ESP Terminal
MightyPork 1:09dfc9fd55f4 179 *
MightyPork 1:09dfc9fd55f4 180 * This clears any saved WiFi config, restores the default AP name
MightyPork 1:09dfc9fd55f4 181 * and switches to AP mode. The module will reset itself.
MightyPork 1:09dfc9fd55f4 182 *
MightyPork 1:09dfc9fd55f4 183 * Expect some ASCII output from the module (and a burst of garbage
MightyPork 1:09dfc9fd55f4 184 * during the reset).
MightyPork 1:09dfc9fd55f4 185 */
MightyPork 1:09dfc9fd55f4 186 void factory_reset(void);
MightyPork 1:09dfc9fd55f4 187
MightyPork 1:09dfc9fd55f4 188
MightyPork 1:09dfc9fd55f4 189 /**
MightyPork 1:09dfc9fd55f4 190 * @brief Set screen size
MightyPork 1:09dfc9fd55f4 191 *
MightyPork 1:09dfc9fd55f4 192 * The total number of characters (rows*cols) is limited by the Terminal
MightyPork 1:09dfc9fd55f4 193 * firmware, at v0.5.2 that is 2000 characters (25x80)
MightyPork 1:09dfc9fd55f4 194 *
MightyPork 1:09dfc9fd55f4 195 * @param rows - number of rows (screen height)
MightyPork 1:09dfc9fd55f4 196 * @param cols - number of columns (screen width)
MightyPork 1:09dfc9fd55f4 197 */
MightyPork 1:09dfc9fd55f4 198 void set_screen_size(int rows, int cols);
MightyPork 0:20fb68233f89 199 };
MightyPork 0:20fb68233f89 200
MightyPork 3:1114012184bf 201
MightyPork 3:1114012184bf 202 /** Convenience alias for using class enums etc */
MightyPork 3:1114012184bf 203 typedef ESPTerm VT;
MightyPork 3:1114012184bf 204
MightyPork 0:20fb68233f89 205 #endif /* ESPTERM_H */