# CTR2-Flex Programmer for Linux and Mac.  Should also work on MSWindows
# MUST have python3 and pip installed
# Lou Scalpati KI5FTY
# >>>> REMEMBER TO MAKE THIS FILE EXECUTABLE <<<<

PYTHON=python3
CHIP=esp32s3

#-----------------------------------------------
# Replace the PORT and DIR variables below to fit your system
#-----------------------------------------------
# Begin Edit

PORT=/dev/<YOUR-USB-DEVICE>
DIR=<DIRECTORY-CONTAINING-FILES>


# End Edit
#------------------------------------------------

pip -q install esptool

read -rsn1 -p "Hold down ENCODER and press any key to continue" 

$PYTHON -m esptool --chip $CHIP --port $PORT  write_flash -z 0x0 $DIR/CTR2-Flex.ino.bootloader_0x0.bin
$PYTHON -m esptool --chip $CHIP --port $PORT  write_flash -z 0x8000 $DIR/CTR2-Flex.ino.partitions_0x8000.bin
$PYTHON -m esptool --chip $CHIP --port $PORT  write_flash -z 0xe000 $DIR/boot_app0_0xe000.bin
$PYTHON -m esptool --chip $CHIP --port $PORT  write_flash -z 0x10000 $DIR/CTR2-Flex.ino_0x10000.bin
