14 namespace duds {
namespace hardware {
namespace devices {
namespace instruments {
21 namespace APDS9301_internal {
104 { 13.7 * 0.001, { 101.0 / 13.7, 0, 5047 } },
105 { 101.0 * 0.001, { 1.0, 1, 37177 } },
106 { 402.0 * 0.001, { 101.0 / 402.0, 2, 65535 } }
111 using namespace APDS9301_internal;
114 com(
std::
move(c)), actualPeriod(-1) {
135 std::map<float, PeriodData>::const_iterator iter =
142 scale = iter->second.scale;
146 scale *= 1.0f / 16.0f;
182 std::map<float, PeriodData>::const_iterator iter =
186 (
double)iter->second.maxcnt *
scale * 0.275,
195 std::map<float, PeriodData>::const_iterator iter =
199 if (iter->second.maxcnt <=
broad) {
200 val = std::numeric_limits<double>::infinity();
231 double ch0 = (double)
broad;
232 double ch1 = (double)
ir;
233 double chr = ch1 / ch0;
236 result = 0.0304 * ch0 - 0.062 * ch0 * std::pow(chr, 1.4);
237 }
else if (chr <= 0.61) {
238 result = 0.0224 * ch0 - 0.031 * ch1;
239 }
else if (chr <= 0.8) {
240 result = 0.0128 * ch0 - 0.0153 * ch1;
241 }
else if (chr <= 1.3) {
242 result = 0.00146 * ch0 - 0.00112 * ch1;
250 result *=
scale * (402.0 / 101.0);
A container for a value and a unit to better describe the value.
constexpr Unit Meter(DUDS_UNIT_VALUE(0, 0, 0, 0, 1, 0, 0, 0, 0))
duds::data::Quantity illuminance() const
Computes a highly approximate value for illuminance based on the broad spectrum and IR samples using ...
int maxcnt
The maximum value the device will report for the sampling period.
void sample()
The device will update samples after it has completed integration.
Channel 0: sensitive to full visible and near IR spectrum.
Channel 1: sensitive to near IR spectrum.
void suspend()
Suspends operation by putting the device into a low-power mode.
duds::data::Quantity irradianceIr() const
Irradiance in infrared light.
float scale
A scalar applied to change the irradiance result based on the sampling period.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
std::unique_ptr< duds::hardware::interface::Smbus > com
The SMBus communication interface.
constexpr Unit Lux(DUDS_UNIT_VALUE(0, 1, 0, 0, -2, 0, 0, 0, 1))
unsigned int hGain
High gain (16x) flag.
An attempt was made to use a device prior to running a required initialization step.
duds::data::Quantity irradiance() const
Broad spectrum irradiance.
Set to start manual integration, and clear to stop.
constexpr Unit Watt(DUDS_UNIT_VALUE(0, 0, 0, 1, 2, 0, -3, 0, 0))
int regval
The value given to the device to select the sampling period.
Information on a particular sampling rate.
void resume()
Resumes operation after a call to suspend().
An invalid integration time was specified.
boost::error_info< struct Info_smbusdevaddr, int > SmbusDeviceAddr
Provides the device (slave) address along with an error.
What the documentation calls timing register; really a general configuration register.
float actualPeriod
Configured integration time.
std::uint16_t broad
The values supplied by the device.
void startOrStop(int val)
Writes a value to the control register, reads it back, and checks for equality.
Transfer two bytes instead of one.
An attempt was made to use a device that seems to exist, but the responding device is not the type th...
Interrupt control; set to zero if not using.
float scale
Multiplier applied to the sample results to account for different integration times and gain setting ...
CmdFlags
The flags refered to as commands in the documentation.
APDS9301(std::unique_ptr< duds::hardware::interface::Smbus > &c)
Attempts to identify the device, then performs a reset.
static const std::map< float, PeriodData > IntegPeriodVals
Integration period values.
Spot for the address of register to read or write.
duds::data::Quantity maxIrradiance() const
The maximum possible irradiance value that the device can report based on its configuration set by th...
unsigned int integTime
Integration time value used in device configuration register.
Regs
The device's registers.
void init(float integration, bool hGain)
Configures the device.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
~APDS9301()
Attempts to suspend the device's operation.
Always set in command byte.