From b33a602d84a5752c1ad2cccd0972b5bfc7859e51 Mon Sep 17 00:00:00 2001 From: LynnL4 Date: Fri, 8 Dec 2023 16:18:59 +0800 Subject: [PATCH] feat: support config wifi & mqtt for Grove Vision AI(WE2) --- src/hooks/deviceManager.ts | 4 +- src/pages/others/comming-soon/index.vue | 30 ++++++++ .../index.vue | 0 src/pages/setup/config/index.vue | 6 +- src/pages/setup/config/xiao_esp32s3/index.vue | 2 +- .../index.vue | 0 src/pages/setup/output/index.vue | 6 +- src/pages/setup/process/components/Device.vue | 18 ++--- .../Device.vue | 4 +- .../index.vue | 0 src/pages/setup/process/index.vue | 6 +- .../index.vue | 2 +- src/pages/utils/index.vue | 8 +-- src/sscma/constants.ts | 6 +- .../Flasher.ts | 0 .../deviceHimax.ts | 70 ++++++++++++++++++- .../ringBuffer.ts | 0 .../serial.ts | 0 .../xmodem.ts | 0 19 files changed, 130 insertions(+), 32 deletions(-) create mode 100644 src/pages/others/comming-soon/index.vue rename src/pages/setup/config/{vision_ai_we_II => grove_ai_we2}/index.vue (100%) rename src/pages/setup/output/{vision_ai_we_II => grove_ai_we2}/index.vue (100%) rename src/pages/setup/process/{vision_ai_we_II => grove_ai_we2}/Device.vue (94%) rename src/pages/setup/process/{vision_ai_we_II => grove_ai_we2}/index.vue (100%) rename src/pages/utils/{vision_ai_we_II => grove_ai_we2}/index.vue (91%) rename src/sscma/{vision_ai_we_II => grove_ai_we2}/Flasher.ts (100%) rename src/sscma/{vision_ai_we_II => grove_ai_we2}/deviceHimax.ts (81%) rename src/sscma/{vision_ai_we_II => grove_ai_we2}/ringBuffer.ts (100%) rename src/sscma/{vision_ai_we_II => grove_ai_we2}/serial.ts (100%) rename src/sscma/{vision_ai_we_II => grove_ai_we2}/xmodem.ts (100%) diff --git a/src/hooks/deviceManager.ts b/src/hooks/deviceManager.ts index 72cb9c9..a5c55c9 100644 --- a/src/hooks/deviceManager.ts +++ b/src/hooks/deviceManager.ts @@ -3,7 +3,7 @@ import { Terminal } from 'xterm'; import { DeviceType, deviceTypeObj } from '@/sscma/constants'; import { useDeviceStore } from '@/store'; import espSerialDevice from '@/sscma/xiao_esp32s3/EspSerialDevice'; -import hiMaxDevice from '@/sscma/vision_ai_we_II/deviceHimax'; +import hiMaxDevice from '@/sscma/grove_ai_we2/deviceHimax'; const term = new Terminal({ cols: 78, rows: 30 }); function useDeviceManager() { @@ -11,7 +11,7 @@ function useDeviceManager() { const device = computed(() => { const obj = { [deviceTypeObj[DeviceType.XiaoEsp32s3].id]: espSerialDevice, - [deviceTypeObj[DeviceType.VisionAIWeII].id]: hiMaxDevice, + [deviceTypeObj[DeviceType.GroveAIWE2].id]: hiMaxDevice, }; return obj[deviceStore.deviceType.id as string]; }); diff --git a/src/pages/others/comming-soon/index.vue b/src/pages/others/comming-soon/index.vue new file mode 100644 index 0000000..69fa495 --- /dev/null +++ b/src/pages/others/comming-soon/index.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/src/pages/setup/config/vision_ai_we_II/index.vue b/src/pages/setup/config/grove_ai_we2/index.vue similarity index 100% rename from src/pages/setup/config/vision_ai_we_II/index.vue rename to src/pages/setup/config/grove_ai_we2/index.vue diff --git a/src/pages/setup/config/index.vue b/src/pages/setup/config/index.vue index 70b3cf3..5f2036b 100644 --- a/src/pages/setup/config/index.vue +++ b/src/pages/setup/config/index.vue @@ -2,7 +2,7 @@ import { DeviceType, deviceTypeObj } from '@/sscma/constants'; import { useDeviceStore } from '@/store'; import XiaoESP32S3OConfig from './xiao_esp32s3/index.vue'; - import VisionAIWeIIConfig from './vision_ai_we_II/index.vue'; + import GroveAIWE2Config from './grove_ai_we2/index.vue'; const deviceStore = useDeviceStore(); @@ -13,9 +13,9 @@ deviceStore.deviceType.id === deviceTypeObj[DeviceType.XiaoEsp32s3].id " /> - diff --git a/src/pages/setup/config/xiao_esp32s3/index.vue b/src/pages/setup/config/xiao_esp32s3/index.vue index 2bcb8b7..e8e462e 100644 --- a/src/pages/setup/config/xiao_esp32s3/index.vue +++ b/src/pages/setup/config/xiao_esp32s3/index.vue @@ -1,5 +1,5 @@ diff --git a/src/pages/setup/process/components/Device.vue b/src/pages/setup/process/components/Device.vue index 1a7d8e2..10486a0 100644 --- a/src/pages/setup/process/components/Device.vue +++ b/src/pages/setup/process/components/Device.vue @@ -322,15 +322,15 @@ const bins = deviceStore.firmware?.bins ?? []; const fileArray = []; const currentVersion = deviceStore.deviceVersion; - if (version !== currentVersion) { - if (bins.length === 0) { - throw new Error(t('workplace.device.message.firmware.no')); - } - // 下载固件 - loadingTip.value = t('workplace.device.message.tip.downloading.firmware'); - const firmwareArray = await downloadFirmware(bins); - fileArray.push(...firmwareArray); - } + // if (version !== currentVersion) { + // if (bins.length === 0) { + // throw new Error(t('workplace.device.message.firmware.no')); + // } + // // 下载固件 + // loadingTip.value = t('workplace.device.message.tip.downloading.firmware'); + // const firmwareArray = await downloadFirmware(bins); + // fileArray.push(...firmwareArray); + // } let finallyModel: Model | null = null; if (isCustom) { if (!modelFile.value) { diff --git a/src/pages/setup/process/vision_ai_we_II/Device.vue b/src/pages/setup/process/grove_ai_we2/Device.vue similarity index 94% rename from src/pages/setup/process/vision_ai_we_II/Device.vue rename to src/pages/setup/process/grove_ai_we2/Device.vue index 7e89ca3..3e6db99 100644 --- a/src/pages/setup/process/vision_ai_we_II/Device.vue +++ b/src/pages/setup/process/grove_ai_we2/Device.vue @@ -6,7 +6,7 @@ import { DeviceStatus } from '@/sscma'; import { useDeviceStore } from '@/store'; import useDeviceManager from '@/hooks/deviceManager'; - import Flasher from '@/sscma/vision_ai_we_II/Flasher'; + import Flasher from '@/sscma/grove_ai_we2/Flasher'; import Device from '../components/Device.vue'; const { device, term } = useDeviceManager(); @@ -61,7 +61,7 @@ const fetchAvailableModels = async () => { const data = await fetch( - `https://files.seeedstudio.com/sscma/sscma-model-test.json?timestamp=${new Date().getTime()}` + `https://files.seeedstudio.com/sscma/sscma-model-we2.json?timestamp=${new Date().getTime()}` ).then((response) => response.json()); deviceStore.setModels(data.models); const firmwares = data.firmwares; diff --git a/src/pages/setup/process/vision_ai_we_II/index.vue b/src/pages/setup/process/grove_ai_we2/index.vue similarity index 100% rename from src/pages/setup/process/vision_ai_we_II/index.vue rename to src/pages/setup/process/grove_ai_we2/index.vue diff --git a/src/pages/setup/process/index.vue b/src/pages/setup/process/index.vue index e13ff8c..0220d8a 100644 --- a/src/pages/setup/process/index.vue +++ b/src/pages/setup/process/index.vue @@ -2,7 +2,7 @@ import { DeviceType, deviceTypeObj } from '@/sscma/constants'; import { useDeviceStore } from '@/store'; import XiaoESP32S3Process from './xiao_esp32s3/index.vue'; - import VisionAIWeIIProcess from './vision_ai_we_II/index.vue'; + import GroveAIWE2Process from './grove_ai_we2/index.vue'; const deviceStore = useDeviceStore(); @@ -14,9 +14,9 @@ " /> - diff --git a/src/pages/utils/vision_ai_we_II/index.vue b/src/pages/utils/grove_ai_we2/index.vue similarity index 91% rename from src/pages/utils/vision_ai_we_II/index.vue rename to src/pages/utils/grove_ai_we2/index.vue index 6604dc7..d4bf6ab 100644 --- a/src/pages/utils/vision_ai_we_II/index.vue +++ b/src/pages/utils/grove_ai_we2/index.vue @@ -3,7 +3,7 @@ @@ -14,10 +14,10 @@ " key="XIAO ESP32S3" /> - diff --git a/src/sscma/constants.ts b/src/sscma/constants.ts index dcd1219..fea5194 100644 --- a/src/sscma/constants.ts +++ b/src/sscma/constants.ts @@ -1,6 +1,6 @@ export const DeviceType = { XiaoEsp32s3: 'xiao_esp32s3', - VisionAIWeII: 'we_ii', + GroveAIWE2: 'we_ii', }; export const DEVICE_LIST = [ @@ -10,8 +10,8 @@ export const DEVICE_LIST = [ filter: [{ vendorId: 0x303a, productId: 0x1001 }], }, { - id: DeviceType.VisionAIWeII, - name: 'Vision AI (WE-II)', + id: DeviceType.GroveAIWE2, + name: 'Grove AI WE2', filter: [{ vendorId: 0x1a86, productId: 0x55d3 }], }, ]; diff --git a/src/sscma/vision_ai_we_II/Flasher.ts b/src/sscma/grove_ai_we2/Flasher.ts similarity index 100% rename from src/sscma/vision_ai_we_II/Flasher.ts rename to src/sscma/grove_ai_we2/Flasher.ts diff --git a/src/sscma/vision_ai_we_II/deviceHimax.ts b/src/sscma/grove_ai_we2/deviceHimax.ts similarity index 81% rename from src/sscma/vision_ai_we_II/deviceHimax.ts rename to src/sscma/grove_ai_we2/deviceHimax.ts index 05eb942..c6e9f12 100644 --- a/src/sscma/vision_ai_we_II/deviceHimax.ts +++ b/src/sscma/grove_ai_we2/deviceHimax.ts @@ -220,7 +220,7 @@ class Himax extends Device { public async requestPort() { const serialPort = await navigator.serial.requestPort({ - filters: deviceTypeObj[DeviceType.VisionAIWeII].filter.map((e) => ({ + filters: deviceTypeObj[DeviceType.GroveAIWE2].filter.map((e) => ({ usbVendorId: e.vendorId, usbProductId: e.productId, })), @@ -273,6 +273,74 @@ class Himax extends Device { this.watchLoop = false; } } + + public async getAction(): Promise { + try { + const tag = 'ACTION?'; + const command = this.client.getAction(); + const response = await this.sendCommand(command, tag); + const code = response.code; + this.deleteMap(tag); + if (code === 0) { + const action = response.data?.action; + const conditionMatches = action.match( + /(\w+\(.*?\))(>=|<=|==|!=|>|<)(\d+)/g + ); + if (conditionMatches) { + return conditionMatches[0]; + } + return null; + } + return null; + } catch (error) { + return null; + } + } + + public async setAction( + target: number, + condition: string, + score: number + ): Promise { + try { + const tag = 'ACTION'; + const command = `AT+ACTION="((max_score(target,${target})${condition}${score})&&led(1))||led(0)"\r`; + const response = await this.sendCommand(command, tag); + const code = response.code; + this.deleteMap(tag); + return code === 0; + } catch (error) { + return false; + } + } + + public async invoke(times: number): Promise { + try { + const tag = 'INVOKE'; + const command = `AT+INVOKE=${times},0,0\r`; + const response = await this.sendCommand(command, tag); + const code = response.code; + this.resolveMap.delete(tag); + this.rejectMap.delete(tag); + if (code === 0) { + const data = response.data; + if (data) { + const config = data.algorithm?.config; + if (config) { + const tiou = config.tiou || 0; + const tscore = config.tscore || 0; + this.deviceStore.setIOU(tiou); + this.deviceStore.setScore(tscore); + } + this.deviceStore.setIsInvoke(true); + } + return data; + } + return null; + } catch (error) { + return null; + } + } } export type { Himax }; export default new Himax(); diff --git a/src/sscma/vision_ai_we_II/ringBuffer.ts b/src/sscma/grove_ai_we2/ringBuffer.ts similarity index 100% rename from src/sscma/vision_ai_we_II/ringBuffer.ts rename to src/sscma/grove_ai_we2/ringBuffer.ts diff --git a/src/sscma/vision_ai_we_II/serial.ts b/src/sscma/grove_ai_we2/serial.ts similarity index 100% rename from src/sscma/vision_ai_we_II/serial.ts rename to src/sscma/grove_ai_we2/serial.ts diff --git a/src/sscma/vision_ai_we_II/xmodem.ts b/src/sscma/grove_ai_we2/xmodem.ts similarity index 100% rename from src/sscma/vision_ai_we_II/xmodem.ts rename to src/sscma/grove_ai_we2/xmodem.ts