]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/handwired/promethium/promethium.c
Implement battery level indicator
[qmk_firmware.git] / keyboards / handwired / promethium / promethium.c
1 #include "promethium.h"
2 #include "analog.h"
3 #include "timer.h"
4 #include "matrix.h"
5
6 float battery_percentage(void) {
7     float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
8     float percentage = (voltage - 3.5) * 143;
9     if (percentage > 100) {
10         return 100;
11     } else if (percentage < 0) {
12         return 0;
13     } else {
14         return percentage;
15     }
16 }
17
18 __attribute__ ((weak))
19 void battery_poll(float percentage) {
20 }
21
22 void matrix_init_kb(void) {
23         matrix_init_user();
24 }
25
26 void matrix_scan_kb(void) {
27     static uint16_t counter = BATTERY_POLL;
28     counter++;
29
30     if (counter > BATTERY_POLL) {
31         counter = 0;
32         battery_poll(battery_percentage());
33     }
34 }
35
36