Skip to content

Commit 95e4e53

Browse files
Merge pull request #549 from NordicSemiconductor/push-nosusnnolzww
Refactor colour algorithm
2 parents 7d8bef7 + f541147 commit 95e4e53

File tree

4 files changed

+19
-48
lines changed

4 files changed

+19
-48
lines changed

src/actions/usbsdfuTargetActions.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
defaultRegion,
4747
getSoftDeviceId,
4848
Region,
49-
RegionColor,
5049
RegionName,
5150
RegionPermission,
5251
} from '../util/regions';
@@ -135,7 +134,6 @@ export const refreshMemoryLayout =
135134
name: RegionName.MBR,
136135
startAddress: coreInfo.mbrBaseAddr,
137136
regionSize: coreInfo.mbrSize,
138-
color: RegionColor.MBR,
139137
permission: RegionPermission.NONE,
140138
});
141139
}
@@ -169,26 +167,11 @@ export const refreshMemoryLayout =
169167
RegionName.APPLICATION,
170168
})[imageType] || RegionName.NONE;
171169

172-
const color =
173-
(<
174-
Partial<{
175-
[key in ImageType]: RegionColor;
176-
}>
177-
>{
178-
NRFDL_IMAGE_TYPE_BOOTLOADER:
179-
RegionColor.BOOTLOADER,
180-
NRFDL_IMAGE_TYPE_SOFTDEVICE:
181-
RegionColor.SOFTDEVICE,
182-
NRFDL_IMAGE_TYPE_APPLICATION:
183-
RegionColor.APPLICATION,
184-
})[imageType] || RegionColor.NONE;
185-
186170
regions.push({
187171
...defaultRegion,
188172
name: regionName,
189173
startAddress,
190174
regionSize,
191-
color,
192175
});
193176
});
194177

src/components/RegionView.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,26 @@ import { colors } from '@nordicsemiconductor/pc-nrfconnect-shared';
1313

1414
import * as fileActions from '../actions/fileActions';
1515
import { CoreInfo } from '../util/devices';
16-
import { Region } from '../util/regions';
16+
import { Region, RegionName } from '../util/regions';
1717
import CoreInfoView from './CoreInfoView';
1818
import RegionInfoView from './RegionInfoView';
1919

