环境光传感器¶
环境光传感器包含光照强度传感器、颜色传感器、紫外线传感器和兼具多种功能的传感器。
已适配列表¶
名称 |
功能 |
总线 |
供应商 |
规格书 |
硬件抽象层 |
---|---|---|---|---|---|
BH1750 |
Light |
I2C |
rohm |
√ |
|
VEML6040 |
Light RGBW |
I2C |
Vishay |
√ |
|
VEML6075 |
Light UVA UVB |
I2C |
Vishay |
√ |
API 参考¶
以下 API 实现了对环境光传感器的硬件抽象,用户可直接调用该层代码编写传感器应用程序,也可以使用 sensor_hub 中的传感器接口,实现更简单的调用。
Header File¶
Functions¶
-
sensor_light_handle_t
light_sensor_create
(bus_handle_t bus, int id)¶ Create a light sensor instance. same series’ sensor or sensor with same address can only be created once.
- Return
sensor_light_handle_t return light sensor handle if succeed, return NULL if failed.
- Parameters
bus
: i2c bus handle the sensor attached toid
: id declared in light_sensor_id_t
-
esp_err_t
light_sensor_delete
(sensor_light_handle_t *sensor)¶ Delete and release the sensor resource.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: point to light sensor handle, will set to NULL if delete succeed.
-
esp_err_t
light_sensor_test
(sensor_light_handle_t sensor)¶ Test if sensor is active.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: light sensor handle to operate.
-
esp_err_t
light_sensor_acquire_light
(sensor_light_handle_t sensor, float *lux)¶ Acquire light sensor illuminance result one time.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: light sensor handle to operate.lux
: result data (unit:lux)
-
esp_err_t
light_sensor_acquire_rgbw
(sensor_light_handle_t sensor, rgbw_t *rgbw)¶ Acquire light sensor color result one time. light color includes red green blue and white.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: light sensor handle to operate.rgbw
: result data (unit:lux)
-
esp_err_t
light_sensor_acquire_uv
(sensor_light_handle_t sensor, uv_t *uv)¶ Acquire light sensor ultra violet result one time. light Ultraviolet includes UVA UVB and UV.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: light sensor handle to operate.uv
: result data (unit:lux)
-
esp_err_t
light_sensor_sleep
(sensor_light_handle_t sensor)¶ Set sensor to sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: light sensor handle to operate.
-
esp_err_t
light_sensor_wakeup
(sensor_light_handle_t sensor)¶ Wakeup sensor from sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: light sensor handle to operate.
-
esp_err_t
light_sensor_acquire
(sensor_light_handle_t sensor, sensor_data_group_t *data_group)¶ acquire a group of sensor data
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: light sensor handle to operatedata_group
: acquired data
-
esp_err_t
light_sensor_control
(sensor_light_handle_t sensor, sensor_command_t cmd, void *args)¶ control sensor mode with control commands and args
- Parameters
sensor
: light sensor handle to operatecmd
: control commands detailed in sensor_command_targs
: control commands argsESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
Type Definitions¶
-
typedef void *
sensor_light_handle_t
¶ light sensor handle