diff 1wire.c @ 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 969bb070b181
children
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 */