-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.c
163 lines (157 loc) · 5.42 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
console.c
Copyright (c) 2018 Bastiaan van Kesteren <bas@edeation.nl>
This program comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
/*!
\file
Simple line console
*/
#include "console.h"
#include "fgui.h"
#include "fgui/hw/ws2812.h"
#include "io.h"
#include <string.h>
void console_incoming(unsigned char c)
{
static unsigned char commandlength=0;
static char command[50];
static char seenReturn = FALSE;
if(c == 0x0D && seenReturn == FALSE) {
seenReturn = TRUE;
return;
}
if(seenReturn && c == 0x0A) {
/* End-of-command. Figure out what it is */
if(commandlength >= 1) {
switch(command[0]) {
/* X = horizontal, y = vertical
*/
case 's':
/* s - get size of display */
dprint("%2d%2d!", FGUI_SCR_W, FGUI_SCR_H);
break;
case 'e':
/* e - Empty display */
fgui_clear();
dprint("!");
break;
case 'c':
/* cRGBRGB - set foreground and background color (both rgb values, 8 bit/color) */
if(commandlength == 7) {
ws2812_setcolors(command[1], command[2], command[3], command[4], command[5], command[6]);
dprint("!");
}
else {
dprint("?");
}
break;
case 'p':
/* pXYn - set pixel at x/y to 0 or 1 */
if(commandlength == 4 && command[3] == 0) {
fgui_pixeloff(command[1], command[2]);
dprint("!");
}
else if(commandlength == 4 && command[3] == 1) {
fgui_pixelon(command[1], command[2]);
dprint("!");
}
else {
dprint("?");
}
break;
case 'd':
/* * dn - set pixel-value to draw with from now on (0 or 1), existing pixels remain as-is */
if(commandlength == 2 && command[1] == '0') {
fgui_setcolor(FGUI_WHITE);
dprint("!");
}
else if(commandlength == 2 && command[1] == '1') {
fgui_setcolor(FGUI_BLACK);
dprint("!");
}
else {
dprint("?");
}
break;
case 'h':
/* hXYL - draw horizontal line starting at x/y with length l */
if(commandlength == 4) {
fgui_lineh(command[1], command[2], command[3]);
dprint("!");
}
else {
dprint("?");
}
break;
case 'v':
/* vXYL - draw vertical line starting at x/y with length l */
if(commandlength == 4) {
fgui_linev(command[1], command[2], command[3]);
dprint("!");
}
else {
dprint("?");
}
break;
case 'l':
/* lXYXY - draw line from x/y to x/y */
if(commandlength == 5) {
fgui_line(command[1], command[2], command[3], command[4]);
dprint("!");
}
else {
dprint("?");
}
break;
case 't':
/* TXYn - text at location x/y */
if(commandlength >= 4) {
fgui_text(command[1], command[2], &command[3]);
dprint("!");
}
else {
dprint("?");
}
break;
case 'i':
/* iXYn - image at location x/y */
if(commandlength >= 4) {
}
else {
dprint("?");
}
break;
case 'u':
/* u - update display */
rts_off();
fgui_refresh();
rts_on();
dprint("!");
break;
case 'r':
RESET();
break;
default:
printf("?");
break;
}
}
else {
printf("?");
}
commandlength = 0;
}
else if(commandlength == sizeof(command)) {
printf("?");
commandlength = 0;
}
else {
command[commandlength] = c;
commandlength++;
}
seenReturn = FALSE;
}