# HG changeset patch # User Daniel O'Connor # Date 1365921449 -34200 # Node ID cc998b0b2baee433f875bf2a0f28502a75437327 # Parent dcac5f08f87ab1728f412f96702501ab63d5f08f Handle missing modules in OWGetTemp. diff -r dcac5f08f87a -r cc998b0b2bae 1wire.c --- a/1wire.c Sun Apr 14 14:29:08 2013 +0930 +++ b/1wire.c Sun Apr 14 16:07:29 2013 +0930 @@ -66,6 +66,8 @@ * wasn't, or 2 if the line appears to be being held low. * * (NOTE: Does not handle alarm presence from DS2404/DS1994) + * + * XXX: should use #defines */ uint8_t OWTouchReset(void) { @@ -201,12 +203,14 @@ /*----------------------------------------------------------------------------- * Send a 1 wire command to a device, or all if no ROM ID provided + * Returns same values as OWTouchReset */ -void +uint8_t OWSendCmd(uint8_t *ROM, uint8_t cmd) { uint8_t i; - OWTouchReset(); + if ((i = OWTouchReset()) != 0) + return i; if (ROM == NULL) OWWriteByte(OW_SKIP_ROM_CMD); @@ -216,6 +220,8 @@ OWWriteByte(ROM[i]); } OWWriteByte(cmd); + + return 0; } /*----------------------------------------------------------------------------- @@ -557,8 +563,15 @@ if (ROM[0] != OW_FAMILY_TEMP) return OW_TEMP_WRONG_FAM; - OWSendCmd(ROM, OW_CONVERTT_CMD); - + switch (OWSendCmd(ROM, OW_CONVERTT_CMD)) { + case 0: + break; + + case 1: + case 2: + return OW_TEMP_NO_ROM; + } + i = 0; /* Wait for the conversion */ diff -r dcac5f08f87a -r cc998b0b2bae 1wire.h --- a/1wire.h Sun Apr 14 14:29:08 2013 +0930 +++ b/1wire.h Sun Apr 14 16:07:29 2013 +0930 @@ -43,7 +43,7 @@ uint8_t OWFirst(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only); uint8_t OWNext(uint8_t *ROM, uint8_t do_reset, uint8_t alarm_only); void OWCRC(uint8_t x, uint8_t *crc); -void OWSendCmd(uint8_t *ROM, uint8_t cmd); +uint8_t OWSendCmd(uint8_t *ROM, uint8_t cmd); uint8_t OWProgROM(uint8_t *ROM, uint8_t start, uint8_t len, uint8_t *data, uint8_t exact, uint8_t status); int16_t OWGetTemp(uint8_t *ROM); const PROGMEM char *OWTempStatusStr(int16_t val, uint8_t shrt);