From a6489118e1ee52ce81f254bb4ab54d8ca2ad3022 Mon Sep 17 00:00:00 2001 From: Tsvetelin Petrov <42267885+tsvetelinpetrov@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:15:18 +0200 Subject: [PATCH 1/6] Add select target in write dialog --- src/actions/mcubootTargetActions.ts | 4 ++- src/components/McuUpdateDialogView.tsx | 46 +++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/actions/mcubootTargetActions.ts b/src/actions/mcubootTargetActions.ts index 0afbedf5..61bded27 100644 --- a/src/actions/mcubootTargetActions.ts +++ b/src/actions/mcubootTargetActions.ts @@ -62,7 +62,8 @@ export const performUpdate = async ( dfuFilePath: string, onProgress: (progress: Progress) => void, abortController: AbortController, - netCoreUploadDelay?: number + netCoreUploadDelay?: number, + target?: string ) => { logger.info(`Writing ${dfuFilePath} to device ${device.serialNumber}`); @@ -75,6 +76,7 @@ export const performUpdate = async ( undefined, { netCoreUploadDelay, + target, }, abortController ); diff --git a/src/components/McuUpdateDialogView.tsx b/src/components/McuUpdateDialogView.tsx index f9118299..17b8a6fd 100644 --- a/src/components/McuUpdateDialogView.tsx +++ b/src/components/McuUpdateDialogView.tsx @@ -23,6 +23,7 @@ import { logger, NumberInlineInput, selectedDevice, + selectedDeviceInfo, setWaitForDevice, Slider, Toggle, @@ -56,8 +57,14 @@ const McuUpdateDialogView = () => { const isVisible = useSelector(getShowMcuBootProgrammingDialog); const mcubootFwPath = useSelector(getMcubootFilePath); const zipFilePath = useSelector(getZipFilePath); + const deviceInfo = useSelector(selectedDeviceInfo); + + const programmingOptions = + deviceInfo?.mcuStateOptions?.filter(s => s.type === 'Programming') ?? + []; const fwPath = mcubootFwPath || zipFilePath; + const [chosenTarget, setChosenTarget] = useState(''); const writingHasStarted = writing || writingFail || writingSucceed; @@ -175,7 +182,8 @@ Are you sure you want to continue?`, setProgress(updatedProgress); }, abortController.current, - showDelayTimeout ? uploadDelay : undefined + showDelayTimeout ? uploadDelay : undefined, + chosenTarget ) .then(() => { setWritingSucceed(true); @@ -247,6 +255,42 @@ Are you sure you want to continue?`, {` ${mcubootFwPath || zipFilePath}`} + + {programmingOptions.length > 1 && ( + + + Target: + + Your device has multiple targets. Please + select the target you want to program. + + } + > + + + + { + setChosenTarget(e.target.value); + }} + > + + {programmingOptions.map(option => ( + + ))} + + + )} + {writing && ( From d7fefa328b4cf94ef1db7954b26ac24205ee62a9 Mon Sep 17 00:00:00 2001 From: Tsvetelin Petrov <42267885+tsvetelinpetrov@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:26:13 +0200 Subject: [PATCH 2/6] Add check if target is selected --- src/components/McuUpdateDialogView.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/McuUpdateDialogView.tsx b/src/components/McuUpdateDialogView.tsx index 17b8a6fd..96f9d630 100644 --- a/src/components/McuUpdateDialogView.tsx +++ b/src/components/McuUpdateDialogView.tsx @@ -239,7 +239,12 @@ Are you sure you want to continue?`, 1 && !chosenTarget) + } > Write From a718638080449374591245e5342bccdcb063b1dc Mon Sep 17 00:00:00 2001 From: Tsvetelin Petrov <42267885+tsvetelinpetrov@users.noreply.github.com> Date: Thu, 17 Oct 2024 08:47:10 +0200 Subject: [PATCH 3/6] Use Dropdown from shared and disable target choose on zip file --- src/components/McuUpdateDialogView.tsx | 51 ++++++++++++++++---------- src/util/dataConstructors.ts | 46 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 src/util/dataConstructors.ts diff --git a/src/components/McuUpdateDialogView.tsx b/src/components/McuUpdateDialogView.tsx index 96f9d630..b89ea796 100644 --- a/src/components/McuUpdateDialogView.tsx +++ b/src/components/McuUpdateDialogView.tsx @@ -18,6 +18,8 @@ import { clearConfirmBeforeClose, clearWaitForDevice, DialogButton, + Dropdown, + DropdownItem, GenericDialog, getPersistentStore, logger, @@ -37,6 +39,10 @@ import { getShowMcuBootProgrammingDialog, setShowMcuBootProgrammingDialog, } from '../reducers/mcubootReducer'; +import { + convertToDropDownItems, + getSelectedDropdownItem, +} from '../util/dataConstructors'; import { WithRequired } from '../util/types'; const TOOLTIP_TEXT = @@ -63,6 +69,11 @@ const McuUpdateDialogView = () => { deviceInfo?.mcuStateOptions?.filter(s => s.type === 'Programming') ?? []; + const targetDropdownItems = convertToDropDownItems( + programmingOptions.map(s => s.arguments?.target), + false + ); + const fwPath = mcubootFwPath || zipFilePath; const [chosenTarget, setChosenTarget] = useState(''); @@ -118,6 +129,12 @@ const McuUpdateDialogView = () => { } }, [device, showDelayTimeout]); + useEffect(() => { + if (targetDropdownItems.length > 0) { + setChosenTarget(targetDropdownItems[0].value); + } + }, [targetDropdownItems]); + const onCancel = () => { dispatch(clearWaitForDevice()); dispatch(setShowMcuBootProgrammingDialog(false)); @@ -183,7 +200,7 @@ Are you sure you want to continue?`, }, abortController.current, showDelayTimeout ? uploadDelay : undefined, - chosenTarget + mcubootFwPath ? chosenTarget : undefined ) .then(() => { setWritingSucceed(true); @@ -243,7 +260,9 @@ Are you sure you want to continue?`, writing || writingSucceed || writingFail || - (programmingOptions.length > 1 && !chosenTarget) + (programmingOptions.length > 1 && + !chosenTarget && + !!mcubootFwPath) } > Write @@ -261,7 +280,7 @@ Are you sure you want to continue?`, - {programmingOptions.length > 1 && ( + {programmingOptions.length > 1 && !zipFilePath && ( Target: @@ -276,23 +295,17 @@ Are you sure you want to continue?`, - { - setChosenTarget(e.target.value); + { + setChosenTarget(item.value); }} - > - - {programmingOptions.map(option => ( - - ))} - + selectedItem={getSelectedDropdownItem( + targetDropdownItems, + chosenTarget + )} + disabled={writingHasStarted} + /> )} diff --git a/src/util/dataConstructors.ts b/src/util/dataConstructors.ts new file mode 100644 index 00000000..ca76b2a9 --- /dev/null +++ b/src/util/dataConstructors.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +import { + DropdownItem, + NumberDropdownItem, +} from '@nordicsemiconductor/pc-nrfconnect-shared'; + +export const getSelectedDropdownItem = ( + itemList: DropdownItem[], + value: unknown, + notFound?: DropdownItem +) => { + if (typeof value === 'boolean') value = value ? 'on' : 'off'; + + if (value === undefined) return notFound ?? itemList[0]; + + const result = itemList[itemList.findIndex(e => e.value === `${value}`)]; + + return result === undefined ? notFound ?? itemList[0] : result; +}; + +export const convertToDropDownItems: ( + data: T[], + addAuto?: boolean +) => DropdownItem[] = (data, addAuto = true) => { + const mappedData = data.map(v => ({ + label: `${v}`, + value: `${v}`, + })); + + return addAuto + ? [{ label: 'Default', value: 'undefined' }, ...mappedData] + : mappedData; +}; + +export const convertToNumberDropDownItems: ( + data: number[] +) => NumberDropdownItem[] = data => + data.map(v => ({ + label: `${v}`, + value: v, + })); From fb90771a7528cebb763382cf0f23b1f45993e9c5 Mon Sep 17 00:00:00 2001 From: Tsvetelin Petrov <42267885+tsvetelinpetrov@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:40:30 +0200 Subject: [PATCH 4/6] Extract dataConstructors in shared --- src/components/McuUpdateDialogView.tsx | 6 ++-- src/util/dataConstructors.ts | 46 -------------------------- 2 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 src/util/dataConstructors.ts diff --git a/src/components/McuUpdateDialogView.tsx b/src/components/McuUpdateDialogView.tsx index b89ea796..4eab33e2 100644 --- a/src/components/McuUpdateDialogView.tsx +++ b/src/components/McuUpdateDialogView.tsx @@ -17,11 +17,13 @@ import { classNames, clearConfirmBeforeClose, clearWaitForDevice, + convertToDropDownItems, DialogButton, Dropdown, DropdownItem, GenericDialog, getPersistentStore, + getSelectedDropdownItem, logger, NumberInlineInput, selectedDevice, @@ -39,10 +41,6 @@ import { getShowMcuBootProgrammingDialog, setShowMcuBootProgrammingDialog, } from '../reducers/mcubootReducer'; -import { - convertToDropDownItems, - getSelectedDropdownItem, -} from '../util/dataConstructors'; import { WithRequired } from '../util/types'; const TOOLTIP_TEXT = diff --git a/src/util/dataConstructors.ts b/src/util/dataConstructors.ts deleted file mode 100644 index ca76b2a9..00000000 --- a/src/util/dataConstructors.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause - */ - -import { - DropdownItem, - NumberDropdownItem, -} from '@nordicsemiconductor/pc-nrfconnect-shared'; - -export const getSelectedDropdownItem = ( - itemList: DropdownItem[], - value: unknown, - notFound?: DropdownItem -) => { - if (typeof value === 'boolean') value = value ? 'on' : 'off'; - - if (value === undefined) return notFound ?? itemList[0]; - - const result = itemList[itemList.findIndex(e => e.value === `${value}`)]; - - return result === undefined ? notFound ?? itemList[0] : result; -}; - -export const convertToDropDownItems: ( - data: T[], - addAuto?: boolean -) => DropdownItem[] = (data, addAuto = true) => { - const mappedData = data.map(v => ({ - label: `${v}`, - value: `${v}`, - })); - - return addAuto - ? [{ label: 'Default', value: 'undefined' }, ...mappedData] - : mappedData; -}; - -export const convertToNumberDropDownItems: ( - data: number[] -) => NumberDropdownItem[] = data => - data.map(v => ({ - label: `${v}`, - value: v, - })); From c0c858bd7bcc21af2e49aa3e0106256dd042f068 Mon Sep 17 00:00:00 2001 From: Tsvetelin Petrov <42267885+tsvetelinpetrov@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:38:32 +0200 Subject: [PATCH 5/6] Change to tooltip from shared --- src/components/McuUpdateDialogView.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/McuUpdateDialogView.tsx b/src/components/McuUpdateDialogView.tsx index 4eab33e2..a01ad094 100644 --- a/src/components/McuUpdateDialogView.tsx +++ b/src/components/McuUpdateDialogView.tsx @@ -26,6 +26,7 @@ import { getSelectedDropdownItem, logger, NumberInlineInput, + Overlay, selectedDevice, selectedDeviceInfo, setWaitForDevice, @@ -45,6 +46,8 @@ import { WithRequired } from '../util/types'; const TOOLTIP_TEXT = 'Delay duration to allow successful image swap from RAM NET to NET core after image upload. Recommended default timeout is 40s. Should be increased for the older Thingy:53 devices'; +const TOOLTIP_TEXT_MULTIPLE_TARGETS = + 'Your device has multiple targets. Please select the target you want to program.'; const NET_CORE_UPLOAD_DELAY = 120; @@ -280,18 +283,20 @@ Are you sure you want to continue?`, {programmingOptions.length > 1 && !zipFilePath && ( - + Target: - - Your device has multiple targets. Please - select the target you want to program. - + {TOOLTIP_TEXT_MULTIPLE_TARGETS} } + keepShowingOnHoverTooltip + tooltipId="test" + placement="right" > - + Date: Fri, 27 Dec 2024 16:18:08 +0200 Subject: [PATCH 6/6] Update changelog --- Changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changelog.md b/Changelog.md index cff2a4a7..4487186e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +## Unreleased + +### Added + +- Write support for 91x + ## 4.5.0 - 2024-12-17 ### Changed