Add rest-color range support
This commit is contained in:
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
|
||||
--color <name|#RRGGBB> Named color or hex color
|
||||
--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%
|
||||
--effect <name|id> Effect name or numeric effect id
|
||||
--preset <name|id> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user