diff --git a/__admin/multidevices_write2.sh b/__admin/multidevices_write2.sh new file mode 100755 index 0000000..50770d6 --- /dev/null +++ b/__admin/multidevices_write2.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +source ../lib.sh + +BUILD_TOOL=$(lib_get_esptool_command) + +allports=$(lib_detect_allports) +if [ -z "$allports" ]; then + lib_no_esp_device_message_and_exit +fi +echo "Detected ports:" +echo "$allports" + +# allports に対して、1つずつ書き込んでいく + +# Define the paths to the firmware files +BUILD_PATH="../FactoryTest/build/esp32.esp32.m5stack_stickc_plus2" +BOOTLOADER_PATH="$BUILD_PATH/FactoryTest.ino.bootloader.bin" +PARTITIONS_PATH="$BUILD_PATH/FactoryTest.ino.partitions.bin" +FIRMWARE_PATH="$BUILD_PATH/FactoryTest.ino.bin" + +for port in ${allports} ; do + echo "Flashing port: $port" + $BUILD_TOOL --chip esp32 --port "$port" --baud 460800 write-flash -z \ + 0x1000 "$BOOTLOADER_PATH" \ + 0x8000 "$PARTITIONS_PATH" \ + 0x10000 "$FIRMWARE_PATH" && echo "Flashing completed." + +done diff --git a/lib.sh b/lib.sh index ad0b319..2ca7f59 100644 --- a/lib.sh +++ b/lib.sh @@ -96,6 +96,30 @@ echo "$PORT" } +lib_detect_allports() { + local OS_TYPE=$(uname -s) + case "$OS_TYPE" in + "Darwin") # macOS + ls /dev/cu.usbserial* /dev/cu.usbmodem* /dev/cu.wchusbserial* 2>/dev/null + ;; + "Linux") # Linux + ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null + ;; + "CYGWIN"*|"MINGW"*|"MSYS"*) # Windows (Git Bash, Cygwin, etc.) + for num in {3..20}; do + if [ -e "/dev/ttyS$((num-1))" ]; then + echo "COM$num" + fi + done + ;; + *) + echo "Unknown OS: $OS_TYPE" + echo "Please manually specify the port using PORT environment variable" + echo "Example: PORT=/dev/ttyUSB0 $0" + ;; + esac +} + lib_no_esp_device_message_and_exit(){ echo "No ESP device found automatically." echo "Please connect your ESP device and ensure drivers are installed."