- 在CMakeLists.txt中添加SU-03T语音模块依赖。 - 在main.cpp中实现SU-03T接收回调函数,处理接收消息。 - 完善各UI源文件文档,包括动作、屏幕和字体,明确模块作用与数据流向。 - 更新主应用逻辑,初始化并启动SU-03T接收器。 - 修改过程中确保兼容性,保留原有接口。
83 lines
2.5 KiB
C
83 lines
2.5 KiB
C
/*
|
|
* 文件: components/bh1750/bh1750_use.c
|
|
* 角色: BH1750 光照传感器驱动封装
|
|
* 说明:
|
|
* - 本文件用于实现当前模块的核心功能或接口定义。
|
|
* - 修改前请先确认该模块与其它任务/外设之间的数据流关系。
|
|
* - 涉及协议与硬件时,优先保持现有接口兼容,避免联调回归。
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "esp_log.h"
|
|
#include "driver/i2c_master.h"
|
|
#include "bh1750.h"
|
|
#include "bh1750_use.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
static const char *TAG = "BH1750_USE";
|
|
|
|
static i2c_master_bus_handle_t s_i2c_bus_handle = NULL;
|
|
static bh1750_handle_t s_bh1750_handle = NULL;
|
|
|
|
/* 函数: bh1750_get_i2c_bus_handle
|
|
* 作用: 执行模块内与函数名对应的业务逻辑。
|
|
* 重点: 关注输入合法性、返回码与并发安全。
|
|
*/
|
|
i2c_master_bus_handle_t bh1750_get_i2c_bus_handle(void)
|
|
{
|
|
return s_i2c_bus_handle;
|
|
}
|
|
|
|
/* 函数: bh1750_user_init
|
|
* 作用: 执行模块内与函数名对应的业务逻辑。
|
|
* 重点: 关注输入合法性、返回码与并发安全。
|
|
*/
|
|
esp_err_t bh1750_user_init(void)
|
|
{
|
|
if (s_i2c_bus_handle == NULL) {
|
|
i2c_master_bus_config_t bus_config = {
|
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
|
.i2c_port = I2C_NUM_0,
|
|
.scl_io_num = (gpio_num_t)BH1750_I2C_SCL_IO,
|
|
.sda_io_num = (gpio_num_t)BH1750_I2C_SDA_IO,
|
|
.glitch_ignore_cnt = 7,
|
|
};
|
|
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &s_i2c_bus_handle));
|
|
}
|
|
|
|
esp_err_t ret = bh1750_create(s_i2c_bus_handle, BH1750_I2C_ADDRESS_DEFAULT, &s_bh1750_handle);
|
|
if (ret != ESP_OK) {
|
|
ESP_LOGE(TAG, "BH1750 设备创建失败");
|
|
return ret;
|
|
}
|
|
|
|
return bh1750_power_on(s_bh1750_handle);
|
|
}
|
|
|
|
/* 函数: bh1750_user_read
|
|
* 作用: 执行模块内与函数名对应的业务逻辑。
|
|
* 重点: 关注输入合法性、返回码与并发安全。
|
|
*/
|
|
esp_err_t bh1750_user_read(float *lux)
|
|
{
|
|
if (s_bh1750_handle == NULL) return ESP_ERR_INVALID_STATE;
|
|
|
|
bh1750_power_on(s_bh1750_handle);
|
|
bh1750_set_measure_mode(s_bh1750_handle, BH1750_ONETIME_1LX_RES);
|
|
vTaskDelay(pdMS_TO_TICKS(180));
|
|
return bh1750_get_data(s_bh1750_handle, lux);
|
|
}
|
|
|
|
/* 函数: bh1750_user_deinit
|
|
* 作用: 执行模块内与函数名对应的业务逻辑。
|
|
* 重点: 关注输入合法性、返回码与并发安全。
|
|
*/
|
|
void bh1750_user_deinit(void)
|
|
{
|
|
if (s_bh1750_handle) {
|
|
bh1750_delete(s_bh1750_handle);
|
|
s_bh1750_handle = NULL;
|
|
}
|
|
}
|