X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=keyboard%2Fhhkb_rn42%2Frn42%2Frn42_task.c;h=c3359ed5069dc62c666fe3a851d3bd4d32b0e956;hb=bfd2d969b48eb2f381137383c6262b60e03cf5b1;hp=437dd46f490983f2512efc02cc00b4bc7f03940e;hpb=4b2b32a14b805a363c5dc035a2d1384e60865ad3;p=tmk_firmware.git diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.c b/keyboard/hhkb_rn42/rn42/rn42_task.c index 437dd46..c3359ed 100644 --- a/keyboard/hhkb_rn42/rn42/rn42_task.c +++ b/keyboard/hhkb_rn42/rn42/rn42_task.c @@ -7,46 +7,28 @@ #include "lufa.h" #include "rn42_task.h" #include "print.h" +#include "debug.h" #include "timer.h" #include "command.h" +#include "battery.h" static bool config_mode = false; static bool force_usb = false; -static void battery_adc_init(void) +static void status_led(bool on) { - ADMUX = (1< // To get the report over UART set bit3 with SH, command. static enum {LED_INIT, LED_FE, LED_02, LED_01} state = LED_INIT; - xprintf("%02X\n", c); switch (state) { case LED_INIT: if (c == 0xFE) state = LED_FE; @@ -79,8 +60,8 @@ void rn42_task(void) else state = LED_INIT; break; case LED_01: - // TODO: move to rn42.c and make accessible with keyboard_leds() - xprintf("LED status: %02X\n", c); + dprintf("LED status: %02X\n", c); + rn42_set_leds(c); state = LED_INIT; break; default: @@ -99,6 +80,55 @@ void rn42_task(void) host_set_driver(&lufa_driver); } } + + + static uint16_t prev_timer = 0; + uint16_t e = timer_elapsed(prev_timer); + if (e > 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); + } } @@ -108,6 +138,8 @@ void rn42_task(void) ******************************************************************************/ bool command_extra(uint8_t code) { + uint32_t t; + uint16_t b; static host_driver_t *prev_driver = &rn42_driver; switch (code) { case KC_H: @@ -166,10 +198,17 @@ bool command_extra(uint8_t code) xprintf("rn42_rts(): %X\n", rn42_rts()); xprintf("config_mode: %X\n", config_mode); xprintf("VBUS: %X\n", USBSTA&(1<