diff 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
line wrap: on
line diff
--- a/main.c	Tue Nov 27 13:19:11 2012 +1030
+++ b/main.c	Tue Nov 27 13:20:52 2012 +1030
@@ -1,5 +1,6 @@
 #include <ctype.h>
 #include <malloc.h>
+#include <math.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <time.h>
@@ -17,6 +18,8 @@
 #include "hw.h"
 #include "lcd.h"
 #include "main.h"
+#include "rtc.h"
+#include "tempctrl.h"
 #include "touch.h"
 
 #define MAXARGS		10
@@ -151,11 +154,15 @@
     lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE);
     lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE);
     
+    /* Setup temperature control stuff */
+    tempctrl_init();
+    
     while (1) {
 	fputs("> ", stdout);
 	
-	while (cmd.state != 255)
-	    ;
+	while (cmd.state != 255) {
+	    tempctrl_update();
+	}
 	
 	if (cmd.len < 1)
 	    goto out;
@@ -196,7 +203,9 @@
 		printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
 	    }
 	} else if (!strcmp("fl", argv[0])) {
-	    flashcmd(argv + 1, argc - 1);
+	    flashcmd(argc - 1, argv + 1);
+	} else if (!strcmp("tc", argv[0])) {
+	    tempctrl_cmd(argc - 1, argv + 1);
 	} else if (!strcmp("pwm", argv[0])) {
 	    lcd_setpwm(atoi(argv[1]));
 	} else if (!strcmp("timing", argv[0])) {
@@ -324,6 +333,20 @@
 		    printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res));
 		    break;
 	    }
+	} else if (!strcmp("rtc", argv[0])) {
+	    float f, err, maxerr;
+	    uint32_t d, i;
+	    
+	    maxerr = 0;
+	    for (i = 0; i < 32768; i++) {
+	 	d = RTC_PS2USEC(32768 - i);
+		f = ((float)i * 1e6) / (float)RTC_PRESCALE;
+		err = fabs(d - f);
+		//rtcprintf("i = %d, d = %d, f = %.3f, err = %.3f\r\n", i, d, f, err);
+		if (err > maxerr)
+		    maxerr = err;
+	    }
+	    printf("Max err = %.3f\r\n", maxerr);
 	} else if (!strcmp("assert", argv[0])) {
 	    assert(0 == 1);
 	} else if (!strcmp("zz", argv[0])) {