diff options
Diffstat (limited to 'stm32/app/hands.c')
-rw-r--r-- | stm32/app/hands.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/stm32/app/hands.c b/stm32/app/hands.c new file mode 100644 index 0000000..5414d9e --- /dev/null +++ b/stm32/app/hands.c @@ -0,0 +1,90 @@ +#include "project.h" + + +unsigned hands_pos[HANDS]; +unsigned hands_ready; + + +static unsigned calc_minute_pos (MTIME *m) +{ + uint64_t p; + + p = m->minute; + p *= 100; + p += m->second; + p *= 1000; + p += m->nanosecond / 1000000; + + p *= MOTOR_STEPS; + p /= 10000000; + + + + return (unsigned) p; + +} + +static unsigned calc_hour_pos (MTIME *m) +{ + uint64_t p; + + p = m->hour; + p *= 100; + p += m->minute; + p *= 100; + p += m->second; + p *= 1000; + p += m->nanosecond / 1000000; + + p *= MOTOR_STEPS; + p /= 100000000; + + + + return (unsigned) p; +} + + + + +void hands_tick (void) +{ + EPOCH e; + UTC u; + MTIME m; + static unsigned old_pos[HANDS]; + unsigned i, p; + + + static uint32_t last; + + if ((ticks - last) < 100) return; + + last = ticks; + + if (!rtc_ready) return; + + + e = rtc_get(); + u = time_epoch_to_utc (e); + m = time_to_metric (e, u); + + + hands_pos[0] = calc_hour_pos (&m); + hands_pos[1] = calc_minute_pos (&m); + hands_ready = 1; + + for (i = 0, p = 0; i < HANDS; ++i) { + if (hands_pos[i] != old_pos[i]) p++; + + old_pos[i] = hands_pos[i]; + + } + + if (p) { + time_print_utc ("UTC: ", &u, NULL); + time_print_metric ("Metric: ", &m, NULL); + printf ("Hands: hour %4d/%4d min %4d/%4d\r\n", hands_pos[0], MOTOR_STEPS, hands_pos[1], MOTOR_STEPS); + } + +} |