fix: matrix key not work

This commit is contained in:
SikongJueluo 2025-05-20 18:11:04 +08:00
parent 2aa2f1dc37
commit 3883cd8304
No known key found for this signature in database
3 changed files with 51 additions and 94 deletions

View File

@ -29,6 +29,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "1", "bindKey": "1",
"bindMatrixKey": "0",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -46,6 +47,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "2", "bindKey": "2",
"bindMatrixKey": "1",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -63,6 +65,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "3", "bindKey": "3",
"bindMatrixKey": "2",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -80,6 +83,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "A", "bindKey": "A",
"bindMatrixKey": "3",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -97,6 +101,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "4", "bindKey": "4",
"bindMatrixKey": "4",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -114,6 +119,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "5", "bindKey": "5",
"bindMatrixKey": "5",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -131,6 +137,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "6", "bindKey": "6",
"bindMatrixKey": "6",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -148,6 +155,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "B", "bindKey": "B",
"bindMatrixKey": "7",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -165,6 +173,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "7", "bindKey": "7",
"bindMatrixKey": "8",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -182,6 +191,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "8", "bindKey": "8",
"bindMatrixKey": "9",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -199,6 +209,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "9", "bindKey": "9",
"bindMatrixKey": "10",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -216,6 +227,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "C", "bindKey": "C",
"bindMatrixKey": "11",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -233,6 +245,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "*", "bindKey": "*",
"bindMatrixKey": "12",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -250,6 +263,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "0", "bindKey": "0",
"bindMatrixKey": "13",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -267,6 +281,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "#", "bindKey": "#",
"bindMatrixKey": "14",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,
@ -284,6 +299,7 @@
"attrs": { "attrs": {
"size": 0.5, "size": 0.5,
"bindKey": "D", "bindKey": "D",
"bindMatrixKey": "15",
"pins": [] "pins": []
}, },
"rotate": 0, "rotate": 0,

View File

