Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG DOCKER_TAG=latest
ARG DOCKER_TAG=v5.3.2
FROM espressif/idf:${DOCKER_TAG}

ENV LC_ALL=C.UTF-8
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and Release

on:
push:
tags:
- 'v*' # 匹配 v 开头的标签,如 v1.0.0

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get tag name
id: tag
run: echo "name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Build MOTORS_4 version
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.3.2
target: esp32c3
command: |
idf.py build -DMOTOR_CONFIG=MOTORS_4 && \
python -m esptool --chip esp32c3 merge_bin -o Top-AMS-MOTORS_4.bin \
--flash_mode dio --flash_freq 80m --flash_size 4MB \
0x0 build/bootloader/bootloader.bin \
0x10000 build/Top-AMS.bin \
0x8000 build/partition_table/partition-table.bin && \
rm -rf build

- name: Build MOTORS_6 version
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.3.2
target: esp32c3
command: |
idf.py build -DMOTOR_CONFIG=MOTORS_6 && \
python -m esptool --chip esp32c3 merge_bin -o Top-AMS-MOTORS_6.bin \
--flash_mode dio --flash_freq 80m --flash_size 4MB \
0x0 build/bootloader/bootloader.bin \
0x10000 build/Top-AMS.bin \
0x8000 build/partition_table/partition-table.bin && \
rm -rf build

- name: Build MOTORS_8 version
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.3.2
target: esp32c3
command: |
idf.py build -DMOTOR_CONFIG=MOTORS_8 && \
python -m esptool --chip esp32c3 merge_bin -o Top-AMS-MOTORS_8.bin \
--flash_mode dio --flash_freq 80m --flash_size 4MB \
0x0 build/bootloader/bootloader.bin \
0x10000 build/Top-AMS.bin \
0x8000 build/partition_table/partition-table.bin

- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag.outputs.name }}
name: Release ${{ steps.tag.outputs.name }}
body: |
## 版本说明

本次发布包含以下三个版本的固件:
- **MOTORS_4**: 4通道版本
- **MOTORS_6**: 6通道版本
- **MOTORS_8**: 8通道版本(其它)

## 使用说明

请根据您的硬件配置选择对应的固件进行刷入。
files: |
Top-AMS-MOTORS_4.bin
Top-AMS-MOTORS_6.bin
Top-AMS-MOTORS_8.bin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ managed_components/
localconfig.hpp
temp/
main/index.hpp
Top-AMS.bin
Top-AMS.bin
.DS_Store
20 changes: 20 additions & 0 deletions doc/编译教程.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
idf.py build
```
首次编译耗时会比较长

**可选:指定电机通道配置**

如果需要编译特定的电机通道版本,可以通过 CMake 参数指定:

- 编译 4 通道版本:
```bash
idf.py build -DMOTOR_CONFIG=MOTORS_4
```

- 编译 6 通道版本:
```bash
idf.py build -DMOTOR_CONFIG=MOTORS_6
```

- 编译 8 通道版本(默认):
```bash
idf.py build -DMOTOR_CONFIG=MOTORS_8
```
或直接使用 `idf.py build`(不传参数默认为 8 通道)
7. 连接设备并烧录
```bash
idf.py -p PORT flash
Expand Down
35 changes: 33 additions & 2 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,42 @@ idf_component_register(
# "../managed_components/s00500_ESPUI/src"
)

# 根据 MOTOR_CONFIG 变量定义相应的宏
if(DEFINED MOTOR_CONFIG)
if(MOTOR_CONFIG STREQUAL "MOTORS_4")
target_compile_definitions(${COMPONENT_LIB} PRIVATE MOTORS_4)
message(STATUS "Building with MOTORS_4 configuration")
elseif(MOTOR_CONFIG STREQUAL "MOTORS_6")
target_compile_definitions(${COMPONENT_LIB} PRIVATE MOTORS_6)
message(STATUS "Building with MOTORS_6 configuration")
elseif(MOTOR_CONFIG STREQUAL "MOTORS_8")
# MOTORS_8 不定义任何宏,使用默认配置
message(STATUS "Building with MOTORS_8 configuration (default)")
else()
message(WARNING "Unknown MOTOR_CONFIG value: ${MOTOR_CONFIG}, using default (MOTORS_8)")
endif()
else()
# 如果没有指定 MOTOR_CONFIG,使用默认的 MOTORS_8 配置
message(STATUS "No MOTOR_CONFIG specified, using default (MOTORS_8)")
endif()

