comparison main.c @ 12:093bc0c3b1cc

Add delay, ellipse and line demos.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 06 Feb 2012 23:55:53 +1030
parents 58d76cf522ff
children 96c345d304af
comparison
equal deleted inserted replaced
11:ca48036c82ef 12:093bc0c3b1cc
104 int 104 int
105 main(void) { 105 main(void) {
106 char buf[40]; 106 char buf[40];
107 struct tm nowtm; 107 struct tm nowtm;
108 time_t now; 108 time_t now;
109 109 uint16_t x, y, x1, y1, z1, z2, r, c, rx, ry;
110 float t, t2;
111 char col;
112
110 cmd.state = cmd.len = 0; 113 cmd.state = cmd.len = 0;
111 114
112 /* Init hardware - configure IO ports and external peripherals */ 115 /* Init hardware - configure IO ports and external peripherals */
113 hw_init(); 116 hw_init();
114 117
126 /* Set stdout to unbuffered */ 129 /* Set stdout to unbuffered */
127 setvbuf(stdout, NULL, _IONBF, 0); 130 setvbuf(stdout, NULL, _IONBF, 0);
128 131
129 /* Say hello */ 132 /* Say hello */
130 fputs("\r\n\r\n\r\nHello world\r\n", stdout); 133 fputs("\r\n\r\n\r\nHello world\r\n", stdout);
134
135 lcd_stripes();
136
137 lcd_circle(20, 20, 20, 1, LCD_RED); /* Bottom left */
138 lcd_circle(300, 220, 20, 1, LCD_WHITE); /* Top right */
139 lcd_circle(20, 220, 20, 1, LCD_BLUE); /* Top left */
140 lcd_circle(300, 20, 20, 1, LCD_GREEN); /* Bottom right */
141
142 lcd_line(20, 20, 20, 220, LCD_BLACK);
143 lcd_line(20, 220, 300, 220, LCD_BLACK);
144 lcd_line(300, 220, 300, 20, LCD_BLACK);
145 lcd_line(300, 20, 20, 20, LCD_BLACK);
146
147 lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE);
148 lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE);
131 149
132 while (1) { 150 while (1) {
133 fputs("> ", stdout); 151 fputs("> ", stdout);
134 152
135 while (cmd.state != 255) 153 while (cmd.state != 255)
147 tv.tv_usec = 0; 165 tv.tv_usec = 0;
148 settimeofday(&tv, NULL); 166 settimeofday(&tv, NULL);
149 } else if (!strncmp("read", cmd.buf, 4)) { 167 } else if (!strncmp("read", cmd.buf, 4)) {
150 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)); 168 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15));
151 } else if (!strncmp("touch", cmd.buf, 5)) { 169 } else if (!strncmp("touch", cmd.buf, 5)) {
152 uint16_t x, y, z1, z2;
153 float t, t2;
154 for (int i = 0; i < 10; i++) { 170 for (int i = 0; i < 10; i++) {
155 tp_getcoords(&x, &y, &z1, &z2, &t, &t2); 171 tp_getcoords(&x, &y, &z1, &z2, &t, &t2);
156 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2); 172 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
157 } 173 }
158 } else if (!strncmp("fl", cmd.buf, 2)) { 174 } else if (!strncmp("fl", cmd.buf, 2)) {
195 } else if (!strncmp("timing", cmd.buf, 6)) { 211 } else if (!strncmp("timing", cmd.buf, 6)) {
196 fputs("Timing..\r\n", stdout); 212 fputs("Timing..\r\n", stdout);
197 delay(10000); 213 delay(10000);
198 fputs("Done\r\n", stdout); 214 fputs("Done\r\n", stdout);
199 } else if (!strncmp("circ ", cmd.buf, 5)) { 215 } else if (!strncmp("circ ", cmd.buf, 5)) {
200 uint16_t x, y, r, c;
201 char col;
202
203 if (sscanf(cmd.buf, "circ %hu %hu %hu %c", &x, &y, &r, &col) != 4) { 216 if (sscanf(cmd.buf, "circ %hu %hu %hu %c", &x, &y, &r, &col) != 4) {
204 printf("Unable to parse circ args\r\n"); 217 printf("Unable to parse circ args\r\n");
205 goto out; 218 goto out;
206 } 219 }
207 220
208 col = toupper(col); 221 c = lcd_parsecol(col);
209 if (col == 'R') 222 lcd_circle(x, y, r, 0, c);
210 c = LCD_RED; 223 } else if (!strncmp("ellip ", cmd.buf, 6)) {
211 else if (col == 'G') 224 if (sscanf(cmd.buf, "ellip %hu %hu %hu %hu %c", &x, &y, &rx, &ry, &col) != 5) {
212 c = LCD_GREEN; 225 printf("Unable to parse circ args\r\n");
213 else if (col == 'B') 226 goto out;
214 c = LCD_BLUE; 227 }
215 else if (col == 'L') 228
216 c = LCD_BLACK; 229 c = lcd_parsecol(col);
217 else 230 lcd_ellipse(x, y, rx, ry, 0, c);
218 c = LCD_WHITE; 231 } else if (!strncmp("line ", cmd.buf, 5)) {
219 lcd_circle(x, y, r, c); 232 if (sscanf(cmd.buf, "line %hu %hu %hu %hu %c", &x, &y, &x1, &y1, &col) != 5) {
233 printf("Unable to parse line args\r\n");
234 goto out;
235 }
236
237 c = lcd_parsecol(col);
238 lcd_line(x, y, x1, y1, c);
239 } else if (!strncmp("delay", cmd.buf, 5)) {
240 for (x = 0; x < 100; x++) {
241 GPIO_SetBits(GPIOE, GPIO_Pin_3);
242 _usleep16(30000);
243 GPIO_ResetBits(GPIOE, GPIO_Pin_3);
244 _usleep16(60000);
245 }
220 } else if (!strncmp("zz", cmd.buf, 2)) { 246 } else if (!strncmp("zz", cmd.buf, 2)) {
221 NVIC_SystemReset(); 247 NVIC_SystemReset();
222 } else { 248 } else {
223 printf("Unknown command\r\n"); 249 printf("Unknown command\r\n");
224 } 250 }