-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #766 from remap-keys/copy-bootloader-type
Support a file copy to flash a firmware.
- Loading branch information
Showing
7 changed files
with
145 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { IBootloader, IBootloaderReadResult } from '../Bootloader'; | ||
import { | ||
FirmwareWriterPhaseListener, | ||
FirmwareWriterProgressListener, | ||
} from '../FirmwareWriter'; | ||
import { IResult } from '../Types'; | ||
|
||
export class WebFileSystem implements IBootloader { | ||
private directoryHandle: any | undefined; | ||
|
||
constructor() { | ||
this.directoryHandle = undefined; | ||
} | ||
|
||
async open(): Promise<IResult> { | ||
try { | ||
this.directoryHandle = await window.showDirectoryPicker({ | ||
mode: 'readwrite', | ||
}); | ||
return { success: true }; | ||
} catch (error) { | ||
return { | ||
success: false, | ||
error: `Opening a directory failed: ${error}`, | ||
cause: error, | ||
}; | ||
} | ||
} | ||
|
||
async read( | ||
// eslint-disable-next-line no-unused-vars | ||
size: number, | ||
// eslint-disable-next-line no-unused-vars | ||
progress: FirmwareWriterProgressListener, | ||
// eslint-disable-next-line no-unused-vars | ||
phase: FirmwareWriterPhaseListener | ||
): Promise<IBootloaderReadResult> { | ||
throw new Error('This method never be called.'); | ||
} | ||
|
||
async verify( | ||
// eslint-disable-next-line no-unused-vars | ||
bytes: Uint8Array, | ||
// eslint-disable-next-line no-unused-vars | ||
progress: FirmwareWriterProgressListener, | ||
// eslint-disable-next-line no-unused-vars | ||
phase: FirmwareWriterPhaseListener | ||
): Promise<IResult> { | ||
throw new Error('This method never be called.'); | ||
} | ||
|
||
async write( | ||
flashBytes: Uint8Array, | ||
// eslint-disable-next-line no-unused-vars | ||
eepromBytes: Uint8Array | null, | ||
progress: FirmwareWriterProgressListener, | ||
phase: FirmwareWriterPhaseListener | ||
): Promise<IResult> { | ||
if (this.directoryHandle === undefined) { | ||
throw new Error('A target directory is not opened.'); | ||
} | ||
try { | ||
progress('Start writing firmware to a file.'); | ||
const fileHandle = await this.directoryHandle.getFileHandle( | ||
'firmware.uf2', | ||
{ create: true } | ||
); | ||
const writable = await fileHandle.createWritable(); | ||
await writable.write(flashBytes); | ||
await writable.close(); | ||
progress('Writing firmware to a file is completed.'); | ||
phase('wrote'); | ||
this.directoryHandle = undefined; | ||
phase('closed'); | ||
return { success: true }; | ||
} catch (error) { | ||
return { | ||
success: false, | ||
error: `Writing firmware to a file failed: ${error}`, | ||
cause: error, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters