-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Battery display and calibration #9426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
3acab08
bf6727f
454ab05
f78159d
5217175
f50ca19
67c9a56
2ade35e
6006aae
171418c
356a4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| #include "mesh/Default.h" | ||
| #include "mesh/MeshTypes.h" | ||
| #include "modules/AdminModule.h" | ||
| #include "modules/BatteryCalibrationModule.h" | ||
| #include "modules/BatteryCalibrationSampler.h" | ||
| #include "modules/CannedMessageModule.h" | ||
| #include "modules/ExternalNotificationModule.h" | ||
| #include "modules/KeyVerificationModule.h" | ||
|
|
@@ -2396,6 +2398,92 @@ void menuHandler::powerMenu() | |
| screen->showOverlayBanner(bannerOptions); | ||
| } | ||
|
|
||
| void menuHandler::batteryCalibrationMenu() | ||
| { | ||
|
|
||
| static const char *optionsArrayIdle[] = {"Back", "Begin Calibration", "Reset OCV Array"}; | ||
| static const char *optionsArrayActive[] = {"Back", "Stop Calibration", "Reset OCV Array", "Save OCV & End"}; | ||
|
|
||
| enum optionsNumbers { Back = 0, Start = 1, Reset = 2, Apply = 3 }; | ||
| BannerOverlayOptions bannerOptions; | ||
| bannerOptions.message = "Battery Calibration Action"; | ||
| const bool calibrationActive = batteryCalibrationModule && batteryCalibrationModule->isCalibrationActive(); | ||
| bannerOptions.optionsArrayPtr = calibrationActive ? optionsArrayActive : optionsArrayIdle; | ||
| bannerOptions.optionsCount = calibrationActive ? 4 : 3; | ||
| bannerOptions.bannerCallback = [](int selected) -> void { | ||
| if (selected == Start) { | ||
| if (batteryCalibrationModule && batteryCalibrationModule->isCalibrationActive()) { | ||
| batteryCalibrationModule->stopCalibration(); | ||
| IF_SCREEN(screen->showSimpleBanner("Calibration stopped.", 2000)); | ||
| } else { | ||
| menuHandler::menuQueue = menuHandler::battery_calibration_confirm_menu; | ||
| screen->runNow(); | ||
| } | ||
| } else if (selected == Reset) { | ||
| if (batteryCalibrationSampler) { | ||
| batteryCalibrationSampler->resetSamples(); | ||
| batteryCalibrationModule->stopCalibration(); | ||
| } | ||
| config.power.ocv_count = 0; | ||
| for (size_t i = 0; i < NUM_OCV_POINTS; ++i) { | ||
| config.power.ocv[i] = 0; | ||
| } | ||
| if (nodeDB) { | ||
| nodeDB->saveToDisk(SEGMENT_CONFIG); | ||
| } | ||
| IF_SCREEN(screen->showSimpleBanner("OCV array reset.\nRebooting...", 2000)); | ||
| rebootAtMsec = (millis() + DEFAULT_REBOOT_SECONDS * 1000); | ||
| screen->runNow(); | ||
| } else if (selected == Apply) { | ||
| if (batteryCalibrationModule && batteryCalibrationModule->isCalibrationActive()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the node restarted due to low battery / brownout, will isCalibrationActive still be true? I was trying to trace this in the code but can't confirm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theres nothing in persistent memory/protobufs right now for saving current state, so brownout/low battery shutdown would reset back to false (See BatteryCalibrationModule.h line 27) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do have future ideas about saving the calibration data to memory periodically to resume after unintentional rebooting though. In testing, its a pain to have to start calibration from scratch if you accidentally hit the reset button several days in with a battery that lasts a week+. |
||
| if (batteryCalibrationModule->persistCalibrationOcv()) { | ||
| if (nodeDB) { | ||
| nodeDB->saveToDisk(SEGMENT_CONFIG); | ||
| } else { | ||
| } | ||
| batteryCalibrationModule->stopCalibration(); | ||
| IF_SCREEN(screen->showSimpleBanner("OCV saved.\nCalibration ended.", 2000)); | ||
| } else { | ||
| IF_SCREEN(screen->showSimpleBanner("OCV not ready yet.", 2000)); | ||
| } | ||
| } else { | ||
| } | ||
| screen->runNow(); | ||
| } | ||
| }; | ||
| screen->showOverlayBanner(bannerOptions); | ||
| } | ||
|
|
||
| void menuHandler::batteryCalibrationConfirmMenu() | ||
| { | ||
| static const char *optionsArray[] = {"Back", "Start Calibration"}; | ||
| enum optionsNumbers { Back = 0, Start = 1 }; | ||
|
|
||
| BannerOverlayOptions bannerOptions; | ||
| bannerOptions.message = "Confirm Battery Calibration\n" | ||
| "1) Fully charge battery\n" | ||
| "2) Remove charger\n" | ||
| "3) Start calibration"; | ||
| bannerOptions.optionsArrayPtr = optionsArray; | ||
| bannerOptions.optionsCount = 2; | ||
| bannerOptions.bannerCallback = [](int selected) -> void { | ||
| if (selected == Start) { | ||
| if (batteryCalibrationModule) { | ||
| batteryCalibrationModule->startCalibration(); | ||
| IF_SCREEN(screen->showSimpleBanner( | ||
|
|
||
| "Calibration started.\nUse device as normal.\nDo not charge until battery dies.", 5000)); | ||
| } else if (batteryCalibrationSampler) { | ||
| batteryCalibrationSampler->resetSamples(); | ||
| } | ||
| } else { | ||
| menuHandler::menuQueue = menuHandler::battery_calibration_menu; | ||
| screen->runNow(); | ||
| } | ||
| }; | ||
| screen->showOverlayBanner(bannerOptions); | ||
| } | ||
|
|
||
| void menuHandler::keyVerificationInitMenu() | ||
| { | ||
| screen->showNodePicker("Node to Verify", 30000, | ||
|
|
@@ -2725,6 +2813,12 @@ void menuHandler::handleMenuSwitch(OLEDDisplay *display) | |
| case power_menu: | ||
| powerMenu(); | ||
| break; | ||
| case battery_calibration_menu: | ||
| batteryCalibrationMenu(); | ||
| break; | ||
| case battery_calibration_confirm_menu: | ||
| batteryCalibrationConfirmMenu(); | ||
| break; | ||
| case FrameToggles: | ||
| FrameToggles_menu(); | ||
| break; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call a batteryCalibrationModule->stopCalibration(); here in order to preempt any issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 356a4e1