Skip to content

Commit

Permalink
chore: 불필요한 주석 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnks2U committed Dec 23, 2023
1 parent fb62c6f commit 94894af
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/class/hardware/webUsbFlasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class WebUsbFlasher {
this.endpointNumber = -1;
}

// TODO: 함수분리 리팩토링
async flashFirmware(firmwareUrl: string, moduleId: string) {
try {
const response = await fetch(firmwareUrl);
Expand All @@ -38,12 +39,10 @@ export default class WebUsbFlasher {
filters: [{ vendorId: 0x0d28 }],
});
await this.device.open();
// selectConfiguration 체크
await this.device.selectConfiguration(1);
this.findInterface();
await this.device.claimInterface(this.claimInterface);

// store.set(flashStateAtom, 'start');
this.flashState = 'start';
const result = await this.writeData([0x8a, 1]);
if (result[1] !== 0) {
Expand All @@ -54,19 +53,16 @@ export default class WebUsbFlasher {
let sentPages = 0;

this.flashState = 'flashing';
// store.set(flashStateAtom, 'flashing');
// webApi타입 ble인 block 파일에 넣어줘야 할듯
while (offset < data.length) {
const end = Math.min(data.length, offset + chunkSize);
const nextPageData = data.slice(offset, end);
const cmdData = new Uint8Array(2 + nextPageData.length);
cmdData[0] = 0x8c;
cmdData[1] = nextPageData.length;
cmdData.set(nextPageData, 2);
// TODO: 퍼센트 로직도 분리하기
// TODO: 퍼센트 로직도 분리
if (sentPages % 128 == 0) {
this.flashingPercent = (offset / data.length) * 100;
// store.set(percentAtom, (offset / data.length) * 100);
console.log(this.flashingPercent);
}
await this.writeBuffer(cmdData);
Expand All @@ -75,25 +71,22 @@ export default class WebUsbFlasher {
}
this.flashingPercent = (offset / data.length) * 100;
console.log(this.flashingPercent);
// store.set(percentAtom, (offset / data.length) * 100);
this.flashState = 'end';
// store.set(flashStateAtom, 'end');

// close
// INFO: close
const flashResult = await this.writeData([0x8b]);
if (flashResult[1] !== 0) {
throw Error('flash failed');
}

// reset
// INFO: reset
await this.writeData([0x89]);
} finally {
this.flashState = 'idle';
// store.set(flashStateAtom, 'idle');
}
}

// study: 좀 더 확인이 필요

findInterface() {
const filteredInterfaces = this.device.configurations[0].interfaces.filter(
(interfaceItem) => {
Expand Down Expand Up @@ -166,7 +159,7 @@ export default class WebUsbFlasher {
}
}

// TODO: buffer랑 합치기?
// TODO: buffer랑 합치기
async writeData(data: Array<number>): Promise<Uint8Array> {
const response = await this.transfer(new Uint8Array(data));
if (!response.data?.buffer) {
Expand Down

0 comments on commit 94894af

Please sign in to comment.