feat: 实现自动刷新示波器
This commit is contained in:
parent
1d35c36da6
commit
ef267721fd
|
@ -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 () => {
|
||||
if (operationMutex.isLocked()) {
|
||||
|
@ -133,12 +154,12 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() =
|
|||
if (!started) throw new Error("无法启动捕获");
|
||||
alert.info("开始捕获...", 2000);
|
||||
|
||||
// 简单轮询,直到捕获完成(可根据后端实际情况优化)
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
await getOscilloscopeData();
|
||||
alert.success("捕获完成", 2000);
|
||||
// 启动定时刷新
|
||||
startAutoRefresh();
|
||||
} catch (error) {
|
||||
alert.error("捕获失败", 3000);
|
||||
isCapturing.value = false;
|
||||
stopAutoRefresh();
|
||||
} finally {
|
||||
isCapturing.value = false;
|
||||
release();
|
||||
|
@ -248,6 +269,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(() =
|
|||
isOperationInProgress,
|
||||
sampleCount,
|
||||
samplePeriodNs,
|
||||
refreshIntervalMs,
|
||||
|
||||
applyConfiguration,
|
||||
resetConfiguration,
|
||||
|
|
Loading…
Reference in New Issue