diff options
author | Priyadi Iman Nurcahyo <priyadi@priyadi.net> | 2017-02-11 14:50:43 +0700 |
---|---|---|
committer | Priyadi Iman Nurcahyo <priyadi@priyadi.net> | 2017-02-11 14:50:43 +0700 |
commit | 9fc3afbef4b3ecc8568c37f247c3c7f1ec87a4c1 (patch) | |
tree | 2eb27cc15f1f14192481d5051939e86139c28331 /keyboards/handwired/promethium/promethium.c | |
parent | b31ac35441a8117877e446b8467e3e34e0a4505b (diff) | |
download | firmware-9fc3afbef4b3ecc8568c37f247c3c7f1ec87a4c1.tar.gz firmware-9fc3afbef4b3ecc8568c37f247c3c7f1ec87a4c1.tar.bz2 firmware-9fc3afbef4b3ecc8568c37f247c3c7f1ec87a4c1.zip |
simplify battery calculation for now
Diffstat (limited to 'keyboards/handwired/promethium/promethium.c')
-rw-r--r-- | keyboards/handwired/promethium/promethium.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c index adfc11e2a..3e369a624 100644 --- a/keyboards/handwired/promethium/promethium.c +++ b/keyboards/handwired/promethium/promethium.c @@ -3,20 +3,17 @@ #include "timer.h" #include "matrix.h" -float battery_percentage(void) { +// cubic fit {3.3, 0}, {3.5, 2.9}, {3.6, 5}, {3.7, 8.6}, {3.8, 36}, {3.9, 62}, {4.0, 73}, {4.05, 83}, {4.1, 89}, {4.15, 94}, {4.2, 100} + +uint8_t battery_level(void) { float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024; - float percentage = (voltage - 3.5) * 143; - if (percentage > 100) { - return 100; - } else if (percentage < 0) { - return 0; - } else { - return percentage; - } + if (voltage < MIN_VOLTAGE) return 0; + if (voltage > MAX_VOLTAGE) return 255; + return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255; } __attribute__ ((weak)) -void battery_poll(float percentage) { +void battery_poll(uint8_t level) { } void matrix_init_kb(void) { @@ -29,7 +26,7 @@ void matrix_scan_kb(void) { if (counter > BATTERY_POLL) { counter = 0; - battery_poll(battery_percentage()); + battery_poll(battery_level()); } matrix_scan_user(); |