Skip to content

Commit

Permalink
fix: is id not name
Browse files Browse the repository at this point in the history
  • Loading branch information
wutiange authored and LynnL4 committed Dec 13, 2023
1 parent 740776c commit e52c925
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/hooks/senseCraftAIComesToFlash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const useSenseCraftAIComesToFlash = () => {
'32': DeviceType.XiaoEsp32s3,
};
if (typeof deviceKeyToId[deviceType] === 'string') {
deviceStore.setDeviceType(deviceKeyToId[deviceType]);
deviceStore.setDeviceTypeById(deviceKeyToId[deviceType]);
}
deviceStore.setComeToSenseCraftAI({
model: {
Expand All @@ -102,7 +102,6 @@ const useSenseCraftAIComesToFlash = () => {
isCustom: true,
},
modelUrl: modelFile.arguments.url,
isFlashed: false,
});
deviceStore.setFlashWay(FlashWayType.ComeToSenseCraftAI);
}
Expand Down
1 change: 1 addition & 0 deletions src/locale/en-US/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ export default {
'There may be a problem with the firmware, please re-burn it.',
'workplace.serial.device.flash.confirm':
'Clicking confirm will deploy the model to the device',
'workplace.serial.device.port.occupied': 'Device is occupied',
};
3 changes: 3 additions & 0 deletions src/locale/zh-CN/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default {
'workplace.device.use.aimodel': '可用的AI模型',
'workplace.device.upload.aimodel': '上传自定义AI模型',
'workplace.device.select.aimodel': '请选择预设AI模型或上传自定义AI模型',
'workplace.device.select.comeToSenseCraft':
'将Al模型发送到设备并预览推理结果',
'workplace.device.send': '发送',
'workplace.device.model.aimodel': '自定义AI模型',
'workplace.device.model.sendmodel': '发送模型',
Expand Down Expand Up @@ -111,4 +113,5 @@ export default {
'workplace.serial.no.port': '用户未选择端口',
'workplace.serial.command.timeout': '固件可能存在问题,请重新烧录',
'workplace.serial.device.flash.confirm': '点击确定将部署模型到设备',
'workplace.serial.device.port.occupied': '设备已被占用',
};
3 changes: 2 additions & 1 deletion src/pages/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
import useDeviceManager from '@/hooks/deviceManager';
import { DEVICE_LIST } from '@/sscma/constants';
import { FlashWayType } from '@/store/modules/device';
import { flashErrorHandle } from '@/utils/flash';
import Menu from './Menu.vue';
const appStore = useAppStore();
Expand Down Expand Up @@ -241,7 +242,7 @@
}
} catch (error: any) {
console.error('Device connection failed: ', error);
Message.error(t('workplace.serial.connected.failed'));
flashErrorHandle(error, t('workplace.serial.connected.failed'));
term.writeln(`Error: ${error?.message}`);
} finally {
loading.value = false;
Expand Down
20 changes: 13 additions & 7 deletions src/pages/setup/process/components/Device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
import FlasherInterface from '@/sscma/FlasherInterface';
import useDeviceManager from '@/hooks/deviceManager';
import { FlashWayType } from '@/store/modules/device';
import { flashErrorHandle } from '@/utils/flash';
export type FileType<T> = {
data: T;
Expand Down Expand Up @@ -421,10 +422,15 @@
};
const comeToSenseCraftAIFlash = async () => {
await flashFirmware().finally(() => {
deviceStore.setComeToSenseCraftAIIsFlashed(true);
});
isComeToFlashFinished.value = true;
try {
await flashFirmware();
isComeToFlashFinished.value = true;
} catch (error: any) {
flashErrorHandle(error);
} finally {
loadingTip.value = '';
loading.value = false;
}
};
const handleUpload = async () => {
Expand Down Expand Up @@ -456,7 +462,7 @@
await flashFirmware();
} catch (error: any) {
console.error(error);
Message.error(error?.message ?? '');
flashErrorHandle(error);
term.writeln(`Error: ${error?.message}`);
} finally {
loadingTip.value = '';
Expand Down Expand Up @@ -526,7 +532,7 @@
return true;
} catch (error: any) {
console.error(error);
Message.error(error?.message);
flashErrorHandle(error);
} finally {
loadingTip.value = '';
loading.value = false;
Expand Down Expand Up @@ -562,7 +568,7 @@
async () => {
if (
deviceStore.flashWay === FlashWayType.ComeToSenseCraftAI &&
!deviceStore.comeToSenseCraftAI.isFlashed
!isComeToFlashFinished.value
) {
visible.value = true;
}
Expand Down
13 changes: 6 additions & 7 deletions src/store/modules/device/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export type ComeToSenseCraftAIType = {
isCustom: boolean;
};
modelUrl: string;
isFlashed: boolean;
};

const useDeviceStore = defineStore('device', {
state: () => ({
deviceStatus: DeviceStatus.UnConnected,
Expand Down Expand Up @@ -85,6 +83,12 @@ const useDeviceStore = defineStore('device', {
this.deviceType = { ...DEVICE_LIST[index] };
}
},
setDeviceTypeById(id: string) {
const index = DEVICE_LIST.findIndex((e) => e.id === id);
if (index !== -1) {
this.deviceType = { ...DEVICE_LIST[index] };
}
},
setDeviceName(name: string) {
this.deviceName = name;
},
Expand All @@ -97,11 +101,6 @@ const useDeviceStore = defineStore('device', {
setComeToSenseCraftAI(data: ComeToSenseCraftAIType) {
this.comeToSenseCraftAI = data;
},
setComeToSenseCraftAIIsFlashed(isFlashed: boolean) {
if (typeof this.comeToSenseCraftAI === 'object') {
this.comeToSenseCraftAI.isFlashed = isFlashed;
}
},
setFlashWay(flashWay: number) {
this.flashWay = flashWay;
},
Expand Down
17 changes: 17 additions & 0 deletions src/utils/flash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Message } from '@arco-design/web-vue';
import i18n from '@/locale';

export function flashErrorHandle(error?: Error, defaultMsg?: string) {
if (
[
`Failed to execute 'open' on 'SerialPort': Failed to open serial port.`,
`Failed to execute 'close' on 'SerialPort': The port is already closed.`,
].includes(error?.message ?? '')
) {
Message.error(i18n.global.t('workplace.serial.device.port.occupied'));
} else {
Message.error(defaultMsg ?? error?.message ?? '');
}
}

export default null;

0 comments on commit e52c925

Please sign in to comment.