修改音量显示的方式
This commit is contained in:
+21
-3
@@ -7,6 +7,8 @@ import {
|
|||||||
LuxsinAPI,
|
LuxsinAPI,
|
||||||
PeqFilter,
|
PeqFilter,
|
||||||
FILTER_TYPE_LABELS,
|
FILTER_TYPE_LABELS,
|
||||||
|
dbToVolume,
|
||||||
|
volumeToDb,
|
||||||
} from "./luxsinApi";
|
} from "./luxsinApi";
|
||||||
|
|
||||||
// Allow override via Vite env / localStorage; default to same origin in prod.
|
// Allow override via Vite env / localStorage; default to same origin in prod.
|
||||||
@@ -238,12 +240,28 @@ export async function executeFrontendTool(
|
|||||||
switch (block.name) {
|
switch (block.name) {
|
||||||
case "get_device_settings": {
|
case "get_device_settings": {
|
||||||
const state = await api.getDeviceState();
|
const state = await api.getDeviceState();
|
||||||
return { ok: true, content: state };
|
// 设备的 volume 是 0-200 的原始值,AI 侧以 dB (-100 ~ 0) 看更直观
|
||||||
|
const content: Record<string, any> = { ...state };
|
||||||
|
if (typeof state.volume === "number") {
|
||||||
|
content.volume = Number(volumeToDb(state.volume).toFixed(1));
|
||||||
|
content.volume_unit = "dB";
|
||||||
|
}
|
||||||
|
return { ok: true, content };
|
||||||
}
|
}
|
||||||
case "set_device_settings": {
|
case "set_device_settings": {
|
||||||
const params = (block.input ?? {}) as Record<string, string | number>;
|
const rawParams = (block.input ?? {}) as Record<string, string | number>;
|
||||||
|
// AI 传进来的 volume 是 dB,需换算回设备 0-200 的原始值
|
||||||
|
const params: Record<string, string | number> = { ...rawParams };
|
||||||
|
if (params.volume !== undefined && params.volume !== null) {
|
||||||
|
const db = Number(params.volume);
|
||||||
|
if (Number.isFinite(db)) {
|
||||||
|
const clampedDb = Math.max(-100, Math.min(0, db));
|
||||||
|
params.volume = dbToVolume(clampedDb);
|
||||||
|
}
|
||||||
|
}
|
||||||
await api.setSetting(params);
|
await api.setSetting(params);
|
||||||
return { ok: true, content: { ok: true, updated: params } };
|
// 回传给 AI 的仍以人类可读的 dB 展示
|
||||||
|
return { ok: true, content: { ok: true, updated: rawParams } };
|
||||||
}
|
}
|
||||||
case "get_peq_list": {
|
case "get_peq_list": {
|
||||||
const peqState = await api.getPeqState();
|
const peqState = await api.getPeqState();
|
||||||
|
|||||||
Reference in New Issue
Block a user