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

@ -71,7 +71,7 @@ BME280::BME280 (int bus, int devAddr) {
* Bus Write * Bus Write
* Bus read * Bus read
* Chip id * Chip id
*-------------------------------------------------------------------------*/ *-------------------------------------------------------------------------*/
bme280_init(&bme280); bme280_init(&bme280);
} }
} }
@ -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
@ -224,7 +212,7 @@ return v_data_uncomp_tem_int32;
/* This function is an example for reading sensor pressure /* This function is an example for reading sensor pressure
* \param: None * \param: None
* \return: uncompensated pressure * \return: uncompensated pressure
*/ */
int32_t BME280::getPressureRawInternal(void) int32_t BME280::getPressureRawInternal(void)
@ -248,7 +236,7 @@ int32_t BME280::getPressureRawInternal(void)
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH" * In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write * register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
* the "BME280_CTRLMEAS_REG" register in the function*/ * the "BME280_CTRLMEAS_REG" register in the function*/
/* set the pressure oversampling*/ /* set the pressure oversampling*/
bme280_set_oversamp_pressure(BME280_OVERSAMP_2X); bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
@ -379,14 +367,14 @@ int32_t BME280::i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt)
{ {
mraa::Result ret; mraa::Result ret;
m_i2c->address(dev_addr); m_i2c->address(dev_addr);
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0) if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
{ {
UPM_THROW("I2C write error"); UPM_THROW("I2C write error");
} }
} }
/* \Brief: The function is used as I2C bus write /* \Brief: The function is used as I2C bus write
* \Return : Status of the I2C write * \Return : Status of the I2C write
@ -403,7 +391,7 @@ int8_t BME280::BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t
int32_t iError = BME280_INIT_VALUE; int32_t iError = BME280_INIT_VALUE;
static uint8_t array[I2C_BUFFER_LEN]; static uint8_t array[I2C_BUFFER_LEN];
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0; for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
uint8_t stringpos = BME280_INIT_VALUE; uint8_t stringpos = BME280_INIT_VALUE;
array[BME280_INIT_VALUE] = reg_addr; array[BME280_INIT_VALUE] = reg_addr;
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) { for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
@ -418,7 +406,7 @@ int32_t BME280::i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_
mraa::Result ret; mraa::Result ret;
m_i2c->address(dev_addr); m_i2c->address(dev_addr);
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt) if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
{ {
UPM_THROW("bme280 register read failed"); UPM_THROW("bme280 register read failed");
@ -453,7 +441,7 @@ int8_t BME280::BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *
void BME280::BME280_delay_msek(uint16_t mseconds) void BME280::BME280_delay_msek(uint16_t mseconds)
{ {
struct timespec sleepTime; struct timespec sleepTime;
sleepTime.tv_sec = mseconds / 1000; // Number of seconds sleepTime.tv_sec = mseconds / 1000; // Number of seconds
sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds
@ -472,7 +460,7 @@ uint16_t BME280::getTemperatureRaw (){ return BME280::getTemperatureRawInternal(
/** /**
* Get temperature measurement. * Get temperature measurement.
*/ */
int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; } int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; }
/** /**
* Get relative humidity measurement. * Get relative humidity measurement.
*/ */

View File

