蜂鸣器+RGB修复

This commit is contained in:
kirl committed 2026-08-01 15:03:02 +08:00
1 parent fef37b36e9
commit 351e22e123
7 files changed
+205 -1

No files matched your search

+17
View File
@@ -13,6 +13,7 @@
* ESP32 GPIO3 -> I2C SCL
* ESP32 GPIO27 -> RGB LED (WS2812)
* ESP32 GPIO8 -> 按钮 (低电平有效, 触发识别)
* ESP32 GPIO9 -> 无源蜂鸣器 (经三极管驱动)
* ESP32 GND -> 电机 GND / MPU GND
*
* 注: 日志控制台已切换到 USB Serial/JTAG (COM 口监视),
@@ -29,6 +30,7 @@
#include "rgb.h"
#include "actuator.h"
#include "key.h"
#include "buzzer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
@@ -46,6 +48,7 @@ static void button_recognize_task(void *pvParam)
while (1) {
if (key_is_pressed()) {
ESP_LOGI(TAG, "按钮按下, 归零后再发送 RECOGNIZE ...");
buzzer_beep(2000, 100); /* 短音: 识别开始 */
/* ---- 归零: 舵机抬起 + Z 回 0° (低速, 最坏行程 270°) ---- */
actuator_servo_up();
@@ -86,6 +89,7 @@ static void button_recognize_task(void *pvParam)
if (actuator_is_last_cycle_valid()) {
got_cycle = true;
ESP_LOGI(TAG, "RECOGNIZE 成功, 已收到 Cycle");
buzzer_beep_twice(2000, 150); /* 双短音: 识别成功 */
break;
}
}
@@ -93,6 +97,7 @@ static void button_recognize_task(void *pvParam)
if (!got_cycle) {
ESP_LOGW(TAG, "RECOGNIZE 超时 (%d ms), 发送 CYCLE_REQUEST",
RECOGNIZE_TIMEOUT_MS);
buzzer_beep(880, 500); /* 长低音: 识别失败/超时 */
edc_proto_send_request();
}
}
@@ -115,6 +120,9 @@ void app_main(void)
/* 初始化按钮 (GPIO8, 低电平有效, 触发识别) */
key_init(GPIO_NUM_8);
/* 初始化无源蜂鸣器 (GPIO9, 提示音) */
buzzer_init(GPIO_NUM_9);
/* 初始化通讯协议 (I2C 从机 GPIO2/3 + UART0 GPIO11/12) */
edc_proto_init(NULL);
@@ -134,16 +142,25 @@ void app_main(void)
/* 系统就绪: 黄灯 (低亮) */
rgb_set(32, 32, 0);
rgb_set_state(RGB_STATE_IDLE);
buzzer_beep(2000, 120); /* 启动/就绪: 短促一声 */
ESP_LOGI(TAG, "系统就绪, 等待网页指令...");
/* 结束提示: 每轮只响一次, 防止慢闪循环重复响 */
bool done_beeped = false;
while (1) {
/* 根据系统状态选择闪烁颜色 */
rgb_state_t st = rgb_get_state();
if (st == RGB_STATE_DONE) {
/* 绿灯慢闪: Cycle 执行完毕 */
if (!done_beeped) {
buzzer_beep_triple(2000, 100); /* 执行结束: 急促三响 */
done_beeped = true;
}
rgb_set(0, 32, 0);
} else {
/* 黄灯慢闪: 待机 */
done_beeped = false;
rgb_set(32, 32, 0);
}
vTaskDelay(pdMS_TO_TICKS(500));