blob: 5414d9e1750a844be35083fb907ba9cecca03bcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
}
}
|