@echo off
ECHO ==========================
ECHO ESP-IDF flashtool
ECHO ==========================
ECHO Available Com ports:
reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM
set /p port="Enter Com port (example: COM6): "
ECHO Menu :
ECHO 1. Upload Program and Delete Prev Data
ECHO 2. Upload Program 
ECHO 3. Serial Monitor
set /p firmware="Select Firmware type (1/2): "
if "%firmware%" == "1" (
	ECHO DELETE DATA
	Python313\python.exe components\esptool_py\esptool\esptool.py -p %port% erase_flash
	REM Menjalankan esptool untuk flashing ESP32-C6
	ECHO Installing New Firmware
	Python313\python.exe components\esptool_py\esptool\esptool.py -p %port% -b 460800 --before default_reset --after hard_reset --chip esp32c6 write_flash --flash_mode dio --flash_freq 40m --flash_size 8MB 0x0 build\bootloader\bootloader.bin 0x10000 build\Xl260-esp32C6.bin 0x8000 build\partition_table\partition-table.bin 0xe000 build\ota_data_initial.bin
	ECHO Done Installing New Firmware
	ECHO Opening Serial Monitor
	Python313\python.exe Python313\Lib\site-packages\serial\tools\miniterm.py %port% 115200
	pause
)
if "%firmware%" == "2" (
    ECHO.
    ECHO Install Firmware
    ECHO Installing New Firmware
	Python313\python.exe components\esptool_py\esptool\esptool.py -p %port% -b 460800 --before default_reset --after hard_reset --chip esp32c6 write_flash --flash_mode dio --flash_freq 40m --flash_size 8MB 0x0 build\bootloader\bootloader.bin 0x10000 build\Xl260-esp32C6.bin 0x8000 build\partition_table\partition-table.bin 0xe000 build\ota_data_initial.bin
	ECHO Done Installing New Firmware
	ECHO Opening Serial Monitor
	Python313\python.exe Python313\Lib\site-packages\serial\tools\miniterm.py %port% 115200
	pause
)
if "%firmware%" == "3" (
	ECHO ==========================
	ECHO Installing New Firmware
	ECHO Opening Serial Monitor
	Python313\python.exe Python313\Lib\site-packages\serial\tools\miniterm.py %port% 115200
	pause
)



