Add persistent battery ADC calibration across boards

Add meter-reference calibration with saved ADC corrections, checked persistence and rollback. Preserve existing board coefficients and nRF52 voltage policy, and merge the Mini Repeater feature gates.

Validation: 69 focused tests, hosted documentation checks, and four firmware builds passed. Mini Repeater retains calibration and its existing filesystem with 376 flash bytes free; earlier Mini Sensor size failures remain documented.
This commit is contained in:
mikecarper committed 2026-10-22 18:56:32 -07:00
1 parent 94a3b7e568
commit ab6412e73c
108 files changed
+1303 -83

No files matched your search

+12
View File
@@ -9,6 +9,7 @@
#include <helpers/ui/OLEDControllerSettings.h>
#endif
#include <helpers/BatteryChargeCLI.h>
#include <helpers/BatteryCalibrationStore.h>
#include <helpers/MorseCLI.h>
#include <helpers/MorseLoopPolicy.h>
#if defined(MESH_HIL_TX_FREQ_MHZ)
@@ -3026,6 +3027,13 @@ void MyMesh::begin(bool has_display, bool radio_available,
// load persisted prefs
const bool prefs_ready =
_store->loadPrefs(_prefs, sensors.node_lat, sensors.node_lon);
FILESYSTEM* battery_calibration_fs = _store->getPrimaryFS();
#if defined(NRF52_PLATFORM)
if (_store->isVolatilePrimaryFS()) battery_calibration_fs = nullptr;
#endif
if (!mesh::power::beginBatteryCalibrationStore(board, battery_calibration_fs)) {
MESH_DEBUG_PRINTLN("Battery calibration could not be restored; using board default");
}
#if defined(ESP32_PLATFORM) && defined(WIFI_SSID)
#ifdef ADMIN_PASSWORD
const char* management_default = ADMIN_PASSWORD;
@@ -10637,6 +10645,8 @@ static bool isCompanionRadioPrefsCommand(const char* command) {
// Called only for directly attached USB/BLE/TCP/browser clients. Commands
// received over LoRa use handleCommand() with a nonzero sender timestamp.
bool MyMesh::handleDirectCommand(const char* command, char* reply, size_t reply_size) {
if (mesh::power::handleStoredBatteryCalibrationCommand(
board, command, reply, reply_size)) return true;
#if MESH_ENABLE_LOST_REPLY
if (mesh::companion::handleLostReplyCommand(
_prefs, command, reply, reply_size, [this]() { return savePrefs(); })) return true;
@@ -10834,6 +10844,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
&& mesh::handleReaderReply(command, reply, reply_capacity)) return true;
#endif
if (mesh::power::handleStoredBatteryCalibrationCommand(
board, command, reply, reply_capacity)) return true;
#if defined(NRF52_POWER_MANAGEMENT)
if (mesh::power::handleVoltagePolicyCommand(command, reply,
reply_capacity)) return true;
-1
View File
@@ -2692,7 +2692,6 @@ void MyMesh::begin(FILESYSTEM *fs) {
updateAdvertTimer();
updateFloodAdvertTimer();
board.setAdcMultiplier(_prefs.adc_multiplier);
#if ENV_INCLUDE_GPS == 1
applyGpsPrefs();
+11
View File
@@ -1,5 +1,6 @@
#include <helpers/RadioProfileCLI.h>
#include <helpers/BatteryChargeCLI.h>
#include <helpers/BatteryCalibrationStore.h>
#include <Arduino.h> // needed for PlatformIO
#include <Mesh.h>
#if MESH_PACKET_LOGGING
@@ -424,6 +425,10 @@ public:
mesh::setUsbLoggingEnabled(_prefs.usb_logging_enabled != 0);
#endif
if (!mesh::power::beginBatteryCalibrationStore(board, volatile_primary_fs ? nullptr : _fs)) {
MESH_DEBUG_PRINTLN("Battery calibration could not be restored; using board default");
}
loadContacts();
_public = addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
}
@@ -470,6 +475,12 @@ public:
}
void handleCommand(const char* command) {
char calibration_reply[160];
if (mesh::power::handleStoredBatteryCalibrationCommand(board, command,
calibration_reply, sizeof(calibration_reply))) {
Serial.println(calibration_reply);
return;
}
#if MESH_BATTERY_CHARGE_CONTROL
char charge_reply[160];
if (mesh::power::handleBatteryChargeCommand(board, command, charge_reply,
-1
View File
@@ -1316,7 +1316,6 @@ void SensorMesh::begin(FILESYSTEM* fs) {
updateAdvertTimer();
updateFloodAdvertTimer();
board.setAdcMultiplier(_prefs.adc_multiplier);
#if ENV_INCLUDE_GPS == 1
applyGpsPrefs();