A feature complete driver for the LM75B temperature sensor from NXP.

Fork of LM75B by Neil Thiessen

Revision:
8:2b797c309258
Parent:
7:bebde8098fca
Child:
9:74b44a27fa40
--- a/LM75B.h	Fri Aug 09 22:21:36 2013 +0000
+++ b/LM75B.h	Wed Aug 14 04:33:25 2013 +0000
@@ -19,12 +19,6 @@
 
 #include "mbed.h"
 
-//i2c register definitions
-#define __LM75B_REG_TEMP  0x00
-#define __LM75B_REG_CONF  0x01
-#define __LM75B_REG_THYST 0x02
-#define __LM75B_REG_TOS   0x03
-
 /** LM75B class.
  *  Used for controlling an LM75B temperature sensor connected via I2C.
  *
@@ -33,16 +27,15 @@
  * #include "mbed.h"
  * #include "LM75B.h"
  *
- * Serial pc(USBTX, USBRX);
  * LM75B sensor(p28, p27, LM75B::ADDRESS_0);
  *
  * int main() {
  *     while (1) {
  *         //Read the temperature
- *         float temp = sensor.getTemp();
+ *         float temp = sensor.temp();
  *
  *         //Print the temperature
- *         pc.printf("Temp = %.3f\n", temp);
+ *         printf("Temp = %.3f\n", temp);
  *
  *         //Sleep for 0.5 seconds
  *         wait(0.5);
@@ -108,89 +101,100 @@
      *
      * @returns The current power mode as a PowerMode enum.
      */
-    LM75B::PowerMode getPowerMode(void);
+    LM75B::PowerMode powerMode(void);
 
     /** Set the power mode of the LM75B
      *
      * @param mode The new power mode as a PowerMode enum.
      */
-    void setPowerMode(PowerMode mode);
+    void powerMode(PowerMode mode);
 
     /** Get the current OS pin mode of the LM75B
      *
      * @returns The current OS pin mode as an OSMode enum.
      */
-    LM75B::OSMode getOSMode(void);
+    LM75B::OSMode osMode(void);
 
     /** Set the OS pin mode of the LM75B
      *
      * @param mode The new OS pin mode as an OSMode enum.
      */
-    void setOSMode(OSMode mode);
+    void osMode(OSMode mode);
 
     /** Get the current OS pin polarity of the LM75B
      *
      * @returns The current OS pin polarity as an OSPolarity enum.
      */
-    LM75B::OSPolarity getOSPolarity(void);
+    LM75B::OSPolarity osPolarity(void);
 
     /** Set the OS pin polarity of the LM75B
      *
      * @param polarity The new OS pin polarity as an OSPolarity enum.
      */
-    void setOSPolarity(OSPolarity polarity);
+    void osPolarity(OSPolarity polarity);
 
     /** Get the current OS pin fault queue length of the LM75B
      *
      * @returns The current OS pin fault queue length as an OSFaultQueue enum.
      */
-    LM75B::OSFaultQueue getOSFaultQueue(void);
+    LM75B::OSFaultQueue osFaultQueue(void);
 
     /** Set the OS pin fault queue length of the LM75B
      *
      * @param queue The new OS pin fault queue length as an OSFaultQueue enum.
      */
-    void setOSFaultQueue(OSFaultQueue queue);
+    void osFaultQueue(OSFaultQueue queue);
 
     /** Get the current alert temperature threshold of the LM75B
      *
      * @returns The current alert temperature threshold in °C.
      */
-    float getAlertTemp(void);
+    float alertTemp(void);
 
     /** Set the alert temperature threshold of the LM75B
      *
      * @param temp The new alert temperature threshold in °C.
      */
-    void setAlertTemp(float temp);
+    void alertTemp(float temp);
 
     /** Get the current alert temperature hysteresis threshold of the LM75B
      *
      * @returns The current alert temperature hysteresis threshold in °C.
      */
-    float getAlertHyst(void);
+    float alertHyst(void);
 
     /** Set the alert temperature hysteresis threshold of the LM75B
      *
      * @param temp The new alert temperature hysteresis threshold in °C.
      */
-    void setAlertHyst(float temp);
+    void alertHyst(float temp);
 
     /** Get the current temperature measurement of the LM75B
      *
      * @returns The current temperature measurement in °C.
      */
-    float getTemp(void);
+    float temp(void);
 
 private:
-    I2C _i2c;
-    int _addr;
-    char _read8(char reg);
-    void _write8(char reg, char data);
-    unsigned short _read16(char reg);
-    void _write16(char reg, unsigned short data);
-    float _readTempHelper(char reg);
-    void _writeTempHelper(char reg, float temp);
+    //I2C register addresses
+    enum Register {
+        REG_TEMP    = 0x00,
+        REG_CONF    = 0x01,
+        REG_THYST   = 0x02,
+        REG_TOS     = 0x03
+    };
+
+    //Member variables
+    I2C m_I2C;
+    int m_Addr;
+
+    //Internal functions
+    char read8(char reg);
+    void write8(char reg, char data);
+    unsigned short read16(char reg);
+    void write16(char reg, unsigned short data);
+    float readAlertTempHelper(char reg);
+    void writeAlertTempHelper(char reg, float temp);
 };
 
 #endif