Supporting multiple boards
This commit is contained in:
@@ -9,17 +9,19 @@ setlocal enabledelayedexpansion
|
||||
:: monitor.bat Open monitor (auto-detect port)
|
||||
:: monitor.bat -p COM3 Specify port
|
||||
:: monitor.bat -b 9600 Override baud rate
|
||||
:: monitor.bat --board mega Use baud from a named board
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "CONFIG=%SCRIPT_DIR%.anvil.toml"
|
||||
set "LOCAL_CONFIG=%SCRIPT_DIR%.anvil.local"
|
||||
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
||||
set "CONFIG=%SCRIPT_DIR%\.anvil.toml"
|
||||
set "LOCAL_CONFIG=%SCRIPT_DIR%\.anvil.local"
|
||||
|
||||
if not exist "%CONFIG%" (
|
||||
echo FAIL: No .anvil.toml found in %SCRIPT_DIR%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: -- Parse .anvil.toml ----------------------------------------------------
|
||||
:: -- Parse .anvil.toml (flat keys) ----------------------------------------
|
||||
for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
||||
set "_K=%%a"
|
||||
if not "!_K:~0,1!"=="#" if not "!_K:~0,1!"=="[" (
|
||||
@@ -29,11 +31,12 @@ for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
||||
set "_V=!_V: =!"
|
||||
set "_V=!_V:"=!"
|
||||
)
|
||||
if "!_K!"=="default" set "DEFAULT_BOARD=!_V!"
|
||||
if "!_K!"=="baud" set "BAUD=!_V!"
|
||||
)
|
||||
)
|
||||
|
||||
:: -- Parse .anvil.local (machine-specific, not in git) --------------------
|
||||
:: -- Parse .anvil.local ---------------------------------------------------
|
||||
set "LOCAL_PORT="
|
||||
set "LOCAL_VID_PID="
|
||||
if exist "%LOCAL_CONFIG%" (
|
||||
@@ -56,6 +59,7 @@ if "%BAUD%"=="" set "BAUD=115200"
|
||||
|
||||
:: -- Parse arguments ------------------------------------------------------
|
||||
set "PORT="
|
||||
set "BOARD_NAME="
|
||||
|
||||
:parse_args
|
||||
if "%~1"=="" goto done_args
|
||||
@@ -63,18 +67,54 @@ 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"=="--board" set "BOARD_NAME=%~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 Usage: monitor.bat [-p PORT] [-b BAUD] [--board NAME]
|
||||
echo Opens serial monitor. Baud rate from .anvil.toml.
|
||||
echo --board NAME selects a board from [boards.NAME].
|
||||
exit /b 0
|
||||
|
||||
:done_args
|
||||
|
||||
:: -- Resolve board --------------------------------------------------------
|
||||
if "%BOARD_NAME%"=="" set "BOARD_NAME=%DEFAULT_BOARD%"
|
||||
|
||||
set "BOARD_SECTION=[boards.%BOARD_NAME%]"
|
||||
set "IN_SECTION=0"
|
||||
set "BOARD_BAUD="
|
||||
for /f "usebackq tokens=*" %%L in ("%CONFIG%") do (
|
||||
set "_LINE=%%L"
|
||||
if "!_LINE!"=="!BOARD_SECTION!" (
|
||||
set "IN_SECTION=1"
|
||||
) else if "!IN_SECTION!"=="1" (
|
||||
if "!_LINE:~0,1!"=="[" (
|
||||
set "IN_SECTION=0"
|
||||
) else if not "!_LINE:~0,1!"=="#" (
|
||||
for /f "tokens=1,* delims==" %%a in ("!_LINE!") do (
|
||||
set "_BK=%%a"
|
||||
set "_BK=!_BK: =!"
|
||||
set "_BV=%%b"
|
||||
if defined _BV (
|
||||
set "_BV=!_BV: =!"
|
||||
set "_BV=!_BV:"=!"
|
||||
)
|
||||
if "!_BK!"=="baud" set "BOARD_BAUD=!_BV!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if not "!BOARD_BAUD!"=="" set "BAUD=!BOARD_BAUD!"
|
||||
|
||||
if not "%BOARD_NAME%"=="%DEFAULT_BOARD%" (
|
||||
echo ok Using board: %BOARD_NAME% -- baud: !BAUD!
|
||||
)
|
||||
|
||||
:: -- Preflight ------------------------------------------------------------
|
||||
where arduino-cli >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
@@ -85,7 +125,7 @@ if errorlevel 1 (
|
||||
:: -- Resolve port ---------------------------------------------------------
|
||||
:: Priority: -p flag > VID:PID resolve > saved port > auto-detect
|
||||
if "%PORT%"=="" (
|
||||
for /f "delims=" %%p in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%_detect_port.ps1" -VidPid "%LOCAL_VID_PID%" -SavedPort "%LOCAL_PORT%"') do (
|
||||
for /f "delims=" %%p in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%\_detect_port.ps1" -VidPid "%LOCAL_VID_PID%" -SavedPort "%LOCAL_PORT%"') do (
|
||||
if "!PORT!"=="" set "PORT=%%p"
|
||||
)
|
||||
if "!PORT!"=="" (
|
||||
|
||||
Reference in New Issue
Block a user