X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=keyboards%2Fhandwired%2Fpromethium%2Fpromethium.c;h=4943f8c9fc6b1d0edb1efc521c325da235ea7c46;hb=3882f97d2e779899c202111e46cf2cf2926b9212;hp=a0035cce1aa2ffa695ed3cc92c5456500deb135d;hpb=d6d0b7eadaa568853b21d74057db306a33b7a847;p=qmk_firmware.git diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c index a0035cce1..4943f8c9f 100644 --- a/keyboards/handwired/promethium/promethium.c +++ b/keyboards/handwired/promethium/promethium.c @@ -1,6 +1,42 @@ #include "promethium.h" +#include "analog.h" +#include "timer.h" +#include "matrix.h" -void matrix_init_kb(void) { +// 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} + +uint8_t battery_level(void) { + float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024; + if (voltage < MIN_VOLTAGE) return 0; + if (voltage > MAX_VOLTAGE) return 255; + return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255; +} + +__attribute__ ((weak)) +void battery_poll(uint8_t level) { +} +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_level()); + } + + matrix_scan_user(); +} + +void led_set_kb(uint8_t usb_led) { + led_set_user(usb_led); +} + +__attribute__ ((weak)) +void led_set_user(uint8_t usb_led) { +} +