From 2637799a857d507c68d272c021d002e06f666631 Mon Sep 17 00:00:00 2001 From: kylebonnici Date: Wed, 14 Feb 2024 14:38:33 +0100 Subject: [PATCH 1/2] Feat: add support for battery slots --- src/appReducer.ts | 2 + .../FuelGauge/FuelGaugeSettings.tsx | 42 +++----- .../FuelGauge/SlotSelectionDownloadDialog.tsx | 96 +++++++++++++++++++ .../Profiling/Dialog/ConfigurationDialog.tsx | 4 +- .../ProfileComponentMenu.tsx | 7 +- .../ProfilingProjects/ProjectCardMenu.tsx | 8 +- src/components/Profiling/helpers.ts | 25 +---- .../pmicControl/downloadBatteryModelSlice.ts | 42 ++++++++ .../pmicControl/npm/basePmicDevice.ts | 4 +- .../npm1300/fuelGauge/fuelGaugeCallbacks.ts | 7 +- .../npm/npm1300/fuelGauge/profileDownload.ts | 12 ++- .../npm/npm1300/pmic1300Device.tsx | 1 + src/features/pmicControl/npm/pmicHelpers.ts | 6 ++ src/features/pmicControl/npm/types.ts | 9 +- src/features/pmicControl/npm/useNpmDevice.tsx | 18 ++-- src/features/pmicControl/pmicControlSlice.ts | 7 +- src/index.tsx | 2 + 17 files changed, 202 insertions(+), 90 deletions(-) create mode 100644 src/components/FuelGauge/SlotSelectionDownloadDialog.tsx create mode 100644 src/features/pmicControl/downloadBatteryModelSlice.ts diff --git a/src/appReducer.ts b/src/appReducer.ts index 5e24e8ac..0c0512d3 100644 --- a/src/appReducer.ts +++ b/src/appReducer.ts @@ -8,6 +8,7 @@ import { NrfConnectState } from '@nordicsemiconductor/pc-nrfconnect-shared'; import { combineReducers } from 'redux'; import confirmBeforeCloseReducer from './features/confirmBeforeClose/confirmBeforeCloseSlice'; +import downloadBatteryModelSlice from './features/pmicControl/downloadBatteryModelSlice'; import pmicControlReducer from './features/pmicControl/pmicControlSlice'; import profilingProjectsReducer from './features/pmicControl/profilingProjectsSlice.'; import profilingReducer from './features/pmicControl/profilingSlice'; @@ -24,6 +25,7 @@ const appReducer = combineReducers({ profiling: profilingReducer, pmicControl: pmicControlReducer, serial: serialReducer, + downloadBatteryModel: downloadBatteryModelSlice, }); export default appReducer; diff --git a/src/components/FuelGauge/FuelGaugeSettings.tsx b/src/components/FuelGauge/FuelGaugeSettings.tsx index 777ce610..63e38e9f 100644 --- a/src/components/FuelGauge/FuelGaugeSettings.tsx +++ b/src/components/FuelGauge/FuelGaugeSettings.tsx @@ -14,6 +14,7 @@ import { } from '@nordicsemiconductor/pc-nrfconnect-shared'; import { getProfileBuffer } from '../../actions/fileActions'; +import { showDialog } from '../../features/pmicControl/downloadBatteryModelSlice'; import { DocumentationTooltip } from '../../features/pmicControl/npm/documentation/documentation'; import { dialogHandler, @@ -29,7 +30,6 @@ import { getStoredBatterModels, } from '../../features/pmicControl/pmicControlSlice'; import { setProfilingStage } from '../../features/pmicControl/profilingSlice'; -import { writeBatterModel } from '../Profiling/helpers'; export default ({ disabled }: { disabled: boolean }) => { const dispatch = useDispatch(); @@ -54,35 +54,23 @@ export default ({ disabled }: { disabled: boolean }) => { const batteryModelItems: DropdownItem[] = useMemo(() => { const items = [...hardcodedBatterModels]; - if (activeBatteryModel) { - if ( - hardcodedBatterModels.filter( - v => v && v.name !== activeBatteryModel.name - ).length > 0 - ) - items.push(activeBatteryModel); - } storedBatterModels?.forEach(storedBatterModel => { if (storedBatterModel) items.push(storedBatterModel); }); - const keys = new Set(items.map(item => item.name)); - return Array.from(keys).map(key => ({ - label: `${key} (${ - getClosest( - items.find(batterModel => batterModel.name === key), - latestAdcSample?.tBat ?? 24 - )?.capacity ?? '' + return items.map(batterModel => ({ + label: `${ + batterModel?.slotIndex != null + ? `#${batterModel?.slotIndex} ` + : '' + }${batterModel.name} (${ + getClosest(batterModel, latestAdcSample?.tBat ?? 24) + ?.capacity ?? '' } mAh)`, - value: key, + value: batterModel.name, })); - }, [ - activeBatteryModel, - hardcodedBatterModels, - latestAdcSample?.tBat, - storedBatterModels, - ]); + }, [hardcodedBatterModels, latestAdcSample?.tBat, storedBatterModels]); const selectedActiveItemBatteryMode = useMemo( () => @@ -112,7 +100,7 @@ export default ({ disabled }: { disabled: boolean }) => { npmDevice?.setActiveBatteryModel(item.value); }} selectedItem={selectedActiveItemBatteryMode} - disabled={disabled} + disabled={disabled || batteryModelItems.length === 0} /> { onClick={() => { getProfileBuffer() .then(buffer => { - if (npmDevice) { - dispatch( - writeBatterModel(buffer, npmDevice) - ); - } + dispatch(showDialog(buffer)); }) .catch(res => { dispatch( diff --git a/src/components/FuelGauge/SlotSelectionDownloadDialog.tsx b/src/components/FuelGauge/SlotSelectionDownloadDialog.tsx new file mode 100644 index 00000000..42418494 --- /dev/null +++ b/src/components/FuelGauge/SlotSelectionDownloadDialog.tsx @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2015 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +import React, { useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { + DialogButton, + Dropdown, + DropdownItem, + GenericDialog, +} from '@nordicsemiconductor/pc-nrfconnect-shared'; + +import { + closeDialog, + getBuffer, + getShowDialog, +} from '../../features/pmicControl/downloadBatteryModelSlice'; +import { + getNpmDevice, + getStoredBatterModels, +} from '../../features/pmicControl/pmicControlSlice'; + +export default () => { + const dispatch = useDispatch(); + const npmDevice = useSelector(getNpmDevice); + const storedBatterModels = useSelector(getStoredBatterModels); + const [slot, setSlot] = useState(0); + const buffer = useSelector(getBuffer); + const showDialog = useSelector(getShowDialog); + + const items: DropdownItem[] = []; + + for ( + let i = 0; + i < (npmDevice?.getNumberOfBatteryModelSlots() ?? 0); + i += 1 + ) { + const module = storedBatterModels?.find(m => m.slotIndex === i); + + items.push({ + value: i, + label: `Slot ${i}: ${module?.name ?? 'Empty'}`, + }); + } + + console.log(items); + + return showDialog ? ( + + { + dispatch(closeDialog()); + if (npmDevice && buffer) { + npmDevice.downloadFuelGaugeProfile( + buffer, + slot + ); + } + }} + variant="primary" + > + Write + + { + dispatch(closeDialog()); + }} + variant="secondary" + > + Cancel + + + } + isVisible + > +
+ {`Writing battery profile will reset the current fuel gauge and + overwrite the model in the slot. Click 'Write' to continue.`} +
+ { + setSlot(item.value); + }} + selectedItem={items[slot]} + /> +
+ ) : null; +}; diff --git a/src/components/Profiling/Dialog/ConfigurationDialog.tsx b/src/components/Profiling/Dialog/ConfigurationDialog.tsx index 424b3c3d..663a5a7d 100644 --- a/src/components/Profiling/Dialog/ConfigurationDialog.tsx +++ b/src/components/Profiling/Dialog/ConfigurationDialog.tsx @@ -179,7 +179,9 @@ export default ({ isVisible }: { isVisible: boolean }) => { setName(event.target.value); const match = event.target.value.match(/^[a-zA-Z0-9]+$/); - setValidName(!!match); + setValidName( + !!match && event.target.value !== 'default' + ); }} value={name} /> diff --git a/src/components/Profiling/ProfilingProjects/ProfileComponentMenu.tsx b/src/components/Profiling/ProfilingProjects/ProfileComponentMenu.tsx index b148c05a..766c34e3 100644 --- a/src/components/Profiling/ProfilingProjects/ProfileComponentMenu.tsx +++ b/src/components/Profiling/ProfilingProjects/ProfileComponentMenu.tsx @@ -12,13 +12,13 @@ import { useDispatch, useSelector } from 'react-redux'; import { showSaveDialog } from '../../../actions/fileActions'; import { stringToFile } from '../../../features/helpers'; import { generateParamsFromCSV } from '../../../features/nrfutillNpm/csvProcessing'; +import { showDialog } from '../../../features/pmicControl/downloadBatteryModelSlice'; import { getNpmDevice } from '../../../features/pmicControl/pmicControlSlice'; import { getProjectProfileProgress } from '../../../features/pmicControl/profilingProjectsSlice.'; import useIsUIDisabled from '../../../features/useIsUIDisabled'; import { isProfileReadyForProcessing, readAndUpdateProjectSettings, - writeBatterModel, } from '../helpers'; import { ProfilingProject } from '../types'; import AddEditProfileDialog from './AddEditProfileDialog'; @@ -123,10 +123,7 @@ export default ({ onClick={() => { if (profile.batteryJson && npmDevice) { dispatch( - writeBatterModel( - Buffer.from(profile.batteryJson), - npmDevice - ) + showDialog(Buffer.from(profile.batteryJson)) ); } }} diff --git a/src/components/Profiling/ProfilingProjects/ProjectCardMenu.tsx b/src/components/Profiling/ProfilingProjects/ProjectCardMenu.tsx index 04e88fda..9fe99084 100644 --- a/src/components/Profiling/ProfilingProjects/ProjectCardMenu.tsx +++ b/src/components/Profiling/ProfilingProjects/ProjectCardMenu.tsx @@ -22,13 +22,14 @@ import { generateParamsFromCSV, mergeBatteryParams, } from '../../../features/nrfutillNpm/csvProcessing'; +import { showDialog } from '../../../features/pmicControl/downloadBatteryModelSlice'; import { getNpmDevice } from '../../../features/pmicControl/pmicControlSlice'; import { getProjectProfileProgress, removeRecentProject, } from '../../../features/pmicControl/profilingProjectsSlice.'; import useIsUIDisabled from '../../../features/useIsUIDisabled'; -import { isProfileReadyForProcessing, writeBatterModel } from '../helpers'; +import { isProfileReadyForProcessing } from '../helpers'; import { ProfilingProject } from '../types'; import AddEditProfileDialog from './AddEditProfileDialog'; import AddEditProjectDialog from './AddEditProjectDialog'; @@ -181,10 +182,7 @@ export default ({ .then(data => { if (npmDevice) { dispatch( - writeBatterModel( - Buffer.from(data.json), - npmDevice - ) + showDialog(Buffer.from(data.json)) ); } setGeneratingBatterModel(false); diff --git a/src/components/Profiling/helpers.ts b/src/components/Profiling/helpers.ts index e275357c..0791ff6c 100644 --- a/src/components/Profiling/helpers.ts +++ b/src/components/Profiling/helpers.ts @@ -14,11 +14,7 @@ import path from 'path'; import packageJsons from '../../../package.json'; import { RootState } from '../../appReducer'; -import { - dialogHandler, - DOWNLOAD_BATTERY_PROFILE_DIALOG_ID, -} from '../../features/pmicControl/npm/pmicHelpers'; -import { NpmDevice, Profile } from '../../features/pmicControl/npm/types'; +import { Profile } from '../../features/pmicControl/npm/types'; import { addRecentProject, loadRecentProject, @@ -148,22 +144,3 @@ export const saveProjectSettings = export const reloadRecentProjects = (): AppThunk => dispatch => dispatch(setRecentProjects(loadRecentProject())); - -export const writeBatterModel = - (data: Buffer, npmDevice: NpmDevice): AppThunk => - dispatch => { - dispatch( - dialogHandler({ - uuid: DOWNLOAD_BATTERY_PROFILE_DIALOG_ID, - message: `Write battery profile will reset the current fuel gauge. Click 'Write' to continue.`, - confirmLabel: 'Write', - confirmClosesDialog: false, - cancelLabel: 'Cancel', - title: 'Write', - onConfirm: () => { - npmDevice.downloadFuelGaugeProfile(Buffer.from(data)); - }, - onCancel: () => {}, - }) - ); - }; diff --git a/src/features/pmicControl/downloadBatteryModelSlice.ts b/src/features/pmicControl/downloadBatteryModelSlice.ts new file mode 100644 index 00000000..431cfc87 --- /dev/null +++ b/src/features/pmicControl/downloadBatteryModelSlice.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-4-Clause + */ + +import { createSlice, PayloadAction } from '@reduxjs/toolkit'; + +import type { RootState } from '../../appReducer'; + +interface DownloadProfileSlice { + showDialog: boolean; + bufferToWite?: Buffer; +} + +const initialState: DownloadProfileSlice = { + showDialog: false, +}; + +const downloadBatteryProfileSlice = createSlice({ + name: 'downloadBatteryProfile', + initialState, + reducers: { + closeDialog() { + return { + ...initialState, + }; + }, + showDialog(state, action: PayloadAction) { + state.showDialog = true; + state.bufferToWite = action.payload; + }, + }, +}); + +export const getShowDialog = (state: RootState) => + state.app.downloadBatteryModel.bufferToWite; +export const getBuffer = (state: RootState) => + state.app.downloadBatteryModel.bufferToWite; + +export const { closeDialog, showDialog } = downloadBatteryProfileSlice.actions; +export default downloadBatteryProfileSlice.reducer; diff --git a/src/features/pmicControl/npm/basePmicDevice.ts b/src/features/pmicControl/npm/basePmicDevice.ts index 966b1eb2..72801bd4 100644 --- a/src/features/pmicControl/npm/basePmicDevice.ts +++ b/src/features/pmicControl/npm/basePmicDevice.ts @@ -40,6 +40,7 @@ export const baseNpmDevice: IBaseNpmDevice = ( noOfLdos?: number; noOfGPIOs?: number; noOfLEDs?: number; + noOfBatterySlots?: number; }, supportsVersion: string ) => { @@ -284,7 +285,7 @@ export const baseNpmDevice: IBaseNpmDevice = ( }, onStoredBatteryModelUpdate: ( - handler: (payload: (BatteryModel | null)[]) => void + handler: (payload: BatteryModel[]) => void ) => { eventEmitter.on('onStoredBatteryModelUpdate', handler); return () => { @@ -344,6 +345,7 @@ export const baseNpmDevice: IBaseNpmDevice = ( getNumberOfLdos: () => devices.noOfLdos ?? 0, getNumberOfGPIOs: () => devices.noOfGPIOs ?? 0, getNumberOfLEDs: () => devices.noOfLEDs ?? 0, + getNumberOfBatteryModelSlots: () => devices.noOfBatterySlots ?? 0, isSupportedVersion: () => new Promise<{ supported: boolean; version: string }>( diff --git a/src/features/pmicControl/npm/npm1300/fuelGauge/fuelGaugeCallbacks.ts b/src/features/pmicControl/npm/npm1300/fuelGauge/fuelGaugeCallbacks.ts index df60c475..a8421cb7 100644 --- a/src/features/pmicControl/npm/npm1300/fuelGauge/fuelGaugeCallbacks.ts +++ b/src/features/pmicControl/npm/npm1300/fuelGauge/fuelGaugeCallbacks.ts @@ -87,17 +87,14 @@ export default ( 'Battery models stored in database:' ); if (models.length < 2) { - eventEmitter.emit( - 'onStoredBatteryModelUpdate', - undefined - ); + eventEmitter.emit('onStoredBatteryModelUpdate', []); return; } const stringModels = models[1].trim().split('\n'); const list = stringModels.map(parseBatteryModel); eventEmitter.emit( 'onStoredBatteryModelUpdate', - list.length !== 0 ? list : undefined + list.filter(item => item != null) ); }, noop diff --git a/src/features/pmicControl/npm/npm1300/fuelGauge/profileDownload.ts b/src/features/pmicControl/npm/npm1300/fuelGauge/profileDownload.ts index 6626baf5..a46be803 100644 --- a/src/features/pmicControl/npm/npm1300/fuelGauge/profileDownload.ts +++ b/src/features/pmicControl/npm/npm1300/fuelGauge/profileDownload.ts @@ -138,7 +138,8 @@ export const profileDownloadSet = ( unique?: boolean ) => void ) => { - const { activeBatteryModel } = fuelGaugeGet(sendCommand); + const { activeBatteryModel, storedBatteryModel } = + fuelGaugeGet(sendCommand); const abortDownloadFuelGaugeProfile = () => new Promise((resolve, reject) => { @@ -159,10 +160,10 @@ export const profileDownloadSet = ( ); }); - const applyDownloadFuelGaugeProfile = () => + const applyDownloadFuelGaugeProfile = (slot = 0) => new Promise((resolve, reject) => { sendCommand( - `fuel_gauge model download apply 0`, + `fuel_gauge model download apply ${slot}`, () => { resolve(); }, @@ -170,7 +171,7 @@ export const profileDownloadSet = ( ); }); - const downloadFuelGaugeProfile = (profile: Buffer) => { + const downloadFuelGaugeProfile = (profile: Buffer, slot?: number) => { const chunkSize = 256; const chunks = Math.ceil(profile.byteLength / chunkSize); @@ -188,6 +189,7 @@ export const profileDownloadSet = ( totalChunks: Math.ceil( profile.byteLength / chunkSize ), + slot, }; eventEmitter.emit( 'onProfileDownloadUpdate', @@ -202,6 +204,7 @@ export const profileDownloadSet = ( downloadData(chunk + 1); } else { resolve(); + storedBatteryModel(); activeBatteryModel(); } }, @@ -213,6 +216,7 @@ export const profileDownloadSet = ( const profileDownload: ProfileDownload = { state: 'failed', alertMessage: parseColonBasedAnswer('res'), + slot, }; eventEmitter.emit( 'onProfileDownloadUpdate', diff --git a/src/features/pmicControl/npm/npm1300/pmic1300Device.tsx b/src/features/pmicControl/npm/npm1300/pmic1300Device.tsx index 94ade71a..d0dc8a9b 100644 --- a/src/features/pmicControl/npm/npm1300/pmic1300Device.tsx +++ b/src/features/pmicControl/npm/npm1300/pmic1300Device.tsx @@ -56,6 +56,7 @@ export const getNPM1300: INpmDevice = (shellParser, dialogHandler) => { noOfLdos: 2, noOfGPIOs: 5, noOfLEDs: 3, + noOfBatterySlots: 3, }; const baseDevice = baseNpmDevice( shellParser, diff --git a/src/features/pmicControl/npm/pmicHelpers.ts b/src/features/pmicControl/npm/pmicHelpers.ts index 35f1c361..b383b330 100644 --- a/src/features/pmicControl/npm/pmicHelpers.ts +++ b/src/features/pmicControl/npm/pmicHelpers.ts @@ -76,8 +76,13 @@ export const parseToBoolean = (message: string) => export const parseBatteryModel = (message: string) => { const slot = message.split(':')[1]; + let slotIndex: number | undefined; if (slot && slot.trim() === 'Empty') return null; if (slot) { + slotIndex = Number.parseInt( + message.split(':')[0].replace('Slot ', ''), + 10 + ); message = slot; } @@ -127,6 +132,7 @@ export const parseBatteryModel = (message: string) => { return { name, characterizations, + slotIndex, } as BatteryModel; }; diff --git a/src/features/pmicControl/npm/types.ts b/src/features/pmicControl/npm/types.ts index 055f4028..f3346396 100644 --- a/src/features/pmicControl/npm/types.ts +++ b/src/features/pmicControl/npm/types.ts @@ -218,6 +218,7 @@ export type BatteryModelCharacterization = { export type BatteryModel = { name: string; characterizations: BatteryModelCharacterization[]; + slotIndex?: number; }; export const USBDetectStatusValues = [ @@ -283,6 +284,7 @@ export interface ProfileDownload { completeChunks?: number; totalChunks?: number; alertMessage?: string; + slot?: number; } export type BaseNpmDevice = { @@ -345,7 +347,7 @@ export type BaseNpmDevice = { ) => () => void; onStoredBatteryModelUpdate: ( - handler: (payload: (BatteryModel | null)[]) => void + handler: (payload: BatteryModel[]) => void ) => () => void; onLoggingEvent: ( @@ -364,6 +366,7 @@ export type BaseNpmDevice = { getNumberOfLdos: () => number; getNumberOfGPIOs: () => number; getNumberOfLEDs: () => number; + getNumberOfBatteryModelSlots: () => number; isSupportedVersion: () => Promise<{ supported: boolean; version: string }>; getSupportedVersion: () => string; @@ -538,9 +541,9 @@ export type NpmDevice = { enterShipHibernateMode: () => void; setFuelGaugeEnabled: (state: boolean) => Promise; - downloadFuelGaugeProfile: (profile: Buffer) => Promise; + downloadFuelGaugeProfile: (profile: Buffer, slot?: number) => Promise; abortDownloadFuelGaugeProfile: () => Promise; - applyDownloadFuelGaugeProfile: () => Promise; + applyDownloadFuelGaugeProfile: (slot?: number) => Promise; getHardcodedBatteryModels: () => Promise; setActiveBatteryModel: (name: string) => Promise; diff --git a/src/features/pmicControl/npm/useNpmDevice.tsx b/src/features/pmicControl/npm/useNpmDevice.tsx index d1528aab..a594f861 100644 --- a/src/features/pmicControl/npm/useNpmDevice.tsx +++ b/src/features/pmicControl/npm/useNpmDevice.tsx @@ -406,9 +406,9 @@ export default () => { releaseAll.push( npmDevice.onProfileDownloadUpdate(payload => { - const progressDialog: PmicDialog = { + const initialProgressDialog: PmicDialog = { uuid: DOWNLOAD_BATTERY_PROFILE_DIALOG_ID, - message: `Writing battery profile will reset the current fuel gauge. Click 'Write' to continue.`, + message: `Write battery model.`, confirmDisabled: true, confirmLabel: 'Write', cancelLabel: 'Close', @@ -424,11 +424,13 @@ export default () => { payload.completeChunks && payload.completeChunks === payload.totalChunks ) { - npmDevice.applyDownloadFuelGaugeProfile(); + npmDevice.applyDownloadFuelGaugeProfile( + payload.slot + ); } dispatch( dialogHandler({ - ...progressDialog, + ...initialProgressDialog, cancelLabel: 'Abort', cancelClosesDialog: false, onCancel: () => { @@ -457,7 +459,7 @@ export default () => { case 'aborting': dispatch( dialogHandler({ - ...progressDialog, + ...initialProgressDialog, message: ( <>
Writing battery profile.
@@ -472,7 +474,7 @@ export default () => { case 'aborted': dispatch( dialogHandler({ - ...progressDialog, + ...initialProgressDialog, message: ( <>
Writing battery profile.
@@ -491,7 +493,7 @@ export default () => { case 'applied': dispatch( dialogHandler({ - ...progressDialog, + ...initialProgressDialog, message: ( <>
Writing battery profile.
@@ -510,7 +512,7 @@ export default () => { case 'failed': dispatch( dialogHandler({ - ...progressDialog, + ...initialProgressDialog, message: ( <>
Writing battery profile.
diff --git a/src/features/pmicControl/pmicControlSlice.ts b/src/features/pmicControl/pmicControlSlice.ts index 0cf0d3c3..5372c883 100644 --- a/src/features/pmicControl/pmicControlSlice.ts +++ b/src/features/pmicControl/pmicControlSlice.ts @@ -47,7 +47,7 @@ interface pmicControlState { eventRecordingPath?: string; activeBatterModel?: BatteryModel; hardcodedBatterModels: BatteryModel[]; - storedBatterModel?: (BatteryModel | null)[]; + storedBatterModel?: BatteryModel[]; usbPower: USBPower; fuelGaugeChargingSamplingRate: number; fuelGaugeNotChargingSamplingRate: number; @@ -223,10 +223,7 @@ const pmicControlSlice = createSlice({ setHardcodedBatterModels(state, action: PayloadAction) { state.hardcodedBatterModels = action.payload; }, - setStoredBatterModel( - state, - action: PayloadAction<(BatteryModel | null)[]> - ) { + setStoredBatterModel(state, action: PayloadAction) { state.storedBatterModel = action.payload; }, setSupportedVersion(state, action: PayloadAction) { diff --git a/src/index.tsx b/src/index.tsx index 708edd0e..38f3dc65 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,6 +15,7 @@ import appReducer from './appReducer'; import Charger from './components/Charger/Charger'; import DashboardControl from './components/Dashboard/DashboardControl'; import DeviceSelector from './components/DeviceSelector'; +import SlotSelectionDownloadDialog from './components/FuelGauge/SlotSelectionDownloadDialog'; import GPIOs from './components/GPIOs/GPIOs'; import Graph from './components/Graph/Graph'; import ProfilingWizard from './components/Profiling/Dialog/ProfilingWizard'; @@ -39,6 +40,7 @@ render( + } feedback={{ categories: ['nPM PowerUP', 'nPM1300'] }} From 09158844f2bee245e22fdb305aeb49e5984ed1c1 Mon Sep 17 00:00:00 2001 From: kylebonnici Date: Wed, 14 Feb 2024 14:52:17 +0100 Subject: [PATCH 2/2] Fix: tests --- .../npm/npm1300/tests/commandCallbacks.test.ts | 9 ++------- .../pmicControl/npm/npm1300/tests/requestUpdates.test.ts | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/features/pmicControl/npm/npm1300/tests/commandCallbacks.test.ts b/src/features/pmicControl/npm/npm1300/tests/commandCallbacks.test.ts index 6cd15dcb..b224b2da 100644 --- a/src/features/pmicControl/npm/npm1300/tests/commandCallbacks.test.ts +++ b/src/features/pmicControl/npm/npm1300/tests/commandCallbacks.test.ts @@ -452,7 +452,6 @@ Battery models stored in database: expect(mockOnStoredBatteryModelUpdate).toBeCalledTimes(1); expect(mockOnStoredBatteryModelUpdate).toBeCalledWith([ - null, { name: 'LP803448', characterizations: [ @@ -469,8 +468,8 @@ Battery models stored in database: capacity: 1413.4, }, ], + slotIndex: 1, }, - null, ] as (BatteryModel | null)[]); }); @@ -495,11 +494,7 @@ Battery models stored in database: callback?.onSuccess(response, command); expect(mockOnStoredBatteryModelUpdate).toBeCalledTimes(1); - expect(mockOnStoredBatteryModelUpdate).toBeCalledWith([ - null, - null, - null, - ]); + expect(mockOnStoredBatteryModelUpdate).toBeCalledWith([]); }); test.each(USBDetectStatusValues.map((state, index) => ({ state, index })))( diff --git a/src/features/pmicControl/npm/npm1300/tests/requestUpdates.test.ts b/src/features/pmicControl/npm/npm1300/tests/requestUpdates.test.ts index eb8d6e76..a450509f 100644 --- a/src/features/pmicControl/npm/npm1300/tests/requestUpdates.test.ts +++ b/src/features/pmicControl/npm/npm1300/tests/requestUpdates.test.ts @@ -725,6 +725,7 @@ describe('PMIC 1300 - Request update commands', () => { capacity: 1413.4, }, ], + slotIndex: undefined, }, { name: 'LP502540', @@ -734,6 +735,7 @@ describe('PMIC 1300 - Request update commands', () => { capacity: 563.08, }, ], + slotIndex: undefined, }, ] as BatteryModel[]);