summaryrefslogtreecommitdiffstats
path: root/keyboard
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-09-05 11:37:05 +0900
committertmk <nobody@nowhere>2014-09-05 11:37:05 +0900
commitd8dd18b4217ce56ee3248e3b09598196e0b6731c (patch)
tree3430e3ed0593fa24fe228f096e6e0d944cf584dc /keyboard
parent38714e8c8554f19279f167be0e0fae2404e21e49 (diff)
Improve rn42_task time resolution
Diffstat (limited to 'keyboard')
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42_task.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/keyboard/hhkb_rn42/rn42/rn42_task.c b/keyboard/hhkb_rn42/rn42/rn42_task.c
index 30914452e5..31a415cedf 100644
--- a/keyboard/hhkb_rn42/rn42/rn42_task.c
+++ b/keyboard/hhkb_rn42/rn42/rn42_task.c
@@ -83,11 +83,10 @@ void rn42_task(void)
static uint16_t prev_timer = 0;
- static uint8_t sec = 0;
- // NOTE: not exact 1 sec
- if (timer_elapsed(prev_timer) > 1000) {
+ uint16_t e = timer_elapsed(prev_timer);
+ if (e > 1000) {
/* every second */
- prev_timer = timer_read();
+ prev_timer += e/1000*1000;
/* Low voltage alert */
uint8_t bs = battery_status();
@@ -110,8 +109,8 @@ void rn42_task(void)
}
/* every minute */
- if (sec == 0) {
- uint32_t t = timer_read32()/1000;
+ 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;
@@ -121,7 +120,6 @@ void rn42_task(void)
xprintf("%02u:%02u:%02u\t%umV\n", (t/3600), (t%3600/60), (t%60), v);
*/
}
- sec++; sec = sec%60;
}