fix: 修复示波器修改后无法配置的问题;修复无法生成api的问题;feat: 新增全局控制七段数码管

This commit is contained in:
2025-08-22 02:17:30 +08:00
parent 8fbd30e69f
commit 7d3ef598de
13 changed files with 204 additions and 58 deletions

View File

@@ -156,6 +156,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(
try {
const proxy = getHubProxy();
// console.log("Applying configuration", config);
const success = await proxy.initialize(config);
if (success) {

View File

@@ -66,7 +66,7 @@
</div>
<div class="divider"></div>
<h1 class="font-bold text-center text-2xl">外设</h1>
<div class="flex flex-row justify-center">
<div class="flex flex-row justify-between columns-2">
<div class="flex flex-row">
<input
type="checkbox"
@@ -76,6 +76,15 @@
/>
<p class="mx-2">启用矩阵键盘</p>
</div>
<div class="flex flex-row">
<input
type="checkbox"
class="checkbox"
:checked="eqps.enableSevenSegmentDisplay"
@change="handleSevenSegmentDisplayCheckboxChange"
/>
<p class="mx-2">启用数码管</p>
</div>
</div>
</div>
</template>
@@ -146,6 +155,15 @@ async function handleMatrixkeyCheckboxChange(event: Event) {
}
}
async function handleSevenSegmentDisplayCheckboxChange(event: Event) {
const target = event.target as HTMLInputElement;
if (target.checked) {
await eqps.sevenSegmentDisplaySetOnOff(true);
} else {
await eqps.sevenSegmentDisplaySetOnOff(false);
}
}
async function toggleJtagBoundaryScan() {
eqps.jtagBoundaryScanSetOnOff(!eqps.enableJtagBoundaryScan);
}

View File

@@ -41,7 +41,7 @@
<!-- 引脚仅在非数字孪生模式下显示 -->
<div
v-if="!props.enableDigitalTwin"
v-if="!eqps.enableSevenSegmentDisplay"
v-for="pin in props.pins"
:key="pin.pinId"
:style="{
@@ -74,6 +74,12 @@ import { ref, computed, watch, onMounted, onUnmounted } from "vue";
import { useConstraintsStore } from "../../stores/constraints";
import Pin from "./Pin.vue";
import { useEquipments } from "@/stores/equipments";
import { watchEffect } from "vue";
import { useRequiredInjection } from "@/utils/Common";
import { useComponentManager } from "../LabCanvas";
const eqps = useEquipments();
const componentManger = useRequiredInjection(useComponentManager);
// ============================================================================
// Linus式极简数据结构一个byte解决一切
@@ -82,7 +88,7 @@ import { useEquipments } from "@/stores/equipments";
interface Props {
size?: number;
color?: string;
enableDigitalTwin?: boolean;
// enableDigitalTwin?: boolean;
digitalTwinNum?: number;
// afterglowDuration?: number;
cathodeType?: "common" | "anode";
@@ -97,7 +103,7 @@ interface Props {
const props = withDefaults(defineProps<Props>(), {
size: 1,
color: "red",
enableDigitalTwin: false,
// enableDigitalTwin: false,
digitalTwinNum: 1,
afterglowDuration: 500,
cathodeType: "common",
@@ -158,7 +164,7 @@ function isBitSet(byte: number, bit: number): boolean {
}
function isSegmentActive(segmentId: keyof typeof SEGMENT_BITS): boolean {
if (props.enableDigitalTwin) {
if (eqps.enableSevenSegmentDisplay) {
// 数字孪生模式余晖优先然后是当前byte
const bit = SEGMENT_BITS[segmentId];
return (
@@ -174,18 +180,16 @@ function isSegmentActive(segmentId: keyof typeof SEGMENT_BITS): boolean {
// SignalR数字孪生集成
// ============================================================================
const eqps = useEquipments();
async function initDigitalTwin() {
if (
!props.enableDigitalTwin ||
!eqps.enableSevenSegmentDisplay ||
props.digitalTwinNum <= 0 ||
props.digitalTwinNum > 31
)
return;
try {
eqps.sevenSegmentDisplaySetOnOff(props.enableDigitalTwin);
eqps.sevenSegmentDisplaySetOnOff(eqps.enableSevenSegmentDisplay);
console.log(
`Digital twin initialized for address: ${props.digitalTwinNum}`,
@@ -205,7 +209,9 @@ watch(
)
return;
handleDigitalTwinData(eqps.sevenSegmentDisplayData[props.digitalTwinNum - 1]);
handleDigitalTwinData(
eqps.sevenSegmentDisplayData[props.digitalTwinNum - 1],
);
},
);
@@ -265,7 +271,7 @@ const { getConstraintState, onConstraintStateChange } = useConstraintsStore();
let constraintUnsubscribe: (() => void) | null = null;
function updateConstraintStates() {
if (props.enableDigitalTwin) return; // 数字孪生模式下忽略约束
if (eqps.enableSevenSegmentDisplay) return; // 数字孪生模式下忽略约束
// 获取COM状态
const comPin = props.pins.find((p) => p.pinId === "COM");
@@ -328,7 +334,7 @@ const pinRefs = ref<Record<string, any>>({});
// ============================================================================
onMounted(async () => {
if (props.enableDigitalTwin) {
if (eqps.enableSevenSegmentDisplay) {
await initDigitalTwin();
} else {
constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
@@ -349,25 +355,24 @@ onUnmounted(() => {
});
// 监听模式切换
watch(
() => [props.enableDigitalTwin],
async () => {
// 清理旧模式
cleanupDigitalTwin();
if (constraintUnsubscribe) {
constraintUnsubscribe();
constraintUnsubscribe = null;
}
// watch(
// () => [eqps.enableSevenSegmentDisplay],
// async () => {
// // 清理旧模式
// if (constraintUnsubscribe) {
// constraintUnsubscribe();
// constraintUnsubscribe = null;
// }
// 初始化新模式
if (props.enableDigitalTwin) {
await initDigitalTwin();
} else {
constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
updateConstraintStates();
}
},
);
// // 初始化新模式
// if (eqps.enableSevenSegmentDisplay) {
// await initDigitalTwin();
// } else {
// constraintUnsubscribe = onConstraintStateChange(updateConstraintStates);
// updateConstraintStates();
// }
// },
// );
</script>
<style scoped>
@@ -393,7 +398,7 @@ export function getDefaultProps() {
return {
size: 1,
color: "red",
enableDigitalTwin: false,
// enableDigitalTwin: false,
digitalTwinNum: 1,
// afterglowDuration: 500,
cathodeType: "common",