|
DUDS
|
Distributed Update of Data from Something
|
A quick try at supporting APDS9301 brightness sensor; will change significantly in the future. More...
#include <APDS9301.hpp>
Public Member Functions | |
| APDS9301 (std::unique_ptr< duds::hardware::interface::Smbus > &c) | |
| Attempts to identify the device, then performs a reset. More... | |
| ~APDS9301 () | |
| Attempts to suspend the device's operation. More... | |
| std::uint16_t | brightnessCount () const |
| The value reported by the device for the broad spectrum brightness. More... | |
| std::uint16_t | brightnessIrCount () const |
| The value reported by the device for the infrared brightness. More... | |
| bool | highGain () const |
| Returns true if the device has been configured to use its 16x gain function by a previous call to init(). More... | |
| duds::data::Quantity | illuminance () const |
| Computes a highly approximate value for illuminance based on the broad spectrum and IR samples using the method documented in the device's data sheet. More... | |
| void | init (float integration, bool hGain) |
| Configures the device. More... | |
| duds::data::Quantity | irradiance () const |
| Broad spectrum irradiance. More... | |
| duds::data::Quantity | irradianceIr () const |
| Irradiance in infrared light. More... | |
| duds::data::Quantity | maxIrradiance () const |
| The maximum possible irradiance value that the device can report based on its configuration set by the last call to init(). More... | |
| float | period () const |
| Returns the sampling period configured for the device. More... | |
| void | resume () |
| Resumes operation after a call to suspend(). More... | |
| void | sample () |
| The device will update samples after it has completed integration. More... | |
| void | suspend () |
| Suspends operation by putting the device into a low-power mode. More... | |
Private Member Functions | |
| void | startOrStop (int val) |
| Writes a value to the control register, reads it back, and checks for equality. More... | |
Private Attributes | |
| struct { | |
| unsigned int hGain: 1 | |
| High gain (16x) flag. More... | |
| unsigned int integTime: 2 | |
| Integration time value used in device configuration register. More... | |
| }; | |
| float | actualPeriod |
| Configured integration time. More... | |
| std::uint16_t | broad |
| The values supplied by the device. More... | |
| std::unique_ptr< duds::hardware::interface::Smbus > | com |
| The SMBus communication interface. More... | |
| std::uint16_t | ir |
| float | scale |
| Multiplier applied to the sample results to account for different integration times and gain setting than what the documentation used to relate the sample values to irradiance. More... | |
A quick try at supporting APDS9301 brightness sensor; will change significantly in the future.
Address can be set to 0x29, 0x39, or 0x49.
Definition at line 36 of file APDS9301.hpp.
| duds::hardware::devices::instruments::APDS9301::APDS9301 | ( | std::unique_ptr< duds::hardware::interface::Smbus > & | c | ) |
Attempts to identify the device, then performs a reset.
This should leave it in a low-power state where it does not sample. Default device address is 0x39. Possible device addresses are: 0x29, 0x39, and 0x49.
| c | The Smbus interface to the device. It must not use PEC. |
| DeviceMisidentified | The reported device ID is incorrect. |
Definition at line 113 of file APDS9301.cpp.
| duds::hardware::devices::instruments::APDS9301::~APDS9301 | ( | ) |
Attempts to suspend the device's operation.
Does not call suspend to avoid an exception.
Definition at line 127 of file APDS9301.cpp.
|
inline |
The value reported by the device for the broad spectrum brightness.
Definition at line 148 of file APDS9301.hpp.
|
inline |
The value reported by the device for the infrared brightness.
Definition at line 163 of file APDS9301.hpp.
|
inline |
Returns true if the device has been configured to use its 16x gain function by a previous call to init().
Definition at line 123 of file APDS9301.hpp.
| duds::data::Quantity duds::hardware::devices::instruments::APDS9301::illuminance | ( | ) | const |
Computes a highly approximate value for illuminance based on the broad spectrum and IR samples using the method documented in the device's data sheet.
The documentation shows how well the approximation matches with only two light sources, and with those the result may be as far off as -67% to +40%.
Definition at line 225 of file APDS9301.cpp.
| void duds::hardware::devices::instruments::APDS9301::init | ( | float | integration, |
| bool | hGain | ||
| ) |
Configures the device.
| integration | The maximum integration time. It may be specified in seconds with values between 13.7 and 402ms. If the value is too low, APDS9301BadIntegration will be thrown. |
| hGain | True to use 16x gain. |
| APDS9301BadIntegration |
Definition at line 134 of file APDS9301.cpp.
| duds::data::Quantity duds::hardware::devices::instruments::APDS9301::irradiance | ( | ) | const |
Broad spectrum irradiance.
Includes visible and infrared. The value can vary greatly from what proper laboratory equipment will report under the same conditions. In particular, the documentation shows that different light sources can cause the result to vary by as much as a factor of 4, and gave few examples, so greater differences are likely possible.
Definition at line 193 of file APDS9301.cpp.
| duds::data::Quantity duds::hardware::devices::instruments::APDS9301::irradianceIr | ( | ) | const |
Irradiance in infrared light.
The value can vary greatly from what proper laboratory equipment will report under the same conditions. In particular, the documentation shows that different light sources can cause the result to vary by more than a factor of 10, and gave few examples, so greater differences are likely possible.
Definition at line 214 of file APDS9301.cpp.
| duds::data::Quantity duds::hardware::devices::instruments::APDS9301::maxIrradiance | ( | ) | const |
The maximum possible irradiance value that the device can report based on its configuration set by the last call to init().
Definition at line 181 of file APDS9301.cpp.
|
inline |
Returns the sampling period configured for the device.
The value will be -1 if init() has not been called.
Definition at line 116 of file APDS9301.hpp.
| void duds::hardware::devices::instruments::APDS9301::resume | ( | ) |
Resumes operation after a call to suspend().
| DeviceUninitalized | init() hasn't been called. |
| DeviceMisidentified | The device did not respond properly to the request. |
Definition at line 167 of file APDS9301.cpp.
| void duds::hardware::devices::instruments::APDS9301::sample | ( | ) |
The device will update samples after it has completed integration.
Sampling faster than that will read old values, but not bad data.
Definition at line 175 of file APDS9301.cpp.
|
private |
Writes a value to the control register, reads it back, and checks for equality.
| val | The value to write and to expect on read. |
| DeviceMisidentified | The value read back did not match val. |
Definition at line 151 of file APDS9301.cpp.
| void duds::hardware::devices::instruments::APDS9301::suspend | ( | ) |
Suspends operation by putting the device into a low-power mode.
| DeviceMisidentified | The device did not respond properly to the request. |
Definition at line 163 of file APDS9301.cpp.
Referenced by APDS9301().
| struct { ... } |
|
private |
Configured integration time.
Definition at line 44 of file APDS9301.hpp.
Referenced by init(), irradiance(), maxIrradiance(), and resume().
|
private |
The values supplied by the device.
Definition at line 54 of file APDS9301.hpp.
Referenced by illuminance(), irradiance(), and sample().
|
private |
The SMBus communication interface.
Definition at line 40 of file APDS9301.hpp.
Referenced by APDS9301(), init(), sample(), startOrStop(), and ~APDS9301().
| unsigned int duds::hardware::devices::instruments::APDS9301::hGain |
| unsigned int duds::hardware::devices::instruments::APDS9301::integTime |
Integration time value used in device configuration register.
Definition at line 63 of file APDS9301.hpp.
Referenced by init().
|
private |
Definition at line 54 of file APDS9301.hpp.
Referenced by illuminance(), irradianceIr(), and sample().
|
private |
Multiplier applied to the sample results to account for different integration times and gain setting than what the documentation used to relate the sample values to irradiance.
Definition at line 50 of file APDS9301.hpp.
Referenced by illuminance(), init(), irradiance(), irradianceIr(), and maxIrradiance().