diff --git a/server/Program.cs b/server/Program.cs index 43e4cd1..e525c32 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -130,7 +130,7 @@ try .AllowAnyHeader() ); options.AddPolicy("SignalR", policy => policy - .WithOrigins("http://localhost:5173") + .WithOrigins([$"http://{Global.LocalHost}:5173", "http://127.0.0.1:5173"]) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() diff --git a/server/src/Peripherals/OscilloscopeClient.cs b/server/src/Peripherals/OscilloscopeClient.cs index 9d092a5..2cff2cf 100644 --- a/server/src/Peripherals/OscilloscopeClient.cs +++ b/server/src/Peripherals/OscilloscopeClient.cs @@ -362,7 +362,7 @@ class OscilloscopeCtrl { // 等待WAVE_READY[0]位为1,最多等待50ms(5次x10ms间隔) var readyResult = await UDPClientPool.ReadAddrWithWait( - this.ep, this.taskID, OscilloscopeAddr.WAVE_READY, 0b00, 0x01, 10, 50); + this.ep, this.taskID, OscilloscopeAddr.WAVE_READY, 0b01, 0x01, 10, 50); if (!readyResult.IsSuccessful) { diff --git a/server/src/Peripherals/WS2812Client.cs b/server/src/Peripherals/WS2812Client.cs index 38a3190..f27c1e4 100644 --- a/server/src/Peripherals/WS2812Client.cs +++ b/server/src/Peripherals/WS2812Client.cs @@ -1,5 +1,6 @@ using System.Net; using DotNext; +using Tapper; namespace Peripherals.WS2812Client; @@ -12,7 +13,8 @@ class WS2812Addr /// /// RGB颜色结构体,包含红、绿、蓝三个颜色分量 /// -public struct RGBColor +[TranspilationSource] +public class RGBColor { public byte Red { get; set; } public byte Green { get; set; } @@ -84,13 +86,13 @@ public class WS2812Client { if (ledIndex < 0 || ledIndex >= WS2812Addr.LED_COUNT) { - return new(new ArgumentOutOfRangeException(nameof(ledIndex), + return new(new ArgumentOutOfRangeException(nameof(ledIndex), $"LED index must be between 0 and {WS2812Addr.LED_COUNT - 1}")); } if (MsgBus.IsRunning) MsgBus.UDPServer.ClearUDPData(this.address, this.taskID); - else + else return new(new Exception("Message Bus not work!")); var addr = WS2812Addr.BASE + (UInt32)(ledIndex * 4); // 每个地址32位,步长为4字节 @@ -123,14 +125,14 @@ public class WS2812Client { if (MsgBus.IsRunning) MsgBus.UDPServer.ClearUDPData(this.address, this.taskID); - else + else return new(new Exception("Message Bus not work!")); try { // 一次性读取所有LED数据,每个LED占用4字节,总共128*4=512字节 var ret = await UDPClientPool.ReadAddr4Bytes(this.ep, this.taskID, WS2812Addr.BASE, WS2812Addr.LED_COUNT, this.timeout); - + if (!ret.IsSuccessful) { logger.Error($"Get all LED colors failed: {ret.Error}"); @@ -139,7 +141,7 @@ public class WS2812Client var data = ret.Value; var expectedLength = WS2812Addr.LED_COUNT * 4; // 128 * 4 = 512 bytes - + if (data.Length < expectedLength) { var error = new Exception($"Invalid data length: expected {expectedLength} bytes, got {data.Length}"); @@ -148,7 +150,7 @@ public class WS2812Client } var colors = new RGBColor[WS2812Addr.LED_COUNT]; - + for (int i = 0; i < WS2812Addr.LED_COUNT; i++) { var offset = i * 4; @@ -156,7 +158,7 @@ public class WS2812Client var colorData = BitConverter.ToUInt32(data, offset); colors[i] = RGBColor.FromUInt32(colorData); } - + return new(colors); } catch (Exception ex) diff --git a/src/components/Oscilloscope/OscilloscopeManager.ts b/src/components/Oscilloscope/OscilloscopeManager.ts index c932ad2..d63abf4 100644 --- a/src/components/Oscilloscope/OscilloscopeManager.ts +++ b/src/components/Oscilloscope/OscilloscopeManager.ts @@ -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) { diff --git a/src/components/equipments/MotherBoardCaps.vue b/src/components/equipments/MotherBoardCaps.vue index 6b95528..9a5c62e 100644 --- a/src/components/equipments/MotherBoardCaps.vue +++ b/src/components/equipments/MotherBoardCaps.vue @@ -66,7 +66,7 @@

外设

-
+

启用矩阵键盘

+
+ +

启用数码管

+
@@ -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); } diff --git a/src/components/equipments/SevenSegmentDisplayUltimate.vue b/src/components/equipments/SevenSegmentDisplayUltimate.vue index 586d442..ce39a80 100644 --- a/src/components/equipments/SevenSegmentDisplayUltimate.vue +++ b/src/components/equipments/SevenSegmentDisplayUltimate.vue @@ -41,7 +41,7 @@
(), { 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>({}); // ============================================================================ 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(); +// } +// }, +// );