feat: add power control
This commit is contained in:
@@ -4,7 +4,7 @@ import { isString, toNumber } from 'lodash';
|
||||
import { Common } from '@/Common';
|
||||
import z from "zod"
|
||||
import { isNumber } from 'mathjs';
|
||||
import { JtagClient, MatrixKeyClient } from "@/APIClient";
|
||||
import { JtagClient, MatrixKeyClient, PowerClient } from "@/APIClient";
|
||||
import { Mutex, withTimeout } from 'async-mutex';
|
||||
import { useConstraintsStore } from "@/stores/constraints";
|
||||
import { useDialogStore } from './dialog';
|
||||
@@ -29,9 +29,14 @@ export const useEquipments = defineStore('equipments', () => {
|
||||
const matrixKeypadClientMutex = withTimeout(new Mutex(), 1000, new Error("Matrixkeyclient Mutex Timeout!"));
|
||||
const matrixKeypadClient = new MatrixKeyClient();
|
||||
|
||||
// Power
|
||||
const powerClientMutex = withTimeout(new Mutex(), 1000, new Error("Matrixkeyclient Mutex Timeout!"));
|
||||
const powerClient = new PowerClient();
|
||||
|
||||
// Enable Setting
|
||||
const enableJtagBoundaryScan = ref(false);
|
||||
const enableMatrixKey = ref(false);
|
||||
const enablePower = ref(false)
|
||||
|
||||
// Watch
|
||||
watchPostEffect(async () => {
|
||||
@@ -212,6 +217,24 @@ export const useEquipments = defineStore('equipments', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function powerSetOnOff(enable: boolean) {
|
||||
const release = await powerClientMutex.acquire();
|
||||
try {
|
||||
const resp = await powerClient.setPowerOnOff(
|
||||
boardAddr.value,
|
||||
boardPort.value,
|
||||
enable
|
||||
);
|
||||
return resp;
|
||||
} catch (e) {
|
||||
dialog.error("无法开关电源");
|
||||
console.error(e);
|
||||
return false;
|
||||
} finally {
|
||||
release();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
boardAddr,
|
||||
boardPort,
|
||||
@@ -237,6 +260,12 @@ export const useEquipments = defineStore('equipments', () => {
|
||||
matrixKeypadClient,
|
||||
matrixKeypadEnable,
|
||||
matrixKeypadSetKeyStates,
|
||||
|
||||
// Power
|
||||
enablePower,
|
||||
powerClient,
|
||||
powerClientMutex,
|
||||
powerSetOnOff,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user