Enhance DeviceContext and LuxsinAPI to support new PEQ apply functionality; update locale files for English and Chinese to include new UI strings for applying and saving PEQ settings. Refactor AudioPage and EQPage to integrate boot sound management and improve state handling.
This commit is contained in:
+64
-13
@@ -58,7 +58,7 @@ export function encodeCustomBase64(data: string): string {
|
||||
// ============================================================
|
||||
export interface DeviceState {
|
||||
device: string;
|
||||
version: string;
|
||||
version: string | number;
|
||||
mac: string;
|
||||
language: number;
|
||||
volume: number;
|
||||
@@ -135,19 +135,27 @@ export interface PeqState {
|
||||
}>;
|
||||
}
|
||||
|
||||
/** Shared PEQ preset fields for device POST bodies. */
|
||||
export interface PeqPresetBody {
|
||||
name: string;
|
||||
filters: PeqFilter[];
|
||||
autoPre?: number;
|
||||
preamp?: number;
|
||||
canDel?: number;
|
||||
brand?: string;
|
||||
model?: string;
|
||||
target?: string;
|
||||
form?: string;
|
||||
}
|
||||
|
||||
/** POST body for `/dev/info.cgi` — full peq preset update (custom base64 `json` field). */
|
||||
export interface PeqChangePayload {
|
||||
peqChange: {
|
||||
name: string;
|
||||
filters: PeqFilter[];
|
||||
autoPre?: number;
|
||||
preamp?: number;
|
||||
canDel?: number;
|
||||
brand?: string;
|
||||
model?: string;
|
||||
target?: string;
|
||||
form?: string;
|
||||
};
|
||||
peqChange: PeqPresetBody;
|
||||
}
|
||||
|
||||
/** POST body for `/dev/info.cgi` — apply A/B comparison curve without saving preset metadata. */
|
||||
export interface PeqApplyPayload {
|
||||
peqApply: PeqPresetBody;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
@@ -248,6 +256,15 @@ export class LuxsinAPI {
|
||||
|
||||
/** Full peq preset: name, filters, autoPre, preamp, canDel — same encoding as legacy `upgradePeq`. */
|
||||
async upgradePeqChange(body: PeqChangePayload): Promise<void> {
|
||||
await this.postPeqJson(body);
|
||||
}
|
||||
|
||||
/** Apply current EQ filters (e.g. A/B curve switch) without a full preset save. */
|
||||
async upgradePeqApply(body: PeqApplyPayload): Promise<void> {
|
||||
await this.postPeqJson(body);
|
||||
}
|
||||
|
||||
private async postPeqJson(body: PeqChangePayload | PeqApplyPayload): Promise<void> {
|
||||
const payload = JSON.stringify(body);
|
||||
const encoded = encodeCustomBase64(payload);
|
||||
await fetch(`${this.baseUrl}/dev/info.cgi`, {
|
||||
@@ -295,11 +312,45 @@ export class LuxsinAPI {
|
||||
setCrossfeedEnable(enable: boolean) { return this.setSetting({ crossfeed_enable: enable ? 1 : 0 }); }
|
||||
setXlrPolarity(reverse: boolean) { return this.setSetting({ xlr: reverse ? 1 : 0 }); }
|
||||
setDacArc(earc: boolean) { return this.setSetting({ dacArc: earc ? 1 : 0 }); }
|
||||
setBootSound(on: boolean) { return this.setSetting({ bootSound: on ? 1 : 0 }); }
|
||||
/** Boot volume level: 0 = default, 1..6 = -5..-30 dB, 7..10 = -35..-50 dB (firmware > 26). */
|
||||
setBootSound(level: number) {
|
||||
return this.setSetting({ bootSound: Math.max(0, Math.min(10, Math.round(level))) });
|
||||
}
|
||||
/** Device power off — `GET .../dev/info.cgi?action=setting&power=0` */
|
||||
powerOff() { return this.setSetting({ power: 0 }); }
|
||||
}
|
||||
|
||||
/** Parse firmware `version` for feature gating (e.g. bootSound extended steps). */
|
||||
export function parseFirmwareVersion(version: unknown): number {
|
||||
if (version === null || version === undefined) return 0;
|
||||
if (typeof version === "number" && Number.isFinite(version)) return version;
|
||||
const text = String(version).trim();
|
||||
if (!text) return 0;
|
||||
const direct = Number(text);
|
||||
if (Number.isFinite(direct)) return direct;
|
||||
const parts = text.match(/\d+/g);
|
||||
if (!parts?.length) return 0;
|
||||
return Number(parts[parts.length - 1]);
|
||||
}
|
||||
|
||||
/** Max `bootSound` index available for the current firmware. */
|
||||
export function getBootSoundMaxIndex(firmwareVersion: number): number {
|
||||
return firmwareVersion > 26 ? 10 : 6;
|
||||
}
|
||||
|
||||
/** Normalize `bootSound` from syncData (0 = default … 10 = -50 dB). */
|
||||
export function normalizeBootSound(value: unknown): number {
|
||||
const n = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isFinite(n)) return 0;
|
||||
return Math.max(0, Math.min(10, Math.round(n)));
|
||||
}
|
||||
|
||||
export function readBootSoundFromState(state: DeviceState | null | undefined): number {
|
||||
if (!state) return 0;
|
||||
const raw = state.bootSound ?? (state as Record<string, unknown>).bootsound;
|
||||
return normalizeBootSound(raw);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Mock data for demo/offline mode
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user