diff --git a/README.md b/README.md index 62d3d49..2ea8d43 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ wled effects wled effects rainbow wled presets wled set --color blue --range 70-80 --brightness 50% +wled set --color green --range 90-100 --effect blink --rest-color white wled set --hex '#00ff88' --effect solid wled set --preset 1 wled raw /json/info @@ -64,6 +65,7 @@ wled raw /json/info - `--range` is **1-based inclusive**. So `70-80` means LEDs 70 through 80. - `--brightness` accepts `1-255` or a percentage like `50%`. +- `--rest-color` / `--rest-hex` lets you paint the LEDs outside the selected range in one shot. - `--effect` accepts a numeric id or a fuzzy name match. - `--preset` accepts a numeric id or a fuzzy preset name match. - For new integrations, prefer WLED's JSON API docs: https://kno.wled.ge/interfaces/json-api/ diff --git a/bin/wled.js b/bin/wled.js index a314a25..84c300e 100755 --- a/bin/wled.js +++ b/bin/wled.js @@ -36,6 +36,8 @@ Options: --range 1-based inclusive LED range, e.g. 70-80 --color Named color or hex color --hex <#RRGGBB> Hex color shortcut + --rest-color Paint LEDs outside --range with a named or hex color + --rest-hex <#RRGGBB> Hex shortcut for --rest-color --brightness 1-255 or percentage like 50% --effect Effect name or numeric effect id --preset Preset name or numeric preset id @@ -46,6 +48,7 @@ Options: Examples: wled on wled set --color blue --range 70-80 --brightness 50% + wled set --color green --range 90-100 --effect blink --rest-color white wled set --hex '#00ff88' --effect solid wled effects rainbow wled presets @@ -201,10 +204,13 @@ async function buildState(baseUrl, options, command) { if (preset != null) payload.ps = preset; const color = parseColor(options.color ?? options.hex); + const restColor = parseColor(options['rest-color'] ?? options['rest-hex']); const effect = await resolveEffect(baseUrl, options.effect); const range = parseRange(options.range); const segmentId = options.segment != null ? Number.parseInt(options.segment, 10) : 0; + if (restColor && !range) fail('--rest-color requires --range'); + const segment = { id: segmentId }; let needsSegment = false; @@ -222,7 +228,44 @@ async function buildState(baseUrl, options, command) { needsSegment = true; } - if (needsSegment) payload.seg = [segment]; + if (needsSegment) { + if (range && restColor) { + const info = await apiGet(baseUrl, '/json/info'); + const ledCount = info?.leds?.count; + if (!Number.isInteger(ledCount) || ledCount < 1) fail('Could not determine LED count for --rest-color'); + if (range.stop > ledCount) fail(`Range end ${range.stop} exceeds LED count ${ledCount}`); + + const segments = []; + let nextId = 0; + + if (range.start > 0) { + segments.push({ + id: nextId++, + start: 0, + stop: range.start, + col: [restColor], + fx: 0, + }); + } + + segments.push({ ...segment, id: nextId++ }); + + if (range.stop < ledCount) { + segments.push({ + id: nextId++, + start: range.stop, + stop: ledCount, + col: [restColor], + fx: 0, + }); + } + + payload.mainseg = 0; + payload.seg = segments; + } else { + payload.seg = [segment]; + } + } return payload; }