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

Committer:
MightyPork
Date:
Mon Mar 06 22:32:37 2017 +0000
Revision:
2:f9f27e2b64a7
Parent:
1:09dfc9fd55f4
Child:
3:1114012184bf
comments

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