diff --git a/src/components/hubPicker/index.ts b/src/components/hubPicker/index.ts index 95f65b2b..a4200da3 100644 --- a/src/components/hubPicker/index.ts +++ b/src/components/hubPicker/index.ts @@ -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'; + } +} diff --git a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx index 664ff4f2..3236c55e 100644 --- a/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx +++ b/src/firmware/installPybricksDialog/InstallPybricksDialog.tsx @@ -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, diff --git a/src/firmware/installPybricksDialog/actions.ts b/src/firmware/installPybricksDialog/actions.ts index 9b3495ce..6653de68 100644 --- a/src/firmware/installPybricksDialog/actions.ts +++ b/src/firmware/installPybricksDialog/actions.ts @@ -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, diff --git a/src/firmware/installPybricksDialog/hooks.ts b/src/firmware/installPybricksDialog/hooks.ts index ad0581ed..42535940 100644 --- a/src/firmware/installPybricksDialog/hooks.ts +++ b/src/firmware/installPybricksDialog/hooks.ts @@ -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.Move, moveHubZip], [Hub.City, cityHubZip], [Hub.Technic, technicHubZip], - [Hub.Move, moveHubZip], + [Hub.Prime, primeHubZip], + [Hub.Essential, essentialHubZip], + [Hub.Inventor, primeHubZip], ]); /** diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index 62d1f483..128314e3 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -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 {