summaryrefslogtreecommitdiffstats
path: root/keyboards/handwired/promethium/promethium.c
diff options
context:
space:
mode:
authorPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 15:28:46 +0100
committerPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 15:28:46 +0100
commit5944ab246a981d6ceca94b0972345277a746c2d3 (patch)
tree01c240c2dd6a39cc44157e51287a7b194c6b4017 /keyboards/handwired/promethium/promethium.c
parent07879bf66b29535214a147b1797f96767b1faa58 (diff)
downloadqmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.tar.gz
qmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.tar.xz
Implement battery level indicator
Diffstat (limited to 'keyboards/handwired/promethium/promethium.c')
-rw-r--r--keyboards/handwired/promethium/promethium.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c
index a0035cce1..7f876c756 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());
+ }
+}
+
+