]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - keyboards/handwired/promethium/promethium.c
Implement battery level indicator
[qmk_firmware.git] / keyboards / handwired / promethium / promethium.c
index a0035cce1aa2ffa695ed3cc92c5456500deb135d..7f876c7562881b11f39efab8c5e36e1d005c99f9 100644 (file)
@@ -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());
+    }
+}
+
+