split firmware flashing from lwp3-bootloader

BLE won't always be the only way to flash firmware
This commit is contained in:
David Lechner
2020-06-09 23:51:32 -05:00
committed by David Lechner
parent 6d81da0df0
commit 07d0b5ef39
8 changed files with 376 additions and 371 deletions
+58
View File
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { Action } from 'redux';
/**
* High-level bootloader actions.
*/
export enum FlashFirmwareActionType {
/**
* Flash new firmware to the device.
*/
FlashFirmware = 'flashFirmware.action.flashFirmware',
/**
* Firmware flash progress.
*/
Progress = 'flashFirmware.action.progress',
}
/**
* Action that flashes firmware to a hub.
*/
export interface FlashFirmwareFlashAction
extends Action<FlashFirmwareActionType.FlashFirmware> {
/** The firmware zip file data or undefined to get firmware later. */
data?: ArrayBuffer;
}
/**
* Creates a new action to flash firmware to a hub.
* @param data The firmware zip file data or undefined to get firmware later.
*/
export function flashFirmware(data?: ArrayBuffer): FlashFirmwareFlashAction {
return { type: FlashFirmwareActionType.FlashFirmware, data };
}
export interface FlashFirmwareProgressAction
extends Action<FlashFirmwareActionType.Progress> {
/**
* The number of bytes that have been flashed so far.
*/
complete: number;
/**
* The total number of bytes to be flashed.
*/
total: number;
}
export function progress(complete: number, total: number): FlashFirmwareProgressAction {
return { type: FlashFirmwareActionType.Progress, complete, total };
}
/**
* Common type for all high-level bootloader actions.
*/
export type FlashFirmwareAction =
| FlashFirmwareFlashAction
| FlashFirmwareProgressAction;
+5 -5
View File
@@ -4,9 +4,9 @@
import { Dispatch as ReduxDispatch } from 'redux';
import { BLEAction, BLEConnectAction, BLEDataAction } from './ble';
import { EditorAction } from './editor';
import { FlashFirmwareAction } from './flash-firmware';
import { HubAction, HubMessageAction } from './hub';
import {
BootloaderAction,
BootloaderConnectionAction,
BootloaderDidRequestAction,
BootloaderRequestAction,
@@ -21,17 +21,17 @@ import { TerminalDataAction } from './terminal';
* Common type for all actions.
*/
export type Action =
| BLEAction
| BLEConnectAction
| BLEDataAction
| BLEAction
| BootloaderConnectionAction
| BootloaderRequestAction
| BootloaderDidRequestAction
| BootloaderRequestAction
| BootloaderResponseAction
| BootloaderAction
| EditorAction
| HubMessageAction
| FlashFirmwareAction
| HubAction
| HubMessageAction
| MpyAction
| NotificationAction
| ServiceWorkerAction
-57
View File
@@ -463,60 +463,3 @@ export type BootloaderResponseAction =
| BootloaderChecksumResponseAction
| BootloaderStateResponseAction
| BootloaderErrorResponseAction;
/**
* High-level bootloader actions.
*/
export enum BootloaderActionType {
/**
* Flash new firmware to the device.
*/
FlashFirmware = 'bootloader.action.flash',
/**
* Firmware flash progress.
*/
FlashProgress = 'bootloader.action.flash.progress',
}
/**
* Action that flashes firmware to a hub.
*/
export interface BootloaderFlashFirmwareAction
extends Action<BootloaderActionType.FlashFirmware> {
/** The firmware zip file data or undefined to get firmware later. */
data?: ArrayBuffer;
}
/**
* Creates a new action to flash firmware to a hub.
* @param data The firmware zip file data or undefined to get firmware later.
*/
export function flashFirmware(data?: ArrayBuffer): BootloaderFlashFirmwareAction {
return { type: BootloaderActionType.FlashFirmware, data };
}
export interface BootloaderFlashProgressAction
extends Action<BootloaderActionType.FlashProgress> {
/**
* The number of bytes that have been flashed so far.
*/
complete: number;
/**
* The total number of bytes to be flashed.
*/
total: number;
}
export function progress(
complete: number,
total: number,
): BootloaderFlashProgressAction {
return { type: BootloaderActionType.FlashProgress, complete, total };
}
/**
* Common type for all high-level bootloader actions.
*/
export type BootloaderAction =
| BootloaderFlashFirmwareAction
| BootloaderFlashProgressAction;