aboutsummaryrefslogtreecommitdiff
path: root/keyboards/handwired/promethium/promethium.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/handwired/promethium/promethium.c')
-rw-r--r--keyboards/handwired/promethium/promethium.c19
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 @@
3#include "timer.h" 3#include "timer.h"
4#include "matrix.h" 4#include "matrix.h"
5 5
6float battery_percentage(void) { 6// 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}
7
8uint8_t battery_level(void) {
7 float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024; 9 float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
8 float percentage = (voltage - 3.5) * 143; 10 if (voltage < MIN_VOLTAGE) return 0;
9 if (percentage > 100) { 11 if (voltage > MAX_VOLTAGE) return 255;
10 return 100; 12 return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
11 } else if (percentage < 0) {
12 return 0;
13 } else {
14 return percentage;
15 }
16} 13}
17 14
18__attribute__ ((weak)) 15__attribute__ ((weak))
19void battery_poll(float percentage) { 16void battery_poll(uint8_t level) {
20} 17}
21 18
22void matrix_init_kb(void) { 19void matrix_init_kb(void) {
@@ -29,7 +26,7 @@ void matrix_scan_kb(void) {
29 26
30 if (counter > BATTERY_POLL) { 27 if (counter > BATTERY_POLL) {
31 counter = 0; 28 counter = 0;
32 battery_poll(battery_percentage()); 29 battery_poll(battery_level());
33 } 30 }
34 31
35 matrix_scan_user(); 32 matrix_scan_user();