Simple cpp wrapper of a ds18b20, onewire 'c' library. Supports multiple sensors.

Dependencies:   mbed

Dependents:   LPC11U68_DS18B20Sensor

Fork of DS18B20Sensor by Steve Spence

Files at this revision

API Documentation at this revision

Comitter:
jsteve
Date:
Sun Mar 03 01:59:15 2013 +0000
Parent:
0:1449f126b241
Child:
2:70ea3ce2f345
Commit message:
First Published

Changed in this revision

DS18B20Sensor.cpp Show annotated file Show diff for this revision Revisions of this file
DS18B20Sensor.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/DS18B20Sensor.cpp	Sun Mar 03 01:41:51 2013 +0000
+++ b/DS18B20Sensor.cpp	Sun Mar 03 01:59:15 2013 +0000
@@ -1,3 +1,8 @@
+/**
+* @file DS18B20Sensor.cpp
+* @brief Wrapper for the OneWireDrv library by Frederic Blanc.
+* @author Steve Spence (Published 3 March 2013 www.mbed.org)
+*/
 #include "DS18B20Sensor.h"
 
 DS18B20Sensor::DS18B20Sensor(PinName pin) : _oneWirePort(pin)
@@ -6,14 +11,14 @@
     nSensors = 0;
 }
 
-void DS18B20Sensor::getReadingText(char * text, uint8_t index)
+void DS18B20Sensor::getReading(char * text, uint8_t index)
 {
     uint8_t subzero, cel, cel_frac_bits;
     DS18X20_read_meas( &gSensorIDs[index][0], &subzero, &cel, &cel_frac_bits);
-    DS18B20Sensor::getReadingText(text, subzero, cel, cel_frac_bits);
+    DS18B20Sensor::getReading(text, subzero, cel, cel_frac_bits);
 }
 
-void DS18B20Sensor::getReadingText(char * text, uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits)
+void DS18B20Sensor::getReading(char * text, uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits)
 {
     uint16_t decicelsius;
     char s[10];
--- a/DS18B20Sensor.h	Sun Mar 03 01:41:51 2013 +0000
+++ b/DS18B20Sensor.h	Sun Mar 03 01:59:15 2013 +0000
@@ -6,38 +6,38 @@
 #include "onewire.h"
  
 /** DS18B20Sensor class.
- *  A wrapper class for the DS18X20 and onewire 'c' library.
- *  Many thanks to Frederic Blanc (among others) for making this code available.
- *
+ *  A wrapper class for the DS18B20 (temperature sensor) and onewire 'c' library.
+ *  Based on the OneWireDrv Library by Frederic Blanc. Many thanks to him for making this code available.
+ *  
  * Simple Example:
  * @code
  #include "mbed.h"
  #include "DS18B20Sensor.h"
- 
+
  DS18B20Sensor sensor(p30);
- 
- int main() 
+
+ int main()
  {
     char sensorBuf[25];
-    
+
     // count will search for sensors, if not already called
-    printf("Found %d sensor/s\r", sensor.count());  
-    
+    printf("Found %d sensor/s\r", sensor.count());
+
     uint8_t result = sensor.startReading(true);     // start sensor readings and wait
-    
+
     for (uint8_t i = 0; i < sensor.count(); i++) {
        sensor.getReadingText(sensorBuf, i);         // get result into buf
        printf("Sensor %d : %s\r", i+1, sensorBuf);  // display it to the world
     }
- 
+
  }
  * @endcode
  */
 class DS18B20Sensor
 {
 public:
-    /** Create Sensor instance
-    * @param pin pin number for the onewire bus
+    /** Create DS18B20Sensor instance
+    * @param pin The pin number used by the onewire bus.
     */
     DS18B20Sensor(PinName pin);
 
@@ -45,7 +45,7 @@
     * @param text The target text buffer.
     * @param index The sensor number.
     */
-    void getReadingText(char * text, uint8_t index);
+    void getReading(char * text, uint8_t index);
 
     /** Copies the sensor results into the parameter text.
     * @param text The target text buffer.
@@ -53,7 +53,15 @@
     * @param cel Degrees Cel
     * @param cel Degrees fraction
     */
-    void getReadingText(char * text, uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits);
+    void getReading(char * text, uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits);
+
+    /** Gets the sensors reading results.
+    * @param index The sensor number.
+    * @param subzero Returns 1 if less than zero.
+    * @param cel Returns degrees Cel
+    * @param cel Returns degrees fraction
+    */
+    void getReading(uint8_t index, uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
 
     /** This searches for sensors on the onewire bus.
     *   It can also invoked by just using count()
@@ -69,14 +77,6 @@
     */
     uint8_t startReading(bool includeWait = true);
 
-    /** Gets the sensors reading results.
-    * @param index The sensor number.
-    * @param subzero Returns 1 if less than zero.
-    * @param cel Returns degrees Cel
-    * @param cel Returns degrees fraction
-    */
-    void getReading(uint8_t index, uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
-
     /** If search() was not called before this, then search() is invoked.
     *   @returns The number of sensors found on the bus.
     */
--- a/mbed.bld	Sun Mar 03 01:41:51 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0