Files
Smart-granary-code/components/human_door/human_door.c
Wang Beihong ffdb7065e3 功能:集成SU-03T语音模块,完善UI代码文档
- 在CMakeLists.txt中添加SU-03T语音模块依赖。
- 在main.cpp中实现SU-03T接收回调函数,处理接收消息。
- 完善各UI源文件文档,包括动作、屏幕和字体,明确模块作用与数据流向。
- 更新主应用逻辑,初始化并启动SU-03T接收器。
- 修改过程中确保兼容性,保留原有接口。
2026-04-22 01:06:10 +08:00

57 lines
1.7 KiB
C

/*
* 文件: components/human_door/human_door.c
* 角色: 人体/门磁输入采集
* 说明:
* - 本文件用于实现当前模块的核心功能或接口定义。
* - 修改前请先确认该模块与其它任务/外设之间的数据流关系。
* - 涉及协议与硬件时,优先保持现有接口兼容,避免联调回归。
*/
#include "human_door.h"
#include "driver/gpio.h"
#include "esp_check.h"
static const char *TAG = "human_door";
static bool s_inited = false;
/* 函数: human_door_init
* 作用: 执行模块内与函数名对应的业务逻辑。
* 重点: 关注输入合法性、返回码与并发安全。
*/
esp_err_t human_door_init(void)
{
if (s_inited) {
return ESP_OK;
}
gpio_config_t io_cfg = {
.pin_bit_mask = (1ULL << HUMAN_SENSOR_GPIO) | (1ULL << DOOR_SWITCH_GPIO),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
ESP_RETURN_ON_ERROR(gpio_config(&io_cfg), TAG, "gpio config failed");
s_inited = true;
return ESP_OK;
}
/* 函数: human_door_read
* 作用: 执行模块内与函数名对应的业务逻辑。
* 重点: 关注输入合法性、返回码与并发安全。
*/
esp_err_t human_door_read(human_door_state_t *out_state)
{
ESP_RETURN_ON_FALSE(out_state != NULL, ESP_ERR_INVALID_ARG, TAG, "out_state is null");
ESP_RETURN_ON_FALSE(s_inited, ESP_ERR_INVALID_STATE, TAG, "not initialized");
int human_level = gpio_get_level((gpio_num_t)HUMAN_SENSOR_GPIO);
int door_level = gpio_get_level((gpio_num_t)DOOR_SWITCH_GPIO);
out_state->human_present = (human_level != 0);
out_state->door_closed = (door_level == 0);
return ESP_OK;
}