Smart

Dependencies:   Hexi_KW40Z

Revision:
0:69293b19ee19
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTU21D.h	Wed Feb 28 16:34:40 2018 +0000
@@ -0,0 +1,91 @@
+/**
+ * EE 4391 Senior Design
+ * Professor Hinkle and Dr. Compeau
+ * @author Team Eta
+ * Texas State University
+ *
+ * @section DESCRIPTION
+ *
+ * Honeywell HTU21D Humidity and Temperature sensor.
+ * Datasheet, specs, and information:
+ * https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf
+ */
+
+#ifndef HTU21D_H
+#define HTU21D_H
+
+/**
+ * Includes
+ */
+#include "mbed.h"
+
+/**
+ * Defines
+ */
+// Acquired from Datasheet.
+
+#define HTU21D_I2C_ADDRESS  0x40 
+#define TRIGGER_TEMP_MEASURE  0xE3
+#define TRIGGER_HUMD_MEASURE  0xE5
+
+
+//Commands.
+#define HTU21D_EEPROM_WRITE 0x80
+#define HTU21D_EEPROM_READ  0x81
+
+
+/**
+ * Honeywell HTU21D digital humidity and temperature sensor.
+ */
+class HTU21D {
+
+public:
+
+    /**
+     * Constructor.
+     *
+     * @param sda mbed pin to use for SDA line of I2C interface.
+     * @param scl mbed pin to use for SCL line of I2C interface.
+     */
+    HTU21D(PinName sda, PinName scl);
+
+
+    //Samples the temperature, input void, outputs an int in celcius.
+    int sample_ctemp(void);
+    
+       //Samples the temperature, input void, outputs an int in fahrenheit.
+    int sample_ftemp(void);
+    
+       //Samples the temperature, input void, outputs an int in kelvin.
+    int sample_ktemp(void);
+    
+    //Samples the humidity, input void, outputs and int.
+    int sample_humid(void);
+
+   
+
+private:
+
+    I2C* i2c_;
+
+    /**
+     * Write to EEPROM or RAM on the device.
+     *
+     * @param EepromOrRam 0x80 -> Writing to EEPROM
+     * @param address Address to write to.
+     * @param data Data to write.
+     */
+    void write(int EepromOrRam, int address, int data);
+
+    /**
+     * Read EEPROM or RAM on the device.
+     *
+     * @param EepromOrRam 0x81 -> Reading from EEPROM
+     * @param address Address to read from.
+     * @return The contents of the memory address.
+     */
+    int read(int EepromOrRam, int address);
+
+};
+
+#endif /* HTU21D_H */