-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NCD-343: Read configuration, merge with defaults, show in GUI
- Loading branch information
Showing
6 changed files
with
175 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export interface BoardConfiguration { | ||
pins?: Map<number, boolean>; | ||
pmicPorts?: Map<number, number>; | ||
} | ||
|
||
export function wrapHardwareConfig( | ||
hardwareConfig: unknown[][] | ||
): BoardConfiguration { | ||
if (hardwareConfig && hardwareConfig.length !== 0) { | ||
const pins = wrapPinConfig(hardwareConfig[0]); | ||
|
||
const pmicPorts = wrapPmicConfig( | ||
hardwareConfig.length > 1 ? hardwareConfig[1] : undefined | ||
); | ||
|
||
return { pins, pmicPorts }; | ||
} | ||
console.log('No current config to apply'); | ||
return {}; | ||
} | ||
|
||
export function wrapPinConfig(hardwarePinConfig: unknown[]) { | ||
const pins = new Map<number, boolean>(); | ||
|
||
// Zip the current config pins array - NB! step of 2 | ||
for (let i = 0; i < hardwarePinConfig.length; i += 2) { | ||
pins.set( | ||
Number(hardwarePinConfig[i]), | ||
Boolean(hardwarePinConfig[i + 1]) | ||
); | ||
} | ||
|
||
return pins; | ||
} | ||
|
||
export function wrapPmicConfig(hardwarePmicConfig: unknown[] | undefined) { | ||
const ports = new Map<number, number>(); | ||
if (hardwarePmicConfig === undefined) { | ||
return ports; | ||
} | ||
|
||
// Zip the current PMIC config port array - NB! step of 2 | ||
for (let i = 0; i < hardwarePmicConfig.length; i += 2) { | ||
ports.set( | ||
Number(hardwarePmicConfig[i]), | ||
Number(hardwarePmicConfig[i + 1]) | ||
); | ||
} | ||
|
||
return ports; | ||
} |