diff options
author | tmk <nobody@nowhere> | 2014-09-04 17:08:23 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-09-04 17:08:23 +0900 |
commit | 3b81ffc16c8cdf260c25f0778d32c721af4f105c (patch) | |
tree | 4d9ef22491bfc77a0956d87718b715742e07497f /keyboard/hhkb_rn42/rn42/rn42_task.c | |
parent | 02939ab1d831ab7bb02edb28cb0b21fb61bced56 (diff) | |
download | qmk_firmware-3b81ffc16c8cdf260c25f0778d32c721af4f105c.tar.gz qmk_firmware-3b81ffc16c8cdf260c25f0778d32c721af4f105c.zip |
Monitor battery and alert low voltage
Diffstat (limited to 'keyboard/hhkb_rn42/rn42/rn42_task.c')
-rw-r--r-- | keyboard/hhkb_rn42/rn42/rn42_task.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.c b/keyboard/hhkb_rn42/rn42/rn42_task.c index 07b34e111a..30914452e5 100644 --- a/keyboard/hhkb_rn42/rn42/rn42_task.c +++ b/keyboard/hhkb_rn42/rn42/rn42_task.c @@ -81,13 +81,50 @@ void rn42_task(void) } } - /* Low voltage alert */ - if (battery_status() == LOW_VOLTAGE) { - battery_led(LED_ON); - } else { - battery_led(LED_CHARGER); + + static uint16_t prev_timer = 0; + static uint8_t sec = 0; + // NOTE: not exact 1 sec + if (timer_elapsed(prev_timer) > 1000) { + /* every second */ + prev_timer = timer_read(); + + /* 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 */ + if (sec == 0) { + uint32_t t = timer_read32()/1000; + 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); + */ + } + sec++; sec = sec%60; } + /* Connection monitor */ if (rn42_linked()) { status_led(true); |