Manages the 1-wire bus

Dependents:   oldheating heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Thu Feb 18 16:47:12 2021 +0000
Parent:
10:b4e0b4c4e045
Commit message:
Added 'value not set' to the list of possible values.

Changed in this revision

1-wire/ds18b20.c Show annotated file Show diff for this revision Revisions of this file
1-wire/ds18b20.h Show annotated file Show diff for this revision Revisions of this file
web/web-1wire-class.inc Show annotated file Show diff for this revision Revisions of this file
web/web-1wire-class.js Show annotated file Show diff for this revision Revisions of this file
--- a/1-wire/ds18b20.c	Wed Jun 10 17:02:21 2020 +0000
+++ b/1-wire/ds18b20.c	Thu Feb 18 16:47:12 2021 +0000
@@ -30,9 +30,23 @@
         case DS18B20_ERROR_TIMED_OUT:               strcpy (buffer, "Timed out"                     ); break;
         case DS18B20_ERROR_NO_DEVICE_PRESENT:       strcpy (buffer, "No device detected after reset"); break;
         case DS18B20_ERROR_NO_DEVICE_PARTICIPATING: strcpy (buffer, "Device removed during search"  ); break;
+        case DS18B20_ERROR_VALUE_NOT_SET:           strcpy (buffer, "Value not set"                 ); break;
         default:                                    sprintf(buffer, "%1.1f", value / 16.0           ); break;
     }
 }
+void DS18B20Log(int16_t value)
+{
+    switch (value)
+    {
+        case DS18B20_ERROR_CRC:                     Log ("CRC error"                     ); break;
+        case DS18B20_ERROR_NOT_FOUND:               Log ("ROM not found"                 ); break;
+        case DS18B20_ERROR_TIMED_OUT:               Log ("Timed out"                     ); break;
+        case DS18B20_ERROR_NO_DEVICE_PRESENT:       Log ("No device detected after reset"); break;
+        case DS18B20_ERROR_NO_DEVICE_PARTICIPATING: Log ("Device removed during search"  ); break;
+        case DS18B20_ERROR_VALUE_NOT_SET:           Log ("Value not set"                 ); break;
+        default:                                    LogF("%1.1f", value / 16.0           ); break;
+    }
+}
 int16_t DS18B20ValueFromRom(char* rom)
 {
     for (int device = 0; device < DeviceCount; device++) if (memcmp(DeviceList + 8 * device, rom, 8) == 0) return DS18B20Value[device];
@@ -59,5 +73,5 @@
 }
 void DS18B20Init()
 {
-    for (int i = 0; i < DEVICE_MAX; i++) DS18B20Value[i] = DS18B20_ERROR_NOT_FOUND;
+    for (int i = 0; i < DEVICE_MAX; i++) DS18B20Value[i] = DS18B20_ERROR_VALUE_NOT_SET;
 }
\ No newline at end of file
--- a/1-wire/ds18b20.h	Wed Jun 10 17:02:21 2020 +0000
+++ b/1-wire/ds18b20.h	Thu Feb 18 16:47:12 2021 +0000
@@ -5,6 +5,7 @@
 #define DS18B20_ERROR_TIMED_OUT               0x7FFD
 #define DS18B20_ERROR_NO_DEVICE_PRESENT       0x7FFC
 #define DS18B20_ERROR_NO_DEVICE_PARTICIPATING 0x7FFB
+#define DS18B20_ERROR_VALUE_NOT_SET           0x7FFA
 
 #define DS18B20_VALUE_STRING_LENGTH 32
 #define DS18B20_FAMILY_CODE 0x28
@@ -17,6 +18,7 @@
 extern int16_t DS18B20ValueFromRom(char* rom);
 extern int     DS18B20IsValidValue(int16_t value);
 extern void    DS18B20ValueToString(int16_t value, char* buffer);
+extern void    DS18B20Log(int16_t value);
 extern void    DS18B20ReadValue(int oneWireResult, int device, char byte0, char byte1);
 
 extern void    DS18B20Init(void);
\ No newline at end of file
--- a/web/web-1wire-class.inc	Wed Jun 10 17:02:21 2020 +0000
+++ b/web/web-1wire-class.inc	Thu Feb 18 16:47:12 2021 +0000
@@ -12,6 +12,7 @@
 "            case 0x7FFD: return 'Timed out'                     ;\n"
 "            case 0x7FFC: return 'No device detected after reset';\n"
 "            case 0x7FFB: return 'Device removed during search'  ;\n"
+"            case 0x7FFA: return 'Value not set'                 ;\n"
 "        }\n"
 "        return (value / 16.0).toFixed(1);\n"
 "    }\n"
--- a/web/web-1wire-class.js	Wed Jun 10 17:02:21 2020 +0000
+++ b/web/web-1wire-class.js	Thu Feb 18 16:47:12 2021 +0000
@@ -12,6 +12,7 @@
             case 0x7FFD: return 'Timed out'                     ;
             case 0x7FFC: return 'No device detected after reset';
             case 0x7FFB: return 'Device removed during search'  ;
+            case 0x7FFA: return 'Value not set'                 ;
         }
         return (value / 16.0).toFixed(1);
     }