Companion: set/get adc.multiplier CLI command, persisted in prefs

Repeaters, room servers and sensors already let the battery ADC multiplier be tuned with 'set adc.multiplier' (CommonCLI). The companion firmware had no equivalent, so a board whose divider differs from the build default (common on DIY ProMicro / Faketec boards) always reported a wrong battery voltage.

Adds the same command to the companion CLI. The value is stored in the companion prefs (comp.adc_mult, 0 = board default) and applied at startup via MainBoard::setAdcMultiplier().
This commit is contained in:
Olexandr Tyshchenko committed 2026-11-08 18:07:58 +02:00
1 parent 351a1ad20c
commit 3f23ba9b2d
3 files changed
+45

No files matched your search

+14
View File
@@ -65,6 +65,20 @@ Since version 1.18 meshcore companion radio firmware has a CLI interface, which
---
#### Fine-tune the battery reading
**Usage:**
- `get adc.multiplier`
- `set adc.multiplier <value>`
**Parameters:**
- `value`: ADC multiplier (0.0-10.0)
**Default:** `0.0` (value defined by board)
**Note:** Returns "Error: unsupported" if the board doesn't support it. Same command as on repeaters, for boards whose battery divider resistors vary (e.g. DIY ProMicro / Faketec).
---
### Radio
Radio parameters are common to all roles and handled by `CommonRadioPrefs`.
+29
View File
@@ -993,6 +993,8 @@ void MyMesh::begin() {
_prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, -9, MAX_LORA_TX_POWER);
_prefs.gps_enabled = constrain(_prefs.gps_enabled, 0, 1); // Ensure boolean 0 or 1
_prefs.gps_interval = constrain(_prefs.gps_interval, 0, 86400); // Max 24 hours
_prefs.adc_multiplier = constrain(_prefs.adc_multiplier, 0.0f, 10.0f);
if (!board.setAdcMultiplier(_prefs.adc_multiplier)) _prefs.adc_multiplier = 0.0f;
_active_ble_pin = _prefs.ble_pin;
@@ -2210,6 +2212,33 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
return true;
}
if (memcmp(command, "set adc.multiplier ", 19) == 0) { // same as CommonCLI
float mult = atof(&command[19]);
if (mult < 0.0f || mult > 10.0f) {
strcpy(reply, "Error, must be from 0 to 10");
} else if (board.setAdcMultiplier(mult)) {
_prefs.adc_multiplier = mult;
savePrefs();
if (mult == 0.0f) {
strcpy(reply, "OK - using default board multiplier");
} else {
sprintf(reply, "OK - multiplier set to %.3f", mult);
}
} else {
strcpy(reply, "Error: unsupported");
}
return true;
}
if (strcmp(command, "get adc.multiplier") == 0) {
float mult = board.getAdcMultiplier();
if (mult == 0.0f) {
strcpy(reply, "Error: unsupported");
} else {
sprintf(reply, "> %.3f", mult);
}
return true;
}
if (strcmp(command, "get tz.offset") == 0) {
float q = _prefs.tz_offset * 4;
sprintf(reply, (q == (int)q && ((int)q & 1)) ? "> %.2f" : "> %.1f", _prefs.tz_offset);
+2
View File
@@ -48,6 +48,7 @@ public:
char default_scope_name[31];
uint8_t default_scope_key[16];
float tz_offset = 0;
float adc_multiplier = 0; // battery ADC multiplier, 0 = board default
#ifdef ENABLE_WIFI_INTERFACE
#ifndef WIFI_SSID
#define WIFI_SSID ""
@@ -194,6 +195,7 @@ private:
def("tel_loc", _parent->telemetry_mode_loc);
def("tel_env", _parent->telemetry_mode_env);
def("tz_offset", _parent->tz_offset);
def("adc_mult", _parent->adc_multiplier);
}
public:
CompanionPrefs(NodePrefs* parent) : _parent(parent) { }