@ -1,28 +1,16 @@
<template> <template>
<div <div class="button-container" :style="{
class="button-container" width: width + 'px',
:style="{ height: height + 'px',
width: width + 'px', position: 'relative',
height: height + 'px', }">
position: 'relative', <svg xmlns="http://www.w3.org/2000/svg" :width="width" :height="height" viewBox="400 400 800 800"
}" class="mechanical-button">
>
<svg
xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
viewBox="400 400 800 800"
class="mechanical-button"
>
<!-- defs 和按钮底座保持不变 --> <!-- defs 和按钮底座保持不变 -->
<defs> <defs>
<filter id="btn-shadow"> <filter id="btn-shadow">
<feGaussianBlur in="SourceAlpha" stdDeviation="20" result="blur" /> <feGaussianBlur in="SourceAlpha" stdDeviation="20" result="blur" />
<feColorMatrix <feColorMatrix result="bluralpha" type="matrix" :values="colorMatrix" />
result="bluralpha"
type="matrix"
:values="colorMatrix"
/>
<feOffset in="bluralpha" dx="20" dy="20" result="offsetBlur" /> <feOffset in="bluralpha" dx="20" dy="20" result="offsetBlur" />
<feMerge> <feMerge>
<feMergeNode in="offsetBlur" /> <feMergeNode in="offsetBlur" />
@ -49,81 +37,42 @@
<circle r="20" cx="525" cy="1075" fill="#171717" /> <circle r="20" cx="525" cy="1075" fill="#171717" />
<!-- 按钮主体 --> <!-- 按钮主体 -->
<circle <circle r="220" cx="800" cy="800" fill="black" filter="url(#btn-shadow)" />
r="220" <circle :r="btnHeight" cx="800" cy="800" :fill="isKeyPressed ? 'url(#pressed)' : 'url(#normal)'"
cx="800" fill-opacity="0.9" @mousedown="toggleButtonState(true)" @mouseup="toggleButtonState(false)"
cy="800" @mouseleave="toggleButtonState(false)" style="
fill="black"
filter="url(#btn-shadow)"
/>
<circle
:r="btnHeight"
cx="800"
cy="800"
:fill="isKeyPressed ? 'url(#pressed)' : 'url(#normal)'"
fill-opacity="0.9"
@mousedown="toggleButtonState(true)"
@mouseup="toggleButtonState(false)"
@mouseleave="toggleButtonState(false)"
style="
pointer-events: auto; pointer-events: auto;
transition: all 20ms ease-in-out; transition: all 20ms ease-in-out;
cursor: pointer; cursor: pointer;
" " />
/>
<!-- 按键文字 - 仅显示绑定的按键 --> <!-- 按键文字 - 仅显示绑定的按键 -->
<text <text v-if="bindKeyDisplay" x="800" y="800" font-size="310" text-anchor="middle" dominant-baseline="central"
v-if="bindKeyDisplay" fill="#ccc" style="
x="800"
y="800"
font-size="310"
text-anchor="middle"
dominant-baseline="central"
fill="#ccc"
style="
font-family: Arial; font-family: Arial;
filter: url(#btn-shadow); filter: url(#btn-shadow);
user-select: none; user-select: none;
pointer-events: none; pointer-events: none;
mix-blend-mode: overlay; mix-blend-mode: overlay;
" ">
>
{{ bindKeyDisplay }} {{ bindKeyDisplay }}
</text> </text>
</svg> </svg>
<!-- 渲染自定义引脚数组 --> <!-- 渲染自定义引脚数组 -->
<div <div v-for="pin in props.pins" :key="pin.pinId" :style="{
v-for="pin in props.pins" position: 'absolute',
:key="pin.pinId" left: `${pin.x * props.size}px`,
:style="{ top: `${pin.y * props.size}px`,
position: 'absolute', transform: 'translate(-50%, -50%)',
left: `${pin.x * props.size}px`, zIndex: 3,
top: `${pin.y * props.size}px`, pointerEvents: 'auto',
transform: 'translate(-50%, -50%)', }" :data-pin-wrapper="`${pin.pinId}`" :data-pin-x="`${pin.x * props.size}`"
zIndex: 3, :data-pin-y="`${pin.y * props.size}`">
pointerEvents: 'auto', <Pin :ref="(el) => {
}" if (el) pinRefs[pin.pinId] = el;
:data-pin-wrapper="`${pin.pinId}`" }
:data-pin-x="`${pin.x * props.size}`" " direction="output" type="digital" :label="pin.pinId" :constraint="pin.constraint" :pinId="pin.pinId"
:data-pin-y="`${pin.y * props.size}`" :size="0.8" :componentId="props.componentId" @value-change="handlePinValueChange" @pin-click="handlePinClick" />
>
<Pin
:ref="
(el) => {
if (el) pinRefs[pin.pinId] = el;
}
"
direction="output"
type="digital"
:label="pin.pinId"
:constraint="pin.constraint"
:pinId="pin.pinId"
:size="0.8"
:componentId="props.componentId"
@value-change="handlePinValueChange"
@pin-click="handlePinClick"
/>
</div> </div>
</div> </div>
</template> </template>
@ -206,7 +155,9 @@ function toggleButtonState(isPressed: boolean) {
// //
if (eqps.enableMatrixKey) { if (eqps.enableMatrixKey) {
const ret = eqps.setMatrixKey(props.bindMatrixKey, isPressed); const ret = eqps.setMatrixKey(props.bindMatrixKey, isPressed);
if (!ret)
if (ret) eqps.matrixKeypadSetKeyStates(eqps.matrixKeyStates);
else
dialog.error( dialog.error(
`绑定的矩阵键盘值只能是0 ~ 15而不是: ${props.bindMatrixKey}`, `绑定的矩阵键盘值只能是0 ~ 15而不是: ${props.bindMatrixKey}`,
); );

View File

@ -38,16 +38,6 @@ export const useEquipments = defineStore('equipments', () => {
if (true === enableJtagBoundaryScan.value) jtagBoundaryScan(); if (true === enableJtagBoundaryScan.value) jtagBoundaryScan();
}); });
watchPostEffect(async () => {
if (true === enableMatrixKey.value) {
const ret = await matrixKeypadSetKeyStates(matrixKeyStates)
if (!ret) {
dialog.error("设置矩阵键盘失败")
enableMatrixKey.value = false;
}
}
})
// Parse and Set // Parse and Set
function setAddr(address: string | undefined): boolean { function setAddr(address: string | undefined): boolean {
if (isString(address) && z.string().ip("4").safeParse(address).success) { if (isString(address) && z.string().ip("4").safeParse(address).success) {
@ -76,7 +66,6 @@ export const useEquipments = defineStore('equipments', () => {
} }
function setMatrixKey(keyNum: number | string | undefined, keyValue: boolean): boolean { function setMatrixKey(keyNum: number | string | undefined, keyValue: boolean): boolean {
let _keyNum: number; let _keyNum: number;
if (isString(keyNum)) { if (isString(keyNum)) {
_keyNum = toNumber(keyNum); _keyNum = toNumber(keyNum);
@ -180,11 +169,12 @@ export const useEquipments = defineStore('equipments', () => {
async function matrixKeypadSetKeyStates(keyStates: boolean[]) { async function matrixKeypadSetKeyStates(keyStates: boolean[]) {
const release = await matrixKeypadClientMutex.acquire(); const release = await matrixKeypadClientMutex.acquire();
console.log("set Key !!!!!!!!!!!!");
try { try {
const resp = await matrixKeypadClient.setMatrixKeyStatus( const resp = await matrixKeypadClient.setMatrixKeyStatus(
boardAddr.value, boardAddr.value,
boardPort.value, boardPort.value,
matrixKeyStates keyStates
); );
return resp; return resp;
} catch (e) { } catch (e) {