comparison main.c @ 75:ca08442635ca

report raw ds18b20 values instead
author Matt Johnston <matt@ucc.asn.au>
date Tue, 03 Jul 2012 22:44:21 +0800
parents 68c1e2b26bc5
children 6e47a61edc47
comparison
equal deleted inserted replaced
74:cb5ea75ee599 75:ca08442635ca
26 // 1 second. we have 1024 prescaler, 32768 crystal. 26 // 1 second. we have 1024 prescaler, 32768 crystal.
27 #define SLEEP_COMPARE 32 27 #define SLEEP_COMPARE 32
28 // limited to uint16_t 28 // limited to uint16_t
29 #define MEASURE_WAKE 60 29 #define MEASURE_WAKE 60
30 30
31 #define VALUE_NOSENSOR -9000 31 #define VALUE_NOSENSOR 0x07D0 // 125 degrees
32 #define VALUE_BROKEN -8000 32 #define VALUE_BROKEN 0x07D1 // 125.0625
33 33
34 // limited to uint16_t 34 // limited to uint16_t
35 #define COMMS_WAKE 3600 // XXX testing 35 #define COMMS_WAKE 3600 // XXX testing
36 // limited to uint8_t 36 // limited to uint8_t
37 #define WAKE_SECS 60 // XXX testing 37 #define WAKE_SECS 60 // XXX testing
79 static uint16_t measure_count; 79 static uint16_t measure_count;
80 // ---- End atomic guards required 80 // ---- End atomic guards required
81 81
82 static uint16_t n_measurements; 82 static uint16_t n_measurements;
83 83
84 // stored as decidegrees 84 // stored as
85 static int16_t measurements[NUM_MEASUREMENTS][MAX_SENSORS]; 85 static uint16_t measurements[NUM_MEASUREMENTS][MAX_SENSORS];
86 static uint32_t first_measurement_clock; 86 static uint32_t first_measurement_clock;
87 // last_measurement_clock is redundant but checks that we're not missing 87 // last_measurement_clock is redundant but checks that we're not missing
88 // samples 88 // samples
89 static uint32_t last_measurement_clock; 89 static uint32_t last_measurement_clock;
90 90
298 for (uint16_t n = 0; n < n_measurements; n++) 298 for (uint16_t n = 0; n < n_measurements; n++)
299 { 299 {
300 fprintf_P(crc_stdout, PSTR("meas%hu="), n); 300 fprintf_P(crc_stdout, PSTR("meas%hu="), n);
301 for (uint8_t s = 0; s < n_sensors; s++) 301 for (uint8_t s = 0; s < n_sensors; s++)
302 { 302 {
303 fprintf_P(crc_stdout, PSTR(" %hu"), measurements[n][s]); 303 fprintf_P(crc_stdout, PSTR(" %04hx"), measurements[n][s]);
304 } 304 }
305 fputc('\n', crc_stdout); 305 fputc('\n', crc_stdout);
306 } 306 }
307 fprintf_P(crc_stdout, PSTR("END\n")); 307 fprintf_P(crc_stdout, PSTR("END\n"));
308 fprintf_P(stdout, PSTR("CRC=%hu\n"), crc_out); 308 fprintf_P(stdout, PSTR("CRC=%hu\n"), crc_out);
660 do_measurement() 660 do_measurement()
661 { 661 {
662 uint8_t n_sensors; 662 uint8_t n_sensors;
663 eeprom_read(n_sensors, n_sensors); 663 eeprom_read(n_sensors, n_sensors);
664 664
665 blink();
666
665 simple_ds18b20_start_meas(NULL); 667 simple_ds18b20_start_meas(NULL);
666 // sleep rather than using a long delay 668 // sleep rather than using a long delay
667 deep_sleep(); 669 deep_sleep();
668 //_delay_ms(DS18B20_TCONV_12BIT); 670 //_delay_ms(DS18B20_TCONV_12BIT);
669 671
672 n_measurements = 0; 674 n_measurements = 0;
673 } 675 }
674 676
675 for (uint8_t s = 0; s < MAX_SENSORS; s++) 677 for (uint8_t s = 0; s < MAX_SENSORS; s++)
676 { 678 {
677 int16_t decicelsius; 679 uint16_t reading;
678 if (s >= n_sensors) 680 if (s >= n_sensors)
679 { 681 {
680 decicelsius = VALUE_NOSENSOR; 682 reading = VALUE_NOSENSOR;
681 } 683 }
682 else 684 else
683 { 685 {
684 uint8_t id[ID_LEN]; 686 uint8_t id[ID_LEN];
685 eeprom_read_to(id, sensor_id[s], ID_LEN); 687 eeprom_read_to(id, sensor_id[s], ID_LEN);
686 688
687 uint8_t ret = simple_ds18b20_read_decicelsius(id, &decicelsius); 689 uint8_t ret = simple_ds18b20_read_raw(id, &reading);
688 if (ret != DS18X20_OK) 690 if (ret != DS18X20_OK)
689 { 691 {
690 decicelsius = VALUE_BROKEN; 692 reading = VALUE_BROKEN;
691 } 693 }
692 } 694 }
693 measurements[n_measurements][s] = decicelsius; 695 measurements[n_measurements][s] = reading;
694 } 696 }
695 697
696 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) 698 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
697 { 699 {
698 if (n_measurements == 0) 700 if (n_measurements == 0)
814 do_comms(); 816 do_comms();
815 continue; 817 continue;
816 } 818 }
817 819
818 deep_sleep(); 820 deep_sleep();
819 if (clock_epoch % 60 == 0)
820 {
821 blink();
822 }
823 } 821 }
824 822
825 return 0; /* never reached */ 823 return 0; /* never reached */
826 } 824 }