Add rest-color range support
This commit is contained in:
@@ -55,6 +55,7 @@ wled effects
|
|||||||
wled effects rainbow
|
wled effects rainbow
|
||||||
wled presets
|
wled presets
|
||||||
wled set --color blue --range 70-80 --brightness 50%
|
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 --hex '#00ff88' --effect solid
|
||||||
wled set --preset 1
|
wled set --preset 1
|
||||||
wled raw /json/info
|
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.
|
- `--range` is **1-based inclusive**. So `70-80` means LEDs 70 through 80.
|
||||||
- `--brightness` accepts `1-255` or a percentage like `50%`.
|
- `--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.
|
- `--effect` accepts a numeric id or a fuzzy name match.
|
||||||
- `--preset` accepts a numeric id or a fuzzy preset 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/
|
- For new integrations, prefer WLED's JSON API docs: https://kno.wled.ge/interfaces/json-api/
|
||||||
|
|||||||
45
bin/wled.js
45
bin/wled.js
@@ -36,6 +36,8 @@ Options:
|
|||||||
--range <start-end> 1-based inclusive LED range, e.g. 70-80
|
--range <start-end> 1-based inclusive LED range, e.g. 70-80
|
||||||
--color <name|#RRGGBB> Named color or hex color
|
--color <name|#RRGGBB> Named color or hex color
|
||||||
--hex <#RRGGBB> Hex color shortcut
|
--hex <#RRGGBB> Hex color shortcut
|
||||||
|
--rest-color <color> Paint LEDs outside --range with a named or hex color
|
||||||
|
--rest-hex <#RRGGBB> Hex shortcut for --rest-color
|
||||||
--brightness <value> 1-255 or percentage like 50%
|
--brightness <value> 1-255 or percentage like 50%
|
||||||
--effect <name|id> Effect name or numeric effect id
|
--effect <name|id> Effect name or numeric effect id
|
||||||
--preset <name|id> Preset name or numeric preset id
|
--preset <name|id> Preset name or numeric preset id
|
||||||
@@ -46,6 +48,7 @@ Options:
|
|||||||
Examples:
|
Examples:
|
||||||
wled on
|
wled on
|
||||||
wled set --color blue --range 70-80 --brightness 50%
|
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 --hex '#00ff88' --effect solid
|
||||||
wled effects rainbow
|
wled effects rainbow
|
||||||
wled presets
|
wled presets
|
||||||
@@ -201,10 +204,13 @@ async function buildState(baseUrl, options, command) {
|
|||||||
if (preset != null) payload.ps = preset;
|
if (preset != null) payload.ps = preset;
|
||||||
|
|
||||||
const color = parseColor(options.color ?? options.hex);
|
const color = parseColor(options.color ?? options.hex);
|
||||||
|
const restColor = parseColor(options['rest-color'] ?? options['rest-hex']);
|
||||||
const effect = await resolveEffect(baseUrl, options.effect);
|
const effect = await resolveEffect(baseUrl, options.effect);
|
||||||
const range = parseRange(options.range);
|
const range = parseRange(options.range);
|
||||||
const segmentId = options.segment != null ? Number.parseInt(options.segment, 10) : 0;
|
const segmentId = options.segment != null ? Number.parseInt(options.segment, 10) : 0;
|
||||||
|
|
||||||
|
if (restColor && !range) fail('--rest-color requires --range');
|
||||||
|
|
||||||
const segment = { id: segmentId };
|
const segment = { id: segmentId };
|
||||||
let needsSegment = false;
|
let needsSegment = false;
|
||||||
|
|
||||||
@@ -222,7 +228,44 @@ async function buildState(baseUrl, options, command) {
|
|||||||
needsSegment = true;
|
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;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user