changeset 118:bb0c946460f3

a bit more logging. make printf floats work
author Matt Johnston <matt@ucc.asn.au>
date Sat, 06 Oct 2012 23:53:28 +0800
parents eecd2612a68e
children 81591bdfa92c
files Makefile main.c
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Oct 05 22:48:49 2012 +0800
+++ b/Makefile	Sat Oct 06 23:53:28 2012 +0800
@@ -56,7 +56,7 @@
 # Tune the lines below only if you know what you are doing:
 
 AVRDUDE = avrdude $(PROGRAMMER) 
-COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues -fdata-sections -ffunction-sections  -Wl,--gc-sections -Wl,--relax --combine -fwhole-program
+COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues -fdata-sections -ffunction-sections  -Wl,--gc-sections -Wl,--relax --combine -fwhole-program  -Wl,-u,vfprintf -lprintf_flt -lm
 
 # symbolic targets:
 all:	main.hex
--- a/main.c	Fri Oct 05 22:48:49 2012 +0800
+++ b/main.c	Sat Oct 06 23:53:28 2012 +0800
@@ -205,6 +205,7 @@
     DDR_SHDN |= _BV(PIN_SHDN);
 
     DDR_FRIDGE |= _BV(PIN_FRIDGE);
+    PORT_FRIDGE &= ~_BV(PIN_FRIDGE);
 
     // set pullup
     PORTD |= _BV(PD2);
@@ -582,6 +583,7 @@
             eeprom_write(fridge_setpoint, fridge_setpoint);
         }
     }
+    printf_P(PSTR("new fridge %.1fº\n"), fridge_setpoint / 10.0f);
 }
 
 static void
@@ -603,6 +605,7 @@
             eeprom_write(fridge_difference, fridge_difference);
         }
     }
+    printf_P(PSTR("new fridge difference %.1fº\n"), fridge_difference / 10.0f);
 }
 
 static void
@@ -624,6 +627,7 @@
             eeprom_write(fridge_delay, fridge_delay);
         }
     }
+    printf_P(PSTR("new fridge delay %hu\n"), fridge_delay);
 }
     
 static void
@@ -810,25 +814,32 @@
 {
     struct epoch_ticks now;
     get_epoch_ticks(&now);
-    if (now.ticks - fridge_off_clock.ticks < fridge_delay)
+    uint16_t delay_delta = now.ticks - fridge_off_clock.ticks;
+    if (delay_delta < fridge_delay)
     {
+        printf_P(PSTR("waiting for fridge delay current %hu, wait %hu\n"),
+                delay_delta, fridge_delay);
         return;
     }
 
     if (last_wort == DS18X20_INVALID_DECICELSIUS)
     {
         // can't really do much sensible.... alert perhaps?
+        printf_P(PSTR("Bad last wort!\n"));
         need_comms = 1;
         return;
     }
 
     int16_t wort_delta = last_wort - fridge_setpoint;
     uint8_t fridge_on = PORT_FRIDGE & _BV(PIN_FRIDGE);
+    printf_P(PSTR("last_wort %hd, setpoint %hd, delta %hd, fridge_on %d\n"), 
+            last_wort, fridge_setpoint, wort_delta, fridge_on);
     if (fridge_on)
     {
         if (last_wort <= fridge_setpoint)
         {
             // too cold, turn off
+            printf_P(PSTR("Turning fridge off\n"));
             PORT_FRIDGE &= ~_BV(PIN_FRIDGE);
             fridge_off_clock = now;
         }
@@ -838,6 +849,7 @@
         if (wort_delta > fridge_difference)
         {
             // too hot, turn on
+            printf_P(PSTR("Turning fridge on\n"));
             PORT_FRIDGE |= _BV(PIN_FRIDGE);
         }
     }