# 确定通道数量
if(DEFINED MOTOR_CONFIG)
if(MOTOR_CONFIG STREQUAL "MOTORS_4")
set(CHANNEL_COUNT 4)
elseif(MOTOR_CONFIG STREQUAL "MOTORS_6")
set(CHANNEL_COUNT 6)
else()
set(CHANNEL_COUNT 8) # MOTORS_8 或默认
endif()
else()
set(CHANNEL_COUNT 8) # 默认8通道
endif()

# 添加自定义目标执行Python脚本
add_custom_target(
run_helloworld ALL # ALL表示包含在默认构建目标中
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH= python ${CMAKE_CURRENT_SOURCE_DIR}/convert_html_to_hpp.py
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH= MOTOR_CONFIG=${MOTOR_CONFIG} CHANNEL_COUNT=${CHANNEL_COUNT} python ${CMAKE_CURRENT_SOURCE_DIR}/convert_html_to_hpp.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} # 设置工作目录为脚本所在位置
COMMENT "RUN convert_html_to_hpp.py..." # 可选:添加构建时的提示信息
COMMENT "RUN convert_html_to_hpp.py with CHANNEL_COUNT=${CHANNEL_COUNT}..." # 可选:添加构建时的提示信息
)
20 changes: 17 additions & 3 deletions main/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


#include "web_sync.hpp"
// #define MOTORS_6// 使用当前配置(6通道)注释掉就是8通道
// #define MOTORS_4 // 使用4通道配置
// #define MOTORS_6 // 使用6通道配置
// 默认8通道配置
// #define LOCAL_CONFIG

