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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#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);
#if 0
hands_pos[0] = calc_hour_pos (&m);
if ((e.s & 31) <5) {
hands_pos[1] =hands_pos[0];
} else {
hands_pos[1] = calc_minute_pos (&m);
}
#endif
hands_pos[0] = calc_second_pos (&m);
hands_pos[1] = calc_minute_pos (&m);
//hands_pos[1] = calc_second_pos (&m);
hands_ready = 1;
#if 0
for (i = 0, p = 0; i < HANDS; ++i) {
if (hands_pos[i] != old_pos[i]) p++;
old_pos[i] = hands_pos[i];
}
if (p) {
printf("Epoch %d.%09d\r\n",(unsigned) e.s,(unsigned) e.ns);
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);
}
#endif
}
|