20+
const regionColorByName: Record<RegionName | 'background', string> = {
21+
[RegionName.MBR_PARAMS]: '#333F48',
22+
[RegionName.MBR]: colors.orange,
23+
[RegionName.MBR_OR_APP]: colors.orange,
24+
[RegionName.BOOTLOADER]: colors.pink,
25+
[RegionName.SOFTDEVICE]: colors.indigo,
26+
[RegionName.APPLICATION]: colors.green,
27+
[RegionName.FICR]: '#333F48',
28+
[RegionName.UICR]: '#333F48',
29+
[RegionName.NONE]: '#333F48',
30+
31+
background: colors.gray100,
32+
};
33+
34+
const color = (name?: RegionName) => regionColorByName[name ?? 'background'];
35+
2036
interface RegionViewProps {
2137
width: number;
2238
active?: boolean;
@@ -47,7 +63,6 @@ const RegionView = ({
4763
setTarget(event.target as HTMLElement);
4864
};
4965

50-
const color = region ? region.color : colors.gray100;
5166
const fileNames = region ? region.fileNames : [];
5267

5368
let className = 'region';
@@ -68,7 +83,7 @@ const RegionView = ({
6883
className={className}
6984
style={{
7085
flexGrow: width,
71-
backgroundColor: color,
86+
backgroundColor: color(region?.name),
7287
}}
7388
>
7489
<Overlay

src/util/regions.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,13 @@ export enum RegionName {
4646
NONE = 'N/A',
4747
}
4848

49-
/**
50-
* Definition of RegionColor
51-
*/
52-
export enum RegionColor {
53-
MBR_PARAMS = '#333F48',
54-
MBR = '#FF9800',
55-
MBR_OR_APP = '#FFC107',
56-
BOOTLOADER = '#E91E63',
57-
SOFTDEVICE = '#3F51B5',
58-
APPLICATION = ' #4CAF50',
59-
UICR = '#333F48', // eslint-disable-line @typescript-eslint/no-duplicate-enum-values -- FIXME: Using an enum is wrong here and could potantially lead to bugs because RegionColor.UICR === RegionColor.NONE is true. Will be fixed later.
60-
NONE = '#333F48', // eslint-disable-line @typescript-eslint/no-duplicate-enum-values
61-
}
62-
6349
/**
6450
* Definition of Region
6551
*/
6652
export interface Region {
6753
name: RegionName;
6854
startAddress: number;
6955
regionSize: number;
70-
color: RegionColor;
7156
fileNames: string[];
7257
permission: RegionPermission;
7358
}
@@ -79,7 +64,6 @@ export const defaultRegion: Region = {
7964
name: RegionName.NONE,
8065
startAddress: 0,
8166
regionSize: 0,
82-
color: RegionColor.NONE,
8367
fileNames: [],
8468
permission: RegionPermission.READ_ONLY,
8569
};
@@ -219,7 +203,6 @@ export const getBootloaderRegion = (
219203
name: RegionName.BOOTLOADER,
220204
startAddress: bootloaderAddress,
221205
regionSize: memMap.get(bootloaderAddress)?.length || 0,
222-
color: RegionColor.BOOTLOADER,
223206
permission: RegionPermission.READ_WRITE,
224207
};
225208
return region;
@@ -248,7 +231,6 @@ export const getMBRParamsRegion = (
248231
name: RegionName.MBR_PARAMS,
249232
startAddress: mbrParamsAddr,
250233
regionSize: memMap.get(mbrParamsAddr)?.length || 0,
251-
color: RegionColor.MBR_PARAMS,
252234
permission: RegionPermission.READ_ONLY,
253235
};
254236
return region;
@@ -276,7 +258,6 @@ export const getMBRRegion = (
276258
name: RegionName.MBR_OR_APP,
277259
startAddress: romBaseAddr,
278260
regionSize: memMap.get(romBaseAddr)?.length || 0,
279-
color: RegionColor.MBR,
280261
permission: RegionPermission.READ_ONLY,
281262
};
282263
return region;
@@ -317,7 +298,6 @@ export const getSoftDeviceRegion = (
317298
name: RegionName.SOFTDEVICE,
318299
startAddress: SOFTDEVICE_MAGIC_START,
319300
regionSize,
320-
color: RegionColor.SOFTDEVICE,
321301
permission: RegionPermission.READ_WRITE,
322302
};
323303
return region;
@@ -517,7 +497,6 @@ const getRegionsFromOverlaps = (
517497
: {
518498
...defaultRegion,
519499
name: RegionName.NONE,
520-
color: RegionColor.NONE,
521500
startAddress,
522501
regionSize,
523502
fileNames,
@@ -536,7 +515,6 @@ const getRegionsFromOverlaps = (
536515
const appRegion = {
537516
...defaultRegion,
538517
name: RegionName.APPLICATION,
539-
color: RegionColor.APPLICATION,
540518
startAddress: startAddress + region.regionSize,
541519
regionSize: regionSize - region.regionSize,
542520
fileNames,
@@ -555,7 +533,6 @@ const getRegionsFromOverlaps = (
555533
region = {
556534
...region,
557535
name: RegionName.APPLICATION,
558-
color: RegionColor.APPLICATION,
559536
};
560537
}
561538

@@ -570,7 +547,6 @@ const getRegionsFromOverlaps = (
570547
region = {
571548
...region,
572549
name: RegionName.APPLICATION,
573-
color: RegionColor.APPLICATION,
574550
};
575551
}
576552

@@ -585,7 +561,6 @@ const getRegionsFromOverlaps = (
585561
region = {
586562
...region,
587563
name: RegionName.APPLICATION,
588-
color: RegionColor.APPLICATION,
589564
};
590565
}
591566

@@ -595,7 +570,6 @@ const getRegionsFromOverlaps = (
595570
region = {
596571
...region,
597572
name: RegionName.APPLICATION,
598-
color: RegionColor.APPLICATION,
599573
};
600574
}
601575

src/util/usbsdfuHelpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { convertDeviceDefinitionToCoreArray } from './devices';
88
import { DeviceDefinition } from './deviceTypes';
9-
import { defaultRegion, Region, RegionColor, RegionName } from './regions';
9+
import { defaultRegion, Region, RegionName } from './regions';
1010

1111
export const generateRegionDetectedNames = (fileRegions: Region[]) => {
1212
const regionChecklist = [
@@ -82,7 +82,6 @@ export const generateFileAppRegions = (
8282
name: RegionName.APPLICATION,
8383
startAddress: appStartAddress,
8484
regionSize: appEndAddress - appStartAddress,
85-
color: RegionColor.APPLICATION,
8685
};
8786
fileRegions = [...restFileRegions, appRegion];
8887
}

0 commit comments

Comments
 (0)