Skip to content

Commit

Permalink
bug meshtastic#279 change battery voltage to millivolts
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed Aug 13, 2020
1 parent 8c7aa07 commit 3de1607
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ class AnalogBatteryLevel : public HasBatteryLevel
*/
virtual int getBattPercentage()
{
float v = getBattVoltage();
float v = getBattVoltage() / 1000;

if (v < 2.1)
return -1;

return 100 * (getBattVoltage() - 3.27) / (4.2 - 3.27);
return 100 * (v - 3.27) / (4.2 - 3.27);
}

/**
* The raw voltage of the battery or NAN if unknown
* The raw voltage of the batteryin millivolts or NAN if unknown
*/
virtual float getBattVoltage()
{
return
#ifdef BATTERY_PIN
analogRead(BATTERY_PIN) * 2.0 * (3.3 / 1024.0);
1000.0 * analogRead(BATTERY_PIN) * 2.0 * (3.3 / 1024.0);
#else
NAN;
#endif
Expand Down Expand Up @@ -213,7 +213,6 @@ bool Power::axp192Init()
#endif
}


void Power::loop()
{
#ifdef PMU_IRQ
Expand Down

0 comments on commit 3de1607

Please sign in to comment.