feat: 实现自动刷新示波器

This commit is contained in:
SikongJueluo 2025-07-22 01:48:05 +08:00
parent 8106f54ae7
commit 17b89aa575
1 changed files with 26 additions and 4 deletions

View File

@ -119,6 +119,27 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() =
} }
}; };
// 定时器引用
let refreshIntervalId: number | undefined;
// 刷新间隔(毫秒),可根据需要调整
const refreshIntervalMs = ref(1000);
// 定时刷新函数
const startAutoRefresh = () => {
if (refreshIntervalId !== undefined) return;
refreshIntervalId = window.setInterval(async () => {
await refreshRAM();
await getOscilloscopeData();
}, refreshIntervalMs.value);
};
const stopAutoRefresh = () => {
if (refreshIntervalId !== undefined) {
clearInterval(refreshIntervalId);
refreshIntervalId = undefined;
}
};
// 启动捕获 // 启动捕获
const startCapture = async () => { const startCapture = async () => {
if (operationMutex.isLocked()) { if (operationMutex.isLocked()) {
@ -133,12 +154,12 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() =
if (!started) throw new Error("无法启动捕获"); if (!started) throw new Error("无法启动捕获");
alert.info("开始捕获...", 2000); alert.info("开始捕获...", 2000);
// 简单轮询,直到捕获完成(可根据后端实际情况优化) // 启动定时刷新
await new Promise((resolve) => setTimeout(resolve, 1000)); startAutoRefresh();
await getOscilloscopeData();
alert.success("捕获完成", 2000);
} catch (error) { } catch (error) {
alert.error("捕获失败", 3000); alert.error("捕获失败", 3000);
isCapturing.value = false;
stopAutoRefresh();
} finally { } finally {
isCapturing.value = false; isCapturing.value = false;
release(); release();
@ -248,6 +269,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() =
isOperationInProgress, isOperationInProgress,
sampleCount, sampleCount,
samplePeriodNs, samplePeriodNs,
refreshIntervalMs,
applyConfiguration, applyConfiguration,
resetConfiguration, resetConfiguration,