-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlarms.cpp
59 lines (49 loc) · 1.14 KB
/
Alarms.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
#include "Alarms.h"
#include <DS3232RTC.h>
#include "Config.h"
Alarms *Alarms::instance = 0;
Alarms::Alarms() {
this->load();
}
Alarms * Alarms::getInstance() {
if (!instance)
instance = new Alarms;
return instance;
}
Alarm * Alarms::get(int i) {
return &alarms[i];
}
void Alarms::load() {
// Load alarms from EEPROM to memory
for (int i = 0; i < NUM_ALARMS; i++) {
EEPROM.get(alarmAddress[i], alarms[i]);
}
}
void Alarms::save() {
// Save alarms to eeprom if new
for (int i = 0; i < NUM_ALARMS; i++) {
EEPROM.put(alarmAddress[i], alarms[i]);
}
}
bool Alarms::isActive() {
if (lastMinute != minute()) {
lastMinute = minute();
for (int i = 0; i < NUM_ALARMS; i++) {
if (alarms[i].firesOn(weekday(), hour(), minute())) {
alarmIsOn = true;
activeAlarm = &alarms[i];
}
}
}
return alarmIsOn && snoozeUntil < now();
}
void Alarms::stop() {
alarmIsOn = false;
}
void Alarms::snooze() {
Config * config = config -> getInstance();
snoozeUntil = now() + config -> getSnoozeTime() * 60; // SnoozeTime from minutes to seconds.
}
Alarm * Alarms::getActive() {
return activeAlarm;
}