comparison main.c @ 117:eecd2612a68e

stay on
author Matt Johnston <matt@ucc.asn.au>
date Fri, 05 Oct 2012 22:48:49 +0800
parents 9afff8f29844
children bb0c946460f3
comparison
equal deleted inserted replaced
116:9afff8f29844 117:eecd2612a68e
162 static const uint8_t wort_id[ID_LEN] = 162 static const uint8_t wort_id[ID_LEN] =
163 {0x28,0x49,0xBC,0x1A,0x03,0x00,0x00,0x54}; 163 {0x28,0x49,0xBC,0x1A,0x03,0x00,0x00,0x54};
164 164
165 static void deep_sleep(); 165 static void deep_sleep();
166 166
167 // 0 or 1
168 static uint8_t
169 is_fridge_on()
170 {
171 if (PORT_FRIDGE & _BV(PIN_FRIDGE))
172 {
173 return 1;
174 }
175 else
176 {
177 return 0;
178 }
179 }
180
167 // Very first setup 181 // Very first setup
168 static void 182 static void
169 setup_chip() 183 setup_chip()
170 { 184 {
171 cli(); 185 cli();
346 fprintf_P(crc_stdout, PSTR("comms=%hu\n"), comms_wake); 360 fprintf_P(crc_stdout, PSTR("comms=%hu\n"), comms_wake);
347 fprintf_P(crc_stdout, PSTR("wake=%hhu\n"), wake_secs); 361 fprintf_P(crc_stdout, PSTR("wake=%hhu\n"), wake_secs);
348 fprintf_P(crc_stdout, PSTR("fridge=%.1f\n"), fridge_setpoint/10.0); 362 fprintf_P(crc_stdout, PSTR("fridge=%.1f\n"), fridge_setpoint/10.0);
349 fprintf_P(crc_stdout, PSTR("fridge_diff=%.1f\n"), fridge_difference/10.0); 363 fprintf_P(crc_stdout, PSTR("fridge_diff=%.1f\n"), fridge_difference/10.0);
350 fprintf_P(crc_stdout, PSTR("fridge_delay=%hu\n"), fridge_delay); 364 fprintf_P(crc_stdout, PSTR("fridge_delay=%hu\n"), fridge_delay);
365 fprintf_P(crc_stdout, PSTR("fridge_status=%hhu\n"), is_fridge_on());
351 fprintf_P(crc_stdout, PSTR("tick_secs=%d\n"), TICK); 366 fprintf_P(crc_stdout, PSTR("tick_secs=%d\n"), TICK);
352 fprintf_P(crc_stdout, PSTR("tick_wake=%d\n"), SLEEP_COMPARE); 367 fprintf_P(crc_stdout, PSTR("tick_wake=%d\n"), SLEEP_COMPARE);
353 fprintf_P(crc_stdout, PSTR("maxsens=%hhu\n"), MAX_SENSORS); 368 fprintf_P(crc_stdout, PSTR("maxsens=%hhu\n"), MAX_SENSORS);
354 fprintf_P(crc_stdout, PSTR("totalmeas=%hu\n"), TOTAL_MEASUREMENTS); 369 fprintf_P(crc_stdout, PSTR("totalmeas=%hu\n"), TOTAL_MEASUREMENTS);
355 fprintf_P(crc_stdout, PSTR("sensors=%hhu\n"), n_sensors); 370 fprintf_P(crc_stdout, PSTR("sensors=%hhu\n"), n_sensors);
394 printf_P(PSTR("rem=%hhu,"), rem); 409 printf_P(PSTR("rem=%hhu,"), rem);
395 printf_P(PSTR("tick_secs=%hhu,"), TICK); 410 printf_P(PSTR("tick_secs=%hhu,"), TICK);
396 printf_P(PSTR("tick_wake=%hhu\n"), SLEEP_COMPARE); 411 printf_P(PSTR("tick_wake=%hhu\n"), SLEEP_COMPARE);
397 _delay_ms(100); 412 _delay_ms(100);
398 comms_timeout = 0; 413 comms_timeout = 0;
414 stay_awake = 0;
399 } 415 }
400 416
401 static void 417 static void
402 cmd_reset() 418 cmd_reset()
403 { 419 {
839 first_measurement_clock = last_measurement_clock; 855 first_measurement_clock = last_measurement_clock;
840 } 856 }
841 857
842 simple_ds18b20_start_meas(NULL); 858 simple_ds18b20_start_meas(NULL);
843 // sleep rather than using a long delay 859 // sleep rather than using a long delay
844 deep_sleep(); 860 idle_sleep();
845 //_delay_ms(DS18B20_TCONV_12BIT); 861 //_delay_ms(DS18B20_TCONV_12BIT);
846 862
847 if (n_measurements == max_measurements) 863 if (n_measurements == max_measurements)
848 { 864 {
849 n_measurements = 0; 865 n_measurements = 0;
965 sei(); 981 sei();
966 982
967 need_comms = 1; 983 need_comms = 1;
968 need_measurement = 1; 984 need_measurement = 1;
969 985
986 stay_awake = 1;
987
970 for(;;) 988 for(;;)
971 { 989 {
972 if (button_pressed) 990 if (button_pressed)
973 { 991 {
974 // debounce 992 // debounce