HomeAut
escapesequence.h
1 /*
2  * escapesequence.h
3  *
4  * Created on: 2016. nov. 29.
5  * Author: Vizi Gábor
6  * E-mail: vizi.gabor90@gmail.com
7  * Function: -
8  * Target: STM32Fx
9  * Version: -
10  * Last modified: 2016. nov. 29.
11  */
12 
13 #ifndef ESCAPESEQUENCE_H_
14 #define ESCAPESEQUENCE_H_
15 
16 
17 /*------------------------------------------------------------------------------
18  * Macros & definitions
19  *----------------------------------------------------------------------------*/
20 
21 // ESCAPE SEQUENCE
22 
23 
24 // 27 = ESCAPE
25 // 91 = [
26 
27 // Delete the line
28 // CSI n K EL – Erase in Line Erases part of the line.
29 // If n is zero (or missing), clear from cursor to the end of the line.
30 // If n is one, clear from cursor to beginning of the line.
31 // If n is two, clear entire line. Cursor position does not change.
32 
33 
34 // CSI 2 K: delete entire line
35 #define ESCAPE_DELETELINE \
36  ("\x1B" "[2K")
37 
38 
39 // CSI n G CHA – Cursor Horizontal Absolute Moves the cursor to column n.
40 // CSI 1 G -> go start of line
41 #define ESCAPE_CURSOR_TO_LINESTART \
42  ("\x1B" "[1G")
43 
44 
45 // CSI n A CUU – Cursor Up Moves the cursor n (default 1) cells in the given direction.
46 // If the cursor is already at the edge of the screen, this has no effect.
47 // CSI n B CUD – Cursor Down
48 // CSI n C CUF – Cursor Forward
49 // CSI n D CUB – Cursor Back
50 #define ESCAPE_CURSORRIGHT \
51  ("\x1B" "[C")
52 
53 
54 // Cursor step left
55 #define ESCAPE_CURSORLEFT \
56  ("\x1B" "[D")
57 
58 
59 // Cursor go left (loft of step)
60 #define ESCAPE_CURSORLEFTLOTOF \
61  ("\x1B" "[100D")
62 
63 
64 // CURSOR SAVE/RESTORE
65 //CSI s SCP – Save Cursor Position Saves the cursor position.
66 #define ESCAPE_SAVECURSOR \
67  ("\x1B" "[s")
68 
69 
70 //CSI u RCP – Restore Cursor Position Restores the cursor position.
71 #define ESCAPE_RESTORECURSOR \
72  ("\x1B" "[u")
73 
74 
75 // Erase Functions:
76 // (CSI in UTF-8 is 0xC2, 0x9B) = ESC+[
77 // ESC[2J Clear screen and home cursor
78 #define ESCAPE_ERASE_CLS \
79  ("\x1B" "[2J")
80 
81 
82 // Goto top left corner
83 // CSI n ; m H CUP – Cursor Position Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted.
84 // A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
85 // n = 1 = row
86 // ;
87 // 1 = column
88 // H
89 #define ESCAPE_CURSOR_TOPLEFT \
90  ("\x1B" "[1;1H")
91 
92 
94 // ESCAPE SEQUENCE - COLORS
96 
97 // CSI n m SGR – Select Graphic Rendition
98 // 40–47 Set background color 40 + x, where x is from the color table below
99 #define ESCAPE_BACKGROUND_GREEN \
100  ("\x1B" "[42m")
101 
102 #define ESCAPE_BACKGROUND_RED \
103  ("\x1B" "[41m")
104 
105 #define ESCAPE_BACKGROUND_WHITE \
106  ("\x1B" "[47m")
107 
108 #define ESCAPE_TEXT_BLACK \
109  ("\x1B" "[30m")
110 
111 
112 // NOTE: Not work in Hyperterminal
113 #define ESCAPE_BACKGROUND_DEFAULT \
114  ("\x1B" "[49m")
115 
116 
117 // NOTE: At Hyperterminal the background will be black
118 #define ESCAPE_RESET \
119  ("\x1B" "[0m")
120 
121 
122 
123 // TODO: Sortörlésre?
124 // CSI n D CUB – Cursor Back
125 // CSI n K EL – Erase in Line Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line.
126 // PROBLEM: this is delete everything after cursor
127 /*
128 // Cursor back
129 USART_SendChar(27); // 27 = ESCAPE
130 USART_SendChar(91); // 91 = [
131 USART_SendChar('1');
132 USART_SendChar('D');
133 
134 // Delete from cursor to end of line
135 USART_SendChar(27); // 27 = ESCAPE
136 USART_SendChar(91); // 91 = [
137 USART_SendChar('0');
138 USART_SendChar('K');
139 */
140 
141 
142 
143 #define ESCAPE_SEND_CLS \
144  ESCAPE_ERASE_CLS \
145  ESCAPE_CURSOR_TOPLEFT
146 
147 
148 
149 
150 
151 
152 #endif /* ESCAPESEQUENCE_H_ */