|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Driver for the LTR-553ALS-01 ambient light + proximity sensor (I2C). More...
#include <SensorLTR553.hpp>
Public Member Functions | |
| SensorLTR553 ()=default | |
| Construct an uninitialized driver instance. | |
| ~SensorLTR553 ()=default | |
| Destructor. | |
| void | setIRQLevel (IrqLevel level) |
| Set interrupt pin polarity. | |
| void | enableIRQ (IrqMode mode) |
| Enable interrupts and select which measurement sources can trigger them. | |
| void | disableIRQ () |
| Disable all interrupt sources (mode bits = 0). | |
| bool | psAvailable () |
| Check PS data ready flag. | |
| void | setLightSensorThreshold (uint16_t low, uint16_t high) |
| Set ALS threshold window. | |
| void | setLightSensorPersists (uint8_t count) |
| Configure ALS interrupt persistence count. | |
| void | setLightSensorRate (IntegrationTime alsIntegrationTime, MeasurementRate alsMeasurementRate) |
| Configure ALS integration time and measurement repeat rate. | |
| void | enableLightSensor () |
| Enable ALS measurement. | |
| void | disableLightSensor () |
| Disable ALS measurement. | |
| void | setLightSensorGain (LightSensorGain gain) |
| Set ALS gain. | |
| int | getLightSensor (uint8_t ch) |
| Read ALS raw data from channel 0 or 1. | |
| void | setProximityPersists (uint8_t count) |
| Configure PS interrupt persistence count. | |
| void | setProximityThreshold (uint16_t low, uint16_t high) |
| Set PS threshold window. | |
| void | setProximityRate (PsRate rate) |
| Set PS measurement rate. | |
| void | enableProximity () |
| Enable proximity measurement. | |
| void | disableProximity () |
| Disable proximity measurement. | |
| void | enablePsIndicator () |
| Enable PS indicator. | |
| void | disablePsIndicator () |
| Disable PS indicator. | |
| int | getProximity (bool *saturated=NULL) |
| Read proximity raw data. | |
| void | setPsLedPulsePeriod (PsLedPeriod period) |
| Set PS LED pulse modulation frequency (REG_PS_LED bits 7:5). | |
| void | setPsLedDutyCycle (PsLedDuty duty) |
| Set PS LED duty cycle (REG_PS_LED bits 4:3). | |
| void | setPsLedCurrent (PsLedCurrent cur) |
| Set PS LED peak current (REG_PS_LED bits 2:0). | |
| void | setPsLedPulses (uint8_t pulesNum) |
| Set number of PS LED pulses (REG_PS_N_PULSES bits 3:0). | |
| int | getPartID () |
| Get Part ID (REG_PART_ID high nibble). | |
| int | getRevisionID () |
| Get Revision ID (REG_PART_ID low nibble). | |
| int | getManufacturerID () |
| Read Manufacturer ID (REG_MANUFAC_ID). | |
| void | reset () |
| Software reset (REG_ALS_CONTR bit1). | |
Public Member Functions inherited from I2CDeviceNoHal | |
| bool | begin (SensorCommCustom::CustomCallback callback, uint8_t addr) |
| Initialize the sensor using custom callback interface. | |
Public Member Functions inherited from DeviceBeginCommon | |
| virtual | ~DeviceBeginCommon () |
| uint8_t | getAddress () const |
| uint8_t | getInterface () const |
Public Member Functions inherited from SensorCommWrapper | |
| SensorCommWrapper ()=default | |
| int | readReg (uint8_t reg) const |
| int | readRegBuff (uint8_t reg, uint8_t *buf, size_t len) const |
| int | readBuff (uint8_t *buf, size_t len) const |
| int | writeReg (uint8_t reg, uint8_t val) |
| int | writeRegBuff (uint8_t reg, uint8_t *buf, size_t len) |
| int | writeBuff (uint8_t *buf, size_t len) |
| int | writeThenRead (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len) |
| bool | setRegBit (uint8_t reg, uint8_t bit) |
| bool | clrRegBit (uint8_t reg, uint8_t bit) |
| bool | getRegBit (uint8_t reg, uint8_t bit) |
| int | updateBits (uint8_t reg, uint8_t mask, uint8_t value_shifted) |
| void | setAddress (uint8_t address) |
| void | setAck (bool enable) |
Public Member Functions inherited from SensorCommInterface | |
| virtual | ~SensorCommInterface ()=default |
Static Protected Attributes | |
| static constexpr uint8_t | REG_ALS_CONTR = 0x80 |
| static constexpr uint8_t | REG_PS_CONTR = 0x81 |
| static constexpr uint8_t | REG_PS_LED = 0x82 |
| static constexpr uint8_t | REG_PS_N_PULSES = 0x83 |
| static constexpr uint8_t | REG_PS_MEAS_RATE = 0x84 |
| static constexpr uint8_t | REG_ALS_MEAS_RATE = 0x85 |
| static constexpr uint8_t | REG_PART_ID = 0x86 |
| static constexpr uint8_t | REG_MANUFAC_ID = 0x87 |
| static constexpr uint8_t | REG_ALS_DATA_CH1_0 = 0x88 |
| static constexpr uint8_t | REG_ALS_DATA_CH1_1 = 0x89 |
| static constexpr uint8_t | REG_ALS_DATA_CH0_0 = 0x8A |
| static constexpr uint8_t | REG_ALS_DATA_CH0_1 = 0x8B |
| static constexpr uint8_t | REG_ALS_PS_STATUS = 0x8C |
| static constexpr uint8_t | REG_PS_DATA_0 = 0x8D |
| static constexpr uint8_t | REG_PS_DATA_1 = 0x8E |
| static constexpr uint8_t | REG_INTERRUPT = 0x8F |
| static constexpr uint8_t | REG_PS_THRES_UP_0 = 0x90 |
| static constexpr uint8_t | REG_PS_THRES_UP_1 = 0x91 |
| static constexpr uint8_t | REG_PS_THRES_LOW_0 = 0x92 |
| static constexpr uint8_t | REG_PS_THRES_LOW_1 = 0x93 |
| static constexpr uint8_t | REG_PS_OFFSET_1 = 0x94 |
| static constexpr uint8_t | REG_PS_OFFSET_0 = 0x95 |
| static constexpr uint8_t | REG_ALS_THRES_UP_0 = 0x97 |
| static constexpr uint8_t | REG_ALS_THRES_UP_1 = 0x98 |
| static constexpr uint8_t | REG_ALS_THRES_LOW_0 = 0x99 |
| static constexpr uint8_t | REG_ALS_THRES_LOW_1 = 0x9A |
| static constexpr uint8_t | REG_INTERRUPT_PERSIST = 0x9E |
| static constexpr uint8_t | LTR553_DEFAULT_MAN_ID = 0x05 |
| Default manufacturer ID. | |
Additional Inherited Members | |
Protected Member Functions inherited from DeviceBeginCommon | |
| DeviceBeginCommon ()=default | |
| virtual bool | ensureValid () const override |
| virtual SensorCommBase * | getComm () const override |
| virtual void | beforeBegin () |
| virtual void | afterCommReady () |
| virtual void | afterInitSuccess (uint8_t param) |
| virtual void | onBeginFail () |
| bool | fail () |
| void | clearCommState () |
| template<typename CreateComm > | |
| bool | beginLifecycle (uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm) |
Protected Attributes inherited from DeviceBeginCommon | |
| std::unique_ptr< SensorCommBase > | comm |
| std::unique_ptr< SensorHal > | hal |
| std::unique_ptr< SensorCommStatic > | staticComm |
| uint8_t | _addr = 0 |
| uint8_t | _iface = COMM_CUSTOM |
Driver for the LTR-553ALS-01 ambient light + proximity sensor (I2C).
This class provides a lightweight register-level driver for:
The register map and bit fields follow the LTR-553ALS-01 datasheet.
Definition at line 53 of file sensor/light_sensor/SensorLTR553.hpp.
ALS integration time (REG_ALS_MEAS_RATE bits 5:3).
Datasheet mapping (bits 5:3):
Definition at line 161 of file sensor/light_sensor/SensorLTR553.hpp.
Interrupt pin active level.
| Enumerator | |
|---|---|
| ALS_IRQ_ACTIVE_LOW | INT pin is active-low (default) |
| ALS_IRQ_ACTIVE_HIGH | INT pin is active-high. |
Definition at line 59 of file sensor/light_sensor/SensorLTR553.hpp.
Interrupt trigger source.
This selects which measurement(s) can assert the interrupt pin.
Definition at line 69 of file sensor/light_sensor/SensorLTR553.hpp.
ALS gain selection.
Note: Actual lux range depends on gain and integration time.
Definition at line 81 of file sensor/light_sensor/SensorLTR553.hpp.
ALS measurement repeat rate (REG_ALS_MEAS_RATE bits 2:0).
Datasheet mapping (bits 2:0):
| Enumerator | |
|---|---|
| ALS_MEASUREMENT_TIME_50MS | |
| ALS_MEASUREMENT_TIME_100MS | |
| ALS_MEASUREMENT_TIME_200MS | |
| ALS_MEASUREMENT_TIME_500MS | |
| ALS_MEASUREMENT_TIME_1000MS | |
| ALS_MEASUREMENT_TIME_2000MS | |
Definition at line 185 of file sensor/light_sensor/SensorLTR553.hpp.
PS LED peak current selection (REG_PS_LED bits 2:0).
| Enumerator | |
|---|---|
| PS_LED_CUR_5MA | 5mA |
| PS_LED_CUR_10MA | 10mA |
| PS_LED_CUR_20MA | 20mA |
| PS_LED_CUR_50MA | 50mA |
| PS_LED_CUR_100MA | 100mA |
Definition at line 124 of file sensor/light_sensor/SensorLTR553.hpp.
PS LED duty cycle (REG_PS_LED bits 4:3).
Datasheet: 00=25%, 01=50%, 10=75%, 11=100%.
| Enumerator | |
|---|---|
| PS_LED_DUTY_25 | 25% |
| PS_LED_DUTY_50 | 50% |
| PS_LED_DUTY_75 | 75% |
| PS_LED_DUTY_100 | 100% (default) |
Definition at line 111 of file sensor/light_sensor/SensorLTR553.hpp.
PS LED pulse modulation frequency (REG_PS_LED bits 7:5).
Datasheet: 000=30kHz ... 111=100kHz.
Definition at line 95 of file sensor/light_sensor/SensorLTR553.hpp.
| enum SensorLTR553::PsRate |
PS measurement rate (REG_PS_MEAS_RATE field).
| Enumerator | |
|---|---|
| PS_MEAS_RATE_50MS | |
| PS_MEAS_RATE_70MS | |
| PS_MEAS_RATE_100MS | |
| PS_MEAS_RATE_200MS | |
| PS_MEAS_RATE_500MS | |
| PS_MEAS_RATE_1000MS | |
| PS_MEAS_RATE_2000MS | |
| PS_MEAS_RATE_10MS | |
Definition at line 137 of file sensor/light_sensor/SensorLTR553.hpp.
|
default |
Construct an uninitialized driver instance.
|
default |
Destructor.
Deinitializes the communication backend if created.
|
inline |
Disable all interrupt sources (mode bits = 0).
Definition at line 234 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_INTERRUPT, and SensorCommWrapper::updateBits().
|
inline |
Disable ALS measurement.
Definition at line 314 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::clrRegBit(), and REG_ALS_CONTR.
|
inline |
Disable proximity measurement.
Definition at line 409 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_CONTR, and SensorCommWrapper::updateBits().
|
inline |
Disable PS indicator.
Definition at line 425 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::clrRegBit(), and REG_PS_CONTR.
|
inline |
Enable interrupts and select which measurement sources can trigger them.
| mode | Interrupt source mode. |
Definition at line 223 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_INTERRUPT, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Enable ALS measurement.
Definition at line 306 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_ALS_CONTR, and SensorCommWrapper::setRegBit().
Referenced by setup().
|
inline |
Enable proximity measurement.
Definition at line 401 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_CONTR, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Enable PS indicator.
Definition at line 417 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_CONTR, and SensorCommWrapper::setRegBit().
Referenced by setup().
|
inline |
Read ALS raw data from channel 0 or 1.
| ch | Channel index (0 or 1). Any non-1 value will be treated as channel 0. |
Definition at line 335 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::getRegBit(), SensorCommWrapper::readRegBuff(), REG_ALS_DATA_CH0_0, REG_ALS_DATA_CH1_0, and REG_ALS_PS_STATUS.
Referenced by loop().
|
inline |
Read Manufacturer ID (REG_MANUFAC_ID).
Expected value is LTR553_DEFAULT_MAN_ID.
Definition at line 536 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::readReg(), and REG_MANUFAC_ID.
|
inline |
Get Part ID (REG_PART_ID high nibble).
Definition at line 506 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::readReg(), and REG_PART_ID.
|
inline |
Read proximity raw data.
Proximity data is 11-bit:
| saturated | Optional pointer; will be set true if saturation flag is asserted (bit7). |
Definition at line 440 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::readRegBuff(), and REG_PS_DATA_0.
Referenced by loop().
|
inline |
Get Revision ID (REG_PART_ID low nibble).
Definition at line 520 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::readReg(), and REG_PART_ID.
|
inline |
Check PS data ready flag.
Definition at line 250 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::getRegBit(), and REG_ALS_PS_STATUS.
|
inline |
Software reset (REG_ALS_CONTR bit1).
Definition at line 545 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_ALS_CONTR, and SensorCommWrapper::setRegBit().
|
inline |
Set interrupt pin polarity.
| level | Desired active level. |
Definition at line 209 of file sensor/light_sensor/SensorLTR553.hpp.
References SensorCommWrapper::clrRegBit(), level, REG_INTERRUPT, and SensorCommWrapper::setRegBit().
Referenced by setup().
|
inline |
Set ALS gain.
| gain | Gain selection. |
Definition at line 324 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_ALS_CONTR, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Configure ALS interrupt persistence count.
Datasheet (REG_INTERRUPT_PERSIST 0x9E):
| count | Number of consecutive ALS out-of-range events before asserting interrupt. |
Definition at line 282 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_INTERRUPT_PERSIST, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Configure ALS integration time and measurement repeat rate.
Datasheet (REG_ALS_MEAS_RATE 0x85):
| alsIntegrationTime | ALS integration time. |
| alsMeasurementRate | ALS measurement repeat rate. |
Definition at line 297 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_ALS_MEAS_RATE, and SensorCommWrapper::writeReg().
|
inline |
Set ALS threshold window.
If ALS measurement is outside [low, high], interrupt may be asserted depending on IRQ settings.
| low | Low threshold. |
| high | High threshold. |
Definition at line 263 of file sensor/light_sensor/SensorLTR553.hpp.
References sensorlib::_highByte(), sensorlib::_lowByte(), REG_ALS_THRES_UP_0, and SensorCommWrapper::writeRegBuff().
Referenced by setup().
|
inline |
Configure PS interrupt persistence count.
Datasheet (REG_INTERRUPT_PERSIST 0x9E):
| count | Number of consecutive PS out-of-range events before asserting interrupt. count=0 maps to register value 0 (every PS out of range). |
Definition at line 365 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_INTERRUPT_PERSIST, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Set PS measurement rate.
| rate | Proximity measurement rate selection. |
Definition at line 393 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_MEAS_RATE, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Set PS threshold window.
| low | Low threshold (12-bit effective). |
| high | High threshold (12-bit effective). |
Definition at line 380 of file sensor/light_sensor/SensorLTR553.hpp.
References sensorlib::_lowByte(), REG_PS_THRES_LOW_0, REG_PS_THRES_LOW_1, REG_PS_THRES_UP_0, REG_PS_THRES_UP_1, and SensorCommWrapper::writeReg().
Referenced by setup().
|
inline |
Set PS LED peak current (REG_PS_LED bits 2:0).
| cur | LED peak current selection. |
Definition at line 482 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_LED, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Set PS LED duty cycle (REG_PS_LED bits 4:3).
| duty | LED duty cycle selection. |
Definition at line 472 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_LED, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Set PS LED pulse modulation frequency (REG_PS_LED bits 7:5).
| period | LED pulse modulation frequency selection. |
Definition at line 462 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_LED, and SensorCommWrapper::updateBits().
Referenced by setup().
|
inline |
Set number of PS LED pulses (REG_PS_N_PULSES bits 3:0).
| pulesNum | Number of pulses (0..15). |
Definition at line 492 of file sensor/light_sensor/SensorLTR553.hpp.
References REG_PS_N_PULSES, and SensorCommWrapper::updateBits().
Referenced by setup().
|
staticconstexprprotected |
Default manufacturer ID.
Definition at line 596 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 567 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by disableLightSensor(), enableLightSensor(), reset(), and setLightSensorGain().
|
staticconstexprprotected |
Definition at line 577 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getLightSensor().
|
staticconstexprprotected |
Definition at line 578 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 575 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getLightSensor().
|
staticconstexprprotected |
Definition at line 576 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 572 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setLightSensorRate().
|
staticconstexprprotected |
Definition at line 579 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getLightSensor(), and psAvailable().
|
staticconstexprprotected |
Definition at line 591 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 592 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 589 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setLightSensorThreshold().
|
staticconstexprprotected |
Definition at line 590 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 582 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by disableIRQ(), enableIRQ(), and setIRQLevel().
|
staticconstexprprotected |
Definition at line 593 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setLightSensorPersists(), and setProximityPersists().
|
staticconstexprprotected |
Definition at line 574 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getManufacturerID().
|
staticconstexprprotected |
Definition at line 573 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getPartID(), and getRevisionID().
|
staticconstexprprotected |
Definition at line 568 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by disableProximity(), disablePsIndicator(), enableProximity(), and enablePsIndicator().
|
staticconstexprprotected |
Definition at line 580 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by getProximity().
|
staticconstexprprotected |
Definition at line 581 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 569 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setPsLedCurrent(), setPsLedDutyCycle(), and setPsLedPulsePeriod().
|
staticconstexprprotected |
Definition at line 571 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setProximityRate().
|
staticconstexprprotected |
Definition at line 570 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setPsLedPulses().
|
staticconstexprprotected |
Definition at line 588 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 587 of file sensor/light_sensor/SensorLTR553.hpp.
|
staticconstexprprotected |
Definition at line 585 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setProximityThreshold().
|
staticconstexprprotected |
Definition at line 586 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setProximityThreshold().
|
staticconstexprprotected |
Definition at line 583 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setProximityThreshold().
|
staticconstexprprotected |
Definition at line 584 of file sensor/light_sensor/SensorLTR553.hpp.
Referenced by setProximityThreshold().