Skip to content

Commit

Permalink
Merge pull request #73 from NordicSemiconductor/NCD-776_limit_voltage…
Browse files Browse the repository at this point in the history
…_presets_to_boards_range

NCD-776: Limit voltage presets to fit the boards range
  • Loading branch information
cybic authored Mar 7, 2024
2 parents 8a5a8a9 + 8a3a8cf commit 829309e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 47 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## NEXT - unreleased

EXPERIMENTAL RELEASE

### Changed

- Showing only the voltage presets that are in range

## 0.1.10 - 2024-03-06

EXPERIMENTAL RELEASE
Expand Down
108 changes: 61 additions & 47 deletions src/features/VoltageConfiguration/VoltageConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ const VoltageConfiguration = ({
pmicPortDescription ??
`Set voltage for PMIC port ${pmicPort} (${label})`;

// Voltage presets in lieu of presets in board definition files
const voltagePresetValues = [1200, 1800, 3300, 2500, 1500]
.filter(
filterVoltage =>
filterVoltage >= voltageMin && filterVoltage <= voltageMax
)
.slice(0, 3)
.sort((a, b) => a - b);

return (
<Card
title={
Expand All @@ -53,53 +62,12 @@ const VoltageConfiguration = ({
<p>{description}</p>
</div>
)}
<div className="tw-flex tw-gap-1">
<Button
variant="secondary"
className="tw-w-full"
onClick={() => {
// Set voltage to 1800
dispatch(
setPmicConfigValue({
pmicConfigPort: pmicPort,
configPinState: 1800,
})
);
}}
>
1.8V
</Button>
<Button
variant="secondary"
className="tw-w-full"
onClick={() => {
// Set voltage to 1800
dispatch(
setPmicConfigValue({
pmicConfigPort: pmicPort,
configPinState: 2000,
})
);
}}
>
2.0V
</Button>
<Button
variant="secondary"
className="tw-w-full"
onClick={() => {
// Set voltage to 3000
dispatch(
setPmicConfigValue({
pmicConfigPort: pmicPort,
configPinState: 3000,
})
);
}}
>
3.0V
</Button>
</div>

<VoltagePresetButtons
voltages={voltagePresetValues}
pmicPort={pmicPort}
/>

<div className="tw-flex tw-flex-col">
<NumberInput
showSlider
Expand All @@ -121,4 +89,50 @@ const VoltageConfiguration = ({
);
};

interface VoltagePresetButtonsProps {
pmicPort: number;
voltages: number[];
}

const VoltagePresetButtons = ({
pmicPort,
voltages,
}: VoltagePresetButtonsProps) => (
<div id="preset-buttons" className="tw-flex tw-gap-1">
{voltages.map(voltage => (
<PresetButton
key={`voltage-preset-${pmicPort}-${voltage}`}
pmicPort={pmicPort}
voltage={voltage}
/>
))}
</div>
);

interface PresetButtonProps {
pmicPort: number;
voltage: number;
}

const PresetButton = ({ pmicPort, voltage }: PresetButtonProps) => {
const dispatch = useDispatch();

return (
<Button
variant="secondary"
className="tw-w-full"
onClick={() => {
dispatch(
setPmicConfigValue({
pmicConfigPort: pmicPort,
configPinState: voltage,
})
);
}}
>
{(voltage / 1000).toFixed(1)}V
</Button>
);
};

export default VoltageConfiguration;

0 comments on commit 829309e

Please sign in to comment.