Placing scripts in the generated project
This commit is contained in:
74
templates/basic/monitor.bat
Normal file
74
templates/basic/monitor.bat
Normal file
@@ -0,0 +1,74 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: monitor.bat -- Open the serial monitor
|
||||
::
|
||||
:: Reads baud rate from .anvil.toml. No Anvil binary required.
|
||||
::
|
||||
:: Usage:
|
||||
:: monitor.bat Open monitor (auto-detect port)
|
||||
:: monitor.bat -p COM3 Specify port
|
||||
:: monitor.bat -b 9600 Override baud rate
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "CONFIG=%SCRIPT_DIR%.anvil.toml"
|
||||
|
||||
if not exist "%CONFIG%" (
|
||||
echo FAIL: No .anvil.toml found in %SCRIPT_DIR%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: -- Parse .anvil.toml ----------------------------------------------------
|
||||
for /f "tokens=1,* delims==" %%a in ('findstr /b "baud " "%CONFIG%"') do (
|
||||
set "BAUD=%%b"
|
||||
)
|
||||
set "BAUD=%BAUD: =%"
|
||||
set "BAUD=%BAUD:"=%"
|
||||
if "%BAUD%"=="" set "BAUD=115200"
|
||||
|
||||
:: -- Parse arguments ------------------------------------------------------
|
||||
set "PORT="
|
||||
|
||||
:parse_args
|
||||
if "%~1"=="" goto done_args
|
||||
if "%~1"=="-p" set "PORT=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--port" set "PORT=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="-b" set "BAUD=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--baud" set "BAUD=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--help" goto show_help
|
||||
if "%~1"=="-h" goto show_help
|
||||
echo FAIL: Unknown option: %~1
|
||||
exit /b 1
|
||||
|
||||
:show_help
|
||||
echo Usage: monitor.bat [-p PORT] [-b BAUD]
|
||||
echo Opens serial monitor. Baud rate from .anvil.toml.
|
||||
exit /b 0
|
||||
|
||||
:done_args
|
||||
|
||||
:: -- Preflight ------------------------------------------------------------
|
||||
where arduino-cli >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo FAIL: arduino-cli not found in PATH.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: -- Auto-detect port -----------------------------------------------------
|
||||
if "%PORT%"=="" (
|
||||
for /f "tokens=1" %%p in ('arduino-cli board list 2^>nul ^| findstr /i "serial" ^| findstr /n "." ^| findstr "^1:"') do (
|
||||
set "PORT=%%p"
|
||||
)
|
||||
set "PORT=!PORT:1:=!"
|
||||
if "!PORT!"=="" (
|
||||
echo FAIL: No serial port detected. Specify with: monitor.bat -p COM3
|
||||
exit /b 1
|
||||
)
|
||||
echo warn Auto-detected port: !PORT! (use -p to override)
|
||||
)
|
||||
|
||||
:: -- Monitor --------------------------------------------------------------
|
||||
echo Opening serial monitor on %PORT% at %BAUD% baud...
|
||||
echo Press Ctrl+C to exit.
|
||||
echo.
|
||||
arduino-cli monitor -p %PORT% -c "baudrate=%BAUD%"
|
||||
Reference in New Issue
Block a user