@ -6,7 +6,7 @@
#define __BME280_H__ #define __BME280_H__
//#define BME280_MDELAY_DATA_TYPE uint32_t //#define BME280_MDELAY_DATA_TYPE uint32_t
/****************************************************/ /****************************************************/
/**\name I2C ADDRESS DEFINITIONS */ /**\name I2C ADDRESS DEFINITIONS */
@ -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.
@ -72,48 +70,39 @@ class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressu
/** /**
* Return calculated pressure (Pa) * Return calculated pressure (Pa)
*/ */
int getPressurePa(); int getPressurePa();
/** /**
* 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

@ -65,7 +65,7 @@ namespace upm {
* @con i2c * @con i2c
* @if ipressuresensor * @if ipressuresensor
* *
*/ */
class BMP180 : public IPressureSensor, public ITemperatureSensor { class BMP180 : public IPressureSensor, public ITemperatureSensor {
@ -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

@ -33,9 +33,9 @@
using namespace upm; using namespace upm;
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_controlAddr(devAddr), m_i2ControlCtx(bus) { BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_controlAddr(devAddr), m_i2ControlCtx(bus) {
m_name = "BMPX8X"; m_name = "BMPX8X";
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr); mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
if (ret != mraa::SUCCESS) { if (ret != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
@ -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));
@ -62,7 +57,7 @@ int DS1808LC::getBrightness()
else else
UPM_THROW("i2c read error"); UPM_THROW("i2c read error");
} }
void DS1808LC::setBrightness(int dutyPercent) void DS1808LC::setBrightness(int dutyPercent)
{ {

View File

@ -40,7 +40,7 @@ namespace upm
* [DS1808](http://www.maximintegrated.com/en/products/analog/data-converters/digital-potentiometers/DS1808.html) * [DS1808](http://www.maximintegrated.com/en/products/analog/data-converters/digital-potentiometers/DS1808.html)
* Dual Log Digital Potentiometer * Dual Log Digital Potentiometer
* *
* *
* @library ds1808lc * @library ds1808lc
* @sensor ds1808lc * @sensor ds1808lc
* @comname Maxim DS1808 as lighting controller * @comname Maxim DS1808 as lighting controller
@ -57,8 +57,7 @@ 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();
void setPowerOff(); void setPowerOff();

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,8 +58,7 @@ 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();
bool isPowered(); bool isPowered();

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;
@ -140,7 +135,7 @@ bool LP8860::isAvailable()
uint8_t id = i2c->readReg(LP8860_ID); uint8_t id = i2c->readReg(LP8860_ID);
// Turn off to save power if not required // Turn off to save power if not required
if (!wasPowered) if (!wasPowered)
MraaUtils::setGpio(pinPower, 0); MraaUtils::setGpio(pinPower, 0);
return id >= 0x10; return id >= 0x10;
} }
@ -174,7 +169,7 @@ int LP8860::getBrightness()
{ {
uint8_t msb = i2cReadByte(LP8860_DISP_CL1_BRT_MSB); uint8_t msb = i2cReadByte(LP8860_DISP_CL1_BRT_MSB);
uint8_t lsb = i2cReadByte(LP8860_DISP_CL1_BRT_LSB); uint8_t lsb = i2cReadByte(LP8860_DISP_CL1_BRT_LSB);
int percent = (100 * ((int)msb << 8 | lsb)) / 0xFFFF; int percent = (100 * ((int)msb << 8 | lsb)) / 0xFFFF;
return percent; return percent;
} }
@ -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");
} }
@ -257,7 +252,7 @@ uint8_t LP8860::i2cReadByte(uint8_t reg)
uint8_t value; uint8_t value;
i2c->address(LP8860_I2C_ADDR); i2c->address(LP8860_I2C_ADDR);
if (i2c->readBytesReg(reg, &value, 1) != 1) if (i2c->readBytesReg(reg, &value, 1) != 1)
UPM_THROW("i2cReadByte failed"); UPM_THROW("i2cReadByte failed");
return value; return value;
} }
@ -275,8 +270,8 @@ 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");
} }
@ -284,6 +279,6 @@ void LP8860::i2cReadBuffer(int reg, uint8_t* buf, int length)
{ {
i2c->address(LP8860_I2C_ADDR); i2c->address(LP8860_I2C_ADDR);
if (i2c->readBytesReg(reg, buf, length) != length) if (i2c->readBytesReg(reg, buf, length) != length)
UPM_THROW("i2cReadBuffer failed"); UPM_THROW("i2cReadBuffer 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");
} }
@ -81,19 +81,14 @@ double
MAX44009::getVisibleLux() { MAX44009::getVisibleLux() {
uint16_t rawValue = getVisibleRaw(); uint16_t rawValue = getVisibleRaw();
uint8_t rawValueMsb = rawValue >> 8; uint8_t rawValueMsb = rawValue >> 8;
uint8_t rawValueLsb = rawValue & 0xFF; uint8_t rawValueLsb = rawValue & 0xFF;
uint8_t exponent = (( rawValueMsb & 0xF0 ) >> 4); uint8_t exponent = (( rawValueMsb & 0xF0 ) >> 4);
uint8_t mantissa = (( rawValueMsb & 0x0F ) << 4 ) | ( rawValueLsb & 0x0F ); uint8_t mantissa = (( rawValueMsb & 0x0F ) << 4 ) | ( rawValueLsb & 0x0F );
// Check for overrange condition // Check for overrange condition
if(exponent == MAX44009_OVERRANGE_CONDITION) if(exponent == MAX44009_OVERRANGE_CONDITION)
UPM_THROW("Overrange error"); UPM_THROW("Overrange error");
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

@ -129,12 +129,8 @@ class MAX44009 : public ILightSensor {
* Read the lux value * Read the lux value
*/ */
double getVisibleLux(); double getVisibleLux();
/** const char* getModuleName() { return "max44009"; }
* Returns whether the sensor is configured.
*/
bool isConfigured();
const char* getModuleName() { return "max44009"; }
private: private:
mraa::Result reset(); mraa::Result reset();

View File

@ -57,13 +57,13 @@
#define SI1132_COMMAND_ALS_FORCE 0x06 #define SI1132_COMMAND_ALS_FORCE 0x06
#define SI1132_COMMAND_PARAM_QUERY 0x80 #define SI1132_COMMAND_PARAM_QUERY 0x80
#define SI1132_COMMAND_PARAM_SET 0xA0 #define SI1132_COMMAND_PARAM_SET 0xA0
#define SI1132_COMMAND_ALS_AUTO 0x0E #define SI1132_COMMAND_ALS_AUTO 0x0E
/* PARAMETER RAM ADDRESSES */ /* PARAMETER RAM ADDRESSES */
#define SI1132_PARAM_CHLIST 0x01 #define SI1132_PARAM_CHLIST 0x01
#define SI1132_PARAM_ALS_VIS_ADC_COUNT 0x10 #define SI1132_PARAM_ALS_VIS_ADC_COUNT 0x10
#define SI1132_PARAM_ALS_VIS_ADC_GAIN 0x11 #define SI1132_PARAM_ALS_VIS_ADC_GAIN 0x11
#define SI1132_PARAM_ALS_VIS_ADC_MISC 0x12 #define SI1132_PARAM_ALS_VIS_ADC_MISC 0x12
/* PARAMETER RAM VALUES */ /* PARAMETER RAM VALUES */
#define SI1132_PARAM_CHLIST_ENALSVIS 0x10 #define SI1132_PARAM_CHLIST_ENALSVIS 0x10
@ -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");
} }
@ -97,14 +97,14 @@ mraa::Result SI1132::reset() {
fprintf(stderr, "SI1132: Read ID failed. Data = %02x\n", regValue); fprintf(stderr, "SI1132: Read ID failed. Data = %02x\n", regValue);
status = mraa::ERROR_UNSPECIFIED; status = mraa::ERROR_UNSPECIFIED;
return status; return status;
} }
// disable automatic updates // disable automatic updates
uint16_t rate = 0; uint16_t rate = 0;
status = i2c->writeWordReg(SI1132_REG_MEAS_RATE0, rate); status = i2c->writeWordReg(SI1132_REG_MEAS_RATE0, rate);
if (status != mraa::SUCCESS) { if (status != mraa::SUCCESS) {
fprintf(stderr, "SI1132_REG_MEAS_RATE0 failed\n"); fprintf(stderr, "SI1132_REG_MEAS_RATE0 failed\n");
return status; return status;
} }
// reset device // reset device
@ -113,7 +113,7 @@ mraa::Result SI1132::reset() {
fprintf(stderr, "SI1132: Reset failed.\n"); fprintf(stderr, "SI1132: Reset failed.\n");
status = mraa::ERROR_UNSPECIFIED; status = mraa::ERROR_UNSPECIFIED;
return status; return status;
} }
sleepMs(30); sleepMs(30);
// start state machine // start state machine
@ -122,17 +122,17 @@ mraa::Result SI1132::reset() {
if (regValue != SI1132_HW_KEY_INIT) { if (regValue != SI1132_HW_KEY_INIT) {
fprintf(stderr, "Si1132: Did not start\n"); fprintf(stderr, "Si1132: Did not start\n");
status = mraa::ERROR_UNSPECIFIED; status = mraa::ERROR_UNSPECIFIED;
return status; return status;
} }
status = writeParam(SI1132_PARAM_CHLIST, SI1132_PARAM_CHLIST_ENALSVIS); status = writeParam(SI1132_PARAM_CHLIST, SI1132_PARAM_CHLIST_ENALSVIS);
// set visible light range for indoor lighting // set visible light range for indoor lighting
status = writeParam(SI1132_PARAM_ALS_VIS_ADC_MISC, SI1132_PARAM_ALS_VIS_RANGE_STD); status = writeParam(SI1132_PARAM_ALS_VIS_ADC_MISC, SI1132_PARAM_ALS_VIS_RANGE_STD);
// set visible light gain to 8 // set visible light gain to 8
status = writeParam(SI1132_PARAM_ALS_VIS_ADC_GAIN, 3); status = writeParam(SI1132_PARAM_ALS_VIS_ADC_GAIN, 3);
status = writeParam(SI1132_PARAM_ALS_VIS_ADC_COUNT, 3 << 4); status = writeParam(SI1132_PARAM_ALS_VIS_ADC_COUNT, 3 << 4);
return status; return status;
} }
@ -141,7 +141,7 @@ uint16_t SI1132::getVisibleRaw() {
status = runCommand(SI1132_COMMAND_ALS_FORCE); status = runCommand(SI1132_COMMAND_ALS_FORCE);
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
UPM_THROW("command failed"); UPM_THROW("command failed");
return i2c->readWordReg(SI1132_REG_ALS_VIS_DATA0); return i2c->readWordReg(SI1132_REG_ALS_VIS_DATA0);
} }
@ -154,19 +154,15 @@ 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()
{ {
uint8_t regValue = 0xFF; uint8_t regValue = 0xFF;
status = i2c->writeReg(SI1132_REG_COMMAND, 0); status = i2c->writeReg(SI1132_REG_COMMAND, 0);
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
return status; return status;
int bytesRead = i2c->readBytesReg(SI1132_REG_RESPONSE, &regValue, 1); int bytesRead = i2c->readBytesReg(SI1132_REG_RESPONSE, &regValue, 1);
if (bytesRead == 1 && regValue == 0) if (bytesRead == 1 && regValue == 0)
status = mraa::SUCCESS; status = mraa::SUCCESS;
else else
status = mraa::ERROR_UNSPECIFIED; status = mraa::ERROR_UNSPECIFIED;
@ -178,13 +174,13 @@ mraa::Result SI1132::runCommand(uint8_t command)
uint8_t response = 0; uint8_t response = 0;
int sleepTimeMs = 5; int sleepTimeMs = 5;
int timeoutMs = 50; int timeoutMs = 50;
int waitTimeMs = 0; int waitTimeMs = 0;
i2c->address(SI1132_ADDRESS); i2c->address(SI1132_ADDRESS);
status = clearResponseRegister(); status = clearResponseRegister();
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
return status; return status;
status = i2c->writeReg(SI1132_REG_COMMAND, command); status = i2c->writeReg(SI1132_REG_COMMAND, command);
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
return status; return status;
while (response == 0 && waitTimeMs < timeoutMs) { while (response == 0 && waitTimeMs < timeoutMs) {
response = i2c->readReg(SI1132_REG_RESPONSE); response = i2c->readReg(SI1132_REG_RESPONSE);
@ -202,7 +198,7 @@ mraa::Result SI1132::writeParam(uint8_t param, uint8_t value)
{ {
i2c->address(SI1132_ADDRESS); i2c->address(SI1132_ADDRESS);
status = i2c->writeReg(SI1132_REG_PARAM_WR, value); status = i2c->writeReg(SI1132_REG_PARAM_WR, value);
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
return status; return status;
return runCommand(SI1132_COMMAND_PARAM_SET | param); return runCommand(SI1132_COMMAND_PARAM_SET | param);
} }
@ -210,11 +206,11 @@ mraa::Result SI1132::writeParam(uint8_t param, uint8_t value)
mraa::Result SI1132::readParam(uint8_t param, uint8_t* value) mraa::Result SI1132::readParam(uint8_t param, uint8_t* value)
{ {
status = runCommand(SI1132_COMMAND_PARAM_QUERY | param); status = runCommand(SI1132_COMMAND_PARAM_QUERY | param);
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
return status; return status;
if (i2c->readBytesReg(SI1132_REG_PARAM_RD, value, 1) != 1) if (i2c->readBytesReg(SI1132_REG_PARAM_RD, value, 1) != 1)
status = mraa::ERROR_UNSPECIFIED; status = mraa::ERROR_UNSPECIFIED;
return status; return status;
} }

View File

@ -41,7 +41,7 @@ namespace upm {
* *
* The Silicon Labs * The Silicon Labs
* [Si1132](https://www.silabs.com/Support%20Documents/TechnicalDocs/Si1132.pdf) * [Si1132](https://www.silabs.com/Support%20Documents/TechnicalDocs/Si1132.pdf)
* is a low-power, ultraviolet (UV) index, and ambient light sensor with I2C * is a low-power, ultraviolet (UV) index, and ambient light sensor with I2C
* digital interface and programmable-event interrupt output. * digital interface and programmable-event interrupt output.
* *
* @library si1132 * @library si1132
@ -78,12 +78,8 @@ class SI1132 : public ILightSensor {
* Read the lux value * Read the lux value
*/ */
double getVisibleLux(); double getVisibleLux();
/** const char* getModuleName() { return "si1132"; }
* Returns whether the sensor is configured.
*/
bool isConfigured();
const char* getModuleName() { return "si1132"; }
private: private:
mraa::Result reset(); mraa::Result reset();

View File

@ -150,7 +150,7 @@ uint16_t SI7005::getMeasurement(uint8_t configValue) {
// Check we got the data we need // Check we got the data we need
if(length != SI7005_REG_DATA_LENGTH) if(length != SI7005_REG_DATA_LENGTH)
UPM_THROW("read error"); UPM_THROW("read error");
// Merge MSB and LSB // Merge MSB and LSB
rawData = ((uint16_t)( data[SI7005_REG_DATA_LOW] & 0xFFFF )) + ( (uint16_t)(( data[SI7005_REG_DATA_HIGH] & 0xFFFF ) << 8 )); rawData = ((uint16_t)( data[SI7005_REG_DATA_LOW] & 0xFFFF )) + ( (uint16_t)(( data[SI7005_REG_DATA_HIGH] & 0xFFFF ) << 8 ));
@ -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

@ -88,20 +88,16 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
* Get relative humidity measurement. * Get relative humidity measurement.
*/ */
uint16_t getHumidityRaw (); uint16_t getHumidityRaw ();
/** /**
* 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
*/ */
const char* getModuleName() { return "si7005"; } const char* getModuleName() { return "si7005"; }
/** /**
* Detects the sensor to ensure it is connected as required. * Detects the sensor to ensure it is connected as required.

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,20 +63,15 @@ T6713::~T6713()
delete i2c; delete i2c;
} }
bool T6713::isConfigured() const char* T6713::getModuleName()
{ {
return status == mraa::SUCCESS; return "t6713";
} }
const char* T6713::getModuleName()
{
return "t6713";
}
uint16_t T6713::getFirmwareRevision() uint16_t T6713::getFirmwareRevision()
{ {
return(getSensorData(T6713_COMMAND_GET_FIRMWARE_REVISION)); return(getSensorData(T6713_COMMAND_GET_FIRMWARE_REVISION));
} }
uint16_t T6713::getPpm () uint16_t T6713::getPpm ()
{ {
@ -115,7 +110,7 @@ uint16_t T6713::getSensorData (MODBUS_COMMANDS cmd)
if (ret != mraa::SUCCESS) if (ret != mraa::SUCCESS)
{ {
UPM_THROW ("I2C error setting slave address"); UPM_THROW ("I2C error setting slave address");
// TODO: need to handle this // TODO: need to handle this
} }
RESPONSE * response = new RESPONSE ; RESPONSE * response = new RESPONSE ;
if(readBytes = i2c->read((uint8_t*)(response), sizeof(RESPONSE) ) != sizeof(RESPONSE)) if(readBytes = i2c->read((uint8_t*)(response), sizeof(RESPONSE) ) != sizeof(RESPONSE))
@ -133,13 +128,13 @@ uint16_t T6713::getSensorData (MODBUS_COMMANDS cmd)
delete(response); response=NULL; delete(response); response=NULL;
return(data); return(data);
break; break;
} }
return 0; return 0;
} }
mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd) mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
{ {
COMMAND * cmdPacket = new COMMAND ; COMMAND * cmdPacket = new COMMAND ;
@ -195,7 +190,7 @@ mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
if (ret != mraa::SUCCESS) if (ret != mraa::SUCCESS)
{ {
UPM_THROW ("I2C error setting slave address"); UPM_THROW ("I2C error setting slave address");
//need to handle this //need to handle this
} }
@ -203,16 +198,16 @@ mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
{ {
UPM_THROW("I2C write failed"); UPM_THROW("I2C write failed");
} }
break; break;
} }
delete cmdPacket; cmdPacket=NULL; delete cmdPacket; cmdPacket=NULL;
return ret; return ret;
} }
STATUS T6713::getStatus() STATUS T6713::getStatus()
{ {
uint16_t responseStatus = 0, readBytes = 0; uint16_t responseStatus = 0, readBytes = 0;
RESPONSE * response = new RESPONSE ; RESPONSE * response = new RESPONSE ;
@ -221,18 +216,18 @@ STATUS T6713::getStatus()
if (ret != mraa::SUCCESS) if (ret != mraa::SUCCESS)
{ {
UPM_THROW ("I2C error setting slave address"); UPM_THROW ("I2C error setting slave address");
//need to handle tnis //need to handle tnis
} }
if(readBytes = i2c->read((uint8_t*) (response), sizeof(RESPONSE)) != sizeof(RESPONSE)) if(readBytes = i2c->read((uint8_t*) (response), sizeof(RESPONSE)) != sizeof(RESPONSE))
{ {
UPM_THROW("I2C read failed"); UPM_THROW("I2C read failed");
} }
if(response->function_code == READ_INPUT_REGISTERS) if(response->function_code == READ_INPUT_REGISTERS)
{ {
if(response->byte_count == 2) if(response->byte_count == 2)
{ {
responseStatus = (response->status_msb << 8 | response->status_lsb); responseStatus = (response->status_msb << 8 | response->status_lsb);
} }
else else
{ {

View File

@ -80,7 +80,7 @@ namespace t6713_co2
{ {
uint8_t function_code; uint8_t function_code;
uint8_t register_address_msb; uint8_t register_address_msb;
uint8_t register_address_lsb; uint8_t register_address_lsb;
uint8_t input_registers_to_read_msb; uint8_t input_registers_to_read_msb;
uint8_t input_registers_to_read_lsb; uint8_t input_registers_to_read_lsb;
@ -119,15 +119,10 @@ class T6713 : public ICO2Sensor {
*/ */
~T6713 (); ~T6713 ();
/**
* Returns whether the sensor is configured.
*/
bool isConfigured();
/** /**
* Returns sensor module name * Returns sensor module name
*/ */
const char* getModuleName(); const char* getModuleName();
/** /**
* Get relative humidity measurement. * Get relative humidity measurement.
@ -143,7 +138,7 @@ class T6713 : public ICO2Sensor {
mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command); mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command);
uint16_t getSensorData (t6713_co2::MODBUS_COMMANDS cmd); uint16_t getSensorData (t6713_co2::MODBUS_COMMANDS cmd);
t6713_co2::STATUS getStatus(); t6713_co2::STATUS getStatus();
int bus; int bus;
mraa::I2c* i2c; mraa::I2c* i2c;
mraa::Result status; mraa::Result status;

View File

@ -34,18 +34,9 @@ namespace upm
#define UPM_THROW(msg) throw std::runtime_error(std::string(__FUNCTION__) + ": " + (msg)) #define UPM_THROW(msg) throw std::runtime_error(std::string(__FUNCTION__) + ": " + (msg))
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_