-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlarm.cpp
83 lines (66 loc) · 1.48 KB
/
Alarm.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
#include "Alarm.h"
#include "Arduino.h"
Alarm::Alarm() {
enabled = false;
weekdaysActive [7];
fireHour = 7;
fireMinute = 0;
}
void Alarm::enable() {
enabled = true;
}
void Alarm::disable() {
enabled = false;
}
void Alarm::toggleEnabled() {
enabled = !enabled;
}
void Alarm::enableWeekday(int weekdayToEnable) {
weekdaysActive[weekdayToEnable - 1] = true;
}
void Alarm::disableWeekday(int weekdayToDisable) {
weekdaysActive[weekdayToDisable - 1] = false;
}
void Alarm::toggleWeekdayEnabled(int weekdayToToggle) {
weekdaysActive[weekdayToToggle - 1] = !weekdaysActive[weekdayToToggle - 1];
}
void Alarm::setFireAt(int hourToFire, int minuteToFire) {
setFireAtHour(hourToFire);
setFireAtMinute(minuteToFire);
}
void Alarm::setFireAtHour(int hourToFire) {
fireHour = hourToFire;
}
void Alarm::setFireAtMinute(int minuteToFire) {
fireMinute = minuteToFire;
}
bool Alarm::isEnabled() {
return enabled;
}
bool Alarm::firesOnWeekday(int testWeekday) {
return weekdaysActive[(testWeekday - 1)];
}
int Alarm::hourToFire() {
return fireHour;
}
int Alarm::minuteToFire() {
return fireMinute;
}
bool Alarm::firesOn(int testWeekday, int testHour, int testMinute) {
if (enabled) {
if (weekdaysActive[testWeekday - 1]) {
if (testHour == fireHour) {
if (testMinute == fireMinute) {
return true;
}
}
}
}
return false;
}
void Alarm::setMelody(int melody) {
this->melody = melody;
}
int Alarm::getMelody() {
return melody;
}