Better
This commit is contained in:
@@ -12,6 +12,7 @@ setlocal enabledelayedexpansion
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
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%
|
||||
@@ -19,11 +20,37 @@ if not exist "%CONFIG%" (
|
||||
)
|
||||
|
||||
:: -- Parse .anvil.toml ----------------------------------------------------
|
||||
for /f "tokens=1,* delims==" %%a in ('findstr /b "baud " "%CONFIG%"') do (
|
||||
set "BAUD=%%b"
|
||||
:: Read file directly, skip comments and section headers
|
||||
for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
||||
set "_K=%%a"
|
||||
if not "!_K:~0,1!"=="#" if not "!_K:~0,1!"=="[" (
|
||||
set "_K=!_K: =!"
|
||||
set "_V=%%b"
|
||||
if defined _V (
|
||||
set "_V=!_V: =!"
|
||||
set "_V=!_V:"=!"
|
||||
)
|
||||
if "!_K!"=="baud" set "BAUD=!_V!"
|
||||
)
|
||||
)
|
||||
set "BAUD=%BAUD: =%"
|
||||
set "BAUD=%BAUD:"=%"
|
||||
|
||||
:: -- Parse .anvil.local (machine-specific, not in git) --------------------
|
||||
set "LOCAL_PORT="
|
||||
if exist "%LOCAL_CONFIG%" (
|
||||
for /f "usebackq tokens=1,* delims==" %%a in ("%LOCAL_CONFIG%") do (
|
||||
set "_K=%%a"
|
||||
if not "!_K:~0,1!"=="#" (
|
||||
set "_K=!_K: =!"
|
||||
set "_V=%%b"
|
||||
if defined _V (
|
||||
set "_V=!_V: =!"
|
||||
set "_V=!_V:"=!"
|
||||
)
|
||||
if "!_K!"=="port" set "LOCAL_PORT=!_V!"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if "%BAUD%"=="" set "BAUD=115200"
|
||||
|
||||
:: -- Parse arguments ------------------------------------------------------
|
||||
@@ -54,21 +81,28 @@ if errorlevel 1 (
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: -- Auto-detect port -----------------------------------------------------
|
||||
:: -- Resolve port ---------------------------------------------------------
|
||||
:: Priority: -p flag > .anvil.local > auto-detect
|
||||
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"
|
||||
if not "%LOCAL_PORT%"=="" (
|
||||
set "PORT=!LOCAL_PORT!"
|
||||
echo info Using port !PORT! ^(from .anvil.local^)
|
||||
) else (
|
||||
:: Use PowerShell helper for reliable JSON-based detection
|
||||
for /f "delims=" %%p in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%_detect_port.ps1"') do (
|
||||
if "!PORT!"=="" set "PORT=%%p"
|
||||
)
|
||||
if "!PORT!"=="" (
|
||||
echo FAIL: No serial port detected. Specify with: monitor.bat -p COM3
|
||||
echo Or save a default: anvil devices --set COM3
|
||||
exit /b 1
|
||||
)
|
||||
echo warn Auto-detected port: !PORT! ^(use -p to override, or: anvil devices --set^)
|
||||
)
|
||||
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%"
|
||||
arduino-cli monitor -p %PORT% -c "baudrate=%BAUD%"
|
||||
Reference in New Issue
Block a user