comparison main.c @ 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 45c051a7db82
comparison
equal deleted inserted replaced
117:eecd2612a68e 118:bb0c946460f3
203 // 3.3v power for bluetooth and SD 203 // 3.3v power for bluetooth and SD
204 DDR_LED |= _BV(PIN_LED); 204 DDR_LED |= _BV(PIN_LED);
205 DDR_SHDN |= _BV(PIN_SHDN); 205 DDR_SHDN |= _BV(PIN_SHDN);
206 206
207 DDR_FRIDGE |= _BV(PIN_FRIDGE); 207 DDR_FRIDGE |= _BV(PIN_FRIDGE);
208 PORT_FRIDGE &= ~_BV(PIN_FRIDGE);
208 209
209 // set pullup 210 // set pullup
210 PORTD |= _BV(PD2); 211 PORTD |= _BV(PD2);
211 // INT0 setup 212 // INT0 setup
212 EICRA = (1<<ISC01); // falling edge - data sheet says it won't work? 213 EICRA = (1<<ISC01); // falling edge - data sheet says it won't work?
580 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) 581 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
581 { 582 {
582 eeprom_write(fridge_setpoint, fridge_setpoint); 583 eeprom_write(fridge_setpoint, fridge_setpoint);
583 } 584 }
584 } 585 }
586 printf_P(PSTR("new fridge %.1fº\n"), fridge_setpoint / 10.0f);
585 } 587 }
586 588
587 static void 589 static void
588 cmd_set_fridge_difference(char *params) 590 cmd_set_fridge_difference(char *params)
589 { 591 {
601 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) 603 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
602 { 604 {
603 eeprom_write(fridge_difference, fridge_difference); 605 eeprom_write(fridge_difference, fridge_difference);
604 } 606 }
605 } 607 }
608 printf_P(PSTR("new fridge difference %.1fº\n"), fridge_difference / 10.0f);
606 } 609 }
607 610
608 static void 611 static void
609 cmd_set_fridge_delay(char *params) 612 cmd_set_fridge_delay(char *params)
610 { 613 {
622 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) 625 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
623 { 626 {
624 eeprom_write(fridge_delay, fridge_delay); 627 eeprom_write(fridge_delay, fridge_delay);
625 } 628 }
626 } 629 }
630 printf_P(PSTR("new fridge delay %hu\n"), fridge_delay);
627 } 631 }
628 632
629 static void 633 static void
630 cmd_awake() 634 cmd_awake()
631 { 635 {
808 static void 812 static void
809 do_fridge() 813 do_fridge()
810 { 814 {
811 struct epoch_ticks now; 815 struct epoch_ticks now;
812 get_epoch_ticks(&now); 816 get_epoch_ticks(&now);
813 if (now.ticks - fridge_off_clock.ticks < fridge_delay) 817 uint16_t delay_delta = now.ticks - fridge_off_clock.ticks;
814 { 818 if (delay_delta < fridge_delay)
819 {
820 printf_P(PSTR("waiting for fridge delay current %hu, wait %hu\n"),
821 delay_delta, fridge_delay);
815 return; 822 return;
816 } 823 }
817 824
818 if (last_wort == DS18X20_INVALID_DECICELSIUS) 825 if (last_wort == DS18X20_INVALID_DECICELSIUS)
819 { 826 {
820 // can't really do much sensible.... alert perhaps? 827 // can't really do much sensible.... alert perhaps?
828 printf_P(PSTR("Bad last wort!\n"));
821 need_comms = 1; 829 need_comms = 1;
822 return; 830 return;
823 } 831 }
824 832
825 int16_t wort_delta = last_wort - fridge_setpoint; 833 int16_t wort_delta = last_wort - fridge_setpoint;
826 uint8_t fridge_on = PORT_FRIDGE & _BV(PIN_FRIDGE); 834 uint8_t fridge_on = PORT_FRIDGE & _BV(PIN_FRIDGE);
835 printf_P(PSTR("last_wort %hd, setpoint %hd, delta %hd, fridge_on %d\n"),
836 last_wort, fridge_setpoint, wort_delta, fridge_on);
827 if (fridge_on) 837 if (fridge_on)
828 { 838 {
829 if (last_wort <= fridge_setpoint) 839 if (last_wort <= fridge_setpoint)
830 { 840 {
831 // too cold, turn off 841 // too cold, turn off
842 printf_P(PSTR("Turning fridge off\n"));
832 PORT_FRIDGE &= ~_BV(PIN_FRIDGE); 843 PORT_FRIDGE &= ~_BV(PIN_FRIDGE);
833 fridge_off_clock = now; 844 fridge_off_clock = now;
834 } 845 }
835 } 846 }
836 else 847 else
837 { 848 {
838 if (wort_delta > fridge_difference) 849 if (wort_delta > fridge_difference)
839 { 850 {
840 // too hot, turn on 851 // too hot, turn on
852 printf_P(PSTR("Turning fridge on\n"));
841 PORT_FRIDGE |= _BV(PIN_FRIDGE); 853 PORT_FRIDGE |= _BV(PIN_FRIDGE);
842 } 854 }
843 } 855 }
844 } 856 }
845 857