toy-hardware/main/main.cc
Rdzleo bc14e60836 Create v1.7.6 聆听空闲超时自动退出 + Bug修复
一、新增功能
1. 聆听状态空闲超时自动退出
   - 聆听状态下无用户交互(无语音对话、无按键操作、无音频播放)超过60秒后,
     设备自动关闭音频通道回到idle待命状态,行为等同于手动按下BOOT按键退出
   - 超时时间通过Kconfig CONFIG_LISTENING_IDLE_TIMEOUT_SECONDS可配置(范围30~300秒,默认60秒)
   - speaking状态期间暂停计时,回到listening后从0重新倒计时,确保用户有完整的思考时间

2. 聆听空闲计时器外部重置接口
   - 新增ResetListeningIdleTimer()公开方法,供板级按键/触摸回调调用
   - 重置触发点:触摸按键(摸脑袋等)、BOOT按键、故事按键、收到服务端stt/tts/music_control/story消息

二、Bug修复
3. 修复超时退出后待命音效无声
   - 原因:超时退出路径中audio_processor_.Stop()关闭了功放,之后才播放待命音效
   - 修复:在SetDeviceState(kDeviceStateIdle)播放待命音效前调用codec->EnableOutput(true)确保功放开启

4. 修复WebSocket断开与tts:stop竞态导致崩溃重启
   - 原因:tts:stop和WebSocket断开同时发生时,设备切换到listening触发SendStartListening失败,
     竞态导致WakeWordDetect堆损坏(StoreProhibited崩溃)
   - 修复:tts:stop处理中先检查IsAudioChannelOpened(),音频通道不可用时直接回退到idle

5. 修复listening状态音频通道不可用时逻辑错误
   - 原因:音频通道不可用时"保持在listening状态"导致后续状态混乱
   - 修复:改为直接回退到idle状态

三、优化调整
6. 版本号从1.7.5升级到1.7.6
7. ADC电量采样间隔从10ms缩短为5ms,提高采样效率
8. 日志配置调整:恢复日志输出能力用于调试
9. WiFi组件代码注释补充
10. 新增.gitignore,忽略build目录和.vscode/settings.json

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:17:37 +08:00

74 lines
3.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <esp_log.h>
#include <esp_err.h>
#include <nvs.h>
#include <nvs_flash.h>
#include <driver/gpio.h>
#include <esp_event.h>
#include <esp_netif.h>
#include "application.h"
#include "system_info.h"
#define TAG "main"
// // 新增禁用日志配置(生产环境)
// // 重定向printf到空函数彻底禁用所有输出 新增禁用日志配置
// // =======================禁用日志参输出=============================
// extern "C" {
// int printf(const char* format, ...) { return 0; }
// int puts(const char* s) { return 0; }
// int putchar(int c) { return c; }
// size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream) { return size * count; }
// }
// // ================================================================
extern "C" void app_main(void)
{
// 新增禁用日志配置(生产环境)
// // 新增禁用日志配置(生产环境)
// // ====================================================================================================
// //全局禁用所有日志输出 - 必须在最开始就设置
// esp_log_level_set("*", ESP_LOG_NONE); // 全局禁用所有日志
// //特别禁用可能的残留日志组件
// esp_log_level_set("coexist", ESP_LOG_NONE);
// esp_log_level_set("main_task", ESP_LOG_NONE);
// esp_log_level_set("MC Quantized wakenet9", ESP_LOG_NONE);
// esp_log_level_set("wakenet", ESP_LOG_NONE);
// esp_log_level_set("esp_netif_lwip", ESP_LOG_NONE);
// esp_log_level_set("wifi", ESP_LOG_NONE);
// esp_log_level_set("phy_init", ESP_LOG_NONE);
// esp_log_level_set("system_api", ESP_LOG_NONE);
// esp_log_level_set("MovecallMojiESP32S3", ESP_LOG_NONE); // 生产环境:屏蔽MovecallMojiESP32S3板级日志
// //esp_log_level_set("MovecallMojiESP32S3", ESP_LOG_INFO); // 启用MovecallMojiESP32S3板级日志以支持触摸检测
// esp_log_level_set("WiFiMAC", ESP_LOG_INFO); // 仅允许WiFiMAC组件的INFO级别日志Wi-Fi MAC地址
// //esp_log_level_set("Airhub", ESP_LOG_INFO); // 仅允许Airhub组件的INFO级别日志生产测试日志
// // =======================================================================================================
// 增加姿态传感器日志打印
esp_log_level_set("Airhub", ESP_LOG_DEBUG); // 看到运动检测日志
esp_log_level_set("Airhub", ESP_LOG_VERBOSE); // 看到详细数据日志
// 屏蔽AFE模块的警告日志
esp_log_level_set("AFE", ESP_LOG_ERROR);
// Initialize the default event loop
ESP_ERROR_CHECK(esp_event_loop_create_default());
// Initialize network interface (必须在WiFi初始化之前)
ESP_ERROR_CHECK(esp_netif_init());
// Initialize NVS flash for WiFi configuration
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGW(TAG, "Erasing NVS flash to fix corruption");
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
// Launch the application
Application::GetInstance().Start();
// The main thread will exit and release the stack memory
}