cli-install.bat 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. set CLI_TEMP=%TEMP%\arduino-cli
  4. set CONFIG_FILE=--config-file .\arduino-cli.yaml
  5. set DEFAULT_BOARD_FQBN=esp32:esp32:esp32cam
  6. set SELECTED_BOARD=%DEFAULT_BOARD_FQBN%
  7. set CLI_FOUND_FOLLOW_UP=0
  8. set COMPILE_FLAG=compile.flag
  9. echo Initializing...
  10. :checkCLI
  11. if not exist "arduino-cli.exe" (
  12. echo The "arduino-cli.exe" file cannot be found. Please download it manually from the following link:
  13. echo https://arduino.github.io/arduino-cli/latest/installation/#download
  14. set /a CLI_FOUND_FOLLOW_UP+=1
  15. if %CLI_FOUND_FOLLOW_UP% geq 2 (
  16. echo If you're still having issues, feel free to open a ticket at the following link:
  17. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  18. )
  19. pause
  20. goto :checkCLI
  21. )
  22. if %CLI_FOUND_FOLLOW_UP% geq 1 (
  23. echo File "arduino-cli.exe" found. Continuing...
  24. )
  25. echo Checking configs...
  26. arduino-cli %CONFIG_FILE% config set directories.data %CLI_TEMP%\data
  27. arduino-cli %CONFIG_FILE% config set directories.downloads %CLI_TEMP%\downloads
  28. arduino-cli %CONFIG_FILE% config set directories.user %CLI_TEMP%\user %*
  29. echo Fetching assets...
  30. if not exist "%CLI_TEMP%" (
  31. arduino-cli %CONFIG_FILE% core update-index
  32. arduino-cli %CONFIG_FILE% core install esp32:esp32
  33. ) else (
  34. echo Assets already installed. Skipping...
  35. )
  36. echo.
  37. echo -------------------------------------------------------------------------
  38. echo Make sure your Flipper Zero is plugged in via a transfer capable USB.
  39. echo Then on your Flipper Zero, open the GPIO menu and select USB-UART Bridge.
  40. echo If you have already done this, you may skip this step.
  41. echo -------------------------------------------------------------------------
  42. echo.
  43. pause
  44. echo.
  45. echo Ready for installation...
  46. if not exist "%COMPILE_FLAG%" (
  47. set /p USE_DEFAULT_BOARD="Install to default AI-Thinker ESP32-CAM board with FQBN '%DEFAULT_BOARD_FQBN%'? (Y/N): "
  48. if /i "%USE_DEFAULT_BOARD%"=="N" (
  49. echo Warning - This script has not been tested with other boards. Please use at your own risk.
  50. set /p SHOW_BOARDS="Display all possible ESP32 board names and FQBN's? (Y/N): "
  51. if /i "!SHOW_BOARDS!"=="Y" (
  52. echo.
  53. arduino-cli board listall
  54. )
  55. set /p SELECTED_BOARD="Please enter your board FQBN. For example '%DEFAULT_BOARD_FQBN%' with no quotes: "
  56. )
  57. goto :compileFirmware
  58. )
  59. if exist "%COMPILE_FLAG%" (
  60. set /p RECOMPILE="A previous firmware build was found, would you like to use it? (Y/N): "
  61. if /i "!RECOMPILE!"=="N" (
  62. goto :compileFirmware
  63. )
  64. )
  65. :continue
  66. echo.
  67. arduino-cli board list
  68. echo Please find your Flipper Zero USB port from the list above (may show as unknown).
  69. set /p PORT_NUMBER="Enter it here. For example 'COM3' capitalized with no quotes: "
  70. echo.
  71. echo Your ESP32-CAM is ready to be flashed. Please follow the instructions below.
  72. :uploadFirmware
  73. echo.
  74. echo 1. Make sure you've grounded your IO0 pin on your ESP32-CAM module to the correct GND pin.
  75. echo 2. Plug in your ESP32-CAM module with the reset button pressed a few seconds before continuing to the next step.
  76. echo 3. When continuing to the next step, simultaneously release the reset button.
  77. echo 4. Your ESP32-CAM should now be in flash mode. Allow the firmware to upload, this will take a moment.
  78. echo 5. It's not uncommon for this to fail many times, keep trying and double check your connections.
  79. echo.
  80. pause
  81. set RETRY_COUNT=1
  82. :uploadLoop
  83. echo.
  84. echo Preparing firmware upload... Attempt number !RETRY_COUNT!...
  85. arduino-cli %CONFIG_FILE% upload -p %PORT_NUMBER% --fqbn !SELECTED_BOARD! ..\firmware.ino
  86. if !ERRORLEVEL! EQU 0 (
  87. goto :uploadSuccess
  88. ) else (
  89. if !RETRY_COUNT! lss 3 (
  90. set /a RETRY_COUNT+=1
  91. goto :uploadLoop
  92. ) else (
  93. echo.
  94. set /p UPLOAD_TRY_AGAIN="Upload failed after 3 attempts, would you like to retry? (Y/N): "
  95. if /i "!UPLOAD_TRY_AGAIN!"=="Y" (
  96. set RETRY_COUNT=1
  97. goto :uploadFirmware
  98. ) else (
  99. echo.
  100. echo If you're still having issues, feel free to open a ticket at the following link:
  101. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  102. )
  103. )
  104. )
  105. :uploadSuccess
  106. echo.
  107. echo Firmware upload was successful.
  108. echo.
  109. echo Fin. Happy programming friend.
  110. echo.
  111. pause
  112. exit /b
  113. :compileFirmware
  114. echo Compiling firmware, this will take a moment...
  115. arduino-cli %CONFIG_FILE% compile --fqbn !SELECTED_BOARD! ..\firmware.ino
  116. if %ERRORLEVEL% EQU 0 (
  117. echo Compile complete. Ready to upload.
  118. type nul > %COMPILE_FLAG%
  119. ) else (
  120. echo Compilation failed. Please correct the errors and try again.
  121. exit /b
  122. )
  123. goto :continue