firmware/installPybricksDialog: add bootloader discrimination

Also fix license not showing for newer hubs.
This commit is contained in:
David Lechner
2022-07-20 18:51:45 -05:00
parent 709c3c554b
commit bb6f86ff18
5 changed files with 43 additions and 5 deletions
+14
View File
@@ -57,3 +57,17 @@ export function hubHasExternalFlash(hub: Hub): boolean {
return false;
}
}
/** Gets the bootloader type for the hub. */
export function hubBootloaderType(hub: Hub) {
switch (hub) {
case Hub.Prime:
case Hub.Essential:
case Hub.Inventor:
return 'usb-lego-dfu';
case Hub.Move:
case Hub.City:
case Hub.Technic:
return 'ble-lwp3-bootloader';
}
}
@@ -28,6 +28,7 @@ import { appName } from '../../app/constants';
import HelpButton from '../../components/HelpButton';
import {
Hub,
hubBootloaderType,
hubHasBluetoothButton,
hubHasExternalFlash,
hubHasUSB,
@@ -426,6 +427,7 @@ export const InstallPybricksDialog: React.VoidFunctionComponent = () => {
onClick: () =>
dispatch(
firmwareInstallPybricksDialogAccept(
hubBootloaderType(hubType),
data?.firmwareZip ?? new ArrayBuffer(0),
selectedIncludeFile?.path,
hubName,
+10 -1
View File
@@ -8,15 +8,24 @@ export const firmwareInstallPybricksDialogShow = createAction(() => ({
type: 'firmware.installPybricksDialog.action.show',
}));
type FlashMethod = 'ble-lwp3-bootloader' | 'usb-lego-dfu';
/**
* Action that indicates the user accepted the install Pybricks firmware dialog.
* @param flashMethod The connection method and protocol used for flashing.
* @param firmwareZip The firmware.zip raw data.
* @param customProgram Optional path of custom program to include when flashing firmware.
* @param hubName The hub name to use when flashing firmware.
*/
export const firmwareInstallPybricksDialogAccept = createAction(
(firmwareZip: ArrayBuffer, customProgram: string | undefined, hubName: string) => ({
(
flashMethod: FlashMethod,
firmwareZip: ArrayBuffer,
customProgram: string | undefined,
hubName: string,
) => ({
type: 'firmware.installPybricksDialog.action.accept',
flashMethod,
firmwareZip,
customProgram,
hubName,
+6 -1
View File
@@ -4,7 +4,9 @@
import { FirmwareReader } from '@pybricks/firmware';
import cityHubZip from '@pybricks/firmware/build/cityhub.zip';
import essentialHubZip from '@pybricks/firmware/build/essentialhub.zip';
import moveHubZip from '@pybricks/firmware/build/movehub.zip';
import primeHubZip from '@pybricks/firmware/build/primehub.zip';
import technicHubZip from '@pybricks/firmware/build/technichub.zip';
import { useEffect, useReducer, useRef } from 'react';
import { Hub } from '../../components/hubPicker';
@@ -30,9 +32,12 @@ type Action =
| { type: 'error'; payload: Error };
const firmwareZipMap = new Map<Hub, string>([
[Hub.Move, moveHubZip],
[Hub.City, cityHubZip],
[Hub.Technic, technicHubZip],
[Hub.Move, moveHubZip],
[Hub.Prime, primeHubZip],
[Hub.Essential, essentialHubZip],
[Hub.Inventor, primeHubZip],
]);
/**
+11 -3
View File
@@ -525,9 +525,17 @@ function* handleInstallPybricks(): Generator {
defined(accepted);
yield* put(
flashFirmware(accepted.firmwareZip, accepted.customProgram, accepted.hubName),
);
switch (accepted.flashMethod) {
case 'ble-lwp3-bootloader':
yield* put(
flashFirmware(
accepted.firmwareZip,
accepted.customProgram,
accepted.hubName,
),
);
break;
}
}
export default function* (): Generator {