Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LM75B by
Diff: LM75B.cpp
- Revision:
- 8:2b797c309258
- Parent:
- 4:06676376766a
- Child:
- 9:74b44a27fa40
--- a/LM75B.cpp Fri Aug 09 22:21:36 2013 +0000 +++ b/LM75B.cpp Wed Aug 14 04:33:25 2013 +0000 @@ -17,16 +17,16 @@ #include "LM75B.h" #include "mbed.h" -LM75B::LM75B(PinName sda, PinName scl, Address addr) : _i2c(sda, scl) +LM75B::LM75B(PinName sda, PinName scl, Address addr) : m_I2C(sda, scl) { //Set the internal device address - _addr = (int)addr; + m_Addr = (int)addr; } -LM75B::PowerMode LM75B::getPowerMode(void) +LM75B::PowerMode LM75B::powerMode(void) { //Read the 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Return the status of the SHUTDOWN bit if (value & (1 << 0)) @@ -35,10 +35,10 @@ return POWER_NORMAL; } -void LM75B::setPowerMode(PowerMode mode) +void LM75B::powerMode(PowerMode mode) { //Read the current 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Set or clear the SHUTDOWN bit if (mode == POWER_SHUTDOWN) @@ -47,13 +47,13 @@ value &= ~(1 << 0); //Write the value back out - _write8(__LM75B_REG_CONF, value); + write8(REG_CONF, value); } -LM75B::OSMode LM75B::getOSMode(void) +LM75B::OSMode LM75B::osMode(void) { //Read the 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Return the status of the OS_COMP_INT bit if (value & (1 << 1)) @@ -62,10 +62,10 @@ return OS_COMPARATOR; } -void LM75B::setOSMode(OSMode mode) +void LM75B::osMode(OSMode mode) { //Read the current 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Set or clear the OS_COMP_INT bit if (mode == OS_INTERRUPT) @@ -74,13 +74,13 @@ value &= ~(1 << 1); //Write the value back out - _write8(__LM75B_REG_CONF, value); + write8(REG_CONF, value); } -LM75B::OSPolarity LM75B::getOSPolarity(void) +LM75B::OSPolarity LM75B::osPolarity(void) { //Read the 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Return the status of the OS_POL bit if (value & (1 << 2)) @@ -89,10 +89,10 @@ return OS_ACTIVE_LOW; } -void LM75B::setOSPolarity(OSPolarity polarity) +void LM75B::osPolarity(OSPolarity polarity) { //Read the current 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Set or clear the OS_POL bit if (polarity == OS_ACTIVE_HIGH) @@ -101,13 +101,13 @@ value &= ~(1 << 2); //Write the value back out - _write8(__LM75B_REG_CONF, value); + write8(REG_CONF, value); } -LM75B::OSFaultQueue LM75B::getOSFaultQueue(void) +LM75B::OSFaultQueue LM75B::osFaultQueue(void) { //Read the 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Return the status of the OS_F_QUE bits if ((value & (1 << 3)) && (value & (1 << 4))) @@ -120,10 +120,10 @@ return OS_FAULT_QUEUE_1; } -void LM75B::setOSFaultQueue(OSFaultQueue queue) +void LM75B::osFaultQueue(OSFaultQueue queue) { //Read the current 8-bit register value - char value = _read8(__LM75B_REG_CONF); + char value = read8(REG_CONF); //Clear the old OS_F_QUE bits value &= ~(3 << 3); @@ -137,40 +137,40 @@ value |= (3 << 3); //Write the value back out - _write8(__LM75B_REG_CONF, value); + write8(REG_CONF, value); } -float LM75B::getAlertTemp(void) +float LM75B::alertTemp(void) { //Use the 9-bit helper to read the TOS register - return _readTempHelper(__LM75B_REG_TOS); + return readAlertTempHelper(REG_TOS); } -void LM75B::setAlertTemp(float temp) +void LM75B::alertTemp(float temp) { //Use the 9-bit helper to write to the TOS register - return _writeTempHelper(__LM75B_REG_TOS, temp); + return writeAlertTempHelper(REG_TOS, temp); } -float LM75B::getAlertHyst(void) +float LM75B::alertHyst(void) { //Use the 9-bit helper to read the THYST register - return _readTempHelper(__LM75B_REG_THYST); + return readAlertTempHelper(REG_THYST); } -void LM75B::setAlertHyst(float temp) +void LM75B::alertHyst(float temp) { //Use the 9-bit helper to write to the THYST register - return _writeTempHelper(__LM75B_REG_THYST, temp); + return writeAlertTempHelper(REG_THYST, temp); } -float LM75B::getTemp(void) +float LM75B::temp(void) { //Signed return value short value; //Read the 11-bit raw temperature value - value = _read16(__LM75B_REG_TEMP) >> 5; + value = read16(REG_TEMP) >> 5; //Sign extend negative numbers if (value & (1 << 10)) @@ -180,19 +180,19 @@ return value * 0.125; } -char LM75B::_read8(char reg) +char LM75B::read8(char reg) { //Select the register - _i2c.write(_addr, ®, 1); + m_I2C.write(m_Addr, ®, 1); //Read the 8-bit register - _i2c.read(_addr, ®, 1); + m_I2C.read(m_Addr, ®, 1); //Return the byte return reg; } -void LM75B::_write8(char reg, char data) +void LM75B::write8(char reg, char data) { //Create a temporary buffer char buff[2]; @@ -202,25 +202,25 @@ buff[1] = data; //Write the data - _i2c.write(_addr, buff, 2); + m_I2C.write(m_Addr, buff, 2); } -unsigned short LM75B::_read16(char reg) +unsigned short LM75B::read16(char reg) { //Create a temporary buffer char buff[2]; //Select the register - _i2c.write(_addr, ®, 1); + m_I2C.write(m_Addr, ®, 1); //Read the 16-bit register - _i2c.read(_addr, buff, 2); + m_I2C.read(m_Addr, buff, 2); //Return the combined 16-bit value return (buff[0] << 8) | buff[1]; } -void LM75B::_write16(char reg, unsigned short data) +void LM75B::write16(char reg, unsigned short data) { //Create a temporary buffer char buff[3]; @@ -231,16 +231,16 @@ buff[2] = data; //Write the data - _i2c.write(_addr, buff, 3); + m_I2C.write(m_Addr, buff, 3); } -float LM75B::_readTempHelper(char reg) +float LM75B::readAlertTempHelper(char reg) { //Signed return value short value; //Read the 9-bit raw temperature value - value = _read16(reg) >> 7; + value = read16(reg) >> 7; //Sign extend negative numbers if (value & (1 << 8)) @@ -250,7 +250,7 @@ return value * 0.5; } -void LM75B::_writeTempHelper(char reg, float temp) +void LM75B::writeAlertTempHelper(char reg, float temp) { //Range limit temp if (temp < -55.0) @@ -263,5 +263,5 @@ value <<= 7; //Send the new value - _write16(reg, value); + write16(reg, value); }