|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
High Sensitivity I2C Ambient Light Sensor (CM32181) driver. More...
#include <SensorCM32181.hpp>
Public Types | |
| enum | Sampling : uint8_t { SAMPLING_X1 = 0 , SAMPLING_X2 = 1 , SAMPLING_X1_8 = 2 , SAMPLING_X1_4 = 3 } |
| ALS sensitivity selection (REG_ALS_CONF bits 12:11). More... | |
| enum | IntegrationTime : uint8_t { INTEGRATION_TIME_25MS = 0x0C , INTEGRATION_TIME_50MS = 0x08 , INTEGRATION_TIME_100MS = 0x00 , INTEGRATION_TIME_200MS = 0x01 , INTEGRATION_TIME_400MS = 0x02 , INTEGRATION_TIME_800MS = 0x03 } |
| ALS integration time (REG_ALS_CONF bits 9:6). More... | |
| enum | PowerSaveMode : uint8_t { PowerSaveMode1 = 0 , PowerSaveMode2 = 1 , PowerSaveMode3 = 2 , PowerSaveMode4 = 3 } |
| Power saving mode (REG_ALS_PSM bits 2:1). More... | |
| enum | InterruptEvent : uint8_t { ALS_EVENT_LOW_TRIGGER = 0 , ALS_EVENT_HIGH_TRIGGER , ALS_EVENT_NULL } |
| Interrupt event type reported by getIrqStatus(). More... | |
Public Member Functions | |
| SensorCM32181 ()=default | |
| Construct a CM32181 driver instance. | |
| ~SensorCM32181 ()=default | |
| Destructor. | |
| void | setSampling (Sampling sampling=SAMPLING_X1, IntegrationTime int_time=INTEGRATION_TIME_200MS) |
| Configure ALS sensitivity and integration time. | |
| void | setIntThreshold (uint16_t low_threshold, uint16_t high_threshold) |
| Set ALS interrupt thresholds. | |
| void | powerSave (PowerSaveMode mode, bool enable) |
| Configure power saving mode. | |
| InterruptEvent | getIrqStatus () |
| Read IRQ status (and clear interrupt by reading status register). | |
| void | enableINT () |
| Enable interrupt function (REG_ALS_CONF bit1). | |
| void | disableINT () |
| Disable interrupt function (REG_ALS_CONF bit1). | |
| void | powerOn () |
| Power on sensor (REG_ALS_CONF bit0 = 0). | |
| void | powerDown () |
| Shutdown sensor (REG_ALS_CONF bit0 = 1). | |
| uint16_t | getRaw () |
| Read raw ALS data (16-bit). | |
| float | getLux () |
| Convert raw ALS to lux (approximate). | |
| int | getChipID () |
| Read chip ID. | |
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 |
Protected Attributes | |
| const float | calibration_factor = 0.286f |
| Fixed raw-to-lux conversion factor (datasheet/manual derived). | |
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 |
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) |
High Sensitivity I2C Ambient Light Sensor (CM32181) driver.
This driver provides:
Definition at line 72 of file sensor/light_sensor/SensorCM32181.hpp.
| enum SensorCM32181::IntegrationTime : uint8_t |
ALS integration time (REG_ALS_CONF bits 9:6).
Datasheet mapping (bits 9:6):
| Enumerator | |
|---|---|
| INTEGRATION_TIME_25MS | 25ms |
| INTEGRATION_TIME_50MS | 25ms |
| INTEGRATION_TIME_100MS | 100ms |
| INTEGRATION_TIME_200MS | 200ms |
| INTEGRATION_TIME_400MS | 400ms |
| INTEGRATION_TIME_800MS | 800ms |
Definition at line 102 of file sensor/light_sensor/SensorCM32181.hpp.
| enum SensorCM32181::InterruptEvent : uint8_t |
Interrupt event type reported by getIrqStatus().
| Enumerator | |
|---|---|
| ALS_EVENT_LOW_TRIGGER | Low threshold window interrupt. |
| ALS_EVENT_HIGH_TRIGGER | High threshold window interrupt. |
| ALS_EVENT_NULL | No interrupt event. |
Definition at line 130 of file sensor/light_sensor/SensorCM32181.hpp.
| enum SensorCM32181::PowerSaveMode : uint8_t |
Power saving mode (REG_ALS_PSM bits 2:1).
Datasheet mapping:
| Enumerator | |
|---|---|
| PowerSaveMode1 | |
| PowerSaveMode2 | |
| PowerSaveMode3 | |
| PowerSaveMode4 | |
Definition at line 120 of file sensor/light_sensor/SensorCM32181.hpp.
| enum SensorCM32181::Sampling : uint8_t |
ALS sensitivity selection (REG_ALS_CONF bits 12:11).
Datasheet mapping:
| Enumerator | |
|---|---|
| SAMPLING_X1 | ALS Sensitivity x1. |
| SAMPLING_X2 | ALS Sensitivity x2. |
| SAMPLING_X1_8 | ALS Sensitivity x(1/8) |
| SAMPLING_X1_4 | ALS Sensitivity x(1/4) |
Definition at line 84 of file sensor/light_sensor/SensorCM32181.hpp.
|
default |
Construct a CM32181 driver instance.
|
default |
Destructor.
Deinitializes communication backend if created.
|
inline |
Disable interrupt function (REG_ALS_CONF bit1).
Definition at line 261 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_bitWrite(), SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
Referenced by loop().
|
inline |
Enable interrupt function (REG_ALS_CONF bit1).
Definition at line 250 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_bitWrite(), SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
|
inline |
Read chip ID.
Definition at line 318 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_lowByte(), and SensorCommWrapper::readRegBuff().
Referenced by setup().
|
inline |
Read IRQ status (and clear interrupt by reading status register).
Definition at line 230 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_bitRead(), ALS_EVENT_HIGH_TRIGGER, ALS_EVENT_LOW_TRIGGER, ALS_EVENT_NULL, and SensorCommWrapper::readRegBuff().
Referenced by loop().
|
inline |
Convert raw ALS to lux (approximate).
Definition at line 308 of file sensor/light_sensor/SensorCM32181.hpp.
References calibration_factor, and getRaw().
Referenced by loop().
|
inline |
Read raw ALS data (16-bit).
Definition at line 296 of file sensor/light_sensor/SensorCM32181.hpp.
References SensorCommWrapper::readRegBuff().
|
inline |
Shutdown sensor (REG_ALS_CONF bit0 = 1).
Definition at line 283 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_bitSet(), SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
|
inline |
Power on sensor (REG_ALS_CONF bit0 = 0).
Definition at line 272 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_bitClear(), SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
Referenced by setup().
|
inline |
Configure power saving mode.
REG_ALS_PSM (0x03):
| mode | Power saving mode. |
| enable | true to enable power saving, false to disable. |
Definition at line 205 of file sensor/light_sensor/SensorCM32181.hpp.
References SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
|
inline |
Set ALS interrupt thresholds.
| low_threshold | Low threshold (raw 16-bit). |
| high_threshold | High threshold (raw 16-bit). |
Definition at line 180 of file sensor/light_sensor/SensorCM32181.hpp.
References sensorlib::_highByte(), sensorlib::_lowByte(), and SensorCommWrapper::writeRegBuff().
Referenced by setup().
|
inline |
Configure ALS sensitivity and integration time.
This updates REG_ALS_CONF bits:
| sampling | ALS sensitivity. |
| int_time | Integration time. |
Definition at line 156 of file sensor/light_sensor/SensorCM32181.hpp.
References SensorCommWrapper::readRegBuff(), and SensorCommWrapper::writeRegBuff().
Referenced by setup().
|
protected |
Fixed raw-to-lux conversion factor (datasheet/manual derived).
Definition at line 374 of file sensor/light_sensor/SensorCM32181.hpp.
Referenced by getLux().