interfaces: Removed isConfigured() from IModuleStaus

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Henry Bruce 2016-01-21 16:25:49 -08:00 committed by Abhishek Malik
parent f268437cd5
commit 9bc3d2ded0
23 changed files with 132 additions and 224 deletions

View File

@ -53,11 +53,6 @@ ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
ADS1015::~ADS1015(){}; ADS1015::~ADS1015(){};
bool
ADS1015::isConfigured() {
return true;
}
const char* const char*
ADS1015::getModuleName() { ADS1015::getModuleName() {
return m_name.c_str(); return m_name.c_str();

View File

@ -165,13 +165,6 @@ namespace upm {
*/ */
unsigned int getResolutionInBits(); unsigned int getResolutionInBits();
/**
* Returns whether the sensor is detected and correctly configured.
*
* @return true if is detected and correctly configured, otherwise false
*/
bool isConfigured();
/** /**
* Returns module name * Returns module name
* *

View File

@ -80,18 +80,6 @@ BME280::~BME280() {
delete m_i2c; delete m_i2c;
} }
bool
BME280::isAvailable() {
return true;
}
bool
BME280::isConfigured() {
return true;
}
/* This function is an example for reading sensor temperature /* This function is an example for reading sensor temperature
* \param: None * \param: None
* \return: compensated temperature * \return: compensated temperature

View File

@ -31,9 +31,7 @@ class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressu
* @param devAddr address of used i2c device * @param devAddr address of used i2c device
* @param mode BME280 mode * @param mode BME280 mode
*/ */
BME280(); BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
//BME280 (int bus, int devAddr= 0x77 , uint8_t mode = 0x03 );
BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
/** /**
* BME280 object destructor, basicaly it close i2c connection. * BME280 object destructor, basicaly it close i2c connection.
@ -79,41 +77,32 @@ class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressu
/** /**
* Return temperature * Return temperature
*/ */
int32_t getTemperatureInternal(void); int32_t getTemperatureInternal(void);
/** /**
* Return pressure * Return pressure
*/ */
int32_t getPressureInternal(void); int32_t getPressureInternal(void);
/**
/**
* Return humidity * Return humidity
*/ */
int32_t getHumidityInternal(void); int32_t getHumidityInternal(void);
/**
/**
* Return temperature * Return temperature
*/ */
int32_t getTemperatureRawInternal(void); int32_t getTemperatureRawInternal(void);
/** /**
* Return pressure * Return pressure
*/ */
int32_t getPressureRawInternal(void); int32_t getPressureRawInternal(void);
/**
/**
* Return humidity * Return humidity
*/ */
int32_t getHumidityRawInternal(void); int32_t getHumidityRawInternal(void);
//int32_t getTemperatureRaw(void);
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
/** /**
* Returns whether the correct chip is present at the given address. * Returns whether the correct chip is present at the given address.

View File

@ -98,7 +98,6 @@ BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
m_name = "BMP180"; m_name = "BMP180";
m_controlAddr = devAddr; m_controlAddr = devAddr;
m_bus = bus; m_bus = bus;
configured = false;
m_i2c = new mraa::I2c(m_bus); m_i2c = new mraa::I2c(m_bus);
@ -113,7 +112,6 @@ BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
UPM_THROW("Init failed"); UPM_THROW("Init failed");
getTemperatureCelcius(); getTemperatureCelcius();
configured = true;
} }
BMP180::~BMP180() { BMP180::~BMP180() {
@ -286,7 +284,3 @@ BMP180::isAvailable() {
return true; return true;
} }
bool
BMP180::isConfigured() {
return configured;
}

View File

@ -100,16 +100,11 @@ class BMP180 : public IPressureSensor, public ITemperatureSensor {
*/ */
int getTemperatureCelcius(); int getTemperatureCelcius();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
/** /**
* Returns whether the correct chip is present at the given address. * Returns whether the correct chip is present at the given address.
*/ */
bool isAvailable(); bool isAvailable();
const char* getModuleName() { return "bmp180"; } const char* getModuleName() { return m_name.c_str(); }
private: private:
std::string m_name; std::string m_name;
@ -125,8 +120,6 @@ class BMP180 : public IPressureSensor, public ITemperatureSensor {
int32_t b5; int32_t b5;
bool configured;
bool getCalibrationData(); bool getCalibrationData();
}; };

View File

@ -93,7 +93,8 @@ BMPX8X::getPressure () {
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling ); B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
if (B7 < 0x80000000) { if (B7 < 0x80000000) {
p = (B7 * 2) / B4; p = (B7 * 2) / B4
;
} else { } else {
p = (B7 / B4) * 2; p = (B7 / B4) * 2;
} }
@ -169,6 +170,18 @@ BMPX8X::getAltitude (float sealevelPressure) {
return altitude; return altitude;
} }
int
BMPX8X::getTemperatureCelcius() {
return static_cast<int>(getTemperature() + 0.5);
}
const char*
BMPX8X::getModuleName() {
return m_name.c_str();
}
int32_t int32_t
BMPX8X::computeB5(int32_t UT) { BMPX8X::computeB5(int32_t UT) {
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;

View File

@ -30,6 +30,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <math.h> #include <math.h>
#include "upm/iTemperatureSensor.h"
#define ADDR 0x77 // device address #define ADDR 0x77 // device address
@ -88,7 +89,7 @@ namespace upm {
* @snippet bmpx8x.cxx Interesting * @snippet bmpx8x.cxx Interesting
*/ */
class BMPX8X { class BMPX8X : public ITemperatureSensor {
public: public:
/** /**
* Instantiates a BMPX8X object * Instantiates a BMPX8X object
@ -141,6 +142,19 @@ class BMPX8X {
*/ */
float getAltitude (float sealevelPressure = 101325); float getAltitude (float sealevelPressure = 101325);
/**
* Return latest calculated temperature value in Celcius
* See ITemperatureSensor
*/
int getTemperatureCelcius();
/**
* Returns name of module. This is the string in library name after libupm_
* @return name of module
*/
const char* getModuleName();
/** /**
* Calculates B5 (check the spec for more information) * Calculates B5 (check the spec for more information)
* *

View File

@ -27,11 +27,6 @@ DS1808LC::~DS1808LC()
} }
bool DS1808LC::isConfigured()
{
return status == mraa::SUCCESS;
}
bool DS1808LC::isPowered() bool DS1808LC::isPowered()
{ {
return static_cast<bool>(MraaUtils::getGpio(pinPower)); return static_cast<bool>(MraaUtils::getGpio(pinPower));

View File

@ -57,7 +57,6 @@ public:
~DS1808LC(); ~DS1808LC();
protected: protected:
bool isConfigured();
const char* getModuleName() { return "ds1808lc"; } const char* getModuleName() { return "ds1808lc"; }
bool isPowered(); bool isPowered();
void setPowerOn(); void setPowerOn();

View File

@ -19,7 +19,7 @@ HLG150H::HLG150H(int pinRelay, int pinPWM)
UPM_THROW("pwm init failed"); UPM_THROW("pwm init failed");
status = pwmBrightness->enable(true); status = pwmBrightness->enable(true);
status = pwmBrightness->period_us(PWM_PERIOD); status = pwmBrightness->period_us(PWM_PERIOD);
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("pwm config failed."); UPM_THROW("pwm config failed.");
dutyPercent = getBrightness(); dutyPercent = getBrightness();
isPoweredShadow = dutyPercent > 10; isPoweredShadow = dutyPercent > 10;
@ -30,12 +30,6 @@ HLG150H::~HLG150H()
delete pwmBrightness; delete pwmBrightness;
} }
bool HLG150H::isConfigured()
{
return status == mraa::SUCCESS;
}
void HLG150H::setPowerOn() void HLG150H::setPowerOn()
{ {
isPoweredShadow = true; isPoweredShadow = true;
@ -68,14 +62,11 @@ void HLG150H::setBrightness(int dutyPercent)
{ {
if (dutyPercent < 10) if (dutyPercent < 10)
dutyPercent = 10; dutyPercent = 10;
if (isConfigured()) int dutyUs = (PWM_PERIOD * dutyPercent) / 100;
{ dutyUs = PWM_PERIOD - dutyUs;
int dutyUs = (PWM_PERIOD * dutyPercent) / 100; status = pwmBrightness->pulsewidth_us(dutyUs);
dutyUs = PWM_PERIOD - dutyUs; // std::cout << "Brightness = " << dutyPercent << "%, duty = " << dutyUs << "us" << std::endl;
status = pwmBrightness->pulsewidth_us(dutyUs); if (status != mraa::SUCCESS)
// std::cout << "Brightness = " << dutyPercent << "%, duty = " << dutyUs << "us" << std::endl;
}
else
UPM_THROW("setBrightness failed"); UPM_THROW("setBrightness failed");
} }
@ -83,14 +74,9 @@ void HLG150H::setBrightness(int dutyPercent)
int HLG150H::getBrightness() int HLG150H::getBrightness()
{ {
if (isConfigured()) float duty = pwmBrightness->read();
{ int dutyPercent = static_cast<int>(100.0 * (1.0 - duty) + 0.5);
float duty = pwmBrightness->read(); return dutyPercent;
int dutyPercent = static_cast<int>(100.0 * (1.0 - duty) + 0.5);
return dutyPercent;
}
else
UPM_THROW("getBrightness failed");
} }

View File

@ -58,7 +58,6 @@ public:
~HLG150H(); ~HLG150H();
protected: protected:
bool isConfigured();
const char* getModuleName() { return "hlg150h"; } const char* getModuleName() { return "hlg150h"; }
void setPowerOn(); void setPowerOn();
void setPowerOff(); void setPowerOff();

View File

@ -110,7 +110,7 @@ LP8860::LP8860(int gpioPower, int i2cBus)
i2c->address(LP8860_I2C_ADDR); i2c->address(LP8860_I2C_ADDR);
if (isAvailable()) if (isAvailable())
status = mraa::SUCCESS; status = mraa::SUCCESS;
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("i2c config failed."); UPM_THROW("i2c config failed.");
} }
@ -120,11 +120,6 @@ LP8860::~LP8860()
} }
bool LP8860::isConfigured()
{
return status == mraa::SUCCESS;
}
bool LP8860::isAvailable() bool LP8860::isAvailable()
{ {
bool wasPowered = true; bool wasPowered = true;
@ -247,7 +242,7 @@ void LP8860::i2cWriteByte(int reg, int value)
{ {
i2c->address(LP8860_I2C_ADDR); i2c->address(LP8860_I2C_ADDR);
status = i2c->writeReg(static_cast<uint8_t>(reg), static_cast<uint8_t>(value)); status = i2c->writeReg(static_cast<uint8_t>(reg), static_cast<uint8_t>(value));
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("i2cWriteByte failed"); UPM_THROW("i2cWriteByte failed");
} }
@ -275,7 +270,7 @@ void LP8860::i2cWriteBuffer(int reg, uint8_t* buf, int length)
} }
else else
status = mraa::ERROR_INVALID_PARAMETER; status = mraa::ERROR_INVALID_PARAMETER;
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("i2cWriteBuffer failed"); UPM_THROW("i2cWriteBuffer failed");
} }

View File

@ -55,7 +55,6 @@ class LP8860 : public upm::ILightController
public: public:
LP8860(int gpioPower, int i2cBus); LP8860(int gpioPower, int i2cBus);
~LP8860(); ~LP8860();
bool isConfigured();
const char* getModuleName() { return "lp8860"; } const char* getModuleName() { return "lp8860"; }
bool isPowered(); bool isPowered();
void setPowerOn(); void setPowerOn();

View File

@ -40,7 +40,7 @@ MAX44009::MAX44009 (int bus, int devAddr) {
// Reset chip to defaults // Reset chip to defaults
status = mraa::SUCCESS; status = mraa::SUCCESS;
reset(); reset();
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("config failure"); UPM_THROW("config failure");
} }
@ -92,8 +92,3 @@ MAX44009::getVisibleLux() {
return pow((double)2,(double)exponent) * mantissa * 0.045; return pow((double)2,(double)exponent) * mantissa * 0.045;
} }
bool
MAX44009::isConfigured() {
return status == mraa::SUCCESS;
}

View File

@ -130,10 +130,6 @@ class MAX44009 : public ILightSensor {
*/ */
double getVisibleLux(); double getVisibleLux();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
const char* getModuleName() { return "max44009"; } const char* getModuleName() { return "max44009"; }
private: private:

View File

@ -80,7 +80,7 @@ SI1132::SI1132 (int bus) {
// Reset chip to defaults // Reset chip to defaults
status = reset(); status = reset();
if (!isConfigured()) if (status != mraa::SUCCESS)
UPM_THROW("config failure"); UPM_THROW("config failure");
} }
@ -154,10 +154,6 @@ double SI1132::getVisibleLux() {
return static_cast<double>(rawValue); return static_cast<double>(rawValue);
} }
bool SI1132::isConfigured() {
return status == mraa::SUCCESS;
}
mraa::Result SI1132::clearResponseRegister() mraa::Result SI1132::clearResponseRegister()
{ {

View File

@ -79,10 +79,6 @@ class SI1132 : public ILightSensor {
*/ */
double getVisibleLux(); double getVisibleLux();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
const char* getModuleName() { return "si1132"; } const char* getModuleName() { return "si1132"; }
private: private:

View File

@ -158,10 +158,6 @@ uint16_t SI7005::getMeasurement(uint8_t configValue) {
return rawData; return rawData;
} }
bool
SI7005::isConfigured() {
return status == mraa::SUCCESS;
}
bool bool
SI7005::isAvailable( ) SI7005::isAvailable( )

View File

@ -93,10 +93,6 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
* Get relative humidity measurement. * Get relative humidity measurement.
*/ */
int getHumidityRelative (); int getHumidityRelative ();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
/** /**
* Returns sensor module name * Returns sensor module name

View File

@ -54,7 +54,7 @@ T6713::T6713 (int bus)
i2c = new mraa::I2c(bus); i2c = new mraa::I2c(bus);
status = i2c->address(T6713_ADDR); status = i2c->address(T6713_ADDR);
uint16_t firmwareRevision = getFirmwareRevision(); uint16_t firmwareRevision = getFirmwareRevision();
if (!isConfigured()) if (firmwareRevision != mraa::SUCCESS)
UPM_THROW("config failure"); UPM_THROW("config failure");
} }
@ -63,11 +63,6 @@ T6713::~T6713()
delete i2c; delete i2c;
} }
bool T6713::isConfigured()
{
return status == mraa::SUCCESS;
}
const char* T6713::getModuleName() const char* T6713::getModuleName()
{ {
return "t6713"; return "t6713";

View File

@ -119,11 +119,6 @@ class T6713 : public ICO2Sensor {
*/ */
~T6713 (); ~T6713 ();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
/** /**
* Returns sensor module name * Returns sensor module name
*/ */

View File

@ -37,15 +37,6 @@ namespace upm
class IModuleStatus class IModuleStatus
{ {
public: public:
/**
* Determines if sensor module is configured correctly
* e.g. if it uses i2c communication can it configure registers
* for correct operation.
*
* @return true if correctly configured, false it not
*/
virtual bool isConfigured() = 0;
/** /**
* Returns name of module. This is the string in library name after libupm_ * Returns name of module. This is the string in library name after libupm_