forked from xiaozhi/xiaozhi-esp32
Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad0c5312f8 | ||
|
|
a66760348f | ||
|
|
849b1a5ddc | ||
|
|
5568c70cb4 | ||
|
|
e1b84e824c | ||
|
|
0842b8f3c3 | ||
|
|
9ead806dc1 | ||
|
|
5c3e1a87d6 | ||
|
|
4bf6fa8324 | ||
|
|
8267f59a6a | ||
|
|
b8bf6bea2e | ||
|
|
968bf0e2eb | ||
|
|
1f803dec16 | ||
|
|
a1bade4e0f | ||
|
|
febcfefd19 | ||
|
|
9335a41220 | ||
|
|
11c146f6ad | ||
|
|
55e000f922 | ||
|
|
bdc4da0650 | ||
|
|
0533bee83e | ||
|
|
b171ae17b2 | ||
|
|
1b338fa71b | ||
|
|
d822fc7512 | ||
|
|
8147746bfa | ||
|
|
f1de536110 | ||
|
|
70cb3410b0 | ||
|
|
20696b37f9 | ||
|
|
40be60ff9b | ||
|
|
f5008af2d1 | ||
|
|
cead024698 | ||
|
|
3609aaa412 | ||
|
|
b587e45562 | ||
|
|
df252e9049 | ||
|
|
b18784bd8e | ||
|
|
ed46a94d27 | ||
|
|
8c826a81de | ||
|
|
2eb8cac140 | ||
|
|
bdda575383 | ||
|
|
6318dd1793 | ||
|
|
1a808962e2 | ||
|
|
5997ff2ac4 | ||
|
|
5a71e1bdd6 | ||
|
|
c60f134093 | ||
|
|
778e4f433f | ||
|
|
0f95444d62 | ||
|
|
01aab961ca | ||
|
|
7945da0c84 | ||
|
|
36d98ce1a4 | ||
|
|
a872ca1bff | ||
|
|
7c2a64cc86 | ||
|
|
cbf479f636 | ||
|
|
e55166b3b3 | ||
|
|
9116dd6c07 | ||
|
|
77db38ca4c | ||
|
|
80fd7736d5 | ||
|
|
799302e1e6 | ||
|
|
ffe0b21d18 | ||
|
|
de783b7c57 | ||
|
|
6b855eae53 | ||
|
|
a23a88cc5d | ||
|
|
c08a1a5310 | ||
|
|
b0f0f4d4db | ||
|
|
20d52def0b | ||
|
|
dc118d2f24 | ||
|
|
63d8b30c02 | ||
|
|
add225ba56 | ||
|
|
216ebc16bf | ||
|
|
e123e37f7d | ||
|
|
cd2fbf2a25 | ||
|
|
8659087f5d | ||
|
|
455c71167e | ||
|
|
01e82ba32e | ||
|
|
d0e3426d9f | ||
|
|
1d1fe3dd2e | ||
|
|
939564b175 | ||
|
|
d5594d01a3 |
103
.github/ISSUE_TEMPLATE/01_build_install_bug.yml
vendored
Normal file
103
.github/ISSUE_TEMPLATE/01_build_install_bug.yml
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
name: Installation or build bug report
|
||||
description: Report installation or build bugs
|
||||
labels: ['bug']
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Answers checklist.
|
||||
description: Before submitting a new issue, please follow the checklist and try to find the answer.
|
||||
options:
|
||||
- label: I have read the documentation [XiaoZhi AI Programming Guide](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb) and the issue is not addressed there.
|
||||
required: true
|
||||
- label: I have updated my branch (master or release) to the latest version and checked that the issue is present there.
|
||||
required: true
|
||||
- label: I have searched the issue tracker for a similar issue and not found a similar issue.
|
||||
required: true
|
||||
- type: input
|
||||
id: xiaozhi_ai_version
|
||||
attributes:
|
||||
label: XiaoZhi AI version.
|
||||
description: On which XiaoZhi AI version does this issue occur on? Run `git describe --tags` to find it.
|
||||
placeholder: ex. v1.1.0-44-g140aab8
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: operating_system
|
||||
attributes:
|
||||
label: Operating System used.
|
||||
multiple: false
|
||||
options:
|
||||
- Windows
|
||||
- Linux
|
||||
- macOS
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: build
|
||||
attributes:
|
||||
label: How did you build your project?
|
||||
multiple: false
|
||||
options:
|
||||
- Command line with CMake
|
||||
- Command line with idf.py
|
||||
- CLion IDE
|
||||
- VS Code IDE/Cursor
|
||||
- Other (please specify in More Information)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: windows_comand_line
|
||||
attributes:
|
||||
label: If you are using Windows, please specify command line type.
|
||||
multiple: false
|
||||
options:
|
||||
- PowerShell
|
||||
- CMD
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: What is the expected behavior?
|
||||
description: Please provide a clear and concise description of the expected behavior.
|
||||
placeholder: I expected it to...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual
|
||||
attributes:
|
||||
label: What is the actual behavior?
|
||||
description: Please describe actual behavior.
|
||||
placeholder: Instead it...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce.
|
||||
description: 'How do you trigger this bug? Please walk us through it step by step. If this is build bug, please attach sdkconfig file (from your project folder). Please attach your code here.'
|
||||
value: |
|
||||
1. Step
|
||||
2. Step
|
||||
3. Step
|
||||
...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: debug_logs
|
||||
attributes:
|
||||
label: Build or installation Logs.
|
||||
description: Build or installation log goes here, should contain the backtrace, as well as the reset source if it is a crash.
|
||||
placeholder: Your log goes here.
|
||||
render: plain
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: more-info
|
||||
attributes:
|
||||
label: More Information.
|
||||
description: Do you have any other information from investigating this?
|
||||
placeholder: ex. Any more.
|
||||
validations:
|
||||
required: false
|
||||
115
.github/ISSUE_TEMPLATE/02_runtime_bug.yml
vendored
Normal file
115
.github/ISSUE_TEMPLATE/02_runtime_bug.yml
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
name: Runtime bug report
|
||||
description: Report runtime bugs
|
||||
labels: ['bug']
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Answers checklist.
|
||||
description: Before submitting a new issue, please follow the checklist and try to find the answer.
|
||||
options:
|
||||
- label: I have read the documentation [XiaoZhi AI Programming Guide](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb) and the issue is not addressed there.
|
||||
required: true
|
||||
- label: I have updated my firmware to the latest version and checked that the issue is present there.
|
||||
required: true
|
||||
- label: I have searched the issue tracker for a similar issue and not found a similar issue.
|
||||
required: true
|
||||
- type: input
|
||||
id: xiaozhi_ai_firmware_version
|
||||
attributes:
|
||||
label: XiaoZhi AI firmware version.
|
||||
description: On which firmware version does this issue occur on?
|
||||
placeholder: ex. v1.2.1_bread-compact-wifi
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: operating_system
|
||||
attributes:
|
||||
label: Operating System used.
|
||||
multiple: false
|
||||
options:
|
||||
- Windows
|
||||
- Linux
|
||||
- macOS
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: build
|
||||
attributes:
|
||||
label: How did you build your project?
|
||||
multiple: false
|
||||
options:
|
||||
- Command line with CMake
|
||||
- Command line with idf.py
|
||||
- CLion IDE
|
||||
- VS Code IDE/Cursor
|
||||
- Other (please specify in More Information)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: windows_comand_line
|
||||
attributes:
|
||||
label: If you are using Windows, please specify command line type.
|
||||
multiple: false
|
||||
options:
|
||||
- PowerShell
|
||||
- CMD
|
||||
validations:
|
||||
required: false
|
||||
- type: dropdown
|
||||
id: power_supply
|
||||
attributes:
|
||||
label: Power Supply used.
|
||||
multiple: false
|
||||
options:
|
||||
- USB
|
||||
- External 5V
|
||||
- External 3.3V
|
||||
- Battery
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: What is the expected behavior?
|
||||
description: Please provide a clear and concise description of the expected behavior.
|
||||
placeholder: I expected it to...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual
|
||||
attributes:
|
||||
label: What is the actual behavior?
|
||||
description: Please describe actual behavior.
|
||||
placeholder: Instead it...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce.
|
||||
description: 'How do you trigger this bug? Please walk us through it step by step. Please attach your code here.'
|
||||
value: |
|
||||
1. Step
|
||||
2. Step
|
||||
3. Step
|
||||
...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: debug_logs
|
||||
attributes:
|
||||
label: Debug Logs.
|
||||
description: Debug log goes here, should contain the backtrace, as well as the reset source if it is a crash.
|
||||
placeholder: Your log goes here.
|
||||
render: plain
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: more-info
|
||||
attributes:
|
||||
label: More Information.
|
||||
description: Do you have any other information from investigating this?
|
||||
placeholder: ex. Any more.
|
||||
validations:
|
||||
required: false
|
||||
34
.github/ISSUE_TEMPLATE/03_feature_request.yml
vendored
Normal file
34
.github/ISSUE_TEMPLATE/03_feature_request.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Feature request
|
||||
description: Suggest an idea for this project.
|
||||
labels: ['enhancement']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
* We welcome any ideas or feature requests! It’s helpful if you can explain exactly why the feature would be useful.
|
||||
* There are usually some outstanding feature requests in the [existing issues list](https://github.com/78/xiaozhi-esp32/labels/enhancement), feel free to add comments to them.
|
||||
* If you would like to contribute, please read the [contributions guide](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb).
|
||||
- type: textarea
|
||||
id: problem-related
|
||||
attributes:
|
||||
label: Is your feature request related to a problem?
|
||||
description: Please provide a clear and concise description of what the problem is.
|
||||
placeholder: ex. I'm always frustrated when ...
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Describe the solution you'd like.
|
||||
description: Please provide a clear and concise description of what you want to happen.
|
||||
placeholder: ex. When using XiaoZhi ...
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Describe alternatives you've considered.
|
||||
description: Please provide a clear and concise description of any alternative solutions or features you've considered.
|
||||
placeholder: ex. Choosing other approach wouldn't work, because ...
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Additional context.
|
||||
description: Please add any other context or screenshots about the feature request here.
|
||||
placeholder: ex. This would work only when ...
|
||||
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: 小智 AI 官方网站
|
||||
url: https://xiaozhi.me/
|
||||
about: 激活设备、配置 AI、声纹识别、声音克隆等应有尽有,DIY 属于你自己的小智
|
||||
- name: 小智 AI 聊天机器人百科全书
|
||||
url: https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb
|
||||
about: 开发文档、硬件制作、烧录教程、FAQ尽在小智百科
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -8,4 +8,6 @@ sdkconfig.old
|
||||
sdkconfig
|
||||
dependencies.lock
|
||||
.env
|
||||
releases/
|
||||
releases/
|
||||
main/assets/lang_config.h
|
||||
.DS_Store
|
||||
@@ -4,7 +4,7 @@
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(PROJECT_VER "1.2.1")
|
||||
set(PROJECT_VER "1.4.6")
|
||||
|
||||
# Add this line to disable the specific warning
|
||||
add_compile_options(-Wno-missing-field-initializers)
|
||||
|
||||
44
README.md
44
README.md
@@ -4,19 +4,21 @@
|
||||
|
||||
这是虾哥的第一个硬件作品。
|
||||
|
||||
👉 [ESP32+SenseVoice+Qwen72B打造你的AI聊天伴侣!【bilibili】](https://www.bilibili.com/video/BV11msTenEH3/?share_source=copy_web&vd_source=ee1aafe19d6e60cf22e60a93881faeba)
|
||||
👉 [ESP32+SenseVoice+Qwen72B打造你的AI聊天伴侣!【bilibili】](https://www.bilibili.com/video/BV11msTenEH3/)
|
||||
|
||||
👉 [给小智装上 DeepSeek 的聪明大脑【bilibili】](https://www.bilibili.com/video/BV1GQP6eNEFG/)
|
||||
|
||||
👉 [手工打造你的 AI 女友,新手入门教程【bilibili】](https://www.bilibili.com/video/BV1XnmFYLEJN/)
|
||||
|
||||
## 项目目的
|
||||
|
||||
本项目基于乐鑫的 ESP-IDF 进行开发。
|
||||
本项目是一个开源项目,以 MIT 许可证发布,允许任何人免费使用,并可以用于商业用途。
|
||||
|
||||
本项目是一个开源项目,主要用于教学目的。我们希望通过这个项目,能够帮助更多人入门 AI 硬件开发,了解如何将当下飞速发展的大语言模型应用到实际的硬件设备中。无论你是对 AI 感兴趣的学生,还是想要探索新技术的开发者,都可以通过这个项目获得宝贵的学习经验。
|
||||
我们希望通过这个项目,能够帮助更多人入门 AI 硬件开发,了解如何将当下飞速发展的大语言模型应用到实际的硬件设备中。无论你是对 AI 感兴趣的学生,还是想要探索新技术的开发者,都可以通过这个项目获得宝贵的学习经验。
|
||||
|
||||
欢迎所有人参与到项目的开发和改进中来。如果你有任何想法或建议,请随时提出 Issue 或加入群聊。
|
||||
|
||||
学习交流 QQ 群:946599635
|
||||
学习交流 QQ 群:376893254
|
||||
|
||||
## 已实现功能
|
||||
|
||||
@@ -32,6 +34,7 @@
|
||||
- 短期记忆,每轮对话后自我总结
|
||||
- OLED / LCD 显示屏,显示信号强弱或对话内容
|
||||
- 支持 LCD 显示图片表情
|
||||
- 支持多语言(中文、英文)
|
||||
|
||||
## 硬件部分
|
||||
|
||||
@@ -57,7 +60,9 @@
|
||||
- <a href="https://github.com/Xinyuan-LilyGO/T-Circle-S3" target="_blank" title="LILYGO T-Circle-S3">LILYGO T-Circle-S3</a>
|
||||
- <a href="https://oshwhub.com/tenclass01/xmini_c3" target="_blank" title="虾哥 Mini C3">虾哥 Mini C3</a>
|
||||
- <a href="https://oshwhub.com/movecall/moji-xiaozhi-ai-derivative-editi" target="_blank" title="Movecall Moji ESP32S3">Moji 小智AI衍生版</a>
|
||||
|
||||
- <a href="https://github.com/WMnologo/xingzhi-ai" target="_blank" title="无名科技Nologo-星智-1.54">无名科技Nologo-星智-1.54TFT</a>
|
||||
- <a href="https://github.com/WMnologo/xingzhi-ai" target="_blank" title="无名科技Nologo-星智-0.96">无名科技Nologo-星智-0.96TFT</a>
|
||||
- <a href="https://www.seeedstudio.com/SenseCAP-Watcher-W1-A-p-5979.html" target="_blank" title="SenseCAP Watcher">SenseCAP Watcher</a>
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<a href="docs/v1/lichuang-s3.jpg" target="_blank" title="立创·实战派 ESP32-S3 开发板">
|
||||
<img src="docs/v1/lichuang-s3.jpg" width="240" />
|
||||
@@ -71,9 +76,6 @@
|
||||
<a href="docs/v1/atoms3r.jpg" target="_blank" title="AtomS3R + Echo Base">
|
||||
<img src="docs/v1/atoms3r.jpg" width="240" />
|
||||
</a>
|
||||
<a href="docs/AtomMatrix-echo-base.jpg" target="_blank" title="AtomMatrix-echo-base + Echo Base">
|
||||
<img src="docs/AtomMatrix-echo-base.jpg" width="240" />
|
||||
</a>
|
||||
<a href="docs/v1/magiclick.jpg" target="_blank" title="神奇按钮 2.4">
|
||||
<img src="docs/v1/magiclick.jpg" width="240" />
|
||||
</a>
|
||||
@@ -89,13 +91,24 @@
|
||||
<a href="docs/v1/movecall-moji-esp32s3.jpg" target="_blank" title="Movecall Moji 小智AI衍生版">
|
||||
<img src="docs/v1/movecall-moji-esp32s3.jpg" width="240" />
|
||||
</a>
|
||||
<a href="docs/v1/wmnologo_xingzhi_1.54.jpg" target="_blank" title="无名科技Nologo-星智-1.54">
|
||||
<img src="docs/v1/wmnologo_xingzhi_1.54.jpg" width="240" />
|
||||
</a>
|
||||
<a href="docs/v1/wmnologo_xingzhi_0.96.jpg" target="_blank" title="无名科技Nologo-星智-0.96">
|
||||
<img src="docs/v1/wmnologo_xingzhi_0.96.jpg" width="240" />
|
||||
</a>
|
||||
<a href="docs/v1/sensecap_watcher.jpg" target="_blank" title="SenseCAP Watcher">
|
||||
<img src="docs/v1/sensecap_watcher.jpg" width="240" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
## 固件部分
|
||||
|
||||
### 免开发环境烧录
|
||||
|
||||
新手第一次操作建议先不要搭建开发环境,直接使用免开发环境烧录的固件。固件使用的是作者友情提供的测试服,目前开放免费使用,请勿用于商业用途。
|
||||
新手第一次操作建议先不要搭建开发环境,直接使用免开发环境烧录的固件。
|
||||
|
||||
固件默认接入 [xiaozhi.me](https://xiaozhi.me) 官方服务器,目前个人用户注册账号可以免费使用 Qwen 实时模型。
|
||||
|
||||
👉 [Flash烧录固件(无IDF开发环境)](https://ccnphfhqs21z.feishu.cn/wiki/Zpz4wXBtdimBrLk25WdcXzxcnNS)
|
||||
|
||||
@@ -105,13 +118,20 @@
|
||||
- Cursor 或 VSCode
|
||||
- 安装 ESP-IDF 插件,选择 SDK 版本 5.3 或以上
|
||||
- Linux 比 Windows 更好,编译速度快,也免去驱动问题的困扰
|
||||
- 使用 Google C++ 代码风格,提交代码时请确保符合规范
|
||||
|
||||
|
||||
## AI 角色配置
|
||||
## 智能体配置
|
||||
|
||||
如果你已经拥有一个小智 AI 聊天机器人,可以参考 👉 [后台操作视频教程](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
如果你已经拥有一个小智 AI 聊天机器人设备,可以登录 [xiaozhi.me](https://xiaozhi.me) 控制台进行配置。
|
||||
|
||||
详细的使用说明以及测试服的注意事项,请参考 👉 [小智测试服的帮助说明](https://xiaozhi.me/help)。
|
||||
👉 [后台操作视频教程(旧版界面)](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
|
||||
## 技术原理与私有化部署
|
||||
|
||||
👉 [一份详细的 WebSocket 通信协议文档](docs/websocket.md)
|
||||
|
||||
在个人电脑上部署服务器,可以参考另一位作者同样以 MIT 许可证开源的项目 [xiaozhi-esp32-server](https://github.com/xinnan-tech/xiaozhi-esp32-server)
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
62
README_en.md
62
README_en.md
@@ -1,62 +1,65 @@
|
||||
# XiaoZhi AI Chatbot
|
||||
|
||||
([中文](README.md) | English | [日本語](README_ja.md))
|
||||
([中文](README.md) | English | [日本語](README_ja.md))
|
||||
|
||||
This is Terrence's first hardware project.
|
||||
|
||||
👉 [Build your AI chat companion with ESP32+SenseVoice+Qwen72B! [bilibili]](https://www.bilibili.com/video/BV11msTenEH3/?share_source=copy_web&vd_source=ee1aafe19d6e60cf22e60a93881faeba)
|
||||
👉 [Build your AI chat companion with ESP32+SenseVoice+Qwen72B!【bilibili】](https://www.bilibili.com/video/BV11msTenEH3/)
|
||||
|
||||
👉 [DIY Your AI Companion - Beginner's Tutorial [bilibili]](https://www.bilibili.com/video/BV1XnmFYLEJN/)
|
||||
👉 [Equipping XiaoZhi with DeepSeek's smart brain【bilibili】](https://www.bilibili.com/video/BV1GQP6eNEFG/)
|
||||
|
||||
👉 [Build your own AI companion, a beginner's guide【bilibili】](https://www.bilibili.com/video/BV1XnmFYLEJN/)
|
||||
|
||||
## Project Purpose
|
||||
|
||||
This project is developed based on Espressif's ESP-IDF.
|
||||
This is an open-source project released under the MIT license, allowing anyone to use it freely, including for commercial purposes.
|
||||
|
||||
This is an open-source project primarily for educational purposes. Through this project, we aim to help more people get started with AI hardware development and understand how to integrate rapidly evolving large language models into actual hardware devices. Whether you're a student interested in AI or a developer looking to explore new technologies, this project offers valuable learning experiences.
|
||||
Through this project, we aim to help more people get started with AI hardware development and understand how to implement rapidly evolving large language models in actual hardware devices. Whether you're a student interested in AI or a developer exploring new technologies, this project offers valuable learning experiences.
|
||||
|
||||
Everyone is welcome to participate in the project's development and improvement. If you have any ideas or suggestions, please feel free to raise an Issue or join our chat group.
|
||||
Everyone is welcome to participate in the project's development and improvement. If you have any ideas or suggestions, please feel free to raise an Issue or join the chat group.
|
||||
|
||||
Learning & Discussion QQ Group: 946599635
|
||||
Learning & Discussion QQ Group: 376893254
|
||||
|
||||
## Implemented Features
|
||||
|
||||
- Wi-Fi / ML307 Cat.1 4G
|
||||
- BOOT button wake-up and interrupt, supporting both click and long-press triggers
|
||||
- BOOT button wake-up and interruption, supporting both click and long-press triggers
|
||||
- Offline voice wake-up [ESP-SR](https://github.com/espressif/esp-sr)
|
||||
- Streaming voice dialogue (WebSocket or UDP protocol)
|
||||
- Support for 5 languages: Mandarin, Cantonese, English, Japanese, Korean [SenseVoice](https://github.com/FunAudioLLM/SenseVoice)
|
||||
- Voice print recognition to identify who's calling AI's name [3D Speaker](https://github.com/modelscope/3D-Speaker)
|
||||
- Large model TTS (Volcengine or CosyVoice)
|
||||
- Large Language Model (Qwen2.5 72B or Doubao API)
|
||||
- Large model TTS (Volcano Engine or CosyVoice)
|
||||
- Large Language Models (Qwen, DeepSeek, Doubao)
|
||||
- Configurable prompts and voice tones (custom characters)
|
||||
- Short-term memory with self-summary after each conversation round
|
||||
- Short-term memory, self-summarizing after each conversation round
|
||||
- OLED / LCD display showing signal strength or conversation content
|
||||
- Support for displaying emoji images on LCD
|
||||
- Support for LCD image expressions
|
||||
- Multi-language support (Chinese, English)
|
||||
|
||||
## Hardware Section
|
||||
|
||||
### Breadboard Practice
|
||||
### Breadboard DIY Practice
|
||||
|
||||
For detailed tutorial, see the Feishu document:
|
||||
See the Feishu document tutorial:
|
||||
|
||||
👉 [XiaoZhi AI Chatbot Encyclopedia](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb?from=from_copylink)
|
||||
|
||||
Breadboard setup shown below:
|
||||
Breadboard demonstration:
|
||||
|
||||

|
||||

|
||||
|
||||
### Supported Open-Source Hardware
|
||||
### Supported Open Source Hardware
|
||||
|
||||
- <a href="https://oshwhub.com/li-chuang-kai-fa-ban/li-chuang-shi-zhan-pai-esp32-s3-kai-fa-ban" target="_blank" title="LiChuang ESP32-S3 Development Board">LiChuang ESP32-S3 Development Board</a>
|
||||
- <a href="https://github.com/espressif/esp-box" target="_blank" title="Espressif ESP32-S3-BOX3">Espressif ESP32-S3-BOX3</a>
|
||||
- <a href="https://docs.m5stack.com/zh_CN/core/CoreS3" target="_blank" title="M5Stack CoreS3">M5Stack CoreS3</a>
|
||||
- <a href="https://docs.m5stack.com/en/atom/Atomic%20Echo%20Base" target="_blank" title="AtomS3R + Echo Base">AtomS3R + Echo Base</a>
|
||||
- <a href="https://docs.m5stack.com/en/core/ATOM%20Matrix" target="_blank" title="AtomMatrix + Echo Base">AtomMatrix + Echo Base</a>
|
||||
- <a href="https://gf.bilibili.com/item/detail/1108782064" target="_blank" title="MagiClick 2.4">MagiClick 2.4</a>
|
||||
- <a href="https://gf.bilibili.com/item/detail/1108782064" target="_blank" title="Magic Button 2.4">Magic Button 2.4</a>
|
||||
- <a href="https://www.waveshare.net/shop/ESP32-S3-Touch-AMOLED-1.8.htm" target="_blank" title="Waveshare ESP32-S3-Touch-AMOLED-1.8">Waveshare ESP32-S3-Touch-AMOLED-1.8</a>
|
||||
- <a href="https://github.com/Xinyuan-LilyGO/T-Circle-S3" target="_blank" title="LILYGO T-Circle-S3">LILYGO T-Circle-S3</a>
|
||||
- <a href="https://oshwhub.com/tenclass01/xmini_c3" target="_blank" title="Xmini C3">Xmini C3</a>
|
||||
- <a href="https://oshwhub.com/movecall/moji-xiaozhi-ai-derivative-editi" target="_blank" title="Movecall Moji ESP32S3">Movecall Moji ESP32S3</a>
|
||||
- <a href="https://oshwhub.com/tenclass01/xmini_c3" target="_blank" title="XiaGe Mini C3">XiaGe Mini C3</a>
|
||||
- <a href="https://oshwhub.com/movecall/moji-xiaozhi-ai-derivative-editi" target="_blank" title="Movecall Moji ESP32S3">Moji XiaoZhi AI Derivative Version</a>
|
||||
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<a href="docs/v1/lichuang-s3.jpg" target="_blank" title="LiChuang ESP32-S3 Development Board">
|
||||
@@ -95,21 +98,30 @@ Breadboard setup shown below:
|
||||
|
||||
### Flashing Without Development Environment
|
||||
|
||||
For beginners, it's recommended to first try flashing the firmware without setting up a development environment. The firmware uses a test server provided by the author, currently available for free use (not for commercial purposes).
|
||||
For beginners, it's recommended to first use the firmware that can be flashed without setting up a development environment.
|
||||
|
||||
👉 [Flash Firmware Guide (No IDF Environment Required)](https://ccnphfhqs21z.feishu.cn/wiki/Zpz4wXBtdimBrLk25WdcXzxcnNS)
|
||||
The firmware connects to the official [xiaozhi.me](https://xiaozhi.me) server by default. Currently, personal users can register an account to use the Qwen real-time model for free.
|
||||
|
||||
👉 [Flash Firmware Guide (No IDF Environment)](https://ccnphfhqs21z.feishu.cn/wiki/Zpz4wXBtdimBrLk25WdcXzxcnNS)
|
||||
|
||||
### Development Environment
|
||||
|
||||
- Cursor or VSCode
|
||||
- Install ESP-IDF plugin, select SDK version 5.3 or above
|
||||
- Linux is preferred over Windows for faster compilation and fewer driver issues
|
||||
- Use Google C++ code style, ensure compliance when submitting code
|
||||
|
||||
## AI Character Configuration
|
||||
## AI Agent Configuration
|
||||
|
||||
If you already have a XiaoZhi AI chatbot, please refer to 👉 [Backend Operation Video Tutorial](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
If you already have a XiaoZhi AI chatbot device, you can configure it through the [xiaozhi.me](https://xiaozhi.me) console.
|
||||
|
||||
For detailed usage instructions and test server notes, please refer to 👉 [XiaoZhi Test Server Help Guide](https://xiaozhi.me/help).
|
||||
👉 [Backend Operation Tutorial (Old Interface)](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
|
||||
## Technical Principles and Private Deployment
|
||||
|
||||
👉 [Detailed WebSocket Communication Protocol Documentation](docs/websocket.md)
|
||||
|
||||
For server deployment on personal computers, refer to another MIT-licensed project [xiaozhi-esp32-server](https://github.com/xinnan-tech/xiaozhi-esp32-server)
|
||||
|
||||
## Star History
|
||||
|
||||
|
||||
95
README_ja.md
95
README_ja.md
@@ -1,49 +1,52 @@
|
||||
# XiaoZhi AI チャットボット
|
||||
# シャオジー AI チャットボット
|
||||
|
||||
([中文](README.md) | [English](README_en.md) | 日本語)
|
||||
([中文](README.md) | [English](README_en.md) | 日本語)
|
||||
|
||||
これはテレンスの最初のハードウェアプロジェクトです。
|
||||
これは シャーガー(Terrence)の最初のハードウェア作品です。
|
||||
|
||||
👉 [ESP32+SenseVoice+Qwen72BでAIチャットコンパニオンを作ろう!【bilibili】](https://www.bilibili.com/video/BV11msTenEH3/?share_source=copy_web&vd_source=ee1aafe19d6e60cf22e60a93881faeba)
|
||||
👉 [ESP32+SenseVoice+Qwen72Bで AI チャット仲間を作ろう!【bilibili】](https://www.bilibili.com/video/BV11msTenEH3/)
|
||||
|
||||
👉 [AIコンパニオンをDIYする - 初心者向けチュートリアル【bilibili】](https://www.bilibili.com/video/BV1XnmFYLEJN/)
|
||||
👉 [シャオジーに DeepSeek のスマートな頭脳を搭載【bilibili】](https://www.bilibili.com/video/BV1GQP6eNEFG/)
|
||||
|
||||
👉 [自分だけの AI パートナーを作る、初心者向けガイド【bilibili】](https://www.bilibili.com/video/BV1XnmFYLEJN/)
|
||||
|
||||
## プロジェクトの目的
|
||||
|
||||
このプロジェクトはEspressifのESP-IDFに基づいて開発されています。
|
||||
このプロジェクトは MIT ライセンスの下で公開されているオープンソースプロジェクトで、商用利用を含め、誰でも自由に使用することができます。
|
||||
|
||||
このプロジェクトは主に教育目的のためのオープンソースプロジェクトです。このプロジェクトを通じて、より多くの人々がAIハードウェア開発を始め、急速に進化する大規模言語モデルを実際のハードウェアデバイスに統合する方法を理解する手助けをすることを目指しています。AIに興味のある学生や新しい技術を探求したい開発者にとって、このプロジェクトは貴重な学習体験を提供します。
|
||||
このプロジェクトを通じて、より多くの人々が AI ハードウェア開発を始め、急速に進化している大規模言語モデルを実際のハードウェアデバイスに実装する方法を理解できるようになることを目指しています。AI に興味のある学生でも、新しい技術を探求する開発者でも、このプロジェクトから貴重な学習経験を得ることができます。
|
||||
|
||||
プロジェクトの開発と改善に参加することを歓迎します。アイデアや提案があれば、Issueを提起するか、チャットグループに参加してください。
|
||||
プロジェクトの開発と改善には誰でも参加できます。アイデアや提案がありましたら、Issue を立てるかチャットグループにご参加ください。
|
||||
|
||||
学習・ディスカッションQQグループ: 946599635
|
||||
学習・交流 QQ グループ:376893254
|
||||
|
||||
## 実装された機能
|
||||
## 実装済みの機能
|
||||
|
||||
- Wi-Fi / ML307 Cat.1 4G
|
||||
- BOOTボタンのウェイクアップと割り込み、クリックと長押しの両方のトリガーをサポート
|
||||
- オフライン音声ウェイクアップ [ESP-SR](https://github.com/espressif/esp-sr)
|
||||
- ストリーミング音声対話(WebSocketまたはUDPプロトコル)
|
||||
- 5つの言語をサポート:標準中国語、広東語、英語、日本語、韓国語 [SenseVoice](https://github.com/FunAudioLLM/SenseVoice)
|
||||
- 音声認識でAIの名前を呼んでいる人を識別 [3D Speaker](https://github.com/modelscope/3D-Speaker)
|
||||
- 大規模モデルTTS(VolcengineまたはCosyVoice)
|
||||
- 大規模言語モデル(Qwen2.5 72BまたはDoubao API)
|
||||
- カスタマイズ可能なプロンプトと音声トーン(カスタムキャラクター)
|
||||
- 短期記憶、各対話ラウンド後の自己要約
|
||||
- 信号強度や対話内容を表示するOLED / LCDディスプレイ
|
||||
- LCDディスプレイでの絵文字表示をサポート
|
||||
- BOOT ボタンによる起動と中断、クリックと長押しの2種類のトリガーに対応
|
||||
- オフライン音声起動 [ESP-SR](https://github.com/espressif/esp-sr)
|
||||
- ストリーミング音声対話(WebSocket または UDP プロトコル)
|
||||
- 5言語対応:標準中国語、広東語、英語、日本語、韓国語 [SenseVoice](https://github.com/FunAudioLLM/SenseVoice)
|
||||
- 話者認識、AI の名前を呼んでいる人を識別 [3D Speaker](https://github.com/modelscope/3D-Speaker)
|
||||
- 大規模モデル TTS(Volcano Engine または CosyVoice)
|
||||
- 大規模言語モデル(Qwen, DeepSeek, Doubao)
|
||||
- 設定可能なプロンプトと音声トーン(カスタムキャラクター)
|
||||
- 短期記憶、各会話ラウンド後の自己要約
|
||||
- OLED / LCD ディスプレイ、信号強度や会話内容を表示
|
||||
- LCD での画像表情表示に対応
|
||||
- 多言語対応(中国語、英語)
|
||||
|
||||
## ハードウェアセクション
|
||||
## ハードウェア部分
|
||||
|
||||
### ブレッドボードの練習
|
||||
### ブレッドボード DIY 実践
|
||||
|
||||
詳細なチュートリアルについては、Feishuドキュメントを参照してください:
|
||||
Feishu ドキュメントチュートリアルをご覧ください:
|
||||
|
||||
👉 [XiaoZhi AI チャットボット百事典](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb?from=from_copylink)
|
||||
👉 [シャオジー AI チャットボット百科事典](https://ccnphfhqs21z.feishu.cn/wiki/F5krwD16viZoF0kKkvDcrZNYnhb?from=from_copylink)
|
||||
|
||||
以下にブレッドボードのセットアップを示します:
|
||||
ブレッドボードのデモ:
|
||||
|
||||

|
||||

|
||||
|
||||
### サポートされているオープンソースハードウェア
|
||||
|
||||
@@ -51,11 +54,12 @@
|
||||
- <a href="https://github.com/espressif/esp-box" target="_blank" title="Espressif ESP32-S3-BOX3">Espressif ESP32-S3-BOX3</a>
|
||||
- <a href="https://docs.m5stack.com/zh_CN/core/CoreS3" target="_blank" title="M5Stack CoreS3">M5Stack CoreS3</a>
|
||||
- <a href="https://docs.m5stack.com/en/atom/Atomic%20Echo%20Base" target="_blank" title="AtomS3R + Echo Base">AtomS3R + Echo Base</a>
|
||||
- <a href="https://gf.bilibili.com/item/detail/1108782064" target="_blank" title="MagiClick 2.4">MagiClick 2.4</a>
|
||||
- <a href="https://docs.m5stack.com/en/core/ATOM%20Matrix" target="_blank" title="AtomMatrix + Echo Base">AtomMatrix + Echo Base</a>
|
||||
- <a href="https://gf.bilibili.com/item/detail/1108782064" target="_blank" title="マジックボタン 2.4">マジックボタン 2.4</a>
|
||||
- <a href="https://www.waveshare.net/shop/ESP32-S3-Touch-AMOLED-1.8.htm" target="_blank" title="Waveshare ESP32-S3-Touch-AMOLED-1.8">Waveshare ESP32-S3-Touch-AMOLED-1.8</a>
|
||||
- <a href="https://github.com/Xinyuan-LilyGO/T-Circle-S3" target="_blank" title="LILYGO T-Circle-S3">LILYGO T-Circle-S3</a>
|
||||
- <a href="https://oshwhub.com/tenclass01/xmini_c3" target="_blank" title="Xmini C3">Xmini C3</a>
|
||||
- <a href="https://oshwhub.com/movecall/moji-xiaozhi-ai-derivative-editi" target="_blank" title="Movecall Moji ESP32S3">Movecall Moji ESP32S3</a>
|
||||
- <a href="https://oshwhub.com/tenclass01/xmini_c3" target="_blank" title="XiaGe Mini C3">XiaGe Mini C3</a>
|
||||
- <a href="https://oshwhub.com/movecall/moji-xiaozhi-ai-derivative-editi" target="_blank" title="Movecall Moji ESP32S3">Moji シャオジー AI 派生版</a>
|
||||
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
<a href="docs/v1/lichuang-s3.jpg" target="_blank" title="LiChuang ESP32-S3 開発ボード">
|
||||
@@ -87,27 +91,36 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
## ファームウェアセクション
|
||||
## ファームウェア部分
|
||||
|
||||
### 開発環境なしでのフラッシュ
|
||||
### 開発環境なしのフラッシュ
|
||||
|
||||
初心者には、最初に開発環境を設定せずにファームウェアをフラッシュすることをお勧めします。ファームウェアは著者が提供するテストサーバーを使用しており、現在無料で使用できます(商業目的では使用しないでください)。
|
||||
初心者の方は、まず開発環境のセットアップなしでフラッシュできるファームウェアを使用することをお勧めします。
|
||||
|
||||
👉 [開発環境なしでのフラッシュガイド](https://ccnphfhqs21z.feishu.cn/wiki/Zpz4wXBtdimBrLk25WdcXzxcnNS)
|
||||
ファームウェアはデフォルトで公式 [xiaozhi.me](https://xiaozhi.me) サーバーに接続します。現在、個人ユーザーはアカウントを登録することで、Qwen リアルタイムモデルを無料で使用できます。
|
||||
|
||||
👉 [フラッシュファームウェアガイド(IDF環境なし)](https://ccnphfhqs21z.feishu.cn/wiki/Zpz4wXBtdimBrLk25WdcXzxcnNS)
|
||||
|
||||
### 開発環境
|
||||
|
||||
- CursorまたはVSCode
|
||||
- ESP-IDFプラグインをインストールし、SDKバージョン5.3以上を選択
|
||||
- LinuxはWindowsよりも優れており、コンパイルが速く、ドライバの問題も少ない
|
||||
- Cursor または VSCode
|
||||
- ESP-IDF プラグインをインストール、SDK バージョン 5.3 以上を選択
|
||||
- Linux は Windows より好ましい(コンパイルが速く、ドライバーの問題も少ない)
|
||||
- Google C++ コードスタイルを使用、コード提出時にはコンプライアンスを確認
|
||||
|
||||
## AIキャラクターの設定
|
||||
## AI エージェント設定
|
||||
|
||||
すでにXiaoZhi AIチャットボットをお持ちの場合は、👉 [バックエンド操作ビデオチュートリアル](https://www.bilibili.com/video/BV1jUCUY2EKM/)を参照してください。
|
||||
シャオジー AI チャットボットデバイスをお持ちの場合は、[xiaozhi.me](https://xiaozhi.me) コンソールで設定できます。
|
||||
|
||||
詳細な使用方法とテストサーバーの注意事項については、👉 [XiaoZhiテストサーバーヘルプガイド](https://xiaozhi.me/help)を参照してください。
|
||||
👉 [バックエンド操作チュートリアル(旧インターフェース)](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
|
||||
## Star History
|
||||
## 技術原理とプライベートデプロイメント
|
||||
|
||||
👉 [詳細な WebSocket 通信プロトコルドキュメント](docs/websocket.md)
|
||||
|
||||
個人のコンピュータでのサーバーデプロイメントについては、同じく MIT ライセンスで公開されている別のプロジェクト [xiaozhi-esp32-server](https://github.com/xinnan-tech/xiaozhi-esp32-server) を参照してください。
|
||||
|
||||
## スター履歴
|
||||
|
||||
<a href="https://star-history.com/#78/xiaozhi-esp32&Date">
|
||||
<picture>
|
||||
|
||||
BIN
docs/v1/sensecap_watcher.jpg
Normal file
BIN
docs/v1/sensecap_watcher.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
BIN
docs/v1/wmnologo_xingzhi_0.96.jpg
Normal file
BIN
docs/v1/wmnologo_xingzhi_0.96.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/v1/wmnologo_xingzhi_1.54.jpg
Normal file
BIN
docs/v1/wmnologo_xingzhi_1.54.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
338
docs/websocket.md
Normal file
338
docs/websocket.md
Normal file
@@ -0,0 +1,338 @@
|
||||
以下是一份基于代码实现整理的 WebSocket 通信协议文档,概述客户端(设备)与服务器之间如何通过 WebSocket 进行交互。该文档仅基于所提供的代码推断,实际部署时可能需要结合服务器端实现进行进一步确认或补充。
|
||||
|
||||
---
|
||||
|
||||
## 1. 总体流程概览
|
||||
|
||||
1. **设备端初始化**
|
||||
- 设备上电、初始化 `Application`:
|
||||
- 初始化音频编解码器、显示屏、LED 等
|
||||
- 连接网络
|
||||
- 创建并初始化实现 `Protocol` 接口的 WebSocket 协议实例(`WebsocketProtocol`)
|
||||
- 进入主循环等待事件(音频输入、音频输出、调度任务等)。
|
||||
|
||||
2. **建立 WebSocket 连接**
|
||||
- 当设备需要开始语音会话时(例如用户唤醒、手动按键触发等),调用 `OpenAudioChannel()`:
|
||||
- 根据编译配置获取 WebSocket URL(`CONFIG_WEBSOCKET_URL`)
|
||||
- 设置若干请求头(`Authorization`, `Protocol-Version`, `Device-Id`, `Client-Id`)
|
||||
- 调用 `Connect()` 与服务器建立 WebSocket 连接
|
||||
|
||||
3. **发送客户端 “hello” 消息**
|
||||
- 连接成功后,设备会发送一条 JSON 消息,示例结构如下:
|
||||
```json
|
||||
{
|
||||
"type": "hello",
|
||||
"version": 1,
|
||||
"transport": "websocket",
|
||||
"audio_params": {
|
||||
"format": "opus",
|
||||
"sample_rate": 16000,
|
||||
"channels": 1,
|
||||
"frame_duration": 60
|
||||
}
|
||||
}
|
||||
```
|
||||
- 其中 `"frame_duration"` 的值对应 `OPUS_FRAME_DURATION_MS`(例如 60ms)。
|
||||
|
||||
4. **服务器回复 “hello”**
|
||||
- 设备等待服务器返回一条包含 `"type": "hello"` 的 JSON 消息,并检查 `"transport": "websocket"` 是否匹配。
|
||||
- 如果匹配,则认为服务器已就绪,标记音频通道打开成功。
|
||||
- 如果在超时时间(默认 10 秒)内未收到正确回复,认为连接失败并触发网络错误回调。
|
||||
|
||||
5. **后续消息交互**
|
||||
- 设备端和服务器端之间可发送两种主要类型的数据:
|
||||
1. **二进制音频数据**(Opus 编码)
|
||||
2. **文本 JSON 消息**(用于传输聊天状态、TTS/STT 事件、IoT 命令等)
|
||||
|
||||
- 在代码里,接收回调主要分为:
|
||||
- `OnData(...)`:
|
||||
- 当 `binary` 为 `true` 时,认为是音频帧;设备会将其当作 Opus 数据进行解码。
|
||||
- 当 `binary` 为 `false` 时,认为是 JSON 文本,需要在设备端用 cJSON 进行解析并做相应业务逻辑处理(见下文消息结构)。
|
||||
|
||||
- 当服务器或网络出现断连,回调 `OnDisconnected()` 被触发:
|
||||
- 设备会调用 `on_audio_channel_closed_()`,并最终回到空闲状态。
|
||||
|
||||
6. **关闭 WebSocket 连接**
|
||||
- 设备在需要结束语音会话时,会调用 `CloseAudioChannel()` 主动断开连接,并回到空闲状态。
|
||||
- 或者如果服务器端主动断开,也会引发同样的回调流程。
|
||||
|
||||
---
|
||||
|
||||
## 2. 通用请求头
|
||||
|
||||
在建立 WebSocket 连接时,代码示例中设置了以下请求头:
|
||||
|
||||
- `Authorization`: 用于存放访问令牌,形如 `"Bearer <token>"`
|
||||
- `Protocol-Version`: 固定示例中为 `"1"`
|
||||
- `Device-Id`: 设备物理网卡 MAC 地址
|
||||
- `Client-Id`: 设备 UUID(可在应用中唯一标识设备)
|
||||
|
||||
这些头会随着 WebSocket 握手一起发送到服务器,服务器可根据需求进行校验、认证等。
|
||||
|
||||
---
|
||||
|
||||
## 3. JSON 消息结构
|
||||
|
||||
WebSocket 文本帧以 JSON 方式传输,以下为常见的 `"type"` 字段及其对应业务逻辑。若消息里包含未列出的字段,可能为可选或特定实现细节。
|
||||
|
||||
### 3.1 客户端→服务器
|
||||
|
||||
1. **Hello**
|
||||
- 连接成功后,由客户端发送,告知服务器基本参数。
|
||||
- 例:
|
||||
```json
|
||||
{
|
||||
"type": "hello",
|
||||
"version": 1,
|
||||
"transport": "websocket",
|
||||
"audio_params": {
|
||||
"format": "opus",
|
||||
"sample_rate": 16000,
|
||||
"channels": 1,
|
||||
"frame_duration": 60
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **Listen**
|
||||
- 表示客户端开始或停止录音监听。
|
||||
- 常见字段:
|
||||
- `"session_id"`:会话标识
|
||||
- `"type": "listen"`
|
||||
- `"state"`:`"start"`, `"stop"`, `"detect"`(唤醒检测已触发)
|
||||
- `"mode"`:`"auto"`, `"manual"` 或 `"realtime"`,表示识别模式。
|
||||
- 例:开始监听
|
||||
```json
|
||||
{
|
||||
"session_id": "xxx",
|
||||
"type": "listen",
|
||||
"state": "start",
|
||||
"mode": "manual"
|
||||
}
|
||||
```
|
||||
|
||||
3. **Abort**
|
||||
- 终止当前说话(TTS 播放)或语音通道。
|
||||
- 例:
|
||||
```json
|
||||
{
|
||||
"session_id": "xxx",
|
||||
"type": "abort",
|
||||
"reason": "wake_word_detected"
|
||||
}
|
||||
```
|
||||
- `reason` 值可为 `"wake_word_detected"` 或其他。
|
||||
|
||||
4. **Wake Word Detected**
|
||||
- 用于客户端向服务器告知检测到唤醒词。
|
||||
- 例:
|
||||
```json
|
||||
{
|
||||
"session_id": "xxx",
|
||||
"type": "listen",
|
||||
"state": "detect",
|
||||
"text": "你好小明"
|
||||
}
|
||||
```
|
||||
|
||||
5. **IoT**
|
||||
- 发送当前设备的物联网相关信息:
|
||||
- **Descriptors**(描述设备功能、属性等)
|
||||
- **States**(设备状态的实时更新)
|
||||
- 例:
|
||||
```json
|
||||
{
|
||||
"session_id": "xxx",
|
||||
"type": "iot",
|
||||
"descriptors": { ... }
|
||||
}
|
||||
```
|
||||
或
|
||||
```json
|
||||
{
|
||||
"session_id": "xxx",
|
||||
"type": "iot",
|
||||
"states": { ... }
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 服务器→客户端
|
||||
|
||||
1. **Hello**
|
||||
- 服务器端返回的握手确认消息。
|
||||
- 必须包含 `"type": "hello"` 和 `"transport": "websocket"`。
|
||||
- 可能会带有 `audio_params`,表示服务器期望的音频参数,或与客户端对齐的配置。
|
||||
- 成功接收后客户端会设置事件标志,表示 WebSocket 通道就绪。
|
||||
|
||||
2. **STT**
|
||||
- `{"type": "stt", "text": "..."}`
|
||||
- 表示服务器端识别到了用户语音。(例如语音转文本结果)
|
||||
- 设备可能将此文本显示到屏幕上,后续再进入回答等流程。
|
||||
|
||||
3. **LLM**
|
||||
- `{"type": "llm", "emotion": "happy", "text": "😀"}`
|
||||
- 服务器指示设备调整表情动画 / UI 表达。
|
||||
|
||||
4. **TTS**
|
||||
- `{"type": "tts", "state": "start"}`:服务器准备下发 TTS 音频,客户端进入 “speaking” 播放状态。
|
||||
- `{"type": "tts", "state": "stop"}`:表示本次 TTS 结束。
|
||||
- `{"type": "tts", "state": "sentence_start", "text": "..."}`
|
||||
- 让设备在界面上显示当前要播放或朗读的文本片段(例如用于显示给用户)。
|
||||
|
||||
5. **IoT**
|
||||
- `{"type": "iot", "commands": [ ... ]}`
|
||||
- 服务器向设备发送物联网的动作指令,设备解析并执行(如打开灯、设置温度等)。
|
||||
|
||||
6. **音频数据:二进制帧**
|
||||
- 当服务器发送音频二进制帧(Opus 编码)时,客户端解码并播放。
|
||||
- 若客户端正在处于 “listening” (录音)状态,收到的音频帧会被忽略或清空以防冲突。
|
||||
|
||||
---
|
||||
|
||||
## 4. 音频编解码
|
||||
|
||||
1. **客户端发送录音数据**
|
||||
- 音频输入经过可能的回声消除、降噪或音量增益后,通过 Opus 编码打包为二进制帧发送给服务器。
|
||||
- 如果客户端每次编码生成的二进制帧大小为 N 字节,则会通过 WebSocket 的 **binary** 消息发送这块数据。
|
||||
|
||||
2. **客户端播放收到的音频**
|
||||
- 收到服务器的二进制帧时,同样认定是 Opus 数据。
|
||||
- 设备端会进行解码,然后交由音频输出接口播放。
|
||||
- 如果服务器的音频采样率与设备不一致,会在解码后再进行重采样。
|
||||
|
||||
---
|
||||
|
||||
## 5. 常见状态流转
|
||||
|
||||
以下简述设备端关键状态流转,与 WebSocket 消息对应:
|
||||
|
||||
1. **Idle** → **Connecting**
|
||||
- 用户触发或唤醒后,设备调用 `OpenAudioChannel()` → 建立 WebSocket 连接 → 发送 `"type":"hello"`。
|
||||
|
||||
2. **Connecting** → **Listening**
|
||||
- 成功建立连接后,若继续执行 `SendStartListening(...)`,则进入录音状态。此时设备会持续编码麦克风数据并发送到服务器。
|
||||
|
||||
3. **Listening** → **Speaking**
|
||||
- 收到服务器 TTS Start 消息 (`{"type":"tts","state":"start"}`) → 停止录音并播放接收到的音频。
|
||||
|
||||
4. **Speaking** → **Idle**
|
||||
- 服务器 TTS Stop (`{"type":"tts","state":"stop"}`) → 音频播放结束。若未继续进入自动监听,则返回 Idle;如果配置了自动循环,则再度进入 Listening。
|
||||
|
||||
5. **Listening** / **Speaking** → **Idle**(遇到异常或主动中断)
|
||||
- 调用 `SendAbortSpeaking(...)` 或 `CloseAudioChannel()` → 中断会话 → 关闭 WebSocket → 状态回到 Idle。
|
||||
|
||||
---
|
||||
|
||||
## 6. 错误处理
|
||||
|
||||
1. **连接失败**
|
||||
- 如果 `Connect(url)` 返回失败或在等待服务器 “hello” 消息时超时,触发 `on_network_error_()` 回调。设备会提示“无法连接到服务”或类似错误信息。
|
||||
|
||||
2. **服务器断开**
|
||||
- 如果 WebSocket 异常断开,回调 `OnDisconnected()`:
|
||||
- 设备回调 `on_audio_channel_closed_()`
|
||||
- 切换到 Idle 或其他重试逻辑。
|
||||
|
||||
---
|
||||
|
||||
## 7. 其它注意事项
|
||||
|
||||
1. **鉴权**
|
||||
- 设备通过设置 `Authorization: Bearer <token>` 提供鉴权,服务器端需验证是否有效。
|
||||
- 如果令牌过期或无效,服务器可拒绝握手或在后续断开。
|
||||
|
||||
2. **会话控制**
|
||||
- 代码中部分消息包含 `session_id`,用于区分独立的对话或操作。服务端可根据需要对不同会话做分离处理,WebSocket 协议为空。
|
||||
|
||||
3. **音频负载**
|
||||
- 代码里默认使用 Opus 格式,并设置 `sample_rate = 16000`,单声道。帧时长由 `OPUS_FRAME_DURATION_MS` 控制,一般为 60ms。可根据带宽或性能做适当调整。
|
||||
|
||||
4. **IoT 指令**
|
||||
- `"type":"iot"` 的消息用户端代码对接 `thing_manager` 执行具体命令,因设备定制而不同。服务器端需确保下发格式与客户端保持一致。
|
||||
|
||||
5. **错误或异常 JSON**
|
||||
- 当 JSON 中缺少必要字段,例如 `{"type": ...}`,客户端会记录错误日志(`ESP_LOGE(TAG, "Missing message type, data: %s", data);`),不会执行任何业务。
|
||||
|
||||
---
|
||||
|
||||
## 8. 消息示例
|
||||
|
||||
下面给出一个典型的双向消息示例(流程简化示意):
|
||||
|
||||
1. **客户端 → 服务器**(握手)
|
||||
```json
|
||||
{
|
||||
"type": "hello",
|
||||
"version": 1,
|
||||
"transport": "websocket",
|
||||
"audio_params": {
|
||||
"format": "opus",
|
||||
"sample_rate": 16000,
|
||||
"channels": 1,
|
||||
"frame_duration": 60
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **服务器 → 客户端**(握手应答)
|
||||
```json
|
||||
{
|
||||
"type": "hello",
|
||||
"transport": "websocket",
|
||||
"audio_params": {
|
||||
"sample_rate": 16000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. **客户端 → 服务器**(开始监听)
|
||||
```json
|
||||
{
|
||||
"session_id": "",
|
||||
"type": "listen",
|
||||
"state": "start",
|
||||
"mode": "auto"
|
||||
}
|
||||
```
|
||||
同时客户端开始发送二进制帧(Opus 数据)。
|
||||
|
||||
4. **服务器 → 客户端**(ASR 结果)
|
||||
```json
|
||||
{
|
||||
"type": "stt",
|
||||
"text": "用户说的话"
|
||||
}
|
||||
```
|
||||
|
||||
5. **服务器 → 客户端**(TTS开始)
|
||||
```json
|
||||
{
|
||||
"type": "tts",
|
||||
"state": "start"
|
||||
}
|
||||
```
|
||||
接着服务器发送二进制音频帧给客户端播放。
|
||||
|
||||
6. **服务器 → 客户端**(TTS结束)
|
||||
```json
|
||||
{
|
||||
"type": "tts",
|
||||
"state": "stop"
|
||||
}
|
||||
```
|
||||
客户端停止播放音频,若无更多指令,则回到空闲状态。
|
||||
|
||||
---
|
||||
|
||||
## 9. 总结
|
||||
|
||||
本协议通过在 WebSocket 上层传输 JSON 文本与二进制音频帧,完成功能包括音频流上传、TTS 音频播放、语音识别与状态管理、IoT 指令下发等。其核心特征:
|
||||
|
||||
- **握手阶段**:发送 `"type":"hello"`,等待服务器返回。
|
||||
- **音频通道**:采用 Opus 编码的二进制帧双向传输语音流。
|
||||
- **JSON 消息**:使用 `"type"` 为核心字段标识不同业务逻辑,包括 TTS、STT、IoT、WakeWord 等。
|
||||
- **扩展性**:可根据实际需求在 JSON 消息中添加字段,或在 headers 里进行额外鉴权。
|
||||
|
||||
服务器与客户端需提前约定各类消息的字段含义、时序逻辑以及错误处理规则,方能保证通信顺畅。上述信息可作为基础文档,便于后续对接、开发或扩展。
|
||||
@@ -3,15 +3,12 @@ set(SOURCES "audio_codecs/audio_codec.cc"
|
||||
"audio_codecs/box_audio_codec.cc"
|
||||
"audio_codecs/es8311_audio_codec.cc"
|
||||
"audio_codecs/es8388_audio_codec.cc"
|
||||
"audio_codecs/cores3_audio_codec.cc"
|
||||
"audio_codecs/tcircles3_audio_codec.cc"
|
||||
"led/single_led.cc"
|
||||
"led/circular_strip.cc"
|
||||
"led/gpio_led.cc"
|
||||
"display/display.cc"
|
||||
"display/no_display.cc"
|
||||
"display/lcd_display.cc"
|
||||
"display/ssd1306_display.cc"
|
||||
"boards/lilygo-t-circle-s3/esp_lcd_gc9d01n.c"
|
||||
"display/oled_display.cc"
|
||||
"protocols/protocol.cc"
|
||||
"iot/thing.cc"
|
||||
"iot/thing_manager.cc"
|
||||
@@ -40,25 +37,39 @@ if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
|
||||
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_ML307)
|
||||
set(BOARD_TYPE "bread-compact-ml307")
|
||||
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_ESP32)
|
||||
set(BOARD_TYPE "bread-compact-esp32")
|
||||
set(BOARD_TYPE "bread-compact-esp32")
|
||||
elseif(CONFIG_BOARD_TYPE_DF_K10)
|
||||
set(BOARD_TYPE "df-k10")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX_3)
|
||||
set(BOARD_TYPE "esp-box-3")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX)
|
||||
set(BOARD_TYPE "esp-box")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX_LITE)
|
||||
set(BOARD_TYPE "esp-box-lite")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_1)
|
||||
set(BOARD_TYPE "kevin-box-1")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_2)
|
||||
set(BOARD_TYPE "kevin-box-2")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_C3)
|
||||
set(BOARD_TYPE "kevin-c3")
|
||||
set(BOARD_TYPE "kevin-c3")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_SP_V3_DEV)
|
||||
set(BOARD_TYPE "kevin-sp-v3-dev")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_SP_V4_DEV)
|
||||
set(BOARD_TYPE "kevin-sp-v4-dev")
|
||||
elseif(CONFIG_BOARD_TYPE_KEVIN_YUYING_313LCD)
|
||||
set(BOARD_TYPE "kevin-yuying-313lcd")
|
||||
elseif(CONFIG_BOARD_TYPE_LICHUANG_DEV)
|
||||
set(BOARD_TYPE "lichuang-dev")
|
||||
elseif(CONFIG_BOARD_TYPE_LICHUANG_C3_DEV)
|
||||
set(BOARD_TYPE "lichuang-c3-dev")
|
||||
elseif(CONFIG_BOARD_TYPE_MAGICLICK_2P4)
|
||||
set(BOARD_TYPE "magiclick-2p4")
|
||||
elseif(CONFIG_BOARD_TYPE_MAGICLICK_2P5)
|
||||
set(BOARD_TYPE "magiclick-2p5")
|
||||
elseif(CONFIG_BOARD_TYPE_MAGICLICK_C3)
|
||||
set(BOARD_TYPE "magiclick-c3")
|
||||
elseif(CONFIG_BOARD_TYPE_MAGICLICK_C3_V2)
|
||||
set(BOARD_TYPE "magiclick-c3-v2")
|
||||
elseif(CONFIG_BOARD_TYPE_M5STACK_CORE_S3)
|
||||
set(BOARD_TYPE "m5stack-core-s3")
|
||||
elseif(CONFIG_BOARD_TYPE_ATOMS3_ECHO_BASE)
|
||||
@@ -66,13 +77,13 @@ elseif(CONFIG_BOARD_TYPE_ATOMS3_ECHO_BASE)
|
||||
elseif(CONFIG_BOARD_TYPE_ATOMS3R_ECHO_BASE)
|
||||
set(BOARD_TYPE "atoms3r-echo-base")
|
||||
elseif(CONFIG_BOARD_TYPE_ATOMMATRIX_ECHO_BASE)
|
||||
set(BOARD_TYPE "atommatrix-echo-base")
|
||||
set(BOARD_TYPE "atommatrix-echo-base")
|
||||
elseif(CONFIG_BOARD_TYPE_XMINI_C3)
|
||||
set(BOARD_TYPE "xmini-c3")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_KORVO2_V3)
|
||||
set(BOARD_TYPE "esp32s3-korvo2-v3")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_SPARKBOT)
|
||||
set(BOARD_TYPE "esp-sparkbot")
|
||||
set(BOARD_TYPE "esp-sparkbot")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_AMOLED_1_8)
|
||||
set(BOARD_TYPE "esp32-s3-touch-amoled-1.8")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_85C)
|
||||
@@ -82,27 +93,38 @@ elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_85)
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_46)
|
||||
set(BOARD_TYPE "esp32-s3-touch-lcd-1.46")
|
||||
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI_LCD)
|
||||
set(BOARD_TYPE "bread-compact-wifi-lcd")
|
||||
set(BOARD_TYPE "bread-compact-wifi-lcd")
|
||||
elseif(CONFIG_BOARD_TYPE_TUDOUZI)
|
||||
set(BOARD_TYPE "tudouzi")
|
||||
set(BOARD_TYPE "tudouzi")
|
||||
elseif(CONFIG_BOARD_TYPE_LILYGO_T_CIRCLE_S3)
|
||||
set(BOARD_TYPE "lilygo-t-circle-s3")
|
||||
set(BOARD_TYPE "lilygo-t-circle-s3")
|
||||
elseif(CONFIG_BOARD_TYPE_LILYGO_T_CAMERAPLUS_S3)
|
||||
set(BOARD_TYPE "lilygo-t-cameraplus-s3")
|
||||
elseif(CONFIG_BOARD_TYPE_MOVECALL_MOJI_ESP32S3)
|
||||
set(BOARD_TYPE "movecall-moji-esp32s3")
|
||||
set(BOARD_TYPE "movecall-moji-esp32s3")
|
||||
elseif(CONFIG_BOARD_TYPE_ATK_DNESP32S3)
|
||||
set(BOARD_TYPE "atk-dnesp32s3")
|
||||
elseif(CONFIG_BOARD_TYPE_ATK_DNESP32S3_BOX)
|
||||
set(BOARD_TYPE "atk-dnesp32s3-box")
|
||||
set(BOARD_TYPE "atk-dnesp32s3-box")
|
||||
elseif(CONFIG_BOARD_TYPE_DU_CHATX)
|
||||
set(BOARD_TYPE "du-chatx")
|
||||
set(BOARD_TYPE "du-chatx")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Taiji_Pi)
|
||||
set(BOARD_TYPE "taiji-pi-s3")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_OLED)
|
||||
set(BOARD_TYPE "xingzhi-cube-oled")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_TFT)
|
||||
set(BOARD_TYPE "xingzhi-cube-tft")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_0_96OLED_WIFI)
|
||||
set(BOARD_TYPE "xingzhi-cube-0.96oled-wifi")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_0_96OLED_ML307)
|
||||
set(BOARD_TYPE "xingzhi-cube-0.96oled-ml307")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_1_54TFT_WIFI)
|
||||
set(BOARD_TYPE "xingzhi-cube-1.54tft-wifi")
|
||||
elseif(CONFIG_BOARD_TYPE_XINGZHI_Cube_1_54TFT_ML307)
|
||||
set(BOARD_TYPE "xingzhi-cube-1.54tft-ml307")
|
||||
elseif(CONFIG_BOARD_TYPE_SENSECAP_WATCHER)
|
||||
set(BOARD_TYPE "sensecap-watcher")
|
||||
endif()
|
||||
file(GLOB BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc)
|
||||
file(GLOB BOARD_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.c
|
||||
)
|
||||
list(APPEND SOURCES ${BOARD_SOURCES})
|
||||
|
||||
if(CONFIG_CONNECTION_TYPE_MQTT_UDP)
|
||||
@@ -111,27 +133,66 @@ elseif(CONFIG_CONNECTION_TYPE_WEBSOCKET)
|
||||
list(APPEND SOURCES "protocols/websocket_protocol.cc")
|
||||
endif()
|
||||
|
||||
if(CONFIG_USE_AUDIO_PROCESSING)
|
||||
list(APPEND SOURCES "audio_processing/audio_processor.cc" "audio_processing/wake_word_detect.cc")
|
||||
if(CONFIG_USE_AUDIO_PROCESSOR)
|
||||
list(APPEND SOURCES "audio_processing/audio_processor.cc")
|
||||
endif()
|
||||
if(CONFIG_USE_WAKE_WORD_DETECT)
|
||||
list(APPEND SOURCES "audio_processing/wake_word_detect.cc")
|
||||
endif()
|
||||
|
||||
# 根据Kconfig选择语言目录
|
||||
if(CONFIG_LANGUAGE_ZH_CN)
|
||||
set(LANG_DIR "zh-CN")
|
||||
elseif(CONFIG_LANGUAGE_ZH_TW)
|
||||
set(LANG_DIR "zh-TW")
|
||||
elseif(CONFIG_LANGUAGE_EN_US)
|
||||
set(LANG_DIR "en-US")
|
||||
elseif(CONFIG_LANGUAGE_JA_JP)
|
||||
set(LANG_DIR "ja-JP")
|
||||
endif()
|
||||
|
||||
# 定义生成路径
|
||||
set(LANG_JSON "${CMAKE_CURRENT_SOURCE_DIR}/assets/${LANG_DIR}/language.json")
|
||||
set(LANG_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/assets/lang_config.h")
|
||||
file(GLOB LANG_SOUNDS ${CMAKE_CURRENT_SOURCE_DIR}/assets/${LANG_DIR}/*.p3)
|
||||
file(GLOB COMMON_SOUNDS ${CMAKE_CURRENT_SOURCE_DIR}/assets/common/*.p3)
|
||||
|
||||
# 如果目标芯片是 ESP32,则排除特定文件
|
||||
if(CONFIG_IDF_TARGET_ESP32)
|
||||
# 排除 "audio_codecs/box_audio_codec.cc" 和 "audio_codecs/cores3_audio_codec.cc"
|
||||
list(REMOVE_ITEM SOURCES "audio_codecs/box_audio_codec.cc"
|
||||
"audio_codecs/cores3_audio_codec.cc"
|
||||
"audio_codecs/es8388_audio_codec.cc")
|
||||
"audio_codecs/es8388_audio_codec.cc"
|
||||
"led/gpio_led.cc"
|
||||
)
|
||||
endif()
|
||||
|
||||
file(GLOB ASSETS ${CMAKE_CURRENT_SOURCE_DIR}/assets/zh/*.p3)
|
||||
|
||||
idf_component_register(SRCS ${SOURCES}
|
||||
EMBED_FILES ${ASSETS}
|
||||
EMBED_FILES ${LANG_SOUNDS} ${COMMON_SOUNDS}
|
||||
INCLUDE_DIRS ${INCLUDE_DIRS}
|
||||
WHOLE_ARCHIVE
|
||||
)
|
||||
|
||||
# 使用 target_compile_definitions 来定义 BOARD_TYPE
|
||||
# 使用 target_compile_definitions 来定义 BOARD_TYPE, BOARD_NAME
|
||||
# 如果 BOARD_NAME 为空,则使用 BOARD_TYPE
|
||||
if(NOT BOARD_NAME)
|
||||
set(BOARD_NAME ${BOARD_TYPE})
|
||||
endif()
|
||||
target_compile_definitions(${COMPONENT_LIB}
|
||||
PRIVATE BOARD_TYPE=\"${BOARD_TYPE}\"
|
||||
PRIVATE BOARD_TYPE=\"${BOARD_TYPE}\" BOARD_NAME=\"${BOARD_NAME}\"
|
||||
)
|
||||
|
||||
# 添加生成规则
|
||||
add_custom_command(
|
||||
OUTPUT ${LANG_HEADER}
|
||||
COMMAND python ${PROJECT_DIR}/scripts/gen_lang.py
|
||||
--input "${LANG_JSON}"
|
||||
--output "${LANG_HEADER}"
|
||||
DEPENDS
|
||||
${LANG_JSON}
|
||||
${PROJECT_DIR}/scripts/gen_lang.py
|
||||
COMMENT "Generating ${LANG_DIR} language config"
|
||||
)
|
||||
|
||||
# 强制建立生成依赖
|
||||
add_custom_target(lang_header ALL
|
||||
DEPENDS ${LANG_HEADER}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,24 @@ config OTA_VERSION_URL
|
||||
help
|
||||
The application will access this URL to check for updates.
|
||||
|
||||
|
||||
choice
|
||||
prompt "语言选择"
|
||||
default LANGUAGE_ZH_CN
|
||||
help
|
||||
Select device display language
|
||||
|
||||
config LANGUAGE_ZH_CN
|
||||
bool "Chinese"
|
||||
config LANGUAGE_ZH_TW
|
||||
bool "Chinese Traditional"
|
||||
config LANGUAGE_EN_US
|
||||
bool "English"
|
||||
config LANGUAGE_JA_JP
|
||||
bool "Japanese"
|
||||
endchoice
|
||||
|
||||
|
||||
choice CONNECTION_TYPE
|
||||
prompt "Connection Type"
|
||||
default CONNECTION_TYPE_MQTT_UDP
|
||||
@@ -46,6 +64,10 @@ choice BOARD_TYPE
|
||||
bool "面包板 ESP32 DevKit"
|
||||
config BOARD_TYPE_ESP_BOX_3
|
||||
bool "ESP BOX 3"
|
||||
config BOARD_TYPE_ESP_BOX
|
||||
bool "ESP BOX"
|
||||
config BOARD_TYPE_ESP_BOX_LITE
|
||||
bool "ESP BOX Lite"
|
||||
config BOARD_TYPE_KEVIN_BOX_1
|
||||
bool "Kevin Box 1"
|
||||
config BOARD_TYPE_KEVIN_BOX_2
|
||||
@@ -54,14 +76,24 @@ choice BOARD_TYPE
|
||||
bool "Kevin C3"
|
||||
config BOARD_TYPE_KEVIN_SP_V3_DEV
|
||||
bool "Kevin SP V3开发板"
|
||||
config BOARD_TYPE_KEVIN_SP_V4_DEV
|
||||
bool "Kevin SP V4开发板"
|
||||
config BOARD_TYPE_KEVIN_YUYING_313LCD
|
||||
bool "鱼鹰科技3.13LCD开发板"
|
||||
config BOARD_TYPE_LICHUANG_DEV
|
||||
bool "立创·实战派ESP32-S3开发板"
|
||||
config BOARD_TYPE_LICHUANG_C3_DEV
|
||||
bool "立创·实战派ESP32-C3开发板"
|
||||
config BOARD_TYPE_DF_K10
|
||||
bool "DFRobot 行空板 k10"
|
||||
config BOARD_TYPE_MAGICLICK_2P4
|
||||
bool "神奇按钮 Magiclick_2.4"
|
||||
bool "神奇按钮 Magiclick_2.4"
|
||||
config BOARD_TYPE_MAGICLICK_2P5
|
||||
bool "神奇按钮 Magiclick_2.5"
|
||||
config BOARD_TYPE_MAGICLICK_C3
|
||||
bool "神奇按钮 Magiclick_C3"
|
||||
bool "神奇按钮 Magiclick_C3"
|
||||
config BOARD_TYPE_MAGICLICK_C3_V2
|
||||
bool "神奇按钮 Magiclick_C3_v2"
|
||||
config BOARD_TYPE_M5STACK_CORE_S3
|
||||
bool "M5Stack CoreS3"
|
||||
config BOARD_TYPE_ATOMS3_ECHO_BASE
|
||||
@@ -75,7 +107,7 @@ choice BOARD_TYPE
|
||||
config BOARD_TYPE_ESP32S3_KORVO2_V3
|
||||
bool "ESP32S3_KORVO2_V3开发板"
|
||||
config BOARD_TYPE_ESP_SPARKBOT
|
||||
bool "ESP-SparkBot开发板"
|
||||
bool "ESP-SparkBot开发板"
|
||||
config BOARD_TYPE_ESP32S3_Touch_AMOLED_1_8
|
||||
bool "Waveshare ESP32-S3-Touch-AMOLED-1.8"
|
||||
config BOARD_TYPE_ESP32S3_Touch_LCD_1_85C
|
||||
@@ -87,21 +119,29 @@ choice BOARD_TYPE
|
||||
config BOARD_TYPE_TUDOUZI
|
||||
bool "土豆子"
|
||||
config BOARD_TYPE_LILYGO_T_CIRCLE_S3
|
||||
bool "LILYGO T-Circle-S3"
|
||||
bool "LILYGO T-Circle-S3"
|
||||
config BOARD_TYPE_LILYGO_T_CAMERAPLUS_S3
|
||||
bool "LILYGO T-CameraPlus-S3"
|
||||
config BOARD_TYPE_MOVECALL_MOJI_ESP32S3
|
||||
bool "Movecall Moji 小智AI衍生版"
|
||||
bool "Movecall Moji 小智AI衍生版"
|
||||
config BOARD_TYPE_ATK_DNESP32S3
|
||||
bool "正点原子DNESP32S3开发板"
|
||||
config BOARD_TYPE_ATK_DNESP32S3_BOX
|
||||
bool "正点原子DNESP32S3-BOX"
|
||||
config BOARD_TYPE_DU_CHATX
|
||||
bool "嘟嘟开发板CHATX(wifi)"
|
||||
bool "嘟嘟开发板CHATX(wifi)"
|
||||
config BOARD_TYPE_ESP32S3_Taiji_Pi
|
||||
bool "太极小派esp32s3"
|
||||
config BOARD_TYPE_XINGZHI_Cube_OLED
|
||||
bool "无名科技星智0.96"
|
||||
config BOARD_TYPE_XINGZHI_Cube_TFT
|
||||
bool "无名科技星智1.54"
|
||||
config BOARD_TYPE_XINGZHI_Cube_0_96OLED_WIFI
|
||||
bool "无名科技星智0.96(WIFI)"
|
||||
config BOARD_TYPE_XINGZHI_Cube_0_96OLED_ML307
|
||||
bool "无名科技星智0.96(ML307)"
|
||||
config BOARD_TYPE_XINGZHI_Cube_1_54TFT_WIFI
|
||||
bool "无名科技星智1.54(WIFI)"
|
||||
config BOARD_TYPE_XINGZHI_Cube_1_54TFT_ML307
|
||||
bool "无名科技星智1.54(ML307)"
|
||||
config BOARD_TYPE_SENSECAP_WATCHER
|
||||
bool "SenseCAP Watcher"
|
||||
endchoice
|
||||
|
||||
choice DISPLAY_OLED_TYPE
|
||||
@@ -125,31 +165,44 @@ choice DISPLAY_LCD_TYPE
|
||||
config LCD_ST7789_240X320
|
||||
bool "ST7789, 分辨率240*320, IPS"
|
||||
config LCD_ST7789_240X320_NO_IPS
|
||||
bool "ST7789, 分辨率240*320, 非IPS"
|
||||
bool "ST7789, 分辨率240*320, 非IPS"
|
||||
config LCD_ST7789_170X320
|
||||
bool "ST7789, 分辨率170*320"
|
||||
bool "ST7789, 分辨率170*320"
|
||||
config LCD_ST7789_172X320
|
||||
bool "ST7789, 分辨率172*320"
|
||||
bool "ST7789, 分辨率172*320"
|
||||
config LCD_ST7789_240X280
|
||||
bool "ST7789, 分辨率240*280"
|
||||
bool "ST7789, 分辨率240*280"
|
||||
config LCD_ST7789_240X240
|
||||
bool "ST7789, 分辨率240*240"
|
||||
bool "ST7789, 分辨率240*240"
|
||||
config LCD_ST7789_240X240_7PIN
|
||||
bool "ST7789, 分辨率240*240, 7PIN"
|
||||
config LCD_ST7789_240X135
|
||||
bool "ST7789, 分辨率240*135"
|
||||
config LCD_ST7735_128X160
|
||||
bool "ST7735, 分辨率128*160"
|
||||
config LCD_ST7735_128X128
|
||||
bool "ST7735, 分辨率128*128"
|
||||
config LCD_ST7796_320X480
|
||||
bool "ST7796, 分辨率320*480"
|
||||
bool "ST7796, 分辨率320*480"
|
||||
config LCD_ILI9341_240X320
|
||||
bool "ILI9341, 分辨率240*320"
|
||||
config LCD_ILI9341_240X320_NO_IPS
|
||||
bool "ILI9341, 分辨率240*320, 非IPS"
|
||||
bool "ILI9341, 分辨率240*320, 非IPS"
|
||||
config LCD_GC9A01_240X240
|
||||
bool "GC9A01, 分辨率240*240, 圆屏"
|
||||
config LCD_CUSTOM
|
||||
bool "自定义屏幕参数"
|
||||
bool "自定义屏幕参数"
|
||||
endchoice
|
||||
|
||||
config USE_AUDIO_PROCESSING
|
||||
bool "启用语音唤醒与音频处理"
|
||||
config USE_AUDIO_PROCESSOR
|
||||
bool "启用音频降噪、增益处理"
|
||||
default y
|
||||
depends on IDF_TARGET_ESP32S3 && USE_AFE
|
||||
help
|
||||
需要 ESP32 S3 与 AFE 支持
|
||||
|
||||
config USE_WAKE_WORD_DETECT
|
||||
bool "启用唤醒词检测"
|
||||
default y
|
||||
depends on IDF_TARGET_ESP32S3 && USE_AFE
|
||||
help
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
#include "websocket_protocol.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "assets/zh/binary.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <esp_log.h>
|
||||
#include <cJSON.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <esp_app_desc.h>
|
||||
|
||||
#define TAG "Application"
|
||||
|
||||
@@ -36,9 +37,25 @@ static const char* const STATE_STRINGS[] = {
|
||||
Application::Application() {
|
||||
event_group_ = xEventGroupCreate();
|
||||
background_task_ = new BackgroundTask(4096 * 8);
|
||||
|
||||
esp_timer_create_args_t clock_timer_args = {
|
||||
.callback = [](void* arg) {
|
||||
Application* app = (Application*)arg;
|
||||
app->OnClockTimer();
|
||||
},
|
||||
.arg = this,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
.name = "clock_timer",
|
||||
.skip_unhandled_events = true
|
||||
};
|
||||
esp_timer_create(&clock_timer_args, &clock_timer_handle_);
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
if (clock_timer_handle_ != nullptr) {
|
||||
esp_timer_stop(clock_timer_handle_);
|
||||
esp_timer_delete(clock_timer_handle_);
|
||||
}
|
||||
if (background_task_ != nullptr) {
|
||||
delete background_task_;
|
||||
}
|
||||
@@ -58,17 +75,17 @@ void Application::CheckNewVersion() {
|
||||
if (!ota_.CheckVersion()) {
|
||||
retry_count++;
|
||||
if (retry_count >= MAX_RETRY) {
|
||||
ESP_LOGE(TAG, "版本检查失败次数过多,退出检查");
|
||||
ESP_LOGE(TAG, "Too many retries, exit version check");
|
||||
return;
|
||||
}
|
||||
ESP_LOGW(TAG, "版本检查失败,%d秒后重试 (%d/%d)", 60, retry_count, MAX_RETRY);
|
||||
ESP_LOGW(TAG, "Check new version failed, retry in %d seconds (%d/%d)", 60, retry_count, MAX_RETRY);
|
||||
vTaskDelay(pdMS_TO_TICKS(60000));
|
||||
continue;
|
||||
}
|
||||
retry_count = 0;
|
||||
|
||||
if (ota_.HasNewVersion()) {
|
||||
Alert("OTA 升级", "正在升级系统", "happy", std::string_view(p3_upgrade_start, p3_upgrade_end - p3_upgrade_start));
|
||||
Alert(Lang::Strings::OTA_UPGRADE, Lang::Strings::UPGRADING, "happy", Lang::Sounds::P3_UPGRADE);
|
||||
// Wait for the chat state to be idle
|
||||
do {
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
@@ -79,11 +96,12 @@ void Application::CheckNewVersion() {
|
||||
SetDeviceState(kDeviceStateUpgrading);
|
||||
|
||||
display->SetIcon(FONT_AWESOME_DOWNLOAD);
|
||||
display->SetChatMessage("system", "新版本 " + ota_.GetFirmwareVersion());
|
||||
std::string message = std::string(Lang::Strings::NEW_VERSION) + ota_.GetFirmwareVersion();
|
||||
display->SetChatMessage("system", message.c_str());
|
||||
|
||||
auto& board = Board::GetInstance();
|
||||
board.SetPowerSaveMode(false);
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_WAKE_WORD_DETECT
|
||||
wake_word_detect_.StopDetection();
|
||||
#endif
|
||||
// 预先关闭音频输出,避免升级过程有音频操作
|
||||
@@ -106,7 +124,7 @@ void Application::CheckNewVersion() {
|
||||
});
|
||||
|
||||
// If upgrade success, the device will reboot and never reach here
|
||||
display->SetStatus("更新失败");
|
||||
display->SetStatus(Lang::Strings::UPGRADE_FAILED);
|
||||
ESP_LOGI(TAG, "Firmware upgrade failed...");
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
Reboot();
|
||||
@@ -117,20 +135,27 @@ void Application::CheckNewVersion() {
|
||||
|
||||
// No new version, mark the current version as valid
|
||||
ota_.MarkCurrentVersionValid();
|
||||
display->ShowNotification("版本 " + ota_.GetCurrentVersion());
|
||||
std::string message = std::string(Lang::Strings::VERSION) + ota_.GetCurrentVersion();
|
||||
display->ShowNotification(message.c_str());
|
||||
|
||||
if (ota_.HasActivationCode()) {
|
||||
// Activation code is valid
|
||||
SetDeviceState(kDeviceStateActivating);
|
||||
ShowActivationCode();
|
||||
// Check again in 60 seconds
|
||||
vTaskDelay(pdMS_TO_TICKS(60000));
|
||||
|
||||
// Check again in 60 seconds or until the device is idle
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
display->SetChatMessage("system", "");
|
||||
|
||||
PlaySound(Lang::Sounds::P3_SUCCESS);
|
||||
// Exit the loop if upgrade or idle
|
||||
break;
|
||||
}
|
||||
@@ -142,24 +167,23 @@ void Application::ShowActivationCode() {
|
||||
|
||||
struct digit_sound {
|
||||
char digit;
|
||||
const char* data;
|
||||
size_t size;
|
||||
const std::string_view& sound;
|
||||
};
|
||||
static const std::array<digit_sound, 10> digit_sounds{{
|
||||
digit_sound{'0', p3_0_start, size_t(p3_0_end - p3_0_start)},
|
||||
digit_sound{'1', p3_1_start, size_t(p3_1_end - p3_1_start)},
|
||||
digit_sound{'2', p3_2_start, size_t(p3_2_end - p3_2_start)},
|
||||
digit_sound{'3', p3_3_start, size_t(p3_3_end - p3_3_start)},
|
||||
digit_sound{'4', p3_4_start, size_t(p3_4_end - p3_4_start)},
|
||||
digit_sound{'5', p3_5_start, size_t(p3_5_end - p3_5_start)},
|
||||
digit_sound{'6', p3_6_start, size_t(p3_6_end - p3_6_start)},
|
||||
digit_sound{'7', p3_7_start, size_t(p3_7_end - p3_7_start)},
|
||||
digit_sound{'8', p3_8_start, size_t(p3_8_end - p3_8_start)},
|
||||
digit_sound{'9', p3_9_start, size_t(p3_9_end - p3_9_start)}
|
||||
digit_sound{'0', Lang::Sounds::P3_0},
|
||||
digit_sound{'1', Lang::Sounds::P3_1},
|
||||
digit_sound{'2', Lang::Sounds::P3_2},
|
||||
digit_sound{'3', Lang::Sounds::P3_3},
|
||||
digit_sound{'4', Lang::Sounds::P3_4},
|
||||
digit_sound{'5', Lang::Sounds::P3_5},
|
||||
digit_sound{'6', Lang::Sounds::P3_6},
|
||||
digit_sound{'7', Lang::Sounds::P3_7},
|
||||
digit_sound{'8', Lang::Sounds::P3_8},
|
||||
digit_sound{'9', Lang::Sounds::P3_9}
|
||||
}};
|
||||
|
||||
// This sentence uses 9KB of SRAM, so we need to wait for it to finish
|
||||
Alert("激活设备", message, "happy", std::string_view(p3_activation_start, p3_activation_end - p3_activation_start));
|
||||
Alert(Lang::Strings::ACTIVATION, message.c_str(), "happy", Lang::Sounds::P3_ACTIVATION);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
background_task_->WaitForCompletion();
|
||||
|
||||
@@ -167,27 +191,37 @@ void Application::ShowActivationCode() {
|
||||
auto it = std::find_if(digit_sounds.begin(), digit_sounds.end(),
|
||||
[digit](const digit_sound& ds) { return ds.digit == digit; });
|
||||
if (it != digit_sounds.end()) {
|
||||
PlayLocalFile(it->data, it->size);
|
||||
PlaySound(it->sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::Alert(const std::string& status, const std::string& message, const std::string& emotion, const std::string_view& sound) {
|
||||
ESP_LOGW(TAG, "Alert %s: %s [%s]", status.c_str(), message.c_str(), emotion.c_str());
|
||||
void Application::Alert(const char* status, const char* message, const char* emotion, const std::string_view& sound) {
|
||||
ESP_LOGW(TAG, "Alert %s: %s [%s]", status, message, emotion);
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetStatus(status);
|
||||
display->SetEmotion(emotion);
|
||||
display->SetChatMessage("system", message);
|
||||
if (!sound.empty()) {
|
||||
PlayLocalFile(sound.data(), sound.size());
|
||||
PlaySound(sound);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::PlayLocalFile(const char* data, size_t size) {
|
||||
ESP_LOGI(TAG, "PlayLocalFile: %zu bytes", size);
|
||||
void Application::DismissAlert() {
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetStatus(Lang::Strings::STANDBY);
|
||||
display->SetEmotion("neutral");
|
||||
display->SetChatMessage("system", "");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::PlaySound(const std::string_view& sound) {
|
||||
auto codec = Board::GetInstance().GetAudioCodec();
|
||||
codec->EnableOutput(true);
|
||||
SetDecodeSampleRate(16000);
|
||||
const char* data = sound.data();
|
||||
size_t size = sound.size();
|
||||
for (const char* p = data; p < data + size; ) {
|
||||
auto p3 = (BinaryProtocol3*)p;
|
||||
p += sizeof(BinaryProtocol3);
|
||||
@@ -204,68 +238,68 @@ void Application::PlayLocalFile(const char* data, size_t size) {
|
||||
}
|
||||
|
||||
void Application::ToggleChatState() {
|
||||
Schedule([this]() {
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
Reboot();
|
||||
return;
|
||||
}
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocol_) {
|
||||
ESP_LOGE(TAG, "Protocol not initialized");
|
||||
return;
|
||||
}
|
||||
if (!protocol_) {
|
||||
ESP_LOGE(TAG, "Protocol not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
Schedule([this]() {
|
||||
SetDeviceState(kDeviceStateConnecting);
|
||||
if (!protocol_->OpenAudioChannel()) {
|
||||
Alert("ERROR", "无法建立音频通道", "sad");
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
return;
|
||||
}
|
||||
|
||||
keep_listening_ = true;
|
||||
protocol_->SendStartListening(kListeningModeAutoStop);
|
||||
SetDeviceState(kDeviceStateListening);
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
});
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
Schedule([this]() {
|
||||
AbortSpeaking(kAbortReasonNone);
|
||||
} else if (device_state_ == kDeviceStateListening) {
|
||||
});
|
||||
} else if (device_state_ == kDeviceStateListening) {
|
||||
Schedule([this]() {
|
||||
protocol_->CloseAudioChannel();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Application::StartListening() {
|
||||
Schedule([this]() {
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
Reboot();
|
||||
return;
|
||||
}
|
||||
if (device_state_ == kDeviceStateActivating) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!protocol_) {
|
||||
ESP_LOGE(TAG, "Protocol not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
keep_listening_ = false;
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
if (!protocol_) {
|
||||
ESP_LOGE(TAG, "Protocol not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
keep_listening_ = false;
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
Schedule([this]() {
|
||||
if (!protocol_->IsAudioChannelOpened()) {
|
||||
SetDeviceState(kDeviceStateConnecting);
|
||||
if (!protocol_->OpenAudioChannel()) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
Alert("ERROR", "无法建立音频通道", "sad");
|
||||
return;
|
||||
}
|
||||
}
|
||||
protocol_->SendStartListening(kListeningModeManualStop);
|
||||
SetDeviceState(kDeviceStateListening);
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
});
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
Schedule([this]() {
|
||||
AbortSpeaking(kAbortReasonNone);
|
||||
protocol_->SendStartListening(kListeningModeManualStop);
|
||||
// FIXME: Wait for the speaker to empty the buffer
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
SetDeviceState(kDeviceStateListening);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Application::StopListening() {
|
||||
@@ -320,20 +354,21 @@ void Application::Start() {
|
||||
Application* app = (Application*)arg;
|
||||
app->MainLoop();
|
||||
vTaskDelete(NULL);
|
||||
}, "main_loop", 4096 * 2, this, 2, nullptr);
|
||||
}, "main_loop", 4096 * 2, this, 3, nullptr);
|
||||
|
||||
/* Wait for the network to be ready */
|
||||
board.StartNetwork();
|
||||
|
||||
// Initialize the protocol
|
||||
display->SetStatus("加载协议...");
|
||||
display->SetStatus(Lang::Strings::LOADING_PROTOCOL);
|
||||
#ifdef CONFIG_CONNECTION_TYPE_WEBSOCKET
|
||||
protocol_ = std::make_unique<WebsocketProtocol>();
|
||||
#else
|
||||
protocol_ = std::make_unique<MqttProtocol>();
|
||||
#endif
|
||||
protocol_->OnNetworkError([this](const std::string& message) {
|
||||
Alert("ERROR", message, "sad");
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
Alert(Lang::Strings::ERROR, message.c_str(), "sad", Lang::Sounds::P3_EXCLAMATION);
|
||||
});
|
||||
protocol_->OnIncomingAudio([this](std::vector<uint8_t>&& data) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -344,14 +379,16 @@ void Application::Start() {
|
||||
protocol_->OnAudioChannelOpened([this, codec, &board]() {
|
||||
board.SetPowerSaveMode(false);
|
||||
if (protocol_->server_sample_rate() != codec->output_sample_rate()) {
|
||||
ESP_LOGW(TAG, "服务器的音频采样率 %d 与设备输出的采样率 %d 不一致,重采样后可能会失真",
|
||||
ESP_LOGW(TAG, "Server sample rate %d does not match device output sample rate %d, resampling may cause distortion",
|
||||
protocol_->server_sample_rate(), codec->output_sample_rate());
|
||||
}
|
||||
SetDecodeSampleRate(protocol_->server_sample_rate());
|
||||
// 物联网设备描述符
|
||||
last_iot_states_.clear();
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
protocol_->SendIotDescriptors(thing_manager.GetDescriptorsJson());
|
||||
std::string states;
|
||||
if (thing_manager.GetStatesJson(states, false)) {
|
||||
protocol_->SendIotStates(states);
|
||||
}
|
||||
});
|
||||
protocol_->OnAudioChannelClosed([this, &board]() {
|
||||
board.SetPowerSaveMode(true);
|
||||
@@ -390,7 +427,7 @@ void Application::Start() {
|
||||
if (text != NULL) {
|
||||
ESP_LOGI(TAG, "<< %s", text->valuestring);
|
||||
Schedule([this, display, message = std::string(text->valuestring)]() {
|
||||
display->SetChatMessage("assistant", message);
|
||||
display->SetChatMessage("assistant", message.c_str());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -399,14 +436,14 @@ void Application::Start() {
|
||||
if (text != NULL) {
|
||||
ESP_LOGI(TAG, ">> %s", text->valuestring);
|
||||
Schedule([this, display, message = std::string(text->valuestring)]() {
|
||||
display->SetChatMessage("user", message);
|
||||
display->SetChatMessage("user", message.c_str());
|
||||
});
|
||||
}
|
||||
} else if (strcmp(type->valuestring, "llm") == 0) {
|
||||
auto emotion = cJSON_GetObjectItem(root, "emotion");
|
||||
if (emotion != NULL) {
|
||||
Schedule([this, display, emotion_str = std::string(emotion->valuestring)]() {
|
||||
display->SetEmotion(emotion_str);
|
||||
display->SetEmotion(emotion_str.c_str());
|
||||
});
|
||||
}
|
||||
} else if (strcmp(type->valuestring, "iot") == 0) {
|
||||
@@ -426,14 +463,17 @@ void Application::Start() {
|
||||
ota_.SetCheckVersionUrl(CONFIG_OTA_VERSION_URL);
|
||||
ota_.SetHeader("Device-Id", SystemInfo::GetMacAddress().c_str());
|
||||
ota_.SetHeader("Client-Id", board.GetUuid());
|
||||
ota_.SetHeader("Accept-Language", Lang::CODE);
|
||||
auto app_desc = esp_app_get_description();
|
||||
ota_.SetHeader("User-Agent", std::string(BOARD_NAME "/") + app_desc->version);
|
||||
|
||||
xTaskCreate([](void* arg) {
|
||||
Application* app = (Application*)arg;
|
||||
app->CheckNewVersion();
|
||||
vTaskDelete(NULL);
|
||||
}, "check_new_version", 4096 * 2, this, 1, nullptr);
|
||||
}, "check_new_version", 4096 * 2, this, 2, nullptr);
|
||||
|
||||
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
audio_processor_.Initialize(codec->input_channels(), codec->input_reference());
|
||||
audio_processor_.OnOutput([this](std::vector<int16_t>&& data) {
|
||||
background_task_->Schedule([this, data = std::move(data)]() mutable {
|
||||
@@ -444,7 +484,9 @@ void Application::Start() {
|
||||
});
|
||||
});
|
||||
});
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_WAKE_WORD_DETECT
|
||||
wake_word_detect_.Initialize(codec->input_channels(), codec->input_reference());
|
||||
wake_word_detect_.OnVadStateChange([this](bool speaking) {
|
||||
Schedule([this, speaking]() {
|
||||
@@ -467,8 +509,6 @@ void Application::Start() {
|
||||
wake_word_detect_.EncodeWakeWordData();
|
||||
|
||||
if (!protocol_->OpenAudioChannel()) {
|
||||
ESP_LOGE(TAG, "Failed to open audio channel");
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
wake_word_detect_.StartDetection();
|
||||
return;
|
||||
}
|
||||
@@ -482,9 +522,11 @@ void Application::Start() {
|
||||
protocol_->SendWakeWordDetected(wake_word);
|
||||
ESP_LOGI(TAG, "Wake word detected: %s", wake_word.c_str());
|
||||
keep_listening_ = true;
|
||||
SetDeviceState(kDeviceStateListening);
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
AbortSpeaking(kAbortReasonWakeWordDetected);
|
||||
} else if (device_state_ == kDeviceStateActivating) {
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
}
|
||||
|
||||
// Resume detection
|
||||
@@ -495,6 +537,32 @@ void Application::Start() {
|
||||
#endif
|
||||
|
||||
SetDeviceState(kDeviceStateIdle);
|
||||
esp_timer_start_periodic(clock_timer_handle_, 1000000);
|
||||
}
|
||||
|
||||
void Application::OnClockTimer() {
|
||||
clock_ticks_++;
|
||||
|
||||
// Print the debug info every 10 seconds
|
||||
if (clock_ticks_ % 10 == 0) {
|
||||
// SystemInfo::PrintRealTimeStats(pdMS_TO_TICKS(1000));
|
||||
int free_sram = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
|
||||
int min_free_sram = heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL);
|
||||
ESP_LOGI(TAG, "Free internal: %u minimal internal: %u", free_sram, min_free_sram);
|
||||
|
||||
// If we have synchronized server time, set the status to clock "HH:MM" if the device is idle
|
||||
if (ota_.HasServerTime()) {
|
||||
if (device_state_ == kDeviceStateIdle) {
|
||||
Schedule([this]() {
|
||||
// Set status to clock "HH:MM"
|
||||
time_t now = time(NULL);
|
||||
char time_str[64];
|
||||
strftime(time_str, sizeof(time_str), "%H:%M ", localtime(&now));
|
||||
Board::GetInstance().GetDisplay()->SetStatus(time_str);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::Schedule(std::function<void()> callback) {
|
||||
@@ -617,14 +685,16 @@ void Application::InputAudio() {
|
||||
data = std::move(resampled);
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
if (audio_processor_.IsRunning()) {
|
||||
audio_processor_.Input(data);
|
||||
}
|
||||
|
||||
#if CONFIG_USE_WAKE_WORD_DETECT
|
||||
if (wake_word_detect_.IsDetectionRunning()) {
|
||||
wake_word_detect_.Feed(data);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
if (audio_processor_.IsRunning()) {
|
||||
audio_processor_.Input(data);
|
||||
}
|
||||
#else
|
||||
if (device_state_ == kDeviceStateListening) {
|
||||
background_task_->Schedule([this, data = std::move(data)]() mutable {
|
||||
@@ -649,6 +719,8 @@ void Application::SetDeviceState(DeviceState state) {
|
||||
return;
|
||||
}
|
||||
|
||||
clock_ticks_ = 0;
|
||||
auto previous_state = device_state_;
|
||||
device_state_ = state;
|
||||
ESP_LOGI(TAG, "STATE: %s", STATE_STRINGS[device_state_]);
|
||||
// The state is changed, wait for all background tasks to finish
|
||||
@@ -662,31 +734,36 @@ void Application::SetDeviceState(DeviceState state) {
|
||||
switch (state) {
|
||||
case kDeviceStateUnknown:
|
||||
case kDeviceStateIdle:
|
||||
display->SetStatus("待命");
|
||||
display->SetStatus(Lang::Strings::STANDBY);
|
||||
display->SetEmotion("neutral");
|
||||
#ifdef CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
audio_processor_.Stop();
|
||||
#endif
|
||||
break;
|
||||
case kDeviceStateConnecting:
|
||||
display->SetStatus("连接中...");
|
||||
display->SetStatus(Lang::Strings::CONNECTING);
|
||||
display->SetEmotion("neutral");
|
||||
display->SetChatMessage("system", "");
|
||||
break;
|
||||
case kDeviceStateListening:
|
||||
display->SetStatus("聆听中...");
|
||||
display->SetStatus(Lang::Strings::LISTENING);
|
||||
display->SetEmotion("neutral");
|
||||
ResetDecoder();
|
||||
opus_encoder_->ResetState();
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
audio_processor_.Start();
|
||||
#endif
|
||||
UpdateIotStates();
|
||||
if (previous_state == kDeviceStateSpeaking) {
|
||||
// FIXME: Wait for the speaker to empty the buffer
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
}
|
||||
break;
|
||||
case kDeviceStateSpeaking:
|
||||
display->SetStatus("说话中...");
|
||||
display->SetStatus(Lang::Strings::SPEAKING);
|
||||
ResetDecoder();
|
||||
codec->EnableOutput(true);
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
audio_processor_.Stop();
|
||||
#endif
|
||||
break;
|
||||
@@ -714,9 +791,8 @@ void Application::SetDecodeSampleRate(int sample_rate) {
|
||||
|
||||
void Application::UpdateIotStates() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
auto states = thing_manager.GetStatesJson();
|
||||
if (states != last_iot_states_) {
|
||||
last_iot_states_ = states;
|
||||
std::string states;
|
||||
if (thing_manager.GetStatesJson(states, true)) {
|
||||
protocol_->SendIotStates(states);
|
||||
}
|
||||
}
|
||||
@@ -735,10 +811,27 @@ void Application::WakeWordInvoke(const std::string& wake_word) {
|
||||
}
|
||||
});
|
||||
} else if (device_state_ == kDeviceStateSpeaking) {
|
||||
AbortSpeaking(kAbortReasonNone);
|
||||
Schedule([this]() {
|
||||
AbortSpeaking(kAbortReasonNone);
|
||||
});
|
||||
} else if (device_state_ == kDeviceStateListening) {
|
||||
if (protocol_) {
|
||||
protocol_->CloseAudioChannel();
|
||||
}
|
||||
Schedule([this]() {
|
||||
if (protocol_) {
|
||||
protocol_->CloseAudioChannel();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::CanEnterSleepMode() {
|
||||
if (device_state_ != kDeviceStateIdle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (protocol_ && protocol_->IsAudioChannelOpened()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now it is safe to enter sleep mode
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/event_groups.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_timer.h>
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
@@ -17,8 +18,10 @@
|
||||
#include "ota.h"
|
||||
#include "background_task.h"
|
||||
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_WAKE_WORD_DETECT
|
||||
#include "wake_word_detect.h"
|
||||
#endif
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
#include "audio_processor.h"
|
||||
#endif
|
||||
|
||||
@@ -56,7 +59,8 @@ public:
|
||||
bool IsVoiceDetected() const { return voice_detected_; }
|
||||
void Schedule(std::function<void()> callback);
|
||||
void SetDeviceState(DeviceState state);
|
||||
void Alert(const std::string& status, const std::string& message, const std::string& emotion = "", const std::string_view& sound = "");
|
||||
void Alert(const char* status, const char* message, const char* emotion = "", const std::string_view& sound = "");
|
||||
void DismissAlert();
|
||||
void AbortSpeaking(AbortReason reason);
|
||||
void ToggleChatState();
|
||||
void StartListening();
|
||||
@@ -64,25 +68,30 @@ public:
|
||||
void UpdateIotStates();
|
||||
void Reboot();
|
||||
void WakeWordInvoke(const std::string& wake_word);
|
||||
void PlaySound(const std::string_view& sound);
|
||||
bool CanEnterSleepMode();
|
||||
|
||||
private:
|
||||
Application();
|
||||
~Application();
|
||||
|
||||
#if CONFIG_USE_AUDIO_PROCESSING
|
||||
#if CONFIG_USE_WAKE_WORD_DETECT
|
||||
WakeWordDetect wake_word_detect_;
|
||||
#endif
|
||||
#if CONFIG_USE_AUDIO_PROCESSOR
|
||||
AudioProcessor audio_processor_;
|
||||
#endif
|
||||
Ota ota_;
|
||||
std::mutex mutex_;
|
||||
std::list<std::function<void()>> main_tasks_;
|
||||
std::unique_ptr<Protocol> protocol_;
|
||||
EventGroupHandle_t event_group_;
|
||||
EventGroupHandle_t event_group_ = nullptr;
|
||||
esp_timer_handle_t clock_timer_handle_ = nullptr;
|
||||
volatile DeviceState device_state_ = kDeviceStateUnknown;
|
||||
bool keep_listening_ = false;
|
||||
bool aborted_ = false;
|
||||
bool voice_detected_ = false;
|
||||
std::string last_iot_states_;
|
||||
int clock_ticks_ = 0;
|
||||
|
||||
// Audio encode / decode
|
||||
BackgroundTask* background_task_ = nullptr;
|
||||
@@ -104,8 +113,7 @@ private:
|
||||
void SetDecodeSampleRate(int sample_rate);
|
||||
void CheckNewVersion();
|
||||
void ShowActivationCode();
|
||||
|
||||
void PlayLocalFile(const char* data, size_t size);
|
||||
void OnClockTimer();
|
||||
};
|
||||
|
||||
#endif // _APPLICATION_H_
|
||||
|
||||
BIN
main/assets/common/exclamation.p3
Normal file
BIN
main/assets/common/exclamation.p3
Normal file
Binary file not shown.
BIN
main/assets/common/low_battery.p3
Normal file
BIN
main/assets/common/low_battery.p3
Normal file
Binary file not shown.
BIN
main/assets/common/success.p3
Normal file
BIN
main/assets/common/success.p3
Normal file
Binary file not shown.
BIN
main/assets/common/vibration.p3
Normal file
BIN
main/assets/common/vibration.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/0.p3
Normal file
BIN
main/assets/en-US/0.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/1.p3
Normal file
BIN
main/assets/en-US/1.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/2.p3
Normal file
BIN
main/assets/en-US/2.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/3.p3
Normal file
BIN
main/assets/en-US/3.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/4.p3
Normal file
BIN
main/assets/en-US/4.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/5.p3
Normal file
BIN
main/assets/en-US/5.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/6.p3
Normal file
BIN
main/assets/en-US/6.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/7.p3
Normal file
BIN
main/assets/en-US/7.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/8.p3
Normal file
BIN
main/assets/en-US/8.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/9.p3
Normal file
BIN
main/assets/en-US/9.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/activation.p3
Normal file
BIN
main/assets/en-US/activation.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/err_pin.p3
Normal file
BIN
main/assets/en-US/err_pin.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/err_reg.p3
Normal file
BIN
main/assets/en-US/err_reg.p3
Normal file
Binary file not shown.
52
main/assets/en-US/language.json
Normal file
52
main/assets/en-US/language.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"language": {
|
||||
"type": "en-US"
|
||||
},
|
||||
"strings": {
|
||||
"WARNING": "Warning",
|
||||
"INFO": "Information",
|
||||
"ERROR": "Error",
|
||||
"VERSION": "Ver ",
|
||||
"LOADING_PROTOCOL": "Loading Protocol...",
|
||||
"INITIALIZING": "Initializing...",
|
||||
"PIN_ERROR": "Please insert SIM card",
|
||||
"REG_ERROR": "Unable to access network, please check SIM card status",
|
||||
"DETECTING_MODULE": "Detecting module...",
|
||||
"REGISTERING_NETWORK": "Waiting for network...",
|
||||
|
||||
"STANDBY": "Standby",
|
||||
"CONNECT_TO": "Connect to ",
|
||||
"CONNECTING": "Connecting...",
|
||||
"CONNECTION_SUCCESSFUL": "Connection Successful",
|
||||
"CONNECTED_TO": "Connected to ",
|
||||
|
||||
"LISTENING": "Listening...",
|
||||
"SPEAKING": "Speaking...",
|
||||
|
||||
"SERVER_NOT_FOUND": "Looking for available service",
|
||||
"SERVER_NOT_CONNECTED": "Unable to connect to service, please try again later",
|
||||
"SERVER_TIMEOUT": "Waiting for response timeout",
|
||||
"SERVER_ERROR": "Sending failed, please check the network",
|
||||
|
||||
"CONNECT_TO_HOTSPOT": "Hotspot: ",
|
||||
"ACCESS_VIA_BROWSER": " Config URL: ",
|
||||
"WIFI_CONFIG_MODE": "Wi-Fi Configuration Mode",
|
||||
"ENTERING_WIFI_CONFIG_MODE": "Entering Wi-Fi configuration mode...",
|
||||
"SCANNING_WIFI": "Scanning Wi-Fi...",
|
||||
|
||||
"NEW_VERSION": "New version ",
|
||||
"OTA_UPGRADE": "OTA Upgrade",
|
||||
"UPGRADING": "System is upgrading...",
|
||||
"UPGRADE_FAILED": "Upgrade failed",
|
||||
"ACTIVATION": "Activation",
|
||||
|
||||
"BATTERY_LOW": "Low battery",
|
||||
"BATTERY_CHARGING": "Charging",
|
||||
"BATTERY_FULL": "Battery full",
|
||||
"BATTERY_NEED_CHARGE": "Low battery, please charge",
|
||||
|
||||
"VOLUME": "Volume ",
|
||||
"MUTED": "Muted",
|
||||
"MAX_VOLUME": "Max volume"
|
||||
}
|
||||
}
|
||||
BIN
main/assets/en-US/upgrade.p3
Normal file
BIN
main/assets/en-US/upgrade.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/welcome.p3
Normal file
BIN
main/assets/en-US/welcome.p3
Normal file
Binary file not shown.
BIN
main/assets/en-US/wificonfig.p3
Normal file
BIN
main/assets/en-US/wificonfig.p3
Normal file
Binary file not shown.
51
main/assets/ja-JP/language.json
Normal file
51
main/assets/ja-JP/language.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"language": {
|
||||
"type": "ja-JP"
|
||||
},
|
||||
"strings": {
|
||||
"WARNING": "警告",
|
||||
"INFO": "情報",
|
||||
"ERROR": "エラー",
|
||||
"VERSION": "バージョン ",
|
||||
"LOADING_PROTOCOL": "プロトコルを読み込み中...",
|
||||
"INITIALIZING": "初期化中...",
|
||||
"PIN_ERROR": "SIMカードを挿入してください",
|
||||
"REG_ERROR": "ネットワークに接続できません。ネットワーク状態を確認してください",
|
||||
"DETECTING_MODULE": "モジュールを検出中...",
|
||||
"REGISTERING_NETWORK": "ネットワーク接続待機中...",
|
||||
|
||||
"STANDBY": "待機中",
|
||||
"CONNECT_TO": "接続先 ",
|
||||
"CONNECTING": "接続中...",
|
||||
"CONNECTED_TO": "接続完了 ",
|
||||
|
||||
"LISTENING": "リスニング中...",
|
||||
"SPEAKING": "話しています...",
|
||||
|
||||
"SERVER_NOT_FOUND": "利用可能なサーバーを探しています",
|
||||
"SERVER_NOT_CONNECTED": "サーバーに接続できません。後でもう一度お試しください",
|
||||
"SERVER_TIMEOUT": "応答待機時間が終了しました",
|
||||
"SERVER_ERROR": "送信に失敗しました。ネットワークを確認してください",
|
||||
|
||||
"CONNECT_TO_HOTSPOT": "スマートフォンをWi-Fi ",
|
||||
"ACCESS_VIA_BROWSER": " に接続し、ブラウザでアクセスしてください ",
|
||||
"WIFI_CONFIG_MODE": "ネットワーク設定モード",
|
||||
"ENTERING_WIFI_CONFIG_MODE": "ネットワーク設定中...",
|
||||
"SCANNING_WIFI": "Wi-Fiをスキャン中...",
|
||||
|
||||
"NEW_VERSION": "新しいバージョン ",
|
||||
"OTA_UPGRADE": "OTAアップグレード",
|
||||
"UPGRADING": "システムをアップグレード中...",
|
||||
"UPGRADE_FAILED": "アップグレード失敗",
|
||||
"ACTIVATION": "デバイスをアクティベート",
|
||||
|
||||
"BATTERY_LOW": "バッテリーが少なくなっています",
|
||||
"BATTERY_CHARGING": "充電中",
|
||||
"BATTERY_FULL": "バッテリー満タン",
|
||||
"BATTERY_NEED_CHARGE": "バッテリーが低下しています。充電してください",
|
||||
|
||||
"VOLUME": "音量 ",
|
||||
"MUTED": "ミュートされています",
|
||||
"MAX_VOLUME": "最大音量"
|
||||
}
|
||||
}
|
||||
51
main/assets/zh-CN/language.json
Normal file
51
main/assets/zh-CN/language.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"language": {
|
||||
"type" :"zh-CN"
|
||||
},
|
||||
"strings": {
|
||||
"WARNING":"警告",
|
||||
"INFO":"信息",
|
||||
"ERROR":"错误",
|
||||
"VERSION": "版本 ",
|
||||
"LOADING_PROTOCOL":"加载协议...",
|
||||
"INITIALIZING":"正在初始化...",
|
||||
"PIN_ERROR":"请插入 SIM 卡",
|
||||
"REG_ERROR":"无法接入网络,请检查流量卡状态",
|
||||
"DETECTING_MODULE":"检测模组...",
|
||||
"REGISTERING_NETWORK":"等待网络...",
|
||||
|
||||
"STANDBY":"待命",
|
||||
"CONNECT_TO":"连接 ",
|
||||
"CONNECTING":"连接中...",
|
||||
"CONNECTED_TO":"已连接 ",
|
||||
|
||||
"LISTENING":"聆听中...",
|
||||
"SPEAKING":"说话中...",
|
||||
|
||||
"SERVER_NOT_FOUND":"正在寻找可用服务",
|
||||
"SERVER_NOT_CONNECTED":"无法连接服务,请稍后再试",
|
||||
"SERVER_TIMEOUT":"等待响应超时",
|
||||
"SERVER_ERROR":"发送失败,请检查网络",
|
||||
|
||||
"CONNECT_TO_HOTSPOT":"手机连接热点 ",
|
||||
"ACCESS_VIA_BROWSER":",浏览器访问 ",
|
||||
"WIFI_CONFIG_MODE":"配网模式",
|
||||
"ENTERING_WIFI_CONFIG_MODE":"进入配网模式...",
|
||||
"SCANNING_WIFI":"扫描 Wi-Fi...",
|
||||
|
||||
"NEW_VERSION": "新版本 ",
|
||||
"OTA_UPGRADE":"OTA 升级",
|
||||
"UPGRADING":"正在升级系统...",
|
||||
"UPGRADE_FAILED":"升级失败",
|
||||
"ACTIVATION":"激活设备",
|
||||
|
||||
"BATTERY_LOW":"电量不足",
|
||||
"BATTERY_CHARGING":"正在充电",
|
||||
"BATTERY_FULL":"电量已满",
|
||||
"BATTERY_NEED_CHARGE":"电量低,请充电",
|
||||
|
||||
"VOLUME":"音量 ",
|
||||
"MUTED":"已静音",
|
||||
"MAX_VOLUME":"最大音量"
|
||||
}
|
||||
}
|
||||
BIN
main/assets/zh-TW/0.p3
Normal file
BIN
main/assets/zh-TW/0.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/1.p3
Normal file
BIN
main/assets/zh-TW/1.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/2.p3
Normal file
BIN
main/assets/zh-TW/2.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/3.p3
Normal file
BIN
main/assets/zh-TW/3.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/4.p3
Normal file
BIN
main/assets/zh-TW/4.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/5.p3
Normal file
BIN
main/assets/zh-TW/5.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/6.p3
Normal file
BIN
main/assets/zh-TW/6.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/7.p3
Normal file
BIN
main/assets/zh-TW/7.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/8.p3
Normal file
BIN
main/assets/zh-TW/8.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/9.p3
Normal file
BIN
main/assets/zh-TW/9.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/activation.p3
Normal file
BIN
main/assets/zh-TW/activation.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/err_pin.p3
Normal file
BIN
main/assets/zh-TW/err_pin.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/err_reg.p3
Normal file
BIN
main/assets/zh-TW/err_reg.p3
Normal file
Binary file not shown.
51
main/assets/zh-TW/language.json
Normal file
51
main/assets/zh-TW/language.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"language": {
|
||||
"type": "zh-TW"
|
||||
},
|
||||
"strings": {
|
||||
"WARNING": "警告",
|
||||
"INFO": "資訊",
|
||||
"ERROR": "錯誤",
|
||||
"VERSION": "版本 ",
|
||||
"LOADING_PROTOCOL": "加載協議...",
|
||||
"INITIALIZING": "正在初始化...",
|
||||
"PIN_ERROR": "請插入 SIM 卡",
|
||||
"REG_ERROR": "無法接入網絡,請檢查網路狀態",
|
||||
"DETECTING_MODULE": "檢測模組...",
|
||||
"REGISTERING_NETWORK": "等待網絡...",
|
||||
|
||||
"STANDBY": "待命",
|
||||
"CONNECT_TO": "連接 ",
|
||||
"CONNECTING": "連接中...",
|
||||
"CONNECTED_TO": "已連接 ",
|
||||
|
||||
"LISTENING": "聆聽中...",
|
||||
"SPEAKING": "說話中...",
|
||||
|
||||
"SERVER_NOT_FOUND": "正在尋找可用服務",
|
||||
"SERVER_NOT_CONNECTED": "無法連接服務,請稍後再試",
|
||||
"SERVER_TIMEOUT": "等待響應超時",
|
||||
"SERVER_ERROR": "發送失敗,請檢查網絡",
|
||||
|
||||
"CONNECT_TO_HOTSPOT": "手機連接WiFi ",
|
||||
"ACCESS_VIA_BROWSER": ",瀏覽器訪問 ",
|
||||
"WIFI_CONFIG_MODE": "網路設定模式",
|
||||
"ENTERING_WIFI_CONFIG_MODE": "正在設定網路...",
|
||||
"SCANNING_WIFI": "掃描 Wi-Fi...",
|
||||
|
||||
"NEW_VERSION": "新版本 ",
|
||||
"OTA_UPGRADE": "OTA 升級",
|
||||
"UPGRADING": "正在升級系統...",
|
||||
"UPGRADE_FAILED": "升級失敗",
|
||||
"ACTIVATION": "啟用設備",
|
||||
|
||||
"BATTERY_LOW": "電量不足",
|
||||
"BATTERY_CHARGING": "正在充電",
|
||||
"BATTERY_FULL": "電量已滿",
|
||||
"BATTERY_NEED_CHARGE": "電量低,請充電",
|
||||
|
||||
"VOLUME": "音量 ",
|
||||
"MUTED": "已靜音",
|
||||
"MAX_VOLUME": "最大音量"
|
||||
}
|
||||
}
|
||||
BIN
main/assets/zh-TW/upgrade.p3
Normal file
BIN
main/assets/zh-TW/upgrade.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/welcome.p3
Normal file
BIN
main/assets/zh-TW/welcome.p3
Normal file
Binary file not shown.
BIN
main/assets/zh-TW/wificonfig.p3
Normal file
BIN
main/assets/zh-TW/wificonfig.p3
Normal file
Binary file not shown.
@@ -1,39 +0,0 @@
|
||||
#ifndef BINARY_H
|
||||
#define BINARY_H
|
||||
|
||||
extern const char p3_err_reg_start[] asm("_binary_err_reg_p3_start");
|
||||
extern const char p3_err_reg_end[] asm("_binary_err_reg_p3_end");
|
||||
extern const char p3_err_pin_start[] asm("_binary_err_pin_p3_start");
|
||||
extern const char p3_err_pin_end[] asm("_binary_err_pin_p3_end");
|
||||
extern const char p3_wificonfig_start[] asm("_binary_wificonfig_p3_start");
|
||||
extern const char p3_wificonfig_end[] asm("_binary_wificonfig_p3_end");
|
||||
extern const char p3_upgrade_start[] asm("_binary_upgrade_p3_start");
|
||||
extern const char p3_upgrade_end[] asm("_binary_upgrade_p3_end");
|
||||
extern const char p3_activation_start[] asm("_binary_activation_p3_start");
|
||||
extern const char p3_activation_end[] asm("_binary_activation_p3_end");
|
||||
extern const char p3_welcome_start[] asm("_binary_welcome_p3_start");
|
||||
extern const char p3_welcome_end[] asm("_binary_welcome_p3_end");
|
||||
|
||||
extern const char p3_0_start[] asm("_binary_0_p3_start");
|
||||
extern const char p3_0_end[] asm("_binary_0_p3_end");
|
||||
extern const char p3_1_start[] asm("_binary_1_p3_start");
|
||||
extern const char p3_1_end[] asm("_binary_1_p3_end");
|
||||
extern const char p3_2_start[] asm("_binary_2_p3_start");
|
||||
extern const char p3_2_end[] asm("_binary_2_p3_end");
|
||||
extern const char p3_3_start[] asm("_binary_3_p3_start");
|
||||
extern const char p3_3_end[] asm("_binary_3_p3_end");
|
||||
extern const char p3_4_start[] asm("_binary_4_p3_start");
|
||||
extern const char p3_4_end[] asm("_binary_4_p3_end");
|
||||
extern const char p3_5_start[] asm("_binary_5_p3_start");
|
||||
extern const char p3_5_end[] asm("_binary_5_p3_end");
|
||||
extern const char p3_6_start[] asm("_binary_6_p3_start");
|
||||
extern const char p3_6_end[] asm("_binary_6_p3_end");
|
||||
extern const char p3_7_start[] asm("_binary_7_p3_start");
|
||||
extern const char p3_7_end[] asm("_binary_7_p3_end");
|
||||
extern const char p3_8_start[] asm("_binary_8_p3_start");
|
||||
extern const char p3_8_end[] asm("_binary_8_p3_end");
|
||||
extern const char p3_9_start[] asm("_binary_9_p3_start");
|
||||
extern const char p3_9_end[] asm("_binary_9_p3_end");
|
||||
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "NoAudioCodec"
|
||||
|
||||
@@ -35,7 +36,7 @@ NoAudioCodecDuplex::NoAudioCodecDuplex(int input_sample_rate, int output_sample_
|
||||
.sample_rate_hz = (uint32_t)output_sample_rate_,
|
||||
.clk_src = I2S_CLK_SRC_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.ext_clk_freq_hz = 0,
|
||||
#endif
|
||||
|
||||
@@ -48,7 +49,7 @@ NoAudioCodecDuplex::NoAudioCodecDuplex(int input_sample_rate, int output_sample_
|
||||
.ws_width = I2S_DATA_BIT_WIDTH_32BIT,
|
||||
.ws_pol = false,
|
||||
.bit_shift = true,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.left_align = true,
|
||||
.big_endian = false,
|
||||
.bit_order_lsb = false
|
||||
@@ -94,7 +95,7 @@ ATK_NoAudioCodecDuplex::ATK_NoAudioCodecDuplex(int input_sample_rate, int output
|
||||
.sample_rate_hz = (uint32_t)output_sample_rate_,
|
||||
.clk_src = I2S_CLK_SRC_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.ext_clk_freq_hz = 0,
|
||||
#endif
|
||||
},
|
||||
@@ -106,7 +107,7 @@ ATK_NoAudioCodecDuplex::ATK_NoAudioCodecDuplex(int input_sample_rate, int output
|
||||
.ws_width = I2S_DATA_BIT_WIDTH_16BIT,
|
||||
.ws_pol = false,
|
||||
.bit_shift = true,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.left_align = true,
|
||||
.big_endian = false,
|
||||
.bit_order_lsb = false
|
||||
@@ -153,7 +154,7 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl
|
||||
.sample_rate_hz = (uint32_t)output_sample_rate_,
|
||||
.clk_src = I2S_CLK_SRC_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.ext_clk_freq_hz = 0,
|
||||
#endif
|
||||
|
||||
@@ -166,7 +167,7 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl
|
||||
.ws_width = I2S_DATA_BIT_WIDTH_32BIT,
|
||||
.ws_pol = false,
|
||||
.bit_shift = true,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.left_align = true,
|
||||
.big_endian = false,
|
||||
.bit_order_lsb = false
|
||||
@@ -222,7 +223,7 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl
|
||||
.sample_rate_hz = (uint32_t)output_sample_rate_,
|
||||
.clk_src = I2S_CLK_SRC_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.ext_clk_freq_hz = 0,
|
||||
#endif
|
||||
|
||||
@@ -235,7 +236,7 @@ NoAudioCodecSimplex::NoAudioCodecSimplex(int input_sample_rate, int output_sampl
|
||||
.ws_width = I2S_DATA_BIT_WIDTH_32BIT,
|
||||
.ws_pol = false,
|
||||
.bit_shift = true,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.left_align = true,
|
||||
.big_endian = false,
|
||||
.bit_order_lsb = false
|
||||
@@ -290,7 +291,7 @@ NoAudioCodecSimplexPdm::NoAudioCodecSimplexPdm(int input_sample_rate, int output
|
||||
.sample_rate_hz = (uint32_t)output_sample_rate_,
|
||||
.clk_src = I2S_CLK_SRC_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
#ifdef I2S_HW_VERSION_2
|
||||
.ext_clk_freq_hz = 0,
|
||||
#endif
|
||||
|
||||
@@ -321,7 +322,7 @@ NoAudioCodecSimplexPdm::NoAudioCodecSimplexPdm(int input_sample_rate, int output
|
||||
.gpio_cfg = {
|
||||
.clk = mic_sck,
|
||||
.din = mic_din,
|
||||
|
||||
|
||||
.invert_flags = {
|
||||
.clk_inv = false,
|
||||
},
|
||||
@@ -372,3 +373,22 @@ int NoAudioCodec::Read(int16_t* dest, int samples) {
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
int NoAudioCodecSimplexPdm::Read(int16_t* dest, int samples) {
|
||||
size_t bytes_read;
|
||||
|
||||
// PDM 解调后的数据位宽为 16 位
|
||||
std::vector<int16_t> bit16_buffer(samples);
|
||||
if (i2s_channel_read(rx_handle_, bit16_buffer.data(), samples * sizeof(int16_t), &bytes_read, portMAX_DELAY) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Read Failed!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 计算实际读取的样本数
|
||||
samples = bytes_read / sizeof(int16_t);
|
||||
|
||||
// 将 16 位数据直接复制到目标缓冲区
|
||||
memcpy(dest, bit16_buffer.data(), samples * sizeof(int16_t));
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
class NoAudioCodecSimplexPdm : public NoAudioCodec {
|
||||
public:
|
||||
NoAudioCodecSimplexPdm(int input_sample_rate, int output_sample_rate, gpio_num_t spk_bclk, gpio_num_t spk_ws, gpio_num_t spk_dout, gpio_num_t mic_sck, gpio_num_t mic_din);
|
||||
int Read(int16_t* dest, int samples);
|
||||
};
|
||||
|
||||
#endif // _NO_AUDIO_CODEC_H
|
||||
|
||||
@@ -53,7 +53,7 @@ void AudioProcessor::Initialize(int channels, bool reference) {
|
||||
auto this_ = (AudioProcessor*)arg;
|
||||
this_->AudioProcessorTask();
|
||||
vTaskDelete(NULL);
|
||||
}, "audio_communication", 4096 * 2, this, 1, NULL);
|
||||
}, "audio_communication", 4096 * 2, this, 2, NULL);
|
||||
}
|
||||
|
||||
AudioProcessor::~AudioProcessor() {
|
||||
|
||||
@@ -88,7 +88,7 @@ void WakeWordDetect::Initialize(int channels, bool reference) {
|
||||
auto this_ = (WakeWordDetect*)arg;
|
||||
this_->AudioDetectionTask();
|
||||
vTaskDelete(NULL);
|
||||
}, "audio_detection", 4096 * 2, this, 1, nullptr);
|
||||
}, "audio_detection", 4096 * 2, this, 2, nullptr);
|
||||
}
|
||||
|
||||
void WakeWordDetect::OnWakeWordDetected(std::function<void(const std::string& wake_word)> callback) {
|
||||
@@ -132,9 +132,6 @@ void WakeWordDetect::AudioDetectionTask() {
|
||||
|
||||
auto res = esp_afe_sr_v1.fetch(afe_detection_data_);
|
||||
if (res == nullptr || res->ret_value == ESP_FAIL) {
|
||||
if (res != nullptr) {
|
||||
ESP_LOGI(TAG, "Error code: %d", res->ret_value);
|
||||
}
|
||||
continue;;
|
||||
}
|
||||
|
||||
@@ -202,7 +199,7 @@ void WakeWordDetect::EncodeWakeWordData() {
|
||||
this_->wake_word_cv_.notify_all();
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}, "encode_detect_packets", 4096 * 8, this, 1, wake_word_encode_task_stack_, &wake_word_encode_task_buffer_);
|
||||
}, "encode_detect_packets", 4096 * 8, this, 2, wake_word_encode_task_stack_, &wake_word_encode_task_buffer_);
|
||||
}
|
||||
|
||||
bool WakeWordDetect::GetWakeWordOpus(std::vector<uint8_t>& opus) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "background_task.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
#define TAG "BackgroundTask"
|
||||
|
||||
@@ -8,7 +9,7 @@ BackgroundTask::BackgroundTask(uint32_t stack_size) {
|
||||
xTaskCreate([](void* arg) {
|
||||
BackgroundTask* task = (BackgroundTask*)arg;
|
||||
task->BackgroundTaskLoop();
|
||||
}, "background_task", stack_size, this, 1, &background_task_handle_);
|
||||
}, "background_task", stack_size, this, 2, &background_task_handle_);
|
||||
}
|
||||
|
||||
BackgroundTask::~BackgroundTask() {
|
||||
|
||||
@@ -152,7 +152,7 @@ private:
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true));
|
||||
|
||||
display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_20_4,
|
||||
|
||||
@@ -132,7 +132,7 @@ private:
|
||||
esp_lcd_panel_invert_color(panel, true);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_20_4,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/es8311_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "display/no_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "i2c_device.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
@@ -110,9 +110,10 @@ private:
|
||||
InitializeSpi();
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
display_->SetStatus("错误");
|
||||
GetBacklight()->SetBrightness(100);
|
||||
display_->SetStatus(Lang::Strings::ERROR);
|
||||
display_->SetEmotion("sad");
|
||||
display_->SetChatMessage("system", "Echo Base\n未连接");
|
||||
display_->SetChatMessage("system", "Echo Base\nnot connected");
|
||||
|
||||
while (1) {
|
||||
ESP_LOGE(TAG, "Atomic Echo Base is disconnected");
|
||||
@@ -177,7 +178,7 @@ private:
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
|
||||
display_ = new LcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
display_ = new SpiLcdDisplay(io_handle, panel_handle,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_16_4,
|
||||
@@ -211,6 +212,7 @@ public:
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
@@ -233,6 +235,11 @@ public:
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(AtomS3EchoBaseBoard);
|
||||
@@ -5,7 +5,7 @@
|
||||
"name": "atoms3-echo-base",
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_SPIRAM=n",
|
||||
"CONFIG_USE_AUDIO_PROCESSING=n",
|
||||
"CONFIG_USE_AFE=n",
|
||||
"CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y",
|
||||
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions_8M.csv\""
|
||||
]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/es8311_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "display/no_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "i2c_device.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
@@ -54,11 +54,29 @@ public:
|
||||
WriteReg(0x08, data);
|
||||
}
|
||||
|
||||
void SetLcdBacklight(uint8_t brightness) {
|
||||
void SetBrightness(uint8_t brightness) {
|
||||
// Map 0~100 to 0~255
|
||||
brightness = brightness * 255 / 100;
|
||||
WriteReg(0x0E, brightness);
|
||||
}
|
||||
};
|
||||
|
||||
class CustomBacklight : public Backlight {
|
||||
public:
|
||||
CustomBacklight(Lp5562* lp5562) : lp5562_(lp5562) {}
|
||||
|
||||
void SetBrightnessImpl(uint8_t brightness) override {
|
||||
if (lp5562_) {
|
||||
lp5562_->SetBrightness(brightness);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "LP5562 not available");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Lp5562* lp5562_ = nullptr;
|
||||
};
|
||||
|
||||
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0xfe, (uint8_t[]){0x00}, 0, 0},
|
||||
@@ -92,9 +110,9 @@ class AtomS3rEchoBaseBoard : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
i2c_master_bus_handle_t i2c_bus_internal_;
|
||||
Pi4ioe* pi4ioe_;
|
||||
Lp5562* lp5562_;
|
||||
Display* display_;
|
||||
Pi4ioe* pi4ioe_ = nullptr;
|
||||
Lp5562* lp5562_ = nullptr;
|
||||
Display* display_ = nullptr;
|
||||
Button boot_button_;
|
||||
bool is_echo_base_connected_ = false;
|
||||
void InitializeI2c() {
|
||||
@@ -158,9 +176,10 @@ private:
|
||||
InitializeSpi();
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
display_->SetStatus("错误");
|
||||
GetBacklight()->SetBrightness(100);
|
||||
display_->SetStatus(Lang::Strings::ERROR);
|
||||
display_->SetEmotion("sad");
|
||||
display_->SetChatMessage("system", "Echo Base\n未连接");
|
||||
display_->SetChatMessage("system", "Echo Base\nnot connected");
|
||||
|
||||
while (1) {
|
||||
ESP_LOGE(TAG, "Atomic Echo Base is disconnected");
|
||||
@@ -189,7 +208,6 @@ private:
|
||||
void InitializeLp5562() {
|
||||
ESP_LOGI(TAG, "Init LP5562");
|
||||
lp5562_ = new Lp5562(i2c_bus_internal_, 0x30);
|
||||
lp5562_->SetLcdBacklight(255);
|
||||
}
|
||||
|
||||
void InitializeSpi() {
|
||||
@@ -236,7 +254,7 @@ private:
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
display_ = new LcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
display_ = new SpiLcdDisplay(io_handle, panel_handle,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_16_4,
|
||||
@@ -259,6 +277,7 @@ private:
|
||||
void InitializeIot() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -272,6 +291,7 @@ public:
|
||||
InitializeGc9107Display();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
@@ -294,6 +314,11 @@ public:
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight *GetBacklight() override {
|
||||
static CustomBacklight backlight(lp5562_);
|
||||
return &backlight;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(AtomS3rEchoBaseBoard);
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
#include "display/ssd1306_display.h"
|
||||
#include "display/oled_display.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
|
||||
#define TAG "ESP32-MarsbearSupport"
|
||||
|
||||
@@ -24,6 +27,9 @@ private:
|
||||
Button asr_button_;
|
||||
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||
Display* display_ = nullptr;
|
||||
|
||||
void InitializeDisplayI2c() {
|
||||
i2c_master_bus_config_t bus_config = {
|
||||
@@ -41,6 +47,54 @@ private:
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeSsd1306Display() {
|
||||
// SSD1306 config
|
||||
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||
.dev_addr = 0x3C,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 6,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.flags = {
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2(display_i2c_bus_, &io_config, &panel_io_));
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = -1;
|
||||
panel_config.bits_per_pixel = 1;
|
||||
|
||||
esp_lcd_panel_ssd1306_config_t ssd1306_config = {
|
||||
.height = static_cast<uint8_t>(DISPLAY_HEIGHT),
|
||||
};
|
||||
panel_config.vendor_config = &ssd1306_config;
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(panel_io_, &panel_config, &panel_));
|
||||
ESP_LOGI(TAG, "SSD1306 driver installed");
|
||||
|
||||
// Reset the display
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
|
||||
if (esp_lcd_panel_init(panel_) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize display");
|
||||
display_ = new NoDisplay();
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the display to on
|
||||
ESP_LOGI(TAG, "Turning display on");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
|
||||
|
||||
display_ = new OledDisplay(panel_io_, panel_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
{&font_puhui_14_1, &font_awesome_14_1});
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
|
||||
// 配置 GPIO
|
||||
@@ -88,6 +142,7 @@ public:
|
||||
CompactWifiBoard() : boot_button_(BOOT_BUTTON_GPIO), touch_button_(TOUCH_BUTTON_GPIO), asr_button_(ASR_BUTTON_GPIO)
|
||||
{
|
||||
InitializeDisplayI2c();
|
||||
InitializeSsd1306Display();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
}
|
||||
@@ -105,9 +160,7 @@ public:
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
&font_puhui_14_1, &font_awesome_14_1);
|
||||
return &display;
|
||||
return display_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
#include "ml307_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/ssd1306_display.h"
|
||||
#include "display/oled_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
|
||||
#define TAG "CompactMl307Board"
|
||||
|
||||
@@ -19,6 +22,9 @@ LV_FONT_DECLARE(font_awesome_14_1);
|
||||
class CompactMl307Board : public Ml307Board {
|
||||
private:
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||
Display* display_ = nullptr;
|
||||
Button boot_button_;
|
||||
Button touch_button_;
|
||||
Button volume_up_button_;
|
||||
@@ -40,6 +46,54 @@ private:
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeSsd1306Display() {
|
||||
// SSD1306 config
|
||||
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||
.dev_addr = 0x3C,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 6,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.flags = {
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2(display_i2c_bus_, &io_config, &panel_io_));
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = -1;
|
||||
panel_config.bits_per_pixel = 1;
|
||||
|
||||
esp_lcd_panel_ssd1306_config_t ssd1306_config = {
|
||||
.height = static_cast<uint8_t>(DISPLAY_HEIGHT),
|
||||
};
|
||||
panel_config.vendor_config = &ssd1306_config;
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(panel_io_, &panel_config, &panel_));
|
||||
ESP_LOGI(TAG, "SSD1306 driver installed");
|
||||
|
||||
// Reset the display
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
|
||||
if (esp_lcd_panel_init(panel_) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize display");
|
||||
display_ = new NoDisplay();
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the display to on
|
||||
ESP_LOGI(TAG, "Turning display on");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
|
||||
|
||||
display_ = new OledDisplay(panel_io_, panel_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
{&font_puhui_14_1, &font_awesome_14_1});
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
Application::GetInstance().ToggleChatState();
|
||||
@@ -58,12 +112,12 @@ private:
|
||||
volume = 100;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_up_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(100);
|
||||
GetDisplay()->ShowNotification("最大音量");
|
||||
GetDisplay()->ShowNotification(Lang::Strings::MAX_VOLUME);
|
||||
});
|
||||
|
||||
volume_down_button_.OnClick([this]() {
|
||||
@@ -73,12 +127,12 @@ private:
|
||||
volume = 0;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_down_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(0);
|
||||
GetDisplay()->ShowNotification("已静音");
|
||||
GetDisplay()->ShowNotification(Lang::Strings::MUTED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,6 +151,7 @@ public:
|
||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
||||
|
||||
InitializeDisplayI2c();
|
||||
InitializeSsd1306Display();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
}
|
||||
@@ -118,9 +173,7 @@ public:
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
&font_puhui_14_1, &font_awesome_14_1);
|
||||
return &display;
|
||||
return display_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,134 +1,198 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#if defined(LCD_ILI9341_240X320) || defined(LCD_ILI9341_240X320_NO_IPS)
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#endif
|
||||
|
||||
#define TAG "CompactWifiBoardLCD"
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_16_4);
|
||||
LV_FONT_DECLARE(font_awesome_16_4);
|
||||
|
||||
class CompactWifiBoardLCD : public WifiBoard {
|
||||
private:
|
||||
|
||||
Button boot_button_;
|
||||
LcdDisplay* display_;
|
||||
|
||||
void InitializeSpi() {
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
|
||||
buscfg.miso_io_num = GPIO_NUM_NC;
|
||||
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
|
||||
buscfg.quadwp_io_num = GPIO_NUM_NC;
|
||||
buscfg.quadhd_io_num = GPIO_NUM_NC;
|
||||
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeLcdDisplay() {
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// 液晶屏控制IO初始化
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
||||
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
||||
io_config.spi_mode = 0;
|
||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
||||
io_config.trans_queue_depth = 10;
|
||||
io_config.lcd_cmd_bits = 8;
|
||||
io_config.lcd_param_bits = 8;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||
|
||||
// 初始化液晶屏驱动芯片
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||
panel_config.rgb_ele_order = DISPLAY_RGB_ORDER;
|
||||
panel_config.bits_per_pixel = 16;
|
||||
#if defined(LCD_ILI9341_240X320) || defined(LCD_ILI9341_240X320_NO_IPS)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(panel_io, &panel_config, &panel));
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||
#endif
|
||||
|
||||
esp_lcd_panel_reset(panel);
|
||||
|
||||
|
||||
esp_lcd_panel_init(panel);
|
||||
esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_16_4,
|
||||
.icon_font = &font_awesome_16_4,
|
||||
.emoji_font = DISPLAY_HEIGHT >= 240 ? font_emoji_64_init() : font_emoji_32_init(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
}
|
||||
|
||||
public:
|
||||
CompactWifiBoardLCD() :
|
||||
boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
}
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
||||
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
||||
#else
|
||||
static NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
||||
#endif
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CompactWifiBoardLCD);
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#if defined(LCD_TYPE_ILI9341_SERIAL)
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#endif
|
||||
|
||||
#if defined(LCD_TYPE_GC9A01_SERIAL)
|
||||
#include "esp_lcd_gc9a01.h"
|
||||
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
|
||||
// {cmd, { data }, data_size, delay_ms}
|
||||
{0xfe, (uint8_t[]){0x00}, 0, 0},
|
||||
{0xef, (uint8_t[]){0x00}, 0, 0},
|
||||
{0xb0, (uint8_t[]){0xc0}, 1, 0},
|
||||
{0xb1, (uint8_t[]){0x80}, 1, 0},
|
||||
{0xb2, (uint8_t[]){0x27}, 1, 0},
|
||||
{0xb3, (uint8_t[]){0x13}, 1, 0},
|
||||
{0xb6, (uint8_t[]){0x19}, 1, 0},
|
||||
{0xb7, (uint8_t[]){0x05}, 1, 0},
|
||||
{0xac, (uint8_t[]){0xc8}, 1, 0},
|
||||
{0xab, (uint8_t[]){0x0f}, 1, 0},
|
||||
{0x3a, (uint8_t[]){0x05}, 1, 0},
|
||||
{0xb4, (uint8_t[]){0x04}, 1, 0},
|
||||
{0xa8, (uint8_t[]){0x08}, 1, 0},
|
||||
{0xb8, (uint8_t[]){0x08}, 1, 0},
|
||||
{0xea, (uint8_t[]){0x02}, 1, 0},
|
||||
{0xe8, (uint8_t[]){0x2A}, 1, 0},
|
||||
{0xe9, (uint8_t[]){0x47}, 1, 0},
|
||||
{0xe7, (uint8_t[]){0x5f}, 1, 0},
|
||||
{0xc6, (uint8_t[]){0x21}, 1, 0},
|
||||
{0xc7, (uint8_t[]){0x15}, 1, 0},
|
||||
{0xf0,
|
||||
(uint8_t[]){0x1D, 0x38, 0x09, 0x4D, 0x92, 0x2F, 0x35, 0x52, 0x1E, 0x0C,
|
||||
0x04, 0x12, 0x14, 0x1f},
|
||||
14, 0},
|
||||
{0xf1,
|
||||
(uint8_t[]){0x16, 0x40, 0x1C, 0x54, 0xA9, 0x2D, 0x2E, 0x56, 0x10, 0x0D,
|
||||
0x0C, 0x1A, 0x14, 0x1E},
|
||||
14, 0},
|
||||
{0xf4, (uint8_t[]){0x00, 0x00, 0xFF}, 3, 0},
|
||||
{0xba, (uint8_t[]){0xFF, 0xFF}, 2, 0},
|
||||
};
|
||||
#endif
|
||||
|
||||
#define TAG "CompactWifiBoardLCD"
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_16_4);
|
||||
LV_FONT_DECLARE(font_awesome_16_4);
|
||||
|
||||
class CompactWifiBoardLCD : public WifiBoard {
|
||||
private:
|
||||
|
||||
Button boot_button_;
|
||||
LcdDisplay* display_;
|
||||
|
||||
void InitializeSpi() {
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
|
||||
buscfg.miso_io_num = GPIO_NUM_NC;
|
||||
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
|
||||
buscfg.quadwp_io_num = GPIO_NUM_NC;
|
||||
buscfg.quadhd_io_num = GPIO_NUM_NC;
|
||||
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeLcdDisplay() {
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// 液晶屏控制IO初始化
|
||||
ESP_LOGD(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
||||
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
||||
io_config.spi_mode = DISPLAY_SPI_MODE;
|
||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
||||
io_config.trans_queue_depth = 10;
|
||||
io_config.lcd_cmd_bits = 8;
|
||||
io_config.lcd_param_bits = 8;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||
|
||||
// 初始化液晶屏驱动芯片
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||
panel_config.rgb_ele_order = DISPLAY_RGB_ORDER;
|
||||
panel_config.bits_per_pixel = 16;
|
||||
#if defined(LCD_TYPE_ILI9341_SERIAL)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(panel_io, &panel_config, &panel));
|
||||
#elif defined(LCD_TYPE_GC9A01_SERIAL)
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(panel_io, &panel_config, &panel));
|
||||
gc9a01_vendor_config_t gc9107_vendor_config = {
|
||||
.init_cmds = gc9107_lcd_init_cmds,
|
||||
.init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t),
|
||||
};
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||
#endif
|
||||
|
||||
esp_lcd_panel_reset(panel);
|
||||
|
||||
|
||||
esp_lcd_panel_init(panel);
|
||||
esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
#ifdef LCD_TYPE_GC9A01_SERIAL
|
||||
panel_config.vendor_config = &gc9107_vendor_config;
|
||||
#endif
|
||||
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_16_4,
|
||||
.icon_font = &font_awesome_16_4,
|
||||
.emoji_font = DISPLAY_HEIGHT >= 240 ? font_emoji_64_init() : font_emoji_32_init(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
CompactWifiBoardLCD() :
|
||||
boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
||||
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
||||
#else
|
||||
static NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
||||
#endif
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CompactWifiBoardLCD);
|
||||
|
||||
@@ -43,9 +43,8 @@
|
||||
#define DISPLAY_CS_PIN GPIO_NUM_41
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -56,9 +55,11 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X320_NO_IPS
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -69,9 +70,11 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_170X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 170
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -82,9 +85,11 @@
|
||||
#define DISPLAY_OFFSET_X 35
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_172X320
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 172
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -95,9 +100,11 @@
|
||||
#define DISPLAY_OFFSET_X 34
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X280
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 280
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -108,9 +115,11 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 20
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X240
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -121,9 +130,26 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X240_7PIN
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 2
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7789_240X135
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 135
|
||||
#define DISPLAY_MIRROR_X true
|
||||
@@ -134,9 +160,11 @@
|
||||
#define DISPLAY_OFFSET_X 40
|
||||
#define DISPLAY_OFFSET_Y 53
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7735_128X160
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 160
|
||||
#define DISPLAY_MIRROR_X true
|
||||
@@ -147,9 +175,26 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7735_128X128
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 128
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y true
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 32
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7796_320X480
|
||||
#define LCD_TYPE_ST7789_SERIAL
|
||||
#define DISPLAY_WIDTH 320
|
||||
#define DISPLAY_HEIGHT 480
|
||||
#define DISPLAY_MIRROR_X false
|
||||
@@ -160,32 +205,52 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ILI9341_240X320
|
||||
#define LCD_TYPE_ILI9341_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ILI9341_240X320_NO_IPS
|
||||
#define LCD_TYPE_ILI9341_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 320
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR false
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_GC9A01_240X240
|
||||
#define LCD_TYPE_GC9A01_SERIAL
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_MIRROR_X true
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
#define DISPLAY_INVERT_COLOR true
|
||||
#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_CUSTOM
|
||||
@@ -199,6 +264,7 @@
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
#define DISPLAY_SPI_MODE 0
|
||||
#endif
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/ssd1306_display.h"
|
||||
#include "display/oled_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "led/single_led.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
|
||||
#define TAG "CompactWifiBoard"
|
||||
|
||||
@@ -20,6 +23,9 @@ LV_FONT_DECLARE(font_awesome_14_1);
|
||||
class CompactWifiBoard : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||
Display* display_ = nullptr;
|
||||
Button boot_button_;
|
||||
Button touch_button_;
|
||||
Button volume_up_button_;
|
||||
@@ -41,6 +47,54 @@ private:
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeSsd1306Display() {
|
||||
// SSD1306 config
|
||||
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||
.dev_addr = 0x3C,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 6,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.flags = {
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2(display_i2c_bus_, &io_config, &panel_io_));
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = -1;
|
||||
panel_config.bits_per_pixel = 1;
|
||||
|
||||
esp_lcd_panel_ssd1306_config_t ssd1306_config = {
|
||||
.height = static_cast<uint8_t>(DISPLAY_HEIGHT),
|
||||
};
|
||||
panel_config.vendor_config = &ssd1306_config;
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(panel_io_, &panel_config, &panel_));
|
||||
ESP_LOGI(TAG, "SSD1306 driver installed");
|
||||
|
||||
// Reset the display
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
|
||||
if (esp_lcd_panel_init(panel_) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize display");
|
||||
display_ = new NoDisplay();
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the display to on
|
||||
ESP_LOGI(TAG, "Turning display on");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
|
||||
|
||||
display_ = new OledDisplay(panel_io_, panel_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
{&font_puhui_14_1, &font_awesome_14_1});
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
@@ -63,12 +117,12 @@ private:
|
||||
volume = 100;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_up_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(100);
|
||||
GetDisplay()->ShowNotification("最大音量");
|
||||
GetDisplay()->ShowNotification(Lang::Strings::MAX_VOLUME);
|
||||
});
|
||||
|
||||
volume_down_button_.OnClick([this]() {
|
||||
@@ -78,12 +132,12 @@ private:
|
||||
volume = 0;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
GetDisplay()->ShowNotification(Lang::Strings::VOLUME + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_down_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(0);
|
||||
GetDisplay()->ShowNotification("已静音");
|
||||
GetDisplay()->ShowNotification(Lang::Strings::MUTED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,6 +155,7 @@ public:
|
||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
||||
InitializeDisplayI2c();
|
||||
InitializeSsd1306Display();
|
||||
InitializeButtons();
|
||||
InitializeIot();
|
||||
}
|
||||
@@ -122,9 +177,7 @@ public:
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y,
|
||||
&font_puhui_14_1, &font_awesome_14_1);
|
||||
return &display;
|
||||
return display_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
37
main/boards/common/axp2101.cc
Normal file
37
main/boards/common/axp2101.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "axp2101.h"
|
||||
#include "board.h"
|
||||
#include "display.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#define TAG "Axp2101"
|
||||
|
||||
Axp2101::Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||
}
|
||||
|
||||
int Axp2101::GetBatteryCurrentDirection() {
|
||||
return (ReadReg(0x01) & 0b01100000) >> 5;
|
||||
}
|
||||
|
||||
bool Axp2101::IsCharging() {
|
||||
return GetBatteryCurrentDirection() == 1;
|
||||
}
|
||||
|
||||
bool Axp2101::IsDischarging() {
|
||||
return GetBatteryCurrentDirection() == 2;
|
||||
}
|
||||
|
||||
bool Axp2101::IsChargingDone() {
|
||||
uint8_t value = ReadReg(0x01);
|
||||
return (value & 0b00000111) == 0b00000100;
|
||||
}
|
||||
|
||||
int Axp2101::GetBatteryLevel() {
|
||||
return ReadReg(0xA4);
|
||||
}
|
||||
|
||||
void Axp2101::PowerOff() {
|
||||
uint8_t value = ReadReg(0x10);
|
||||
value = value | 0x01;
|
||||
WriteReg(0x10, value);
|
||||
}
|
||||
113
main/boards/common/backlight.cc
Normal file
113
main/boards/common/backlight.cc
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "backlight.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/ledc.h>
|
||||
|
||||
#define TAG "Backlight"
|
||||
|
||||
|
||||
Backlight::Backlight() {
|
||||
// 创建背光渐变定时器
|
||||
const esp_timer_create_args_t timer_args = {
|
||||
.callback = [](void* arg) {
|
||||
auto self = static_cast<Backlight*>(arg);
|
||||
self->OnTransitionTimer();
|
||||
},
|
||||
.arg = this,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
.name = "backlight_timer",
|
||||
.skip_unhandled_events = true,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_timer_create(&timer_args, &transition_timer_));
|
||||
}
|
||||
|
||||
Backlight::~Backlight() {
|
||||
if (transition_timer_ != nullptr) {
|
||||
esp_timer_stop(transition_timer_);
|
||||
esp_timer_delete(transition_timer_);
|
||||
}
|
||||
}
|
||||
|
||||
void Backlight::RestoreBrightness() {
|
||||
// Load brightness from settings
|
||||
Settings settings("display");
|
||||
SetBrightness(settings.GetInt("brightness", 75));
|
||||
}
|
||||
|
||||
void Backlight::SetBrightness(uint8_t brightness, bool permanent) {
|
||||
if (brightness > 100) {
|
||||
brightness = 100;
|
||||
}
|
||||
|
||||
if (brightness_ == brightness) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (permanent) {
|
||||
Settings settings("display", true);
|
||||
settings.SetInt("brightness", brightness);
|
||||
}
|
||||
|
||||
target_brightness_ = brightness;
|
||||
step_ = (target_brightness_ > brightness_) ? 1 : -1;
|
||||
|
||||
if (transition_timer_ != nullptr) {
|
||||
// 启动定时器,每 5ms 更新一次
|
||||
esp_timer_start_periodic(transition_timer_, 5 * 1000);
|
||||
}
|
||||
ESP_LOGI(TAG, "Set brightness to %d", brightness);
|
||||
}
|
||||
|
||||
void Backlight::OnTransitionTimer() {
|
||||
if (brightness_ == target_brightness_) {
|
||||
esp_timer_stop(transition_timer_);
|
||||
return;
|
||||
}
|
||||
|
||||
brightness_ += step_;
|
||||
SetBrightnessImpl(brightness_);
|
||||
|
||||
if (brightness_ == target_brightness_) {
|
||||
esp_timer_stop(transition_timer_);
|
||||
}
|
||||
}
|
||||
|
||||
PwmBacklight::PwmBacklight(gpio_num_t pin, bool output_invert) : Backlight() {
|
||||
const ledc_timer_config_t backlight_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_10_BIT,
|
||||
.timer_num = LEDC_TIMER_0,
|
||||
.freq_hz = 20000, //背光pwm频率需要高一点,防止电感啸叫
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_timer_config(&backlight_timer));
|
||||
|
||||
// Setup LEDC peripheral for PWM backlight control
|
||||
const ledc_channel_config_t backlight_channel = {
|
||||
.gpio_num = pin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = LEDC_CHANNEL_0,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
.flags = {
|
||||
.output_invert = output_invert,
|
||||
}
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&backlight_channel));
|
||||
}
|
||||
|
||||
PwmBacklight::~PwmBacklight() {
|
||||
ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0);
|
||||
}
|
||||
|
||||
void PwmBacklight::SetBrightnessImpl(uint8_t brightness) {
|
||||
// LEDC resolution set to 10bits, thus: 100% = 1023
|
||||
uint32_t duty_cycle = (1023 * brightness) / 100;
|
||||
ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, duty_cycle);
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
|
||||
}
|
||||
|
||||
36
main/boards/common/backlight.h
Normal file
36
main/boards/common/backlight.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_timer.h>
|
||||
|
||||
|
||||
class Backlight {
|
||||
public:
|
||||
Backlight();
|
||||
~Backlight();
|
||||
|
||||
void RestoreBrightness();
|
||||
void SetBrightness(uint8_t brightness, bool permanent = false);
|
||||
inline uint8_t brightness() const { return brightness_; }
|
||||
|
||||
protected:
|
||||
void OnTransitionTimer();
|
||||
virtual void SetBrightnessImpl(uint8_t brightness) = 0;
|
||||
|
||||
esp_timer_handle_t transition_timer_ = nullptr;
|
||||
uint8_t brightness_ = 0;
|
||||
uint8_t target_brightness_ = 0;
|
||||
uint8_t step_ = 1;
|
||||
};
|
||||
|
||||
|
||||
class PwmBacklight : public Backlight {
|
||||
public:
|
||||
PwmBacklight(gpio_num_t pin, bool output_invert = false);
|
||||
~PwmBacklight();
|
||||
|
||||
void SetBrightnessImpl(uint8_t brightness) override;
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "board.h"
|
||||
#include "system_info.h"
|
||||
#include "settings.h"
|
||||
#include "display/no_display.h"
|
||||
#include "display/display.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_ota_ops.h>
|
||||
@@ -17,7 +18,7 @@ Board::Board() {
|
||||
uuid_ = GenerateUuid();
|
||||
settings.SetString("uuid", uuid_);
|
||||
}
|
||||
ESP_LOGI(TAG, "UUID: %s", uuid_.c_str());
|
||||
ESP_LOGI(TAG, "UUID=%s SKU=%s", uuid_.c_str(), BOARD_NAME);
|
||||
}
|
||||
|
||||
std::string Board::GenerateUuid() {
|
||||
@@ -99,6 +100,7 @@ std::string Board::GetJson() {
|
||||
*/
|
||||
std::string json = "{";
|
||||
json += "\"version\":2,";
|
||||
json += "\"language\":\"" + std::string(Lang::CODE) + "\",";
|
||||
json += "\"flash_size\":" + std::to_string(SystemInfo::GetFlashSize()) + ",";
|
||||
json += "\"minimum_free_heap_size\":" + std::to_string(SystemInfo::GetMinimumFreeHeapSize()) + ",";
|
||||
json += "\"mac_address\":\"" + SystemInfo::GetMacAddress() + "\",";
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "led/led.h"
|
||||
#include "backlight.h"
|
||||
|
||||
void* create_board();
|
||||
class AudioCodec;
|
||||
@@ -34,6 +35,7 @@ public:
|
||||
virtual ~Board() = default;
|
||||
virtual std::string GetBoardType() = 0;
|
||||
virtual std::string GetUuid() { return uuid_; }
|
||||
virtual Backlight* GetBacklight() { return nullptr; }
|
||||
virtual Led* GetLed();
|
||||
virtual AudioCodec* GetAudioCodec() = 0;
|
||||
virtual Display* GetDisplay();
|
||||
|
||||
@@ -3,6 +3,21 @@
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "Button";
|
||||
#if CONFIG_SOC_ADC_SUPPORTED
|
||||
Button::Button(const button_adc_config_t& adc_cfg) {
|
||||
button_config_t button_config = {
|
||||
.type = BUTTON_TYPE_ADC,
|
||||
.long_press_time = 1000,
|
||||
.short_press_time = 50,
|
||||
.adc_button_config = adc_cfg
|
||||
};
|
||||
button_handle_ = iot_button_create(&button_config);
|
||||
if (button_handle_ == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create button handle");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Button::Button(gpio_num_t gpio_num, bool active_high) : gpio_num_(gpio_num) {
|
||||
if (gpio_num == GPIO_NUM_NC) {
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
class Button {
|
||||
public:
|
||||
#if CONFIG_SOC_ADC_SUPPORTED
|
||||
Button(const button_adc_config_t& cfg);
|
||||
#endif
|
||||
Button(gpio_num_t gpio_num, bool active_high = false);
|
||||
~Button();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ I2cDevice::I2cDevice(i2c_master_bus_handle_t i2c_bus, uint8_t addr) {
|
||||
i2c_device_config_t i2c_device_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = addr,
|
||||
.scl_speed_hz = 100000,
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
.scl_wait_us = 0,
|
||||
.flags = {
|
||||
.disable_ack_check = 0,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "application.h"
|
||||
#include "display.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
#include "assets/zh/binary.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_timer.h>
|
||||
@@ -25,7 +25,7 @@ std::string Ml307Board::GetBoardType() {
|
||||
|
||||
void Ml307Board::StartNetwork() {
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetStatus("检测模组...");
|
||||
display->SetStatus(Lang::Strings::DETECTING_MODULE);
|
||||
modem_.SetDebug(false);
|
||||
modem_.SetBaudRate(921600);
|
||||
|
||||
@@ -45,13 +45,13 @@ void Ml307Board::StartNetwork() {
|
||||
void Ml307Board::WaitForNetworkReady() {
|
||||
auto& application = Application::GetInstance();
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetStatus("等待网络...");
|
||||
display->SetStatus(Lang::Strings::REGISTERING_NETWORK);
|
||||
int result = modem_.WaitForNetworkReady();
|
||||
if (result == -1) {
|
||||
application.Alert("PIN_ERROR", "请插入SIM卡", "sad", std::string_view(p3_err_pin_start, p3_err_pin_end - p3_err_pin_start));
|
||||
application.Alert(Lang::Strings::ERROR, Lang::Strings::PIN_ERROR, "sad", Lang::Sounds::P3_ERR_PIN);
|
||||
return;
|
||||
} else if (result == -2) {
|
||||
application.Alert("REG_ERROR", "无法接入网络,请检查流量卡状态", "sad", std::string_view(p3_err_reg_start, p3_err_reg_end - p3_err_reg_start));
|
||||
application.Alert(Lang::Strings::ERROR, Lang::Strings::REG_ERROR, "sad", Lang::Sounds::P3_ERR_REG);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ const char* Ml307Board::GetNetworkStateIcon() {
|
||||
|
||||
std::string Ml307Board::GetBoardJson() {
|
||||
// Set the board type for OTA
|
||||
std::string board_type = BOARD_TYPE;
|
||||
std::string board_json = std::string("{\"type\":\"" + board_type + "\",");
|
||||
std::string board_json = std::string("{\"type\":\"" BOARD_TYPE "\",");
|
||||
board_json += "\"name\":\"" BOARD_NAME "\",";
|
||||
board_json += "\"revision\":\"" + modem_.GetModuleName() + "\",";
|
||||
board_json += "\"carrier\":\"" + modem_.GetCarrierName() + "\",";
|
||||
board_json += "\"csq\":\"" + std::to_string(modem_.GetCsq()) + "\",";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user