source: azure_iot_hub/trunk/ntshell/ntshell/core/vtsend.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 5.6 KB
Line 
1/**
2 * @file vtsend.c
3 * @author CuBeatSystems
4 * @author Shinichiro Nakamura
5 * @copyright
6 * ===============================================================
7 * Natural Tiny Shell (NT-Shell) Version 0.3.1
8 * ===============================================================
9 * Copyright (c) 2010-2016 Shinichiro Nakamura
10 *
11 * Permission is hereby granted, free of charge, to any person
12 * obtaining a copy of this software and associated documentation
13 * files (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use,
15 * copy, modify, merge, publish, distribute, sublicense, and/or
16 * sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following
18 * conditions:
19 *
20 * The above copyright notice and this permission notice shall be
21 * included in all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33#include "vtsend.h"
34
35#define ESC (0x1B)
36#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj)
37
38int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj)
39{
40 p->uart_write = uart_write;
41 p->extobj = extobj;
42 return 0;
43}
44
45int vtsend_cursor_position(vtsend_t *p, const int column, const int line)
46{
47 char buf[8];
48 buf[0] = ESC;
49 buf[1] = '[';
50 buf[2] = '0' + (line / 10);
51 buf[3] = '0' + (line % 10);
52 buf[4] = ';';
53 buf[5] = '0' + (column / 10);
54 buf[6] = '0' + (column % 10);
55 buf[7] = 'H';
56 UART_WRITE(p, buf, sizeof(buf));
57 return 0;
58}
59
60int vtsend_cursor_up(vtsend_t *p, const int n)
61{
62 char buf[5];
63 buf[0] = ESC;
64 buf[1] = '[';
65 buf[2] = '0' + (n / 10);
66 buf[3] = '0' + (n % 10);
67 buf[4] = 'A';
68 UART_WRITE(p, buf, sizeof(buf));
69 return 0;
70}
71
72int vtsend_cursor_down(vtsend_t *p, const int n)
73{
74 char buf[5];
75 buf[0] = ESC;
76 buf[1] = '[';
77 buf[2] = '0' + (n / 10);
78 buf[3] = '0' + (n % 10);
79 buf[4] = 'B';
80 UART_WRITE(p, buf, sizeof(buf));
81 return 0;
82}
83
84int vtsend_cursor_forward(vtsend_t *p, const int n)
85{
86 char buf[5];
87 buf[0] = ESC;
88 buf[1] = '[';
89 buf[2] = '0' + (n / 10);
90 buf[3] = '0' + (n % 10);
91 buf[4] = 'C';
92 UART_WRITE(p, buf, sizeof(buf));
93 return 0;
94}
95
96int vtsend_cursor_backward(vtsend_t *p, const int n)
97{
98 char buf[5];
99 buf[0] = ESC;
100 buf[1] = '[';
101 buf[2] = '0' + (n / 10);
102 buf[3] = '0' + (n % 10);
103 buf[4] = 'D';
104 UART_WRITE(p, buf, sizeof(buf));
105 return 0;
106}
107
108int vtsend_cursor_position_save(vtsend_t *p)
109{
110 char buf[3];
111 buf[0] = ESC;
112 buf[1] = '[';
113 buf[2] = 's';
114 UART_WRITE(p, buf, sizeof(buf));
115 return 0;
116}
117
118int vtsend_cursor_position_restore(vtsend_t *p)
119{
120 char buf[3];
121 buf[0] = ESC;
122 buf[1] = '[';
123 buf[2] = 'u';
124 UART_WRITE(p, buf, sizeof(buf));
125 return 0;
126}
127
128int vtsend_erase_display(vtsend_t *p)
129{
130 char buf[4];
131 buf[0] = ESC;
132 buf[1] = '[';
133 buf[2] = '2';
134 buf[3] = 'J';
135 UART_WRITE(p, buf, sizeof(buf));
136 return 0;
137}
138
139int vtsend_erase_line(vtsend_t *p)
140{
141 char buf[4];
142 buf[0] = ESC;
143 buf[1] = '[';
144 buf[2] = '2';
145 buf[3] = 'K';
146 UART_WRITE(p, buf, sizeof(buf));
147 return 0;
148}
149
150int vtsend_set_color_foreground(vtsend_t *p, const int color)
151{
152 char buf[5];
153 buf[0] = ESC;
154 buf[1] = '[';
155 buf[2] = '0' + ((30 + color) / 10);
156 buf[3] = '0' + ((30 + color) % 10);
157 buf[4] = 'm';
158 UART_WRITE(p, buf, sizeof(buf));
159 return 0;
160}
161
162int vtsend_set_color_background(vtsend_t *p, const int color)
163{
164 char buf[5];
165 buf[0] = ESC;
166 buf[1] = '[';
167 buf[2] = '0' + ((40 + color) / 10);
168 buf[3] = '0' + ((40 + color) % 10);
169 buf[4] = 'm';
170 UART_WRITE(p, buf, sizeof(buf));
171 return 0;
172}
173
174int vtsend_set_attribute(vtsend_t *p, const int attr)
175{
176 char buf[5];
177 buf[0] = ESC;
178 buf[1] = '[';
179 buf[2] = '0' + ((attr) / 10);
180 buf[3] = '0' + ((attr) % 10);
181 buf[4] = 'm';
182 UART_WRITE(p, buf, sizeof(buf));
183 return 0;
184}
185
186int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom)
187{
188 char buf[8];
189 buf[0] = ESC;
190 buf[1] = '[';
191 buf[2] = '0' + (top / 10);
192 buf[3] = '0' + (top % 10);
193 buf[4] = ';';
194 buf[5] = '0' + (bottom / 10);
195 buf[6] = '0' + (bottom % 10);
196 buf[7] = 'r';
197 UART_WRITE(p, buf, sizeof(buf));
198 return 0;
199}
200
201int vtsend_set_cursor(vtsend_t *p, const int visible)
202{
203 if (visible) {
204 char buf[6];
205 buf[0] = ESC;
206 buf[1] = '[';
207 buf[2] = '?';
208 buf[3] = '2';
209 buf[4] = '5';
210 buf[5] = 'h';
211 UART_WRITE(p, buf, sizeof(buf));
212 }
213 else {
214 char buf[6];
215 buf[0] = ESC;
216 buf[1] = '[';
217 buf[2] = '?';
218 buf[3] = '2';
219 buf[4] = '5';
220 buf[5] = 'l';
221 UART_WRITE(p, buf, sizeof(buf));
222 }
223 return 0;
224}
225
226int vtsend_reset(vtsend_t *p)
227{
228 char buf[2];
229 buf[0] = ESC;
230 buf[1] = 'c';
231 UART_WRITE(p, buf, sizeof(buf));
232 return 0;
233}
234
235int vtsend_draw_box(
236 vtsend_t *p,
237 const int x1, const int y1, const int x2, const int y2)
238{
239 int i;
240
241 vtsend_cursor_position(p, x1, y1);
242 for (i = x1; i <= x2; i++) {
243 UART_WRITE(p, " ", 1);
244 }
245 vtsend_cursor_position(p, x1, y2);
246 for (i = x1; i <= x2; i++) {
247 UART_WRITE(p, " ", 1);
248 }
249 for (i = y1; i <= y2; i++) {
250 vtsend_cursor_position(p, x1, i);
251 UART_WRITE(p, " ", 1);
252 vtsend_cursor_position(p, x2, i);
253 UART_WRITE(p, " ", 1);
254 }
255 return 0;
256}
257
258int vtsend_fill_box(
259 vtsend_t *p,
260 const int x1, const int y1, const int x2, const int y2)
261{
262 int i, j;
263 for (i = y1; i <= y2; i++) {
264 vtsend_cursor_position(p, x1, i);
265 for (j = x1; j <= x2; j++) {
266 UART_WRITE(p, " ", 1);
267 }
268 }
269 return 0;
270}
Note: See TracBrowser for help on using the repository browser.