mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
split firmware flashing from lwp3-bootloader
BLE won't always be the only way to flash firmware
This commit is contained in:
committed by
David Lechner
parent
6d81da0df0
commit
07d0b5ef39
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user