namespace config {
Expand Down Expand Up @@ -45,7 +47,9 @@ namespace config {
//**********************用户配置区开始******************************


#ifdef MOTORS_6
#ifdef MOTORS_4
inline gpio_num_t forward_click = GPIO_NUM_7;//进料微动
#elif defined(MOTORS_6)
inline gpio_num_t forward_click = GPIO_NUM_4;//进料微动
#else
inline gpio_num_t forward_click = GPIO_NUM_7;
Expand All @@ -60,7 +64,17 @@ namespace config {


inline std::array<motor, 8> motors{
#ifdef MOTORS_6
#ifdef MOTORS_4
// 4通道配置
motor{1, GPIO_NUM_2, GPIO_NUM_3},// 通道1
motor{2, GPIO_NUM_10, GPIO_NUM_6},// 通道2
motor{3, GPIO_NUM_5, GPIO_NUM_4},// 通道3
motor{4, GPIO_NUM_8, GPIO_NUM_9},// 通道4
motor{5, GPIO_NUM_NC, GPIO_NUM_NC},// 通道5(未使用)
motor{6, GPIO_NUM_NC, GPIO_NUM_NC},// 通道6(未使用)
motor{7, GPIO_NUM_NC, GPIO_NUM_NC},// 通道7(未使用)
motor{8, GPIO_NUM_NC, GPIO_NUM_NC}// 通道8(未使用)
#elif defined(MOTORS_6)
// 当前配置(6通道)
motor{1, GPIO_NUM_1, GPIO_NUM_0},// 通道1
motor{2, GPIO_NUM_19, GPIO_NUM_18},// 通道2
Expand Down
18 changes: 15 additions & 3 deletions main/convert_html_to_hpp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
convert_html_to_hpp.py
功能:将HTML文件转换为HPP头文件,并添加自定义头尾注释
根据MOTOR_CONFIG环境变量动态调整通道数量
"""

import argparse
import os

def convert_html_to_hpp(input_file, output_file, header_str="", footer_str=""):
def convert_html_to_hpp(input_file, output_file, header_str="", footer_str="", channel_count=8):
try:
# 读取并处理HTML内容
processed_lines = []
Expand All @@ -31,19 +33,25 @@ def convert_html_to_hpp(input_file, output_file, header_str="", footer_str=""):
# 将所有行合并为单个字符串(无换行符)
compressed_html = ''.join(processed_lines)

# 替换通道数量占位符
compressed_html = compressed_html.replace('CHANNEL_COUNT_PLACEHOLDER', str(channel_count))

# 拼接新内容
new_content = f"{header_str}\n{compressed_html}\n{footer_str}"

# 写入HPP文件
with open(output_file, 'w', encoding='utf-8') as f:
f.write(new_content)

print(f"转换成功!生成文件: {output_file}")
print(f"转换成功!生成文件: {output_file} (通道数: {channel_count})")

except Exception as e:
print(f"错误: {str(e)}")

if __name__ == "__main__":
# 从环境变量获取通道数量,默认为8
channel_count = int(os.environ.get('CHANNEL_COUNT', '8'))

parser = argparse.ArgumentParser(description="HTML转HPP工具")
parser.add_argument('-i', '--input', default='index.html', help='输入文件路径')
parser.add_argument('-o', '--output', default='index.hpp', help='输出文件路径')
Expand All @@ -58,12 +66,16 @@ def convert_html_to_hpp(input_file, output_file, header_str="", footer_str=""):
')rawliteral";',
help='尾部自定义字符串')

parser.add_argument('--channels', type=int, default=channel_count,
help=f'通道数量 (默认: {channel_count}, 从环境变量CHANNEL_COUNT读取)')

args = parser.parse_args()

convert_html_to_hpp(
input_file=args.input,
output_file=args.output,
header_str=args.header,
footer_str=args.footer
footer_str=args.footer,
channel_count=args.channels
)

51 changes: 29 additions & 22 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,6 @@ <h4><i class="fas fa-terminal"></i> 系统运行日志</h4>
<label for="extruder">当前通道:</label>
<select class="material-select" id="extruder" onchange="sendKeyValue('extruder', this.value)">
<option value="0">无耗材</option>
<option value="1">通道 1</option>
<option value="2">通道 2</option>
<option value="3">通道 3</option>
<option value="4">通道 4</option>
<option value="5">通道 5</option>
<option value="6">通道 6</option>
<option value="7">通道 7</option>
<option value="8">通道 8</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -649,21 +641,26 @@ <h4><i class="fas fa-terminal"></i> 系统运行日志</h4>
</div>

<script>
const channels = [
{ id: 1, color: "#3498db", name: "PLA" },
{ id: 2, color: "#e74c3c", name: "PETG" },
{ id: 3, color: "#2ecc71", name: "ABS" },
{ id: 4, color: "#f1c40f", name: "TPU" },
{ id: 5, color: "#9b59b6", name: "PLA" },
{ id: 6, color: "#1abc9c", name: "PETG" },
{ id: 7, color: "#e67e22", name: "ABS" },
{ id: 8, color: "#34495e", name: "TPU" }
];

//生成下拉框选项
// 通道配置:由 Python 脚本传入
const CHANNEL_COUNT = CHANNEL_COUNT_PLACEHOLDER;

// 预设颜色数组
const COLOR_PRESETS = ["#3498db", "#e74c3c", "#2ecc71", "#f1c40f", "#9b59b6", "#1abc9c", "#e67e22", "#34495e"];

// 预设材料名称数组
const MATERIAL_NAMES = ["PLA", "PETG", "ABS", "TPU"];

// 自动生成 channels 数组
const channels = Array.from({ length: CHANNEL_COUNT }, (_, index) => ({
id: index + 1,
color: COLOR_PRESETS[index % COLOR_PRESETS.length],
name: MATERIAL_NAMES[index % MATERIAL_NAMES.length]
}));

// 生成下拉框选项
function createOptions(selectedId) {
let opts = "";
for (let i = 1; i <= 8; i++) {
for (let i = 1; i <= CHANNEL_COUNT; i++) {
opts += `<option value="${i}" ${i === selectedId ? "selected" : ""}>通道 ${i}</option>`;
}
return opts;
Expand Down Expand Up @@ -843,8 +840,18 @@ <h4><i class="fas fa-terminal"></i> 系统运行日志</h4>
sendKeyValue(this.id, this.value);
}

// 初始化状态指示器
// 初始化状态指示器和通道选择下拉框
document.addEventListener('DOMContentLoaded', function () {
// 初始化通道选择下拉框
const extruderSelect = document.getElementById("extruder");
for (let i = 1; i <= CHANNEL_COUNT; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = `通道 ${i}`;
extruderSelect.appendChild(option);
}

// 初始化状态指示器
espDot.classList.add('disconnected');
mqttDot.classList.add('disconnected');
addLog('AMS控制台已加载', 'success');
Expand Down