Skip to content

Commit

Permalink
feat: support config wifi & mqtt for Grove Vision AI(WE2)
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnL4 committed Dec 8, 2023
1 parent f099a6d commit b33a602
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/hooks/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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() {
const deviceStore = useDeviceStore();
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];
});
Expand Down
30 changes: 30 additions & 0 deletions src/pages/others/comming-soon/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<div class="content">
<a-result class="result" :subtitle="'comming soon'"> </a-result>
<div class="operation-row">
<a-button key="back" type="primary" @click="back"> back </a-button>
</div>
</div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router';
const router = useRouter();
const back = () => {
// warning: Go to the node that has the permission
router.push({ name: 'setup' });
};
</script>

<style scoped lang="less">
.content {
// padding-top: 100px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -121px;
margin-left: -95px;
text-align: center;
}
</style>
6 changes: 3 additions & 3 deletions src/pages/setup/config/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
</script>
Expand All @@ -13,9 +13,9 @@
deviceStore.deviceType.id === deviceTypeObj[DeviceType.XiaoEsp32s3].id
"
/>
<VisionAIWeIIConfig
<GroveAIWE2Config
v-else-if="
deviceStore.deviceType.id === deviceTypeObj[DeviceType.VisionAIWeII].id
deviceStore.deviceType.id === deviceTypeObj[DeviceType.GroveAIWE2].id
"
/>
</template>
2 changes: 1 addition & 1 deletion src/pages/setup/config/xiao_esp32s3/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import Config from '../components/Config.vue';
import Config from '../../../others/comming-soon/index.vue';
</script>

<template>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/setup/output/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { DeviceType, deviceTypeObj } from '@/sscma/constants';
import { useDeviceStore } from '@/store';
import XiaoESP32S3Output from './xiao_esp32s3/index.vue';
import VisionAIWeIIOutput from './vision_ai_we_II/index.vue';
import GroveAIWE2Output from './grove_ai_we2/index.vue';
const deviceStore = useDeviceStore();
</script>
Expand All @@ -13,9 +13,9 @@
deviceStore.deviceType.id === deviceTypeObj[DeviceType.XiaoEsp32s3].id
"
/>
<VisionAIWeIIOutput
<GroveAIWE2Output
v-else-if="
deviceStore.deviceType.id === deviceTypeObj[DeviceType.VisionAIWeII].id
deviceStore.deviceType.id === deviceTypeObj[DeviceType.GroveAIWE2].id
"
/>
</template>
18 changes: 9 additions & 9 deletions src/pages/setup/process/components/Device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/pages/setup/process/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
</script>
Expand All @@ -14,9 +14,9 @@
"
/>

<VisionAIWeIIProcess
<GroveAIWE2Process
v-else-if="
deviceStore.deviceType.id === deviceTypeObj[DeviceType.VisionAIWeII].id
deviceStore.deviceType.id === deviceTypeObj[DeviceType.GroveAIWE2].id
"
/>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</template>

<script lang="ts" setup>
import Flasher from '@/sscma/vision_ai_we_II/Flasher';
import Flasher from '@/sscma/grove_ai_we2/Flasher';
import Tools from '../components/Tools.vue';
const flasher = new Flasher();
Expand Down
8 changes: 4 additions & 4 deletions src/pages/utils/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { DeviceType, deviceTypeObj } from '@/sscma/constants';
import { useDeviceStore } from '@/store';
import XiaoESP32S3Tools from './xiao_esp32s3/index.vue';
import VisionAiWeIITools from './vision_ai_we_II/index.vue';
import GroveAIWE2Tools from './grove_ai_we2/index.vue';
const deviceStore = useDeviceStore();
</script>
Expand All @@ -14,10 +14,10 @@
"
key="XIAO ESP32S3"
/>
<VisionAiWeIITools
<GroveAIWE2Tools
v-else-if="
deviceStore.deviceType.id === deviceTypeObj[DeviceType.VisionAIWeII].id
deviceStore.deviceType.id === deviceTypeObj[DeviceType.GroveAIWE2].id
"
key="Vision AI (WE-II)"
key="GROVE AI WE2"
/>
</template>
6 changes: 3 additions & 3 deletions src/sscma/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DeviceType = {
XiaoEsp32s3: 'xiao_esp32s3',
VisionAIWeII: 'we_ii',
GroveAIWE2: 'we_ii',
};

export const DEVICE_LIST = [
Expand All @@ -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 }],
},
];
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})),
Expand Down Expand Up @@ -273,6 +273,74 @@ class Himax extends Device {
this.watchLoop = false;
}
}

public async getAction(): Promise<any> {
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<boolean> {
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<any> {
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();
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b33a602

Please sign in to comment.