环境光传感器

[English]

环境光传感器包含光照强度传感器、颜色传感器、紫外线传感器和兼具多种功能的传感器。

已适配列表

名称

功能

总线

供应商

规格书

硬件抽象层

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.

参数
  • bus – i2c bus handle the sensor attached to

  • id – id declared in light_sensor_id_t

返回

sensor_light_handle_t return light sensor handle if succeed, return NULL if failed.

esp_err_t light_sensor_delete(sensor_light_handle_t *sensor)

Delete and release the sensor resource.

参数

sensor – point to light sensor handle, will set to NULL if delete succeed.

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t light_sensor_test(sensor_light_handle_t sensor)

Test if sensor is active.

参数

sensor – light sensor handle to operate.

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t light_sensor_acquire_light(sensor_light_handle_t sensor, float *lux)

Acquire light sensor illuminance result one time.

参数
  • sensor – light sensor handle to operate.

  • lux – result data (unit:lux)

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

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.

参数
  • sensor – light sensor handle to operate.

  • rgbw – result data (unit:lux)

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

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.

参数
  • sensor – light sensor handle to operate.

  • uv – result data (unit:lux)

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t light_sensor_sleep(sensor_light_handle_t sensor)

Set sensor to sleep mode.

参数

sensor – light sensor handle to operate.

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t light_sensor_wakeup(sensor_light_handle_t sensor)

Wakeup sensor from sleep mode.

参数

sensor – light sensor handle to operate.

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t light_sensor_acquire(sensor_light_handle_t sensor, sensor_data_group_t *data_group)

acquire a group of sensor data

参数
  • sensor – light sensor handle to operate

  • data_group – acquired data

返回

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

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

参数
  • sensor – light sensor handle to operate

  • cmd – control commands detailed in sensor_command_t

  • args – control commands args

    • ESP_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

Enumerations

enum light_sensor_id_t

light sensor id, used for light_sensor_create

Values:

enumerator BH1750_ID

BH1750 light sensor id

enumerator VEML6040_ID

VEML6040 light sensor id

enumerator VEML6075_ID

VEML6075 light sensor id

enumerator LIGHT_MAX_ID

max light sensor id