cli-install.bat 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 Ensure your Flipper Zero is plugged in via USB before continuing.
  37. pause
  38. echo Ready for installation...
  39. if not exist "%COMPILE_FLAG%" (
  40. set /p USE_DEFAULT_BOARD="Install to default AI-Thinker ESP32-CAM board with FQBN '%DEFAULT_BOARD_FQBN%'? (Y/N): "
  41. if /i "%USE_DEFAULT_BOARD%"=="N" (
  42. echo Warning - This script has not been tested with other boards. Please use at your own risk.
  43. set /p SHOW_BOARDS="Display all possible ESP32 board names and FQBN's? (Y/N): "
  44. if /i "!SHOW_BOARDS!"=="Y" (
  45. echo.
  46. arduino-cli board listall
  47. )
  48. set /p SELECTED_BOARD="Please enter your board FQBN. For example '%DEFAULT_BOARD_FQBN%' with no quotes: "
  49. )
  50. goto :compileFirmware
  51. )
  52. if exist "%COMPILE_FLAG%" (
  53. set /p RECOMPILE="A previous firmware build was found, would you like to use it? (Y/N): "
  54. if /i "!RECOMPILE!"=="N" (
  55. goto :compileFirmware
  56. )
  57. )
  58. :continue
  59. echo.
  60. arduino-cli board list
  61. echo Please find your Flipper Zero USB port from the list above (may show as unknown).
  62. set /p PORT_NUMBER="Enter it here. For example 'COM3' capitalized with no quotes: "
  63. echo.
  64. echo Your ESP32-CAM is ready to be flashed. Please follow the instructions below.
  65. :uploadFirmware
  66. echo.
  67. echo 1. Make sure you've grounded your IO0 pin on your ESP32-CAM module to the correct GND pin.
  68. echo 2. Plug in your ESP32-CAM module with the reset button pressed a few seconds before continuing to the next step.
  69. echo 3. When continuing to the next step, simultaneously release the reset button.
  70. echo 4. Your ESP32-CAM should now be in flash mode. Allow the firmware to upload, this will take a moment.
  71. echo 5. It's not uncommon for this to fail many times, keep trying and double check your connections.
  72. echo.
  73. pause
  74. set RETRY_COUNT=1
  75. :uploadLoop
  76. echo.
  77. echo Preparing firmware upload... Attempt number !RETRY_COUNT!...
  78. arduino-cli %CONFIG_FILE% upload -p %PORT_NUMBER% --fqbn !SELECTED_BOARD! ..\firmware.ino
  79. if !ERRORLEVEL! EQU 0 (
  80. goto :uploadSuccess
  81. ) else (
  82. if !RETRY_COUNT! lss 3 (
  83. set /a RETRY_COUNT+=1
  84. goto :uploadLoop
  85. ) else (
  86. echo.
  87. set /p UPLOAD_TRY_AGAIN="Upload failed after 3 attempts, would you like to retry? (Y/N): "
  88. if /i "!UPLOAD_TRY_AGAIN!"=="Y" (
  89. set RETRY_COUNT=1
  90. goto :uploadFirmware
  91. ) else (
  92. echo.
  93. echo If you're still having issues, feel free to open a ticket at the following link:
  94. echo https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues
  95. )
  96. )
  97. )
  98. :uploadSuccess
  99. echo.
  100. echo Firmware upload was successful.
  101. echo.
  102. echo Fin. Happy programming friend.
  103. echo.
  104. pause
  105. exit /b
  106. :compileFirmware
  107. echo Compiling firmware, this will take a moment...
  108. arduino-cli %CONFIG_FILE% compile --fqbn !SELECTED_BOARD! ..\firmware.ino
  109. if %ERRORLEVEL% EQU 0 (
  110. echo Compile complete. Ready to upload.
  111. type nul > %COMPILE_FLAG%
  112. ) else (
  113. echo Compilation failed. Please correct the errors and try again.
  114. exit /b
  115. )
  116. goto :continue