feat: main's import/export, zones, audio API and web UI
Profiles, presets and sequences export and import as main's bundles. Zones carry group_ids, preset_group_ids, sequence_ids, content_kind and brightness; profiles seed rainbow as colour_cycle, and deleting a profile also deletes its sequences. Groups, zones and sequences written by older versions are migrated at boot. /api/audio (status, event stream, start/stop, reset, anchor-bar, devices) maps main's audio detector onto the mic's beat detector. Audio start/stop picks whether mic beats or the BPM clock time sequences; the clock's beats also go to the drivers while the mic is off. /ws now greets from a post-handshake callback (httpd does not call the handler for the upgrade). The web UI is main's, plus v2's outputs editor, list search and hostname/static IP settings; the bridge, Wi-Fi AP and led-tool parts are gone. API tests follow main's behaviour (119 pass on the board). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
04b56c6ef2
commit
bfeeb958df
44 files changed
+8709
-2338
No files matched your search
+55
-45
@@ -33,6 +33,33 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return Number.isFinite(t) ? t : def;
|
||||
};
|
||||
|
||||
const coercePresetAuto = (preset) => {
|
||||
if (!preset || typeof preset !== 'object') {
|
||||
return true;
|
||||
}
|
||||
const v =
|
||||
preset.auto !== undefined && preset.auto !== null ? preset.auto : preset.a;
|
||||
if (typeof v === 'boolean') {
|
||||
return v;
|
||||
}
|
||||
if (v === 0 || v === '0') {
|
||||
return false;
|
||||
}
|
||||
if (v === 1 || v === '1') {
|
||||
return true;
|
||||
}
|
||||
if (typeof v === 'string') {
|
||||
const l = v.trim().toLowerCase();
|
||||
if (['false', '0', 'no', 'off'].includes(l)) {
|
||||
return false;
|
||||
}
|
||||
if (['true', '1', 'yes', 'on'].includes(l)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const getCurrentProfileId = async () => {
|
||||
try {
|
||||
const response = await fetch('/profiles/current', { headers: { Accept: 'application/json' } });
|
||||
@@ -71,24 +98,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
: [];
|
||||
};
|
||||
|
||||
const postDriverSequence = async (sequence, targetMacs, delayS = 0.05) => {
|
||||
const body = {
|
||||
sequence,
|
||||
targets: Array.isArray(targetMacs) && targetMacs.length ? [...new Set(targetMacs)] : undefined,
|
||||
delay_s: delayS,
|
||||
};
|
||||
const res = await fetch('/presets/push', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error((err && err.error) || res.statusText || 'Send failed');
|
||||
}
|
||||
return res.json().catch(() => ({}));
|
||||
};
|
||||
const postDriverSequence = (sequence, targetMacs, delayS, pushOptions) =>
|
||||
window.postDriverSequence(sequence, targetMacs, delayS, pushOptions);
|
||||
|
||||
const nReadableStringFromMeta = (meta, key) => {
|
||||
if (!meta || typeof meta !== 'object') {
|
||||
@@ -257,10 +268,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
throw new Error((data && data.error) || 'Create failed');
|
||||
}
|
||||
alert(data.message || 'Pattern created.');
|
||||
resetCreateForm();
|
||||
if (patternEditorModal) {
|
||||
patternEditorModal.classList.remove('active');
|
||||
}
|
||||
await loadPatterns();
|
||||
} catch (e) {
|
||||
console.error('Create pattern failed:', e);
|
||||
@@ -397,13 +404,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
row.appendChild(label);
|
||||
|
||||
if (isFirmwareBuiltinPattern(patternName)) {
|
||||
const note = document.createElement('span');
|
||||
note.className = 'muted-text';
|
||||
note.style.fontSize = '0.85em';
|
||||
note.textContent = 'Built-in (no OTA module)';
|
||||
row.appendChild(note);
|
||||
} else {
|
||||
if (!isFirmwareBuiltinPattern(patternName)) {
|
||||
const sendBtn = document.createElement('button');
|
||||
sendBtn.className = 'btn btn-primary btn-small';
|
||||
sendBtn.textContent = 'Send';
|
||||
@@ -531,6 +532,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const colors = Array.isArray(preset.colors) && preset.colors.length
|
||||
? preset.colors
|
||||
: ['#FFFFFF'];
|
||||
const presetAuto = coercePresetAuto(preset);
|
||||
wirePresets[presetId] = {
|
||||
pattern: preset.pattern || 'off',
|
||||
colors,
|
||||
@@ -538,13 +540,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
brightness: typeof preset.brightness === 'number'
|
||||
? preset.brightness
|
||||
: (typeof preset.br === 'number' ? preset.br : 127),
|
||||
auto: typeof preset.auto === 'boolean' ? preset.auto : true,
|
||||
auto: presetAuto,
|
||||
a: presetAuto,
|
||||
n1: coercePresetInt(preset.n1),
|
||||
n2: coercePresetInt(preset.n2),
|
||||
n3: coercePresetInt(preset.n3),
|
||||
n4: coercePresetInt(preset.n4),
|
||||
n5: coercePresetInt(preset.n5),
|
||||
n6: coercePresetInt(preset.n6),
|
||||
n6: (() => {
|
||||
if (preset.mode !== undefined && preset.mode !== null && preset.mode !== '') {
|
||||
return coercePresetInt(preset.mode);
|
||||
}
|
||||
return coercePresetInt(preset.n6);
|
||||
})(),
|
||||
};
|
||||
});
|
||||
if (!Object.keys(wirePresets).length) {
|
||||
@@ -552,26 +560,28 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const select = {};
|
||||
deviceNames.forEach((name) => {
|
||||
if (name) {
|
||||
select[name] = zonePresetIds.slice();
|
||||
}
|
||||
});
|
||||
const targetMacs =
|
||||
typeof window.tabsManager !== 'undefined' &&
|
||||
typeof window.tabsManager.resolveTabDeviceMacs === 'function'
|
||||
? await window.tabsManager.resolveTabDeviceMacs(deviceNames)
|
||||
: [];
|
||||
const groupIds =
|
||||
typeof window.zonesManager !== 'undefined' &&
|
||||
typeof window.zonesManager.effectiveGroupIdsForZonePreset === 'function'
|
||||
? window.zonesManager.effectiveGroupIdsForZonePreset(zoneData)
|
||||
: Array.isArray(zoneData.group_ids)
|
||||
? zoneData.group_ids.map((g) => String(g).trim()).filter((g) => g.length > 0)
|
||||
: [];
|
||||
|
||||
const sequence = [
|
||||
{ v: '1', clear_presets: true, save: true },
|
||||
{ v: '1', presets: wirePresets, save: true },
|
||||
];
|
||||
if (Object.keys(select).length) {
|
||||
sequence.push({ v: '1', select });
|
||||
if (groupIds.length) {
|
||||
sequence[0].groups = groupIds;
|
||||
sequence[1].groups = groupIds;
|
||||
}
|
||||
await postDriverSequence(sequence, targetMacs, 0.05);
|
||||
if (deviceNames.length > 0 && zonePresetIds.length > 0) {
|
||||
const sel = { v: '1', select: zonePresetIds.slice() };
|
||||
if (groupIds.length) sel.groups = groupIds;
|
||||
sequence.push(sel);
|
||||
}
|
||||
await postDriverSequence(sequence, [], 0.05, { groupIds });
|
||||
} catch (error) {
|
||||
console.error('Send all patterns failed:', error);
|
||||
alert('Failed to send all patterns.');
|
||||
|
||||
Reference in new issue
Block a user