Mercurial > templog
changeset 75:ca08442635ca
report raw ds18b20 values instead
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 03 Jul 2012 22:44:21 +0800 |
parents | cb5ea75ee599 |
children | 6e47a61edc47 |
files | main.c simple_ds18b20.c simple_ds18b20.h web/log.py web/test.py |
diffstat | 5 files changed, 44 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Tue Jul 03 21:55:50 2012 +0800 +++ b/main.c Tue Jul 03 22:44:21 2012 +0800 @@ -28,8 +28,8 @@ // limited to uint16_t #define MEASURE_WAKE 60 -#define VALUE_NOSENSOR -9000 -#define VALUE_BROKEN -8000 +#define VALUE_NOSENSOR 0x07D0 // 125 degrees +#define VALUE_BROKEN 0x07D1 // 125.0625 // limited to uint16_t #define COMMS_WAKE 3600 // XXX testing @@ -81,8 +81,8 @@ static uint16_t n_measurements; -// stored as decidegrees -static int16_t measurements[NUM_MEASUREMENTS][MAX_SENSORS]; +// stored as +static uint16_t measurements[NUM_MEASUREMENTS][MAX_SENSORS]; static uint32_t first_measurement_clock; // last_measurement_clock is redundant but checks that we're not missing // samples @@ -300,7 +300,7 @@ fprintf_P(crc_stdout, PSTR("meas%hu="), n); for (uint8_t s = 0; s < n_sensors; s++) { - fprintf_P(crc_stdout, PSTR(" %hu"), measurements[n][s]); + fprintf_P(crc_stdout, PSTR(" %04hx"), measurements[n][s]); } fputc('\n', crc_stdout); } @@ -662,6 +662,8 @@ uint8_t n_sensors; eeprom_read(n_sensors, n_sensors); + blink(); + simple_ds18b20_start_meas(NULL); // sleep rather than using a long delay deep_sleep(); @@ -674,23 +676,23 @@ for (uint8_t s = 0; s < MAX_SENSORS; s++) { - int16_t decicelsius; + uint16_t reading; if (s >= n_sensors) { - decicelsius = VALUE_NOSENSOR; + reading = VALUE_NOSENSOR; } else { uint8_t id[ID_LEN]; eeprom_read_to(id, sensor_id[s], ID_LEN); - uint8_t ret = simple_ds18b20_read_decicelsius(id, &decicelsius); + uint8_t ret = simple_ds18b20_read_raw(id, &reading); if (ret != DS18X20_OK) { - decicelsius = VALUE_BROKEN; + reading = VALUE_BROKEN; } } - measurements[n_measurements][s] = decicelsius; + measurements[n_measurements][s] = reading; } ATOMIC_BLOCK(ATOMIC_RESTORESTATE) @@ -816,10 +818,6 @@ } deep_sleep(); - if (clock_epoch % 60 == 0) - { - blink(); - } } return 0; /* never reached */
--- a/simple_ds18b20.c Tue Jul 03 21:55:50 2012 +0800 +++ b/simple_ds18b20.c Tue Jul 03 22:44:21 2012 +0800 @@ -125,6 +125,23 @@ return ret; } +uint8_t +simple_ds18b20_read_raw( uint8_t id[], uint16_t *reading ) +{ + uint8_t sp[DS18X20_SP_SIZE]; + uint8_t ret; + + if (id) + { + ow_reset(); + } + ret = read_scratchpad( id, sp, DS18X20_SP_SIZE ); + if ( ret == DS18X20_OK ) { + *reading = sp[0] | (sp[1] << 8); + } + return ret; +} + static void printhex_nibble(const unsigned char b, FILE *stream) {
--- a/simple_ds18b20.h Tue Jul 03 21:55:50 2012 +0800 +++ b/simple_ds18b20.h Tue Jul 03 22:44:21 2012 +0800 @@ -9,6 +9,7 @@ void printhex(uint8_t *id, uint8_t n, FILE *stream); void printhex_byte( const unsigned char b, FILE *stream ); uint8_t simple_ds18b20_read_decicelsius( uint8_t id[], int16_t *decicelsius ); +uint8_t simple_ds18b20_read_raw( uint8_t id[], uint16_t *reading ); uint8_t simple_ds18b20_read_all(); #endif // SIMPLE_DS18B20_H_
--- a/web/log.py Tue Jul 03 21:55:50 2012 +0800 +++ b/web/log.py Tue Jul 03 22:44:21 2012 +0800 @@ -11,6 +11,7 @@ import sqlite3 import traceback import datetime +import struct from colorsys import hls_to_rgb import config @@ -143,6 +144,10 @@ f.flush() return f +def convert_ds18b20_12bit(reading): + value = struct.unpack('>h', binascii.unhexlify(reading))[0] + return value * 0.0625 + def parse(lines): debugf = record_debug(lines) @@ -160,10 +165,6 @@ for s in sensors: meas.append([]) - def val_scale(v): - # convert decidegrees to degrees - return 0.1 * v - for n in xrange(num_measurements): vals = [val_scale(int(x)) for x in entries["meas%d" % n].strip().split()] if len(vals) != num_sensors:
--- a/web/test.py Tue Jul 03 21:55:50 2012 +0800 +++ b/web/test.py Tue Jul 03 22:44:21 2012 +0800 @@ -1,5 +1,12 @@ #!/usr/bin/env python -import log import time +import struct +import sys +import binascii -log.sensor_update("test1", [22,22,22.1,22.4,22.5], time.time() - 10, 300) +def convert_ds18b20_12bit(reading): + value = struct.unpack('>h', binascii.unhexlify(reading))[0] + return value * 0.0625 + +if __name__ == '__main__': + print convert_ds18b20_12bit(sys.argv[1])