优化示波器与连线对应,优化接线错误提示
This commit is contained in:
@@ -31,6 +31,15 @@ const props = defineProps({
|
||||
// 声速,单位m/s
|
||||
soundSpeed: { type: Number, default: 340 },
|
||||
|
||||
// 接线状态:控制通道是否真正有信号
|
||||
// CH1:仅当 [信号发生器 发射端 波形] -> [示波器 CH1] 接入时为 true
|
||||
ch1HasSignal: { type: Boolean, default: false },
|
||||
// CH2:仅当三条线都接入时为 true
|
||||
// [信号发生器 发射端 换能器] -> [换能器 左侧输入]
|
||||
// [信号发生器 接收端 波形] -> [示波器 CH2]
|
||||
// [信号发生器 接收端 换能器] -> [换能器 右侧输出]
|
||||
ch2HasSignal: { type: Boolean, default: false },
|
||||
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -147,8 +156,8 @@ function drawOscilloscope() {
|
||||
const gainCH1 = getGain(vdch1.value);
|
||||
const gainCH2 = getGain(vdch2.value);
|
||||
|
||||
// X-Y 模式下检测“李萨如图形出现直线”的进入事件
|
||||
if (power.value && isXYMode.value) {
|
||||
// X-Y 模式下检测“李萨如图形出现直线”的进入事件(需两路都有信号)
|
||||
if (power.value && isXYMode.value && props.ch1HasSignal && props.ch2HasSignal) {
|
||||
const phase = phy.phaseRadTotal;
|
||||
const isLineNow = Math.abs(Math.sin(phase)) < 0.10 && phy.resonanceFactor > 0.05;
|
||||
if (isLineNow && !lastWasLine.value) {
|
||||
@@ -171,7 +180,8 @@ function drawOscilloscope() {
|
||||
|
||||
if (isXYMode.value) {
|
||||
// ================= X-Y Mode (李萨如图形) =================
|
||||
const opacity = 0.3 + 0.7 * phy.resonanceFactor;
|
||||
const hasAnySignal = props.ch1HasSignal || props.ch2HasSignal;
|
||||
const opacity = hasAnySignal ? (0.3 + 0.7 * phy.resonanceFactor) : 0.15;
|
||||
ctx.strokeStyle = `rgba(0, 255, 0, ${opacity})`;
|
||||
|
||||
// 强辉光效果 - 多层叠加
|
||||
@@ -180,8 +190,8 @@ function drawOscilloscope() {
|
||||
|
||||
ctx.beginPath();
|
||||
const phase = phy.phaseRadTotal;
|
||||
const ampX = gainCH1;
|
||||
const ampY = phy.resonanceFactor * gainCH2;
|
||||
const ampX = props.ch1HasSignal ? gainCH1 : 0;
|
||||
const ampY = props.ch2HasSignal ? (phy.resonanceFactor * gainCH2) : 0;
|
||||
|
||||
for (let t = 0; t <= 2 * Math.PI; t += 0.03) {
|
||||
const x = scale * ampX * Math.cos(t);
|
||||
@@ -197,6 +207,12 @@ function drawOscilloscope() {
|
||||
|
||||
ctx.shadowBlur = 0;
|
||||
|
||||
// 两路都没信号时,画一个中心点(避免完全不可见)
|
||||
if (!props.ch1HasSignal && !props.ch2HasSignal) {
|
||||
ctx.fillStyle = 'rgba(0, 255, 0, 0.25)';
|
||||
ctx.fillRect(cx - 1.5, cy - 1.5, 3, 3);
|
||||
}
|
||||
|
||||
// 中心点装饰
|
||||
ctx.fillStyle = 'rgba(0, 255, 0, 0.3)';
|
||||
ctx.fillRect(cx - 1, cy - 5, 2, 10);
|
||||
@@ -218,18 +234,52 @@ function drawOscilloscope() {
|
||||
|
||||
ctx.lineWidth = 3;
|
||||
|
||||
// CH1 (Source) - 黄色参考信号(在CH1、双踪、叠加模式下显示)
|
||||
if (currentModeIndex.value === 0 || currentModeIndex.value === 2 || currentModeIndex.value === 3) {
|
||||
// 叠加模式:直接绘制 CH1 + CH2 的合成波形(形状更复杂)
|
||||
if (currentModeIndex.value === 3) {
|
||||
const opacity = 0.45 + 0.55 * phy.resonanceFactor;
|
||||
ctx.beginPath();
|
||||
// 用 CH1 的黄色线条 + CH2 的绿色辉光,便于与单通道/双踪区分
|
||||
ctx.strokeStyle = `rgba(255, 230, 0, ${opacity})`;
|
||||
ctx.shadowBlur = 14 * (0.4 + 0.6 * phy.resonanceFactor);
|
||||
ctx.shadowColor = '#00ff00';
|
||||
|
||||
const phaseShift = phy.phaseRadTotal;
|
||||
const amp1 = gainCH1 * 0.8;
|
||||
const amp2 = phy.resonanceFactor * gainCH2 * 0.8;
|
||||
|
||||
for (let x = 0; x < w; x += 2) {
|
||||
const t = (x / pixPerCycle) * 2 * Math.PI;
|
||||
const y1 = props.ch1HasSignal ? (amp1 * Math.sin(t + time)) : 0;
|
||||
const y2 = props.ch2HasSignal ? (amp2 * Math.sin(t - phaseShift + time)) : 0;
|
||||
const yVal = scale * (y1 + y2);
|
||||
if (x === 0) ctx.moveTo(x, cy - yVal);
|
||||
else ctx.lineTo(x, cy - yVal);
|
||||
}
|
||||
ctx.stroke();
|
||||
|
||||
// 第二层辉光
|
||||
ctx.shadowBlur = 22 * (0.4 + 0.6 * phy.resonanceFactor);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// CH1 (Source) - 黄色参考信号(在CH1、双踪模式下显示)
|
||||
if (currentModeIndex.value === 0 || currentModeIndex.value === 2) {
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = 'rgba(255, 230, 0, 0.9)';
|
||||
ctx.shadowBlur = 12;
|
||||
ctx.shadowColor = '#ffff00';
|
||||
|
||||
for (let x = 0; x < w; x += 2) {
|
||||
const t = (x / pixPerCycle) * 2 * Math.PI;
|
||||
const yVal = scale * gainCH1 * 0.8 * Math.sin(t + time);
|
||||
if (x === 0) ctx.moveTo(x, cy - yVal);
|
||||
else ctx.lineTo(x, cy - yVal);
|
||||
if (props.ch1HasSignal) {
|
||||
for (let x = 0; x < w; x += 2) {
|
||||
const t = (x / pixPerCycle) * 2 * Math.PI;
|
||||
const yVal = scale * gainCH1 * 0.8 * Math.sin(t + time);
|
||||
if (x === 0) ctx.moveTo(x, cy - yVal);
|
||||
else ctx.lineTo(x, cy - yVal);
|
||||
}
|
||||
} else {
|
||||
// 未接线:显示中心直线
|
||||
ctx.moveTo(0, cy);
|
||||
ctx.lineTo(w, cy);
|
||||
}
|
||||
ctx.stroke();
|
||||
|
||||
@@ -238,8 +288,8 @@ function drawOscilloscope() {
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// CH2 (Receiver) - 绿色接收信号(在CH2、双踪、叠加模式下显示)
|
||||
if (currentModeIndex.value === 1 || currentModeIndex.value === 2 || currentModeIndex.value === 3) {
|
||||
// CH2 (Receiver) - 绿色接收信号(在CH2、双踪模式下显示)
|
||||
if (currentModeIndex.value === 1 || currentModeIndex.value === 2) {
|
||||
const opacity = 0.3 + 0.7 * phy.resonanceFactor;
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = `rgba(0, 255, 0, ${opacity})`;
|
||||
@@ -249,11 +299,18 @@ function drawOscilloscope() {
|
||||
const phaseShift = phy.phaseRadTotal;
|
||||
const ampY = phy.resonanceFactor * gainCH2 * 0.8;
|
||||
|
||||
for (let x = 0; x < w; x += 2) {
|
||||
const t = (x / pixPerCycle) * 2 * Math.PI;
|
||||
const yVal = scale * ampY * Math.sin(t - phaseShift + time);
|
||||
if (x === 0) ctx.moveTo(x, cy - yVal);
|
||||
else ctx.lineTo(x, cy - yVal);
|
||||
if (props.ch2HasSignal) {
|
||||
for (let x = 0; x < w; x += 2) {
|
||||
const t = (x / pixPerCycle) * 2 * Math.PI;
|
||||
const yVal = scale * ampY * Math.sin(t - phaseShift + time);
|
||||
if (x === 0) ctx.moveTo(x, cy - yVal);
|
||||
else ctx.lineTo(x, cy - yVal);
|
||||
}
|
||||
} else {
|
||||
// 未接线:显示中心直线
|
||||
ctx.shadowBlur = 0;
|
||||
ctx.moveTo(0, cy);
|
||||
ctx.lineTo(w, cy);
|
||||
}
|
||||
ctx.stroke();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user