Files
MeshCore/variants/thinknode_m3/ThinkNodeM3Board.cpp
T
mikecarper ab6412e73c 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.
2026-10-22 18:56:32 -07:00

29 lines
721 B
C++

#include <Arduino.h>
#include "ThinkNodeM3Board.h"
#include <Wire.h>
#include <bluefruit.h>
void ThinkNodeM3Board::begin() {
NRF52Board::begin();
btn_prev_state = HIGH;
Wire.begin();
delay(10); // give sx1262 some time to power up
}
uint16_t ThinkNodeM3Board::getBattMilliVolts() {
int adcvalue = 0;
analogReference(AR_INTERNAL_2_4);
analogReadResolution(ADC_RESOLUTION);
delay(10);
// ADC range is 0..2400mV and resolution is 12-bit (0..4095)
adcvalue = analogRead(PIN_VBAT_READ);
// Convert the raw value to compensated mv, taking the resistor-
// divider into account (providing the actual LIPO voltage)
return calibrateBatteryMillivolts((uint16_t)((float)adcvalue * ADC_FACTOR));
}