/*
* lm75a.cpp: part of the "VoluMaster(tm)" system
*
* An open-source arduino controller-based digital volume control and input/output selector
*
*
* LICENSE
* -------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "lm75a.h"
#include
#include //not needed yet
#include //needed for strlen()
#include
#include "WConstants.h" //all things wiring / arduino
#include "config.h"
// ctor
LM75A::LM75A( uint8_t passed_i2c_addr )
{
my_dev_addr = passed_i2c_addr;
}
void
LM75A::init( void )
{
}
#if 0
void
LM75A::set( uint8_t reg, uint8_t val )
{
Wire.beginTransmission(my_dev_addr);
Wire.send(reg);
Wire.send(val);
Wire.endTransmission();
}
#endif
float
LM75A::get_temp( void )
{
unsigned int val = 0;
unsigned int shifted = 0;
float val_f = 0.0;
Wire.beginTransmission(my_dev_addr);
Wire.send(0x00); // 0 = 'temperature register' and this implies that we expect 2 bytes (msb, lsb) in return to our request
Wire.endTransmission();
Wire.requestFrom((uint8_t)my_dev_addr, (uint8_t)2); // read 2 bytes
while (Wire.available() < 2) { } // note the null loop!
val = (Wire.receive() << 8); // MSB
val |= Wire.receive(); // LSB
// now, deal with the funky lm75a bit-shifting
shifted = (val >> 5);
// NOTE!!! I'm making a big assumption here; that the MS bit (highest bit in MS byte) is not 1 and therefore this is not
// a 2's compliment number. this only happens when you are below 0 in binary value (0 binary == 0C, 1 binary == 0.125C, etc)
// for room temperature electronics, we should rarely see freezing temperatures (lol)
val_f = (float)shifted * 0.125;
return val_f;
}