Library for the DS1721, 2-Wire Digital Thermometer and Thermostat from Dallas Semiconductor (Maxim Integrated)
Diff: DS1721.h
- Revision:
- 2:22dbeccb82be
- Parent:
- 1:4fd830a97574
--- a/DS1721.h Thu May 02 17:12:06 2013 +0000 +++ b/DS1721.h Tue Jul 30 20:23:07 2013 +0000 @@ -1,14 +1,38 @@ -/*********************************************************************************** - * @file DS1721.h - * - * @version 1.00 - * @date 04/29/2013 +/* + * @file DS1721.h + * @author Cameron Haegle + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * @section DESCRIPTION + * + * Library for the DS1721, 2-Wire Digital Thermometer and Thermostat, from Maxim Semiconductor + * (www.maiximintegrated.com). + * + * @section LIMITATIONS * - * @author Cameron Haegle - * @company Digi International - * @copyright - * - **********************************************************************************/ + * This library was not written with for use with the mbed-RTOS, as the I2C read/write calls are + * not thread safe. + * + * ChangeLog + * 07/30/2013 + * - + */ #ifndef DS1721_H #define DS1721_H @@ -52,13 +76,13 @@ * #define DS1721_I2C_ADDRESS (0x48<<1) * * int main(void) { - * - * DS1721 thermo(PTC9, PTC8, DS1721_I2C_ADDRESS); + * I2C m_i2c(PTC9, PTC8); + * DS1721 thermo(m_i2c, DS1721_I2C_ADDRESS); * * // initialize the temperature sensor * thermo.startConversion(); - * thermo.setLowSetpoint(25); - * thermo.setHighSetpoint(27); + * thermo.setLowSp(25); + * thermo.setHighSp(27); * thermo.setPolarity(POLARITY_ACTIVE_HIGH); * * while (true) { @@ -73,23 +97,21 @@ /** * DS1721 constructor * - * @param sda SDA pin - * @param sdl SCL pin - * @param addr addr of the I2C peripheral + * @param &i2c pointer to i2c object + * @param addr addr of the I2C peripheral default = (DS1721_ADDR<<1) **/ - DS1721(PinName sda, PinName scl, int addr); + DS1721(I2C &i2c, int addr = (DS1721_ADDR<<1)); /** * DS1721 constructor * - * @param sda SDA pin - * @param sdl SCL pin - * @param addr addr of the I2C peripheral + * @param &i2c pointer to I2C object * @param resolution readout resolution of the theremometer (9, 10, 11, 12 bit) * @param polarity the state on which the thermostat output is enabled * @param mode the temperature conversion mode (single shot or continuous) + * @param addr addr of the I2C peripheral default = (DS1721_ADDR<<1) **/ - DS1721(PinName sda, PinName scl, int addr,int resolution, int polarity, int mode); + DS1721(I2C &i2c,int resolution, int polarity, int mode, int addr = (DS1721_ADDR<<1)); /*! * DS1721 destructor @@ -99,9 +121,9 @@ /** * Reads the temperature from the DS1721 and converts it to a useable value. * - * @returns the current temperature, as in integer + * @returns the current temperature, as a float **/ - int getTemp(void); + float getTemp(void); /** * Sets the temperature polarity (POL) bit of the sensor. This bit determines @@ -114,7 +136,7 @@ /** * Gets the temperature polarity (POL) bit of the sensor. This bit determines - * upon which set point the theremostat output is active. + * upon which set point the theremostat output (Tout) is active. * * @returns the value of the POL bit (0 - active low, 1 - active high) **/ @@ -155,7 +177,7 @@ * * @returns the current low temperature set point value (degrees C) **/ - int getLowSetpoint(void); + float getLowSp(void); /** * Sets the low temperature set point value. @@ -163,14 +185,14 @@ * @param int the new low set point temperature (degrees C) * @returns the result of the function (0 - Failure, 1 - Success) **/ - int setLowSetpoint(int newSp); + int setLowSp(float newSp); /** * Retrieves the configured high temperature set point value. * * @returns the current high temperature set point value (degrees C) **/ - int getHighSetpoint(void); + float getHighSp(void); /** * Sets the high temperature set point value. @@ -178,10 +200,27 @@ * @param int the new high temperature set point value (degrees C) * @returns the result of the function (0 - Failure, 1 - Success) **/ - int setHighSetpoint(int newSp); + int setHighSp(float newSp); + + /* + * Helper function to convert degrees Celcius to Fahrenheit + * + * @param temperature in degrees Celcius + * @return temperature in degrees Fahrenheit + */ + float temp_CtoF(float tempC); + + /* + * Helper function to convert degrees Fahrenheit to Celcius + * + * @param temperature in degrees Fahrenheit + * @return temperature in degrees Celcius + */ + float temp_FtoC(float tempF); + private: - I2C m_i2c; + I2C &m_i2c; int m_addr; int _resolution; int _polarity; @@ -189,6 +228,9 @@ int _tl; int _num_read; int _th; + + int writeData(char* data, int length); + int readData(char* data, int length); }; #endif