-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSensorRTC.cpp
73 lines (55 loc) · 2.1 KB
/
SensorRTC.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
#include "SensorRTC.h"
//Initialize
SensorRTC::SensorRTC()
{
alarme=0;
}
//----------------------------------------- Begin RTC -------------------------------------------
int SensorRTC::begin()
{
#ifdef USE_RCTInt
rtc.begin(TIME_H24); //RTC initializing with 24 hour representation mode
return 0;
#else
return 1;
#endif
}
//----------------------------------------------------------------------------------------------
//---------------------------------------- Config RTC ------------------------------------------
void SensorRTC::configRTC()
{
#ifdef USE_RCTInt
rtc.setTime(0,0,0,0); //setting time (hour minute and second)
rtc.setDate(13,8,15); //setting date
rtc.enableAlarm(SEC, ALARM_INTERRUPT, isr2); //enabling alarm and match on second
SensorRTC_instance = this;
rtc.local_time.second=59; //setting second to match
rtc.setAlarm(); //write second in alarm register
#endif
}
//----------------------------------------------------------------------------------------------
//------------------------------ RTC Alarm Interrupt Routine -----------------------------------
void SensorRTC::ISR_RTC()
{
alarme=1;
}
//----------------------------------------------------------------------------------------------
//----------------------------- Auxiliar RTC Interrupt ISR -------------------------------------
void SensorRTC::isr2()
{
SensorRTC_instance->ISR_RTC();
}
//----------------------------------------------------------------------------------------------
SensorRTC * SensorRTC::SensorRTC_instance; // Auxiliar instance to RTC Interrupt ISR
//---------------------------------- Clear RTC alarme state ------------------------------------
void SensorRTC::clearRTCAlarm()
{
alarme=0;
}
//----------------------------------------------------------------------------------------------
//------------------------------------ Get RTC alarme state ------------------------------------
int SensorRTC::getRTCAlarm()
{
return alarme;
}
//----------------------------------------------------------------------------------------------