Skip to content

Commit fb4c0cd

Browse files
authored
Merge pull request #613 from NordicSemiconductor/refactor/rename-device-setup-types
Refactor/rename device setup types
2 parents 340772b + ffc574c commit fb4c0cd

13 files changed

Lines changed: 48 additions & 45 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/coverage
44
/scripts/nordic-publish.js
55
/dist
6-
/typings/generated/tsconfig.tsbuildinfo
6+
/typings/generated/tsconfig.tsbuildinfo
7+
.vscode/settings.json

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ every new version is a new major version.
1616
- Optional `choiceMessage` to `DeviceSetup`
1717
- `react-dom` is now listed as an external package.
1818

19+
### Changed
20+
21+
- `IDeviceSetup` renamed to `DeviceSetup`
22+
- `DeviceSetup` renamed to `DeviceSetupConfig`
23+
1924
### Removed
2025

2126
- `needSerialport` property from `DeviceSetup`.
@@ -26,6 +31,8 @@ every new version is a new major version.
2631
- `needSerialport` has been removed from `IDeviceSetup`. If needed, it should
2732
be placed into the `supportsProgrammingMode` callback or can be passed as a
2833
parameter to the `jprogDeviceSetup` or `sdfuDeviceSetup` wrappers.
34+
- Replace type `DeviceSetup` with `DeviceSetupConfig`
35+
- Replace type `IDeviceSetup` with `DeviceSetup`
2936

3037
## 46 - 2023-05-19
3138

src/Device/DeviceSelector/DeviceSelector.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('DeviceSelector', () => {
231231
jlink: true,
232232
mcuBoot: true,
233233
}}
234-
deviceSetup={{
234+
deviceSetupConfig={{
235235
deviceSetups: [
236236
jprogDeviceSetup([
237237
{
@@ -263,7 +263,7 @@ describe('DeviceSelector', () => {
263263
jlink: true,
264264
mcuBoot: true,
265265
}}
266-
deviceSetup={{
266+
deviceSetupConfig={{
267267
deviceSetups: [
268268
jprogDeviceSetup([
269269
{
@@ -301,7 +301,7 @@ describe('DeviceSelector', () => {
301301
jlink: true,
302302
mcuBoot: true,
303303
}}
304-
deviceSetup={validFirmware}
304+
deviceSetupConfig={validFirmware}
305305
/>,
306306
[setDevices([testDevice])]
307307
);
@@ -323,7 +323,7 @@ describe('DeviceSelector', () => {
323323
jlink: true,
324324
mcuBoot: true,
325325
}}
326-
deviceSetup={validFirmware}
326+
deviceSetupConfig={validFirmware}
327327
/>,
328328
[setDevices([testDevice])]
329329
);

src/Device/DeviceSelector/DeviceSelector.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
setAutoSelectDevice,
1717
} from '../deviceAutoSelectSlice';
1818
import { startWatchingDevices, stopWatchingDevices } from '../deviceLister';
19-
import { DeviceSetup as DeviceSetupShared, setupDevice } from '../deviceSetup';
19+
import { DeviceSetupConfig, setupDevice } from '../deviceSetup';
2020
import DeviceSetupView from '../DeviceSetup/DeviceSetupView';
2121
import {
2222
deselectDevice,
@@ -35,7 +35,7 @@ interface OutdatedDeviceTraits {
3535

3636
export interface Props {
3737
deviceListing: DeviceTraits & OutdatedDeviceTraits;
38-
deviceSetup?: DeviceSetupShared;
38+
deviceSetupConfig?: DeviceSetupConfig;
3939
onDeviceSelected?: (device: Device, autoReselected: boolean) => void;
4040
onDeviceDeselected?: () => void;
4141
onDeviceConnected?: (device: Device) => void;
@@ -47,7 +47,7 @@ export interface Props {
4747
const noop = () => {};
4848
export default ({
4949
deviceListing,
50-
deviceSetup,
50+
deviceSetupConfig,
5151
onDeviceSelected = noop,
5252
onDeviceDeselected = noop,
5353
onDeviceConnected = noop,
@@ -80,19 +80,19 @@ export default ({
8080
dispatch(selectDevice(device));
8181
dispatch(setAutoSelectDevice(device));
8282
onDeviceSelected(device, autoReselected);
83-
if (deviceSetup) {
83+
if (deviceSetupConfig) {
8484
dispatch(
8585
setupDevice(
8686
device,
87-
deviceSetup,
87+
deviceSetupConfig,
8888
onDeviceIsReady,
8989
doDeselectDevice
9090
)
9191
);
9292
}
9393
},
9494
[
95-
deviceSetup,
95+
deviceSetupConfig,
9696
dispatch,
9797
doDeselectDevice,
9898
onDeviceIsReady,

src/Device/deviceSetup.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
55
*/
6-
import { SerialPort } from 'serialport';
7-
86
import logger from '../logging';
97
import describeError from '../logging/describeError';
108
import { Device, RootState, TDispatch } from '../state';
@@ -33,7 +31,7 @@ export interface JprogEntry {
3331
fwVersion: string;
3432
}
3533

36-
export interface IDeviceSetup {
34+
export interface DeviceSetup {
3735
supportsProgrammingMode: (device: Device) => boolean; // Return true if this device can be programed using this interface e.g. MCU Boot or DFU
3836
getFirmwareOptions: (device: Device) => {
3937
key: string;
@@ -60,17 +58,17 @@ export interface IDeviceSetup {
6058
) => Promise<Device | null>; // returns the device after switched to app mode. If this is not possible or not relevant return null
6159
}
6260

63-
export interface DeviceSetup {
64-
deviceSetups: IDeviceSetup[];
65-
allowCustomDevice?: boolean; // allow custom J-Link device
61+
export interface DeviceSetupConfig {
62+
deviceSetups: DeviceSetup[];
63+
allowCustomDevice?: boolean;
6664
confirmMessage?: string;
6765
choiceMessage?: string;
6866
}
6967

7068
export const prepareDevice =
7169
(
7270
device: Device,
73-
deviceSetupConfig: DeviceSetup,
71+
deviceSetupConfig: DeviceSetupConfig,
7472
onSuccess: (device: Device) => void,
7573
onFail: (reason?: unknown) => void,
7674
checkCurrentFirmwareVersion = true,
@@ -225,20 +223,18 @@ export const prepareDevice =
225223
export const setupDevice =
226224
(
227225
device: Device,
228-
deviceSetup: DeviceSetup,
226+
deviceSetupConfig: DeviceSetupConfig,
229227
onDeviceIsReady: (device: Device) => void,
230228
doDeselectDevice: () => void
231229
) =>
232-
(dispatch: TDispatch, getState: () => RootState) => {
233-
const deviceSetupConfig = {
234-
allowCustomDevice: false,
235-
...deviceSetup,
236-
};
237-
230+
(dispatch: TDispatch, getState: () => RootState) =>
238231
dispatch(
239232
prepareDevice(
240233
device,
241-
deviceSetupConfig,
234+
{
235+
allowCustomDevice: false,
236+
...deviceSetupConfig,
237+
},
242238
d => {
243239
// Given that this task has async elements to it one might call setupDevice and
244240
// while that is still in progress select some other device
@@ -260,4 +256,3 @@ export const setupDevice =
260256
}
261257
)
262258
);
263-
};

src/Device/jprogOperations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import nrfDeviceLib, {
1616
import logger from '../logging';
1717
import { Device, RootState, TDispatch } from '../state';
1818
import { getDeviceLibContext } from './deviceLibWrapper';
19-
import { IDeviceSetup, JprogEntry } from './deviceSetup';
19+
import { DeviceSetup, JprogEntry } from './deviceSetup';
2020
import { setReadbackProtected } from './deviceSlice';
2121

2222
const program = (
@@ -155,7 +155,7 @@ const firmwareOptions = (device: Device, firmware: JprogEntry[]) =>
155155
export const jprogDeviceSetup = (
156156
firmware: JprogEntry[],
157157
needSerialport = false
158-
): IDeviceSetup => ({
158+
): DeviceSetup => ({
159159
supportsProgrammingMode: (device: Device) =>
160160
(needSerialport === !!device.traits.serialPorts || !needSerialport) &&
161161
!!device.traits.jlink,

src/Device/sdfuOperations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Device, TDispatch } from '../state';
1515
import { getAppFile } from '../utils/appDirs';
1616
import { setWaitForDevice } from './deviceAutoSelectSlice';
1717
import { getDeviceLibContext } from './deviceLibWrapper';
18-
import { DfuEntry, IDeviceSetup } from './deviceSetup';
18+
import { DeviceSetup, DfuEntry } from './deviceSetup';
1919
import { openDeviceSetupDialog } from './deviceSetupSlice';
2020
import {
2121
createInitPacketBuffer,
@@ -549,7 +549,7 @@ const programDeviceWithFw =
549549
export const sdfuDeviceSetup = (
550550
dfuFirmware: DfuEntry[],
551551
needSerialport = false
552-
): IDeviceSetup => ({
552+
): DeviceSetup => ({
553553
supportsProgrammingMode: (device: Device) =>
554554
((!!device.dfuTriggerVersion &&
555555
device.dfuTriggerVersion.semVer.length > 0) ||

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export type { Props as DeviceSelectorProps } from './Device/DeviceSelector/Devic
125125

126126
export type { PaneProps } from './App/App';
127127
export type { DfuImage } from './Device/initPacket';
128-
export type { DeviceSetup, IDeviceSetup } from './Device/deviceSetup';
128+
export type { DeviceSetupConfig, DeviceSetup } from './Device/deviceSetup';
129129
export { prepareDevice } from './Device/deviceSetup';
130130
export type {
131131
AppInfo,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/// <reference types="react" />
22
import { DeviceTraits } from '@nordicsemiconductor/nrf-device-lib-js';
33
import { Device } from '../../state';
4-
import { DeviceSetup as DeviceSetupShared } from '../deviceSetup';
4+
import { DeviceSetupConfig } from '../deviceSetup';
55
interface OutdatedDeviceTraits {
66
serialPort?: boolean;
77
serialport?: boolean;
88
}
99
export interface Props {
1010
deviceListing: DeviceTraits & OutdatedDeviceTraits;
11-
deviceSetup?: DeviceSetupShared;
11+
deviceSetupConfig?: DeviceSetupConfig;
1212
onDeviceSelected?: (device: Device, autoReselected: boolean) => void;
1313
onDeviceDeselected?: () => void;
1414
onDeviceConnected?: (device: Device) => void;
1515
onDeviceDisconnected?: (device: Device) => void;
1616
onDeviceIsReady?: (device: Device) => void;
1717
deviceFilter?: (device: Device) => boolean;
1818
}
19-
declare const _default: ({ deviceListing, deviceSetup, onDeviceSelected, onDeviceDeselected, onDeviceConnected, onDeviceDisconnected, onDeviceIsReady, deviceFilter, }: Props) => JSX.Element;
19+
declare const _default: ({ deviceListing, deviceSetupConfig, onDeviceSelected, onDeviceDeselected, onDeviceConnected, onDeviceDisconnected, onDeviceIsReady, deviceFilter, }: Props) => JSX.Element;
2020
export default _default;

typings/generated/src/Device/deviceSetup.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface JprogEntry {
1616
fwIdAddress: number;
1717
fwVersion: string;
1818
}
19-
export interface IDeviceSetup {
19+
export interface DeviceSetup {
2020
supportsProgrammingMode: (device: Device) => boolean;
2121
getFirmwareOptions: (device: Device) => {
2222
key: string;
@@ -29,11 +29,11 @@ export interface IDeviceSetup {
2929
}>;
3030
tryToSwitchToApplicationMode: (device: Device) => (dispatch: TDispatch, getState: () => RootState) => Promise<Device | null>;
3131
}
32-
export interface DeviceSetup {
33-
deviceSetups: IDeviceSetup[];
32+
export interface DeviceSetupConfig {
33+
deviceSetups: DeviceSetup[];
3434
allowCustomDevice?: boolean;
3535
confirmMessage?: string;
3636
choiceMessage?: string;
3737
}
38-
export declare const prepareDevice: (device: Device, deviceSetupConfig: DeviceSetup, onSuccess: (device: Device) => void, onFail: (reason?: unknown) => void, checkCurrentFirmwareVersion?: boolean, requireUserConfirmation?: boolean) => (dispatch: TDispatch) => Promise<void>;
39-
export declare const setupDevice: (device: Device, deviceSetup: DeviceSetup, onDeviceIsReady: (device: Device) => void, doDeselectDevice: () => void) => (dispatch: TDispatch, getState: () => RootState) => void;
38+
export declare const prepareDevice: (device: Device, deviceSetupConfig: DeviceSetupConfig, onSuccess: (device: Device) => void, onFail: (reason?: unknown) => void, checkCurrentFirmwareVersion?: boolean, requireUserConfirmation?: boolean) => (dispatch: TDispatch) => Promise<void>;
39+
export declare const setupDevice: (device: Device, deviceSetupConfig: DeviceSetupConfig, onDeviceIsReady: (device: Device) => void, doDeselectDevice: () => void) => (dispatch: TDispatch, getState: () => RootState) => Promise<void>;

0 commit comments

Comments
 (0)