From 5944ab246a981d6ceca94b0972345277a746c2d3 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Fri, 10 Feb 2017 21:28:46 +0700 Subject: Implement battery level indicator --- keyboards/handwired/promethium/promethium.c | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'keyboards/handwired/promethium/promethium.c') diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c index a0035cce1a..7f876c7562 100644 --- a/keyboards/handwired/promethium/promethium.c +++ b/keyboards/handwired/promethium/promethium.c @@ -1,6 +1,36 @@ #include "promethium.h" +#include "analog.h" +#include "timer.h" +#include "matrix.h" -void matrix_init_kb(void) { +float battery_percentage(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; + } +} + +__attribute__ ((weak)) +void battery_poll(float percentage) { +} +void matrix_init_kb(void) { matrix_init_user(); -} \ No newline at end of file +} + +void matrix_scan_kb(void) { + static uint16_t counter = BATTERY_POLL; + counter++; + + if (counter > BATTERY_POLL) { + counter = 0; + battery_poll(battery_percentage()); + } +} + + -- cgit v1.2.3