Created
January 12, 2018 10:09
-
-
Save papylhomme/e5111e4f63b63acb1ec02e107a5cd7d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Battery.cpp b/Battery.cpp | |
index 0c61063..dc444e3 100644 | |
--- a/Battery.cpp | |
+++ b/Battery.cpp | |
@@ -36,13 +36,16 @@ void Battery::begin(uint16_t refVoltage, float dividerRatio) { | |
} | |
uint8_t Battery::level() { | |
- int16_t sense = this->voltage(); | |
- if (sense <= minVoltage) { | |
+ this->level(this->voltage()); | |
+} | |
+ | |
+uint8_t Battery::level(uint16_t voltage) { | |
+ if (voltage <= minVoltage) { | |
return 0; | |
- } else if (sense >= maxVoltage) { | |
+ } else if (voltage >= maxVoltage) { | |
return 100; | |
} else { | |
- return (unsigned long)(sense - minVoltage) * 100 / (maxVoltage - minVoltage); | |
+ return (unsigned long)(voltage - minVoltage) * 100 / (maxVoltage - minVoltage); | |
} | |
} | |
diff --git a/Battery.h b/Battery.h | |
index 6593853..1a41050 100644 | |
--- a/Battery.h | |
+++ b/Battery.h | |
@@ -46,6 +46,7 @@ class Battery { | |
* completely full battery. | |
*/ | |
uint8_t level(); | |
+ uint8_t level(uint16_t voltage); | |
/** | |
* Returns the current battery voltage in millivolts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment