DUDS
Distributed Update of Data from Something
duds::hardware::devices::instruments::APDS9301 Class Reference

A quick try at supporting APDS9301 brightness sensor; will change significantly in the future. More...

#include <APDS9301.hpp>

Inheritance diagram for duds::hardware::devices::instruments::APDS9301:
Collaboration diagram for duds::hardware::devices::instruments::APDS9301:

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::Smbuscom
 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...
 

Detailed Description

A quick try at supporting APDS9301 brightness sensor; will change significantly in the future.

Address can be set to 0x29, 0x39, or 0x49.

Author
Jeff Jackowski
Examples:
apds9301test.cpp.

Definition at line 36 of file APDS9301.hpp.

Constructor & Destructor Documentation

◆ APDS9301()

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.

Parameters
cThe Smbus interface to the device. It must not use PEC.
Exceptions
DeviceMisidentifiedThe reported device ID is incorrect.

Definition at line 113 of file APDS9301.cpp.

◆ ~APDS9301()

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.

Member Function Documentation

◆ brightnessCount()

std::uint16_t duds::hardware::devices::instruments::APDS9301::brightnessCount ( ) const
inline

The value reported by the device for the broad spectrum brightness.

Definition at line 148 of file APDS9301.hpp.

◆ brightnessIrCount()

std::uint16_t duds::hardware::devices::instruments::APDS9301::brightnessIrCount ( ) const
inline

The value reported by the device for the infrared brightness.

Definition at line 163 of file APDS9301.hpp.

◆ highGain()

bool duds::hardware::devices::instruments::APDS9301::highGain ( ) const
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.

◆ illuminance()

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%.

Examples:
apds9301test.cpp.

Definition at line 225 of file APDS9301.cpp.

◆ init()

void duds::hardware::devices::instruments::APDS9301::init ( float  integration,
bool  hGain 
)

Configures the device.

Parameters
integrationThe 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.
hGainTrue to use 16x gain.
Exceptions
APDS9301BadIntegration
Examples:
apds9301test.cpp.

Definition at line 134 of file APDS9301.cpp.

◆ irradiance()

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.

Todo:
Avoid a map lookup.
Examples:
apds9301test.cpp.

Definition at line 193 of file APDS9301.cpp.

◆ irradianceIr()

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.

Examples:
apds9301test.cpp.

Definition at line 214 of file APDS9301.cpp.

◆ maxIrradiance()

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().

Examples:
apds9301test.cpp.

Definition at line 181 of file APDS9301.cpp.

◆ period()

float duds::hardware::devices::instruments::APDS9301::period ( ) const
inline

Returns the sampling period configured for the device.

The value will be -1 if init() has not been called.

Todo:
Offer a way to report potential error on the remote clock. Maybe a maximum period function.
Examples:
apds9301test.cpp.

Definition at line 116 of file APDS9301.hpp.

◆ resume()

void duds::hardware::devices::instruments::APDS9301::resume ( )

Resumes operation after a call to suspend().

Exceptions
DeviceUninitalizedinit() hasn't been called.
DeviceMisidentifiedThe device did not respond properly to the request.
Examples:
apds9301test.cpp.

Definition at line 167 of file APDS9301.cpp.

◆ sample()

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.

Examples:
apds9301test.cpp.

Definition at line 175 of file APDS9301.cpp.

◆ startOrStop()

void duds::hardware::devices::instruments::APDS9301::startOrStop ( int  val)
private

Writes a value to the control register, reads it back, and checks for equality.

Parameters
valThe value to write and to expect on read.
Exceptions
DeviceMisidentifiedThe value read back did not match val.

Definition at line 151 of file APDS9301.cpp.

Referenced by resume(), and suspend().

◆ suspend()

void duds::hardware::devices::instruments::APDS9301::suspend ( )

Suspends operation by putting the device into a low-power mode.

Exceptions
DeviceMisidentifiedThe device did not respond properly to the request.

Definition at line 163 of file APDS9301.cpp.

Referenced by APDS9301().

Member Data Documentation

◆ @9

struct { ... }

◆ actualPeriod

float duds::hardware::devices::instruments::APDS9301::actualPeriod
private

Configured integration time.

Definition at line 44 of file APDS9301.hpp.

Referenced by init(), irradiance(), maxIrradiance(), and resume().

◆ broad

std::uint16_t duds::hardware::devices::instruments::APDS9301::broad
private

The values supplied by the device.

Definition at line 54 of file APDS9301.hpp.

Referenced by illuminance(), irradiance(), and sample().

◆ com

std::unique_ptr<duds::hardware::interface::Smbus> duds::hardware::devices::instruments::APDS9301::com
private

The SMBus communication interface.

Definition at line 40 of file APDS9301.hpp.

Referenced by APDS9301(), init(), sample(), startOrStop(), and ~APDS9301().

◆ hGain

unsigned int duds::hardware::devices::instruments::APDS9301::hGain

High gain (16x) flag.

Definition at line 59 of file APDS9301.hpp.

Referenced by init().

◆ integTime

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().

◆ ir

std::uint16_t duds::hardware::devices::instruments::APDS9301::ir
private

Definition at line 54 of file APDS9301.hpp.

Referenced by illuminance(), irradianceIr(), and sample().

◆ scale

float duds::hardware::devices::instruments::APDS9301::scale
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().


The documentation for this class was generated from the following files: