#include "project.h" unsigned hands_pos[HANDS]; unsigned hands_ready; static unsigned calc_second_pos (MTIME *m) { uint64_t p; p += m->second; p *= 1000; p += m->nanosecond / 1000000; p *= MOTOR_STEPS; p /= 100000; return (unsigned) p; } 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) < 10) 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_pos[1] = calc_second_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); } }