-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatorRTC.cpp
179 lines (161 loc) · 2.74 KB
/
gatorRTC.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "pxt.h"
#include <cstdint>
#include <math.h>
#include "SparkFun_RV3028.h"
using namespace pxt;
namespace gatorRTC {
RV3028 *rtc = NULL;
void init() {
if ( rtc == NULL) {
rtc = new RV3028;
}
}
//%
void set24Time(uint8_t hours, uint8_t minutes, uint8_t seconds)
{
init();
rtc->set24Hour();
rtc->setHours(hours);
rtc->setMinutes(minutes);
rtc->setSeconds(seconds);
}
//%
void set12Time(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t amPm)
{
init();
rtc->set24Hour();
rtc->setHours(hours + (amPm * 12));
rtc->setMinutes(minutes);
rtc->setSeconds(seconds);
rtc->set12Hour();
}
//%
void set12HourMode()
{
init();
rtc->set12Hour();
}
//%
void set24HourMode()
{
init();
rtc->set24Hour();
}
//%
bool is12HourMode()
{
init();
return rtc->is12Hour();
}
//%
bool isAfternoon()
{
init();
return rtc->isPM();
}
//%
void setDate(uint8_t weekday, uint8_t month, uint8_t day, uint8_t year)
{
init();
rtc->setWeekday(weekday);
rtc->setMonth(month);
rtc->setDate(day);
rtc->setYear(year);
}
//%
void setTimeComponent(uint8_t timeComponent, uint8_t value)
{
init();
switch (timeComponent)
{
case 1:
rtc->setSeconds(value);
break;
case 2:
rtc->setMinutes(value);
break;
case 3:
rtc->setHours(value);
break;
case 4:
rtc->setDate(value);
break;
case 5:
rtc->setMonth(value);
break;
case 6:
rtc->setYear(value);
break;
case 7:
rtc->setWeekday(value);
break;
}
}
//%
uint16_t timeComponent(uint8_t timeComponent)
{
init();
rtc->updateTime();
uint16_t returnValue;
switch (timeComponent)
{
case 1:
returnValue = rtc->getSeconds();
break;
case 2:
returnValue = rtc->getMinutes();
break;
case 3:
returnValue = rtc->getHours();
break;
case 4:
returnValue = rtc->getDate();
break;
case 5:
returnValue = rtc->getMonth();
break;
case 6:
returnValue = rtc->getYear();
break;
case 7:
returnValue = rtc->getWeekday();
break;
default:
returnValue = 0;
break;
}
return returnValue;
}
//%
uint16_t timestampComponent(uint8_t timeComponent)
{
init();
rtc->updateTimestamp();
uint16_t returnValue;
switch (timeComponent)
{
case 1:
returnValue = rtc->getSecondsTimestamp();
break;
case 2:
returnValue = rtc->getMinutesTimestamp();
break;
case 3:
returnValue = rtc->getHoursTimestamp();
break;
case 4:
returnValue = rtc->getDateTimestamp();
break;
case 5:
returnValue = rtc->getMonthTimestamp();
break;
case 6:
returnValue = rtc->getYearTimestamp();
break;
default:
returnValue = 0;
break;
}
return returnValue;
}
}