mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
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:
parent
f268437cd5
commit
9bc3d2ded0
@ -53,11 +53,6 @@ ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
|
||||
|
||||
ADS1015::~ADS1015(){};
|
||||
|
||||
bool
|
||||
ADS1015::isConfigured() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char*
|
||||
ADS1015::getModuleName() {
|
||||
return m_name.c_str();
|
||||
|
@ -165,13 +165,6 @@ namespace upm {
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -71,7 +71,7 @@ BME280::BME280 (int bus, int devAddr) {
|
||||
* Bus Write
|
||||
* Bus read
|
||||
* Chip id
|
||||
*-------------------------------------------------------------------------*/
|
||||
*-------------------------------------------------------------------------*/
|
||||
bme280_init(&bme280);
|
||||
}
|
||||
}
|
||||
@ -80,18 +80,6 @@ BME280::~BME280() {
|
||||
delete m_i2c;
|
||||
}
|
||||
|
||||
bool
|
||||
BME280::isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BME280::isConfigured() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* This function is an example for reading sensor temperature
|
||||
* \param: None
|
||||
* \return: compensated temperature
|
||||
@ -224,7 +212,7 @@ return v_data_uncomp_tem_int32;
|
||||
|
||||
/* This function is an example for reading sensor pressure
|
||||
* \param: None
|
||||
* \return: uncompensated pressure
|
||||
* \return: uncompensated pressure
|
||||
*/
|
||||
|
||||
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"
|
||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
||||
|
||||
|
||||
/* set the pressure oversampling*/
|
||||
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;
|
||||
m_i2c->address(dev_addr);
|
||||
|
||||
|
||||
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
|
||||
{
|
||||
UPM_THROW("I2C write error");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* \Brief: The function is used as I2C bus 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;
|
||||
static uint8_t array[I2C_BUFFER_LEN];
|
||||
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
|
||||
|
||||
|
||||
uint8_t stringpos = BME280_INIT_VALUE;
|
||||
array[BME280_INIT_VALUE] = reg_addr;
|
||||
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;
|
||||
|
||||
m_i2c->address(dev_addr);
|
||||
|
||||
|
||||
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
|
||||
{
|
||||
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)
|
||||
{
|
||||
struct timespec sleepTime;
|
||||
|
||||
|
||||
sleepTime.tv_sec = mseconds / 1000; // Number of seconds
|
||||
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.
|
||||
*/
|
||||
int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; }
|
||||
int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; }
|
||||
/**
|
||||
* Get relative humidity measurement.
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@
|
||||
#define __BME280_H__
|
||||
|
||||
|
||||
//#define BME280_MDELAY_DATA_TYPE uint32_t
|
||||
//#define BME280_MDELAY_DATA_TYPE uint32_t
|
||||
|
||||
/****************************************************/
|
||||
/**\name I2C ADDRESS DEFINITIONS */
|
||||
@ -31,9 +31,7 @@ class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressu
|
||||
* @param devAddr address of used i2c device
|
||||
* @param mode BME280 mode
|
||||
*/
|
||||
BME280();
|
||||
//BME280 (int bus, int devAddr= 0x77 , uint8_t mode = 0x03 );
|
||||
BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
|
||||
BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
|
||||
|
||||
/**
|
||||
* BME280 object destructor, basicaly it close i2c connection.
|
||||
@ -72,48 +70,39 @@ class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressu
|
||||
|
||||
/**
|
||||
* Return calculated pressure (Pa)
|
||||
*/
|
||||
*/
|
||||
int getPressurePa();
|
||||
|
||||
|
||||
/**
|
||||
* Return temperature
|
||||
*/
|
||||
int32_t getTemperatureInternal(void);
|
||||
int32_t getTemperatureInternal(void);
|
||||
|
||||
/**
|
||||
* Return pressure
|
||||
*/
|
||||
int32_t getPressureInternal(void);
|
||||
/**
|
||||
int32_t getPressureInternal(void);
|
||||
|
||||
/**
|
||||
* Return humidity
|
||||
*/
|
||||
int32_t getHumidityInternal(void);
|
||||
int32_t getHumidityInternal(void);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Return temperature
|
||||
*/
|
||||
int32_t getTemperatureRawInternal(void);
|
||||
int32_t getTemperatureRawInternal(void);
|
||||
|
||||
/**
|
||||
* Return pressure
|
||||
*/
|
||||
int32_t getPressureRawInternal(void);
|
||||
/**
|
||||
int32_t getPressureRawInternal(void);
|
||||
|
||||
/**
|
||||
* Return humidity
|
||||
*/
|
||||
int32_t getHumidityRawInternal(void);
|
||||
|
||||
|
||||
|
||||
|
||||
//int32_t getTemperatureRaw(void);
|
||||
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
int32_t getHumidityRawInternal(void);
|
||||
|
||||
/**
|
||||
* Returns whether the correct chip is present at the given address.
|
||||
|
@ -98,7 +98,6 @@ BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
|
||||
m_name = "BMP180";
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
configured = false;
|
||||
|
||||
m_i2c = new mraa::I2c(m_bus);
|
||||
|
||||
@ -113,7 +112,6 @@ BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
|
||||
UPM_THROW("Init failed");
|
||||
|
||||
getTemperatureCelcius();
|
||||
configured = true;
|
||||
}
|
||||
|
||||
BMP180::~BMP180() {
|
||||
@ -286,7 +284,3 @@ BMP180::isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BMP180::isConfigured() {
|
||||
return configured;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ namespace upm {
|
||||
* @con i2c
|
||||
* @if ipressuresensor
|
||||
*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class BMP180 : public IPressureSensor, public ITemperatureSensor {
|
||||
@ -100,16 +100,11 @@ class BMP180 : public IPressureSensor, public ITemperatureSensor {
|
||||
*/
|
||||
int getTemperatureCelcius();
|
||||
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
|
||||
/**
|
||||
* Returns whether the correct chip is present at the given address.
|
||||
*/
|
||||
bool isAvailable();
|
||||
const char* getModuleName() { return "bmp180"; }
|
||||
const char* getModuleName() { return m_name.c_str(); }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
@ -125,8 +120,6 @@ class BMP180 : public IPressureSensor, public ITemperatureSensor {
|
||||
|
||||
int32_t b5;
|
||||
|
||||
bool configured;
|
||||
|
||||
bool getCalibrationData();
|
||||
};
|
||||
|
||||
|
@ -33,9 +33,9 @@
|
||||
using namespace upm;
|
||||
|
||||
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_controlAddr(devAddr), m_i2ControlCtx(bus) {
|
||||
|
||||
|
||||
m_name = "BMPX8X";
|
||||
|
||||
|
||||
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
||||
if (ret != mraa::SUCCESS) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
@ -93,7 +93,8 @@ BMPX8X::getPressure () {
|
||||
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
|
||||
|
||||
if (B7 < 0x80000000) {
|
||||
p = (B7 * 2) / B4;
|
||||
p = (B7 * 2) / B4
|
||||
;
|
||||
} else {
|
||||
p = (B7 / B4) * 2;
|
||||
}
|
||||
@ -169,6 +170,18 @@ BMPX8X::getAltitude (float sealevelPressure) {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
BMPX8X::getTemperatureCelcius() {
|
||||
return static_cast<int>(getTemperature() + 0.5);
|
||||
}
|
||||
|
||||
const char*
|
||||
BMPX8X::getModuleName() {
|
||||
return m_name.c_str();
|
||||
}
|
||||
|
||||
|
||||
int32_t
|
||||
BMPX8X::computeB5(int32_t UT) {
|
||||
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
#include "upm/iTemperatureSensor.h"
|
||||
|
||||
#define ADDR 0x77 // device address
|
||||
|
||||
@ -88,7 +89,7 @@ namespace upm {
|
||||
* @snippet bmpx8x.cxx Interesting
|
||||
*/
|
||||
|
||||
class BMPX8X {
|
||||
class BMPX8X : public ITemperatureSensor {
|
||||
public:
|
||||
/**
|
||||
* Instantiates a BMPX8X object
|
||||
@ -141,6 +142,19 @@ class BMPX8X {
|
||||
*/
|
||||
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)
|
||||
*
|
||||
|
@ -27,11 +27,6 @@ DS1808LC::~DS1808LC()
|
||||
}
|
||||
|
||||
|
||||
bool DS1808LC::isConfigured()
|
||||
{
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
||||
bool DS1808LC::isPowered()
|
||||
{
|
||||
return static_cast<bool>(MraaUtils::getGpio(pinPower));
|
||||
@ -62,7 +57,7 @@ int DS1808LC::getBrightness()
|
||||
else
|
||||
UPM_THROW("i2c read error");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DS1808LC::setBrightness(int dutyPercent)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ namespace upm
|
||||
* [DS1808](http://www.maximintegrated.com/en/products/analog/data-converters/digital-potentiometers/DS1808.html)
|
||||
* Dual Log Digital Potentiometer
|
||||
*
|
||||
*
|
||||
*
|
||||
* @library ds1808lc
|
||||
* @sensor ds1808lc
|
||||
* @comname Maxim DS1808 as lighting controller
|
||||
@ -57,8 +57,7 @@ public:
|
||||
~DS1808LC();
|
||||
|
||||
protected:
|
||||
bool isConfigured();
|
||||
const char* getModuleName() { return "ds1808lc"; }
|
||||
const char* getModuleName() { return "ds1808lc"; }
|
||||
bool isPowered();
|
||||
void setPowerOn();
|
||||
void setPowerOff();
|
||||
|
@ -19,7 +19,7 @@ HLG150H::HLG150H(int pinRelay, int pinPWM)
|
||||
UPM_THROW("pwm init failed");
|
||||
status = pwmBrightness->enable(true);
|
||||
status = pwmBrightness->period_us(PWM_PERIOD);
|
||||
if (!isConfigured())
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("pwm config failed.");
|
||||
dutyPercent = getBrightness();
|
||||
isPoweredShadow = dutyPercent > 10;
|
||||
@ -30,12 +30,6 @@ HLG150H::~HLG150H()
|
||||
delete pwmBrightness;
|
||||
}
|
||||
|
||||
bool HLG150H::isConfigured()
|
||||
{
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void HLG150H::setPowerOn()
|
||||
{
|
||||
isPoweredShadow = true;
|
||||
@ -68,14 +62,11 @@ void HLG150H::setBrightness(int dutyPercent)
|
||||
{
|
||||
if (dutyPercent < 10)
|
||||
dutyPercent = 10;
|
||||
if (isConfigured())
|
||||
{
|
||||
int dutyUs = (PWM_PERIOD * dutyPercent) / 100;
|
||||
dutyUs = PWM_PERIOD - dutyUs;
|
||||
status = pwmBrightness->pulsewidth_us(dutyUs);
|
||||
// std::cout << "Brightness = " << dutyPercent << "%, duty = " << dutyUs << "us" << std::endl;
|
||||
}
|
||||
else
|
||||
int dutyUs = (PWM_PERIOD * dutyPercent) / 100;
|
||||
dutyUs = PWM_PERIOD - dutyUs;
|
||||
status = pwmBrightness->pulsewidth_us(dutyUs);
|
||||
// std::cout << "Brightness = " << dutyPercent << "%, duty = " << dutyUs << "us" << std::endl;
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("setBrightness failed");
|
||||
|
||||
}
|
||||
@ -83,14 +74,9 @@ void HLG150H::setBrightness(int dutyPercent)
|
||||
|
||||
int HLG150H::getBrightness()
|
||||
{
|
||||
if (isConfigured())
|
||||
{
|
||||
float duty = pwmBrightness->read();
|
||||
int dutyPercent = static_cast<int>(100.0 * (1.0 - duty) + 0.5);
|
||||
return dutyPercent;
|
||||
}
|
||||
else
|
||||
UPM_THROW("getBrightness failed");
|
||||
float duty = pwmBrightness->read();
|
||||
int dutyPercent = static_cast<int>(100.0 * (1.0 - duty) + 0.5);
|
||||
return dutyPercent;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,8 +58,7 @@ public:
|
||||
~HLG150H();
|
||||
|
||||
protected:
|
||||
bool isConfigured();
|
||||
const char* getModuleName() { return "hlg150h"; }
|
||||
const char* getModuleName() { return "hlg150h"; }
|
||||
void setPowerOn();
|
||||
void setPowerOff();
|
||||
bool isPowered();
|
||||
|
@ -110,7 +110,7 @@ LP8860::LP8860(int gpioPower, int i2cBus)
|
||||
i2c->address(LP8860_I2C_ADDR);
|
||||
if (isAvailable())
|
||||
status = mraa::SUCCESS;
|
||||
if (!isConfigured())
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("i2c config failed.");
|
||||
}
|
||||
|
||||
@ -120,11 +120,6 @@ LP8860::~LP8860()
|
||||
}
|
||||
|
||||
|
||||
bool LP8860::isConfigured()
|
||||
{
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
||||
bool LP8860::isAvailable()
|
||||
{
|
||||
bool wasPowered = true;
|
||||
@ -140,7 +135,7 @@ bool LP8860::isAvailable()
|
||||
uint8_t id = i2c->readReg(LP8860_ID);
|
||||
// Turn off to save power if not required
|
||||
if (!wasPowered)
|
||||
MraaUtils::setGpio(pinPower, 0);
|
||||
MraaUtils::setGpio(pinPower, 0);
|
||||
|
||||
return id >= 0x10;
|
||||
}
|
||||
@ -174,7 +169,7 @@ int LP8860::getBrightness()
|
||||
{
|
||||
uint8_t msb = i2cReadByte(LP8860_DISP_CL1_BRT_MSB);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -247,7 +242,7 @@ void LP8860::i2cWriteByte(int reg, int value)
|
||||
{
|
||||
i2c->address(LP8860_I2C_ADDR);
|
||||
status = i2c->writeReg(static_cast<uint8_t>(reg), static_cast<uint8_t>(value));
|
||||
if (!isConfigured())
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("i2cWriteByte failed");
|
||||
}
|
||||
|
||||
@ -257,7 +252,7 @@ uint8_t LP8860::i2cReadByte(uint8_t reg)
|
||||
uint8_t value;
|
||||
i2c->address(LP8860_I2C_ADDR);
|
||||
if (i2c->readBytesReg(reg, &value, 1) != 1)
|
||||
UPM_THROW("i2cReadByte failed");
|
||||
UPM_THROW("i2cReadByte failed");
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -275,8 +270,8 @@ void LP8860::i2cWriteBuffer(int reg, uint8_t* buf, int length)
|
||||
}
|
||||
else
|
||||
status = mraa::ERROR_INVALID_PARAMETER;
|
||||
if (!isConfigured())
|
||||
UPM_THROW("i2cWriteBuffer failed");
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("i2cWriteBuffer failed");
|
||||
}
|
||||
|
||||
|
||||
@ -284,6 +279,6 @@ void LP8860::i2cReadBuffer(int reg, uint8_t* buf, int length)
|
||||
{
|
||||
i2c->address(LP8860_I2C_ADDR);
|
||||
if (i2c->readBytesReg(reg, buf, length) != length)
|
||||
UPM_THROW("i2cReadBuffer failed");
|
||||
UPM_THROW("i2cReadBuffer failed");
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,6 @@ class LP8860 : public upm::ILightController
|
||||
public:
|
||||
LP8860(int gpioPower, int i2cBus);
|
||||
~LP8860();
|
||||
bool isConfigured();
|
||||
const char* getModuleName() { return "lp8860"; }
|
||||
bool isPowered();
|
||||
void setPowerOn();
|
||||
|
@ -40,7 +40,7 @@ MAX44009::MAX44009 (int bus, int devAddr) {
|
||||
// Reset chip to defaults
|
||||
status = mraa::SUCCESS;
|
||||
reset();
|
||||
if (!isConfigured())
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("config failure");
|
||||
}
|
||||
|
||||
@ -81,19 +81,14 @@ double
|
||||
MAX44009::getVisibleLux() {
|
||||
uint16_t rawValue = getVisibleRaw();
|
||||
uint8_t rawValueMsb = rawValue >> 8;
|
||||
uint8_t rawValueLsb = rawValue & 0xFF;
|
||||
uint8_t rawValueLsb = rawValue & 0xFF;
|
||||
uint8_t exponent = (( rawValueMsb & 0xF0 ) >> 4);
|
||||
uint8_t mantissa = (( rawValueMsb & 0x0F ) << 4 ) | ( rawValueLsb & 0x0F );
|
||||
|
||||
// Check for overrange condition
|
||||
if(exponent == MAX44009_OVERRANGE_CONDITION)
|
||||
UPM_THROW("Overrange error");
|
||||
if(exponent == MAX44009_OVERRANGE_CONDITION)
|
||||
UPM_THROW("Overrange error");
|
||||
|
||||
return pow((double)2,(double)exponent) * mantissa * 0.045;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
MAX44009::isConfigured() {
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
@ -129,12 +129,8 @@ class MAX44009 : public ILightSensor {
|
||||
* Read the lux value
|
||||
*/
|
||||
double getVisibleLux();
|
||||
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
const char* getModuleName() { return "max44009"; }
|
||||
|
||||
const char* getModuleName() { return "max44009"; }
|
||||
|
||||
private:
|
||||
mraa::Result reset();
|
||||
|
@ -57,13 +57,13 @@
|
||||
#define SI1132_COMMAND_ALS_FORCE 0x06
|
||||
#define SI1132_COMMAND_PARAM_QUERY 0x80
|
||||
#define SI1132_COMMAND_PARAM_SET 0xA0
|
||||
#define SI1132_COMMAND_ALS_AUTO 0x0E
|
||||
#define SI1132_COMMAND_ALS_AUTO 0x0E
|
||||
|
||||
/* PARAMETER RAM ADDRESSES */
|
||||
#define SI1132_PARAM_CHLIST 0x01
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_COUNT 0x10
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_GAIN 0x11
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_MISC 0x12
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_COUNT 0x10
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_GAIN 0x11
|
||||
#define SI1132_PARAM_ALS_VIS_ADC_MISC 0x12
|
||||
|
||||
/* PARAMETER RAM VALUES */
|
||||
#define SI1132_PARAM_CHLIST_ENALSVIS 0x10
|
||||
@ -80,7 +80,7 @@ SI1132::SI1132 (int bus) {
|
||||
|
||||
// Reset chip to defaults
|
||||
status = reset();
|
||||
if (!isConfigured())
|
||||
if (status != mraa::SUCCESS)
|
||||
UPM_THROW("config failure");
|
||||
}
|
||||
|
||||
@ -97,14 +97,14 @@ mraa::Result SI1132::reset() {
|
||||
fprintf(stderr, "SI1132: Read ID failed. Data = %02x\n", regValue);
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
// disable automatic updates
|
||||
uint16_t rate = 0;
|
||||
status = i2c->writeWordReg(SI1132_REG_MEAS_RATE0, rate);
|
||||
if (status != mraa::SUCCESS) {
|
||||
fprintf(stderr, "SI1132_REG_MEAS_RATE0 failed\n");
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
// reset device
|
||||
@ -113,7 +113,7 @@ mraa::Result SI1132::reset() {
|
||||
fprintf(stderr, "SI1132: Reset failed.\n");
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
sleepMs(30);
|
||||
|
||||
// start state machine
|
||||
@ -122,17 +122,17 @@ mraa::Result SI1132::reset() {
|
||||
if (regValue != SI1132_HW_KEY_INIT) {
|
||||
fprintf(stderr, "Si1132: Did not start\n");
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
status = writeParam(SI1132_PARAM_CHLIST, SI1132_PARAM_CHLIST_ENALSVIS);
|
||||
|
||||
// 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
|
||||
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_GAIN, 3);
|
||||
status = writeParam(SI1132_PARAM_ALS_VIS_ADC_COUNT, 3 << 4);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ uint16_t SI1132::getVisibleRaw() {
|
||||
status = runCommand(SI1132_COMMAND_ALS_FORCE);
|
||||
if (status != mraa::SUCCESS)
|
||||
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);
|
||||
}
|
||||
|
||||
bool SI1132::isConfigured() {
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
mraa::Result SI1132::clearResponseRegister()
|
||||
{
|
||||
uint8_t regValue = 0xFF;
|
||||
status = i2c->writeReg(SI1132_REG_COMMAND, 0);
|
||||
if (status != mraa::SUCCESS)
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
int bytesRead = i2c->readBytesReg(SI1132_REG_RESPONSE, ®Value, 1);
|
||||
if (bytesRead == 1 && regValue == 0)
|
||||
if (bytesRead == 1 && regValue == 0)
|
||||
status = mraa::SUCCESS;
|
||||
else
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
@ -178,13 +174,13 @@ mraa::Result SI1132::runCommand(uint8_t command)
|
||||
uint8_t response = 0;
|
||||
int sleepTimeMs = 5;
|
||||
int timeoutMs = 50;
|
||||
int waitTimeMs = 0;
|
||||
int waitTimeMs = 0;
|
||||
i2c->address(SI1132_ADDRESS);
|
||||
status = clearResponseRegister();
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
status = i2c->writeReg(SI1132_REG_COMMAND, command);
|
||||
if (status != mraa::SUCCESS)
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
while (response == 0 && waitTimeMs < timeoutMs) {
|
||||
response = i2c->readReg(SI1132_REG_RESPONSE);
|
||||
@ -202,7 +198,7 @@ mraa::Result SI1132::writeParam(uint8_t param, uint8_t value)
|
||||
{
|
||||
i2c->address(SI1132_ADDRESS);
|
||||
status = i2c->writeReg(SI1132_REG_PARAM_WR, value);
|
||||
if (status != mraa::SUCCESS)
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
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)
|
||||
{
|
||||
status = runCommand(SI1132_COMMAND_PARAM_QUERY | param);
|
||||
if (status != mraa::SUCCESS)
|
||||
if (status != mraa::SUCCESS)
|
||||
return status;
|
||||
if (i2c->readBytesReg(SI1132_REG_PARAM_RD, value, 1) != 1)
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
return status;
|
||||
status = mraa::ERROR_UNSPECIFIED;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace upm {
|
||||
*
|
||||
* The Silicon Labs
|
||||
* [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.
|
||||
*
|
||||
* @library si1132
|
||||
@ -78,12 +78,8 @@ class SI1132 : public ILightSensor {
|
||||
* Read the lux value
|
||||
*/
|
||||
double getVisibleLux();
|
||||
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
const char* getModuleName() { return "si1132"; }
|
||||
|
||||
const char* getModuleName() { return "si1132"; }
|
||||
|
||||
private:
|
||||
mraa::Result reset();
|
||||
|
@ -150,7 +150,7 @@ uint16_t SI7005::getMeasurement(uint8_t configValue) {
|
||||
|
||||
// Check we got the data we need
|
||||
if(length != SI7005_REG_DATA_LENGTH)
|
||||
UPM_THROW("read error");
|
||||
UPM_THROW("read error");
|
||||
|
||||
// Merge MSB and LSB
|
||||
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;
|
||||
}
|
||||
|
||||
bool
|
||||
SI7005::isConfigured() {
|
||||
return status == mraa::SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
SI7005::isAvailable( )
|
||||
|
@ -88,20 +88,16 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
|
||||
* Get relative humidity measurement.
|
||||
*/
|
||||
uint16_t getHumidityRaw ();
|
||||
|
||||
|
||||
/**
|
||||
* Get relative humidity measurement.
|
||||
*/
|
||||
int getHumidityRelative ();
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
|
||||
/**
|
||||
* Returns sensor module name
|
||||
*/
|
||||
const char* getModuleName() { return "si7005"; }
|
||||
const char* getModuleName() { return "si7005"; }
|
||||
|
||||
/**
|
||||
* Detects the sensor to ensure it is connected as required.
|
||||
|
@ -54,7 +54,7 @@ T6713::T6713 (int bus)
|
||||
i2c = new mraa::I2c(bus);
|
||||
status = i2c->address(T6713_ADDR);
|
||||
uint16_t firmwareRevision = getFirmwareRevision();
|
||||
if (!isConfigured())
|
||||
if (firmwareRevision != mraa::SUCCESS)
|
||||
UPM_THROW("config failure");
|
||||
}
|
||||
|
||||
@ -63,20 +63,15 @@ T6713::~T6713()
|
||||
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()
|
||||
{
|
||||
return(getSensorData(T6713_COMMAND_GET_FIRMWARE_REVISION));
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t T6713::getPpm ()
|
||||
{
|
||||
@ -115,7 +110,7 @@ uint16_t T6713::getSensorData (MODBUS_COMMANDS cmd)
|
||||
if (ret != mraa::SUCCESS)
|
||||
{
|
||||
UPM_THROW ("I2C error setting slave address");
|
||||
// TODO: need to handle this
|
||||
// TODO: need to handle this
|
||||
}
|
||||
RESPONSE * response = new 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;
|
||||
return(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
|
||||
mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
|
||||
{
|
||||
|
||||
COMMAND * cmdPacket = new COMMAND ;
|
||||
@ -195,7 +190,7 @@ mraa::Result T6713::runCommand(MODBUS_COMMANDS cmd)
|
||||
if (ret != mraa::SUCCESS)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
delete cmdPacket; cmdPacket=NULL;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
STATUS T6713::getStatus()
|
||||
STATUS T6713::getStatus()
|
||||
{
|
||||
uint16_t responseStatus = 0, readBytes = 0;
|
||||
RESPONSE * response = new RESPONSE ;
|
||||
@ -221,18 +216,18 @@ STATUS T6713::getStatus()
|
||||
if (ret != mraa::SUCCESS)
|
||||
{
|
||||
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))
|
||||
{
|
||||
UPM_THROW("I2C read failed");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(response->function_code == READ_INPUT_REGISTERS)
|
||||
{
|
||||
if(response->byte_count == 2)
|
||||
{
|
||||
responseStatus = (response->status_msb << 8 | response->status_lsb);
|
||||
{
|
||||
responseStatus = (response->status_msb << 8 | response->status_lsb);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ namespace t6713_co2
|
||||
{
|
||||
uint8_t function_code;
|
||||
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_lsb;
|
||||
|
||||
@ -119,15 +119,10 @@ class T6713 : public ICO2Sensor {
|
||||
*/
|
||||
~T6713 ();
|
||||
|
||||
/**
|
||||
* Returns whether the sensor is configured.
|
||||
*/
|
||||
bool isConfigured();
|
||||
|
||||
/**
|
||||
* Returns sensor module name
|
||||
*/
|
||||
const char* getModuleName();
|
||||
const char* getModuleName();
|
||||
|
||||
/**
|
||||
* Get relative humidity measurement.
|
||||
@ -143,7 +138,7 @@ class T6713 : public ICO2Sensor {
|
||||
mraa::Result runCommand(t6713_co2::MODBUS_COMMANDS command);
|
||||
uint16_t getSensorData (t6713_co2::MODBUS_COMMANDS cmd);
|
||||
t6713_co2::STATUS getStatus();
|
||||
|
||||
|
||||
int bus;
|
||||
mraa::I2c* i2c;
|
||||
mraa::Result status;
|
||||
|
@ -34,18 +34,9 @@ namespace upm
|
||||
|
||||
#define UPM_THROW(msg) throw std::runtime_error(std::string(__FUNCTION__) + ": " + (msg))
|
||||
|
||||
class IModuleStatus
|
||||
class IModuleStatus
|
||||
{
|
||||
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_
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user