X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;ds=sidebyside;f=keyboard%2Fhhkb_rn42%2Frn42%2Frn42_task.c;h=31a415cedfe1ba232553f71fa7b3cce7b4214ab6;hb=2015027da325e9f9b602af1f36ceeeebbcd6c78d;hp=fd5a814b294fc459679a3cb96f63022fe2e4992e;hpb=ae28b16fc630cc8219676f1bfb9cee41f0b36a79;p=max%2Ftmk_keyboard.git diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.c b/keyboard/hhkb_rn42/rn42/rn42_task.c index fd5a814b..31a415ce 100644 --- a/keyboard/hhkb_rn42/rn42/rn42_task.c +++ b/keyboard/hhkb_rn42/rn42/rn42_task.c @@ -9,6 +9,7 @@ #include "print.h" #include "timer.h" #include "command.h" +#include "battery.h" static bool config_mode = false; static bool force_usb = false; @@ -24,65 +25,9 @@ static void status_led(bool on) } } -static void battery_adc_init(void) -{ - ADMUX = (1< 1000) { + /* every second */ + prev_timer += e/1000*1000; + + /* Low voltage alert */ + uint8_t bs = battery_status(); + if (bs == LOW_VOLTAGE) { + battery_led(LED_ON); + } else { + battery_led(LED_CHARGER); + } + + static uint8_t prev_status = UNKNOWN; + if (bs != prev_status) { + prev_status = bs; + switch (bs) { + case FULL_CHARGED: xprintf("FULL_CHARGED\n"); break; + case CHARGING: xprintf("CHARGING\n"); break; + case DISCHARGING: xprintf("DISCHARGING\n"); break; + case LOW_VOLTAGE: xprintf("LOW_VOLTAGE\n"); break; + default: xprintf("UNKNOWN STATUS\n"); break; + }; + } + + /* every minute */ + uint32_t t = timer_read32()/1000; + if (t%60 == 0) { + uint16_t v = battery_voltage(); + uint8_t h = t/3600; + uint8_t m = t%3600/60; + uint8_t s = t%60; + xprintf("%02u:%02u:%02u\t%umV\n", h, m, s, v); + /* TODO: xprintf doesn't work for this. + xprintf("%02u:%02u:%02u\t%umV\n", (t/3600), (t%3600/60), (t%60), v); + */ + } + } + + + /* Connection monitor */ + if (rn42_linked()) { + status_led(true); + } else { + status_led(false); + } } @@ -205,12 +199,13 @@ bool command_extra(uint8_t code) xprintf("config_mode: %X\n", config_mode); xprintf("VBUS: %X\n", USBSTA&(1<