diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dafb8ad..27d1459 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2d89957 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} + diff --git a/.gitignore b/.gitignore index e4c961a..eb3b7c6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ managed_components/ localconfig.hpp temp/ main/index.hpp -Top-AMS.bin \ No newline at end of file +Top-AMS.bin +.DS_Store \ No newline at end of file diff --git "a/doc/\347\274\226\350\257\221\346\225\231\347\250\213.md" "b/doc/\347\274\226\350\257\221\346\225\231\347\250\213.md" index 9757c64..a65f2cd 100644 --- "a/doc/\347\274\226\350\257\221\346\225\231\347\250\213.md" +++ "b/doc/\347\274\226\350\257\221\346\225\231\347\250\213.md" @@ -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 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ded3a4a..95aa06e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -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}..." # 可选:添加构建时的提示信息 ) \ No newline at end of file diff --git a/main/config.hpp b/main/config.hpp index 3a5f68f..ca37f1d 100644 --- a/main/config.hpp +++ b/main/config.hpp @@ -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 { @@ -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; @@ -60,7 +64,17 @@ namespace config { inline std::array 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 diff --git a/main/convert_html_to_hpp.py b/main/convert_html_to_hpp.py index 701cf6b..b10f5fd 100644 --- a/main/convert_html_to_hpp.py +++ b/main/convert_html_to_hpp.py @@ -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 = [] @@ -31,6 +33,9 @@ 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}" @@ -38,12 +43,15 @@ def convert_html_to_hpp(input_file, output_file, header_str="", footer_str=""): 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='输出文件路径') @@ -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 ) diff --git a/main/index.html b/main/index.html index 11e4f4a..87f0194 100644 --- a/main/index.html +++ b/main/index.html @@ -559,14 +559,6 @@

系统运行日志

@@ -649,21 +641,26 @@

系统运行日志