comparison main.c @ 31:03592ca4d37e

Port tempctrl.c from AVR. I removed the beep code as I don't have a beeper on the STM32 board. Reworked the heat/cool stuff so it can use separate ports.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 27 Nov 2012 13:20:52 +1030
parents 198ac9d95770
children 1fdfbad9eca7
comparison
equal deleted inserted replaced
30:435c6330896c 31:03592ca4d37e
1 #include <ctype.h> 1 #include <ctype.h>
2 #include <malloc.h> 2 #include <malloc.h>
3 #include <math.h>
3 #include <stdio.h> 4 #include <stdio.h>
4 #include <stdint.h> 5 #include <stdint.h>
5 #include <time.h> 6 #include <time.h>
6 #include <string.h> 7 #include <string.h>
7 #include <sys/time.h> 8 #include <sys/time.h>
15 #include "delay.h" 16 #include "delay.h"
16 #include "flash.h" 17 #include "flash.h"
17 #include "hw.h" 18 #include "hw.h"
18 #include "lcd.h" 19 #include "lcd.h"
19 #include "main.h" 20 #include "main.h"
21 #include "rtc.h"
22 #include "tempctrl.h"
20 #include "touch.h" 23 #include "touch.h"
21 24
22 #define MAXARGS 10 25 #define MAXARGS 10
23 #define LINEBUF 40 26 #define LINEBUF 40
24 typedef struct { 27 typedef struct {
149 lcd_line(300, 20, 20, 20, LCD_BLACK); 152 lcd_line(300, 20, 20, 20, LCD_BLACK);
150 153
151 lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE); 154 lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE);
152 lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE); 155 lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE);
153 156
157 /* Setup temperature control stuff */
158 tempctrl_init();
159
154 while (1) { 160 while (1) {
155 fputs("> ", stdout); 161 fputs("> ", stdout);
156 162
157 while (cmd.state != 255) 163 while (cmd.state != 255) {
158 ; 164 tempctrl_update();
165 }
159 166
160 if (cmd.len < 1) 167 if (cmd.len < 1)
161 goto out; 168 goto out;
162 169
163 /* Split command string on space/tab boundaries into argv/argc */ 170 /* Split command string on space/tab boundaries into argv/argc */
194 for (int i = 0; i < 10; i++) { 201 for (int i = 0; i < 10; i++) {
195 tp_getcoords(&x, &y, &z1, &z2, &t, &t2); 202 tp_getcoords(&x, &y, &z1, &z2, &t, &t2);
196 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2); 203 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
197 } 204 }
198 } else if (!strcmp("fl", argv[0])) { 205 } else if (!strcmp("fl", argv[0])) {
199 flashcmd(argv + 1, argc - 1); 206 flashcmd(argc - 1, argv + 1);
207 } else if (!strcmp("tc", argv[0])) {
208 tempctrl_cmd(argc - 1, argv + 1);
200 } else if (!strcmp("pwm", argv[0])) { 209 } else if (!strcmp("pwm", argv[0])) {
201 lcd_setpwm(atoi(argv[1])); 210 lcd_setpwm(atoi(argv[1]));
202 } else if (!strcmp("timing", argv[0])) { 211 } else if (!strcmp("timing", argv[0])) {
203 fputs("Timing..\r\n", stdout); 212 fputs("Timing..\r\n", stdout);
204 delay(10000); 213 delay(10000);
322 331
323 default: 332 default:
324 printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res)); 333 printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res));
325 break; 334 break;
326 } 335 }
336 } else if (!strcmp("rtc", argv[0])) {
337 float f, err, maxerr;
338 uint32_t d, i;
339
340 maxerr = 0;
341 for (i = 0; i < 32768; i++) {
342 d = RTC_PS2USEC(32768 - i);
343 f = ((float)i * 1e6) / (float)RTC_PRESCALE;
344 err = fabs(d - f);
345 //rtcprintf("i = %d, d = %d, f = %.3f, err = %.3f\r\n", i, d, f, err);
346 if (err > maxerr)
347 maxerr = err;
348 }
349 printf("Max err = %.3f\r\n", maxerr);
327 } else if (!strcmp("assert", argv[0])) { 350 } else if (!strcmp("assert", argv[0])) {
328 assert(0 == 1); 351 assert(0 == 1);
329 } else if (!strcmp("zz", argv[0])) { 352 } else if (!strcmp("zz", argv[0])) {
330 NVIC_SystemReset(); 353 NVIC_SystemReset();
331 } else { 354 } else {