mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 14:55:46 +00:00
tweak getBattMilliVolts to report battery more accurately
This commit is contained in:
@@ -19,14 +19,21 @@ void ThinknodeM2Board::begin() {
|
||||
enterDeepSleep(0);
|
||||
}
|
||||
|
||||
uint16_t ThinknodeM2Board::getBattMilliVolts() {
|
||||
uint16_t ThinknodeM2Board::getBattMilliVolts() {
|
||||
analogReadResolution(12);
|
||||
delay(10);
|
||||
float volts = (analogRead(PIN_VBAT_READ) * ADC_MULTIPLIER * AREF_VOLTAGE) / 4096;
|
||||
analogReadResolution(10);
|
||||
return volts * 1000;
|
||||
}
|
||||
analogSetPinAttenuation(PIN_VBAT_READ, ADC_11db);
|
||||
|
||||
uint32_t mv = 0;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
mv += analogReadMilliVolts(PIN_VBAT_READ);
|
||||
delayMicroseconds(200);
|
||||
}
|
||||
mv /= 8;
|
||||
|
||||
analogReadResolution(10);
|
||||
return static_cast<uint16_t>(mv * ADC_MULTIPLIER );
|
||||
}
|
||||
|
||||
const char* ThinknodeM2Board::getManufacturerName() const {
|
||||
return "Elecrow ThinkNode M2";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user