feat: 添加嵌入式逻辑分析仪
This commit is contained in:
73
src/components/WaveformDisplay/WaveformManager.ts
Normal file
73
src/components/WaveformDisplay/WaveformManager.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { createInjectionState } from "@vueuse/core";
|
||||
import { shallowRef } from "vue";
|
||||
|
||||
export type LogicDataType = {
|
||||
x: number[];
|
||||
y: {
|
||||
enabled: boolean;
|
||||
type: "logic" | "number";
|
||||
name: string;
|
||||
color: string;
|
||||
value: number[];
|
||||
base: "bin" | "dec" | "hex";
|
||||
}[];
|
||||
xUnit: "s" | "ms" | "us" | "ns";
|
||||
};
|
||||
|
||||
// 生成4路测试数据的函数
|
||||
export function generateTestData(): LogicDataType {
|
||||
// 生成时间轴数据 (0-100ns,每1ns一个采样点)
|
||||
const timePoints = Array.from({ length: 101 }, (_, i) => i);
|
||||
|
||||
return {
|
||||
x: timePoints,
|
||||
y: [
|
||||
{
|
||||
enabled: true,
|
||||
type: "logic",
|
||||
name: "CLK",
|
||||
color: "#ff0000",
|
||||
value: timePoints.map((t) => t % 2), // 时钟信号,每1ns翻转
|
||||
base: "bin",
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
type: "logic",
|
||||
name: "RESET",
|
||||
color: "#00ff00",
|
||||
value: timePoints.map((t) => (t < 10 ? 1 : 0)), // 复位信号,前10ns为高电平
|
||||
base: "bin",
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
type: "number",
|
||||
name: "DATA",
|
||||
color: "#0000ff",
|
||||
value: timePoints.map((t) => Math.floor(t / 4) % 16), // 计数器,每4ns递增
|
||||
base: "hex",
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
type: "logic",
|
||||
name: "ENABLE",
|
||||
color: "#ff8800",
|
||||
value: timePoints.map((t) => (t >= 20 && t < 80 ? 1 : 0)), // 使能信号,20-80ns为高电平
|
||||
base: "bin",
|
||||
},
|
||||
],
|
||||
xUnit: "ns",
|
||||
};
|
||||
}
|
||||
|
||||
const [useProvideWaveformManager, useWaveformManager] = createInjectionState(
|
||||
() => {
|
||||
const logicData = shallowRef<LogicDataType>();
|
||||
|
||||
return {
|
||||
logicData,
|
||||
generateTestData,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export { useProvideWaveformManager, useWaveformManager };
|
||||
Reference in New Issue
Block a user