-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from NordicSemiconductor/feat/add-support-for…
…-battery-slots Feat/add support for battery slots
- Loading branch information
Showing
19 changed files
with
206 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<number>[] = []; | ||
|
||
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 ? ( | ||
<GenericDialog | ||
title="Write battery model" | ||
footer={ | ||
<> | ||
<DialogButton | ||
onClick={() => { | ||
dispatch(closeDialog()); | ||
if (npmDevice && buffer) { | ||
npmDevice.downloadFuelGaugeProfile( | ||
buffer, | ||
slot | ||
); | ||
} | ||
}} | ||
variant="primary" | ||
> | ||
Write | ||
</DialogButton> | ||
<DialogButton | ||
onClick={() => { | ||
dispatch(closeDialog()); | ||
}} | ||
variant="secondary" | ||
> | ||
Cancel | ||
</DialogButton> | ||
</> | ||
} | ||
isVisible | ||
> | ||
<div> | ||
{`Writing battery profile will reset the current fuel gauge and | ||
overwrite the model in the slot. Click 'Write' to continue.`} | ||
</div> | ||
<Dropdown | ||
label="Programming slot" | ||
items={items} | ||
onSelect={item => { | ||
setSlot(item.value); | ||
}} | ||
selectedItem={items[slot]} | ||
/> | ||
</GenericDialog> | ||
) : null; | ||
}; |
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,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<Buffer>) { | ||
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; |
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
Oops, something went wrong.