mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +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:

committed by
Abhishek Malik

parent
f268437cd5
commit
9bc3d2ded0
@ -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();
|
||||
|
Reference in New Issue
Block a user