changeset 68:cc998b0b2bae

Handle missing modules in OWGetTemp.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 14 Apr 2013 16:07:29 +0930
parents dcac5f08f87a
children cf9eb08b8b23
files 1wire.c 1wire.h
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 */
--- 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);