-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.cpp
More file actions
115 lines (84 loc) · 2.29 KB
/
Clock.cpp
File metadata and controls
115 lines (84 loc) · 2.29 KB
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
#include <iostream>
#include <string>
#include <chrono>
#include <thread>
#include <time.h>
#include "lightbulb.h"
using namespace std;
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
int main() {
//TODO: take different approach for this problem....
//Connect to smart lighting
Lightbulb bulb("192.168.1.26");
bulb.setAllowTimeouts(false);
Lightstate initialState = bulb.getState();
HSBColor firstMinorChime(0, 100, 100);
HSBColor secondMinorChime(60, 100, 100);
HSBColor thirdMinorChime(120, 100, 100);
HSBColor fourthMinorChime(240, 100, 100);
HSBColor majorChime(0, 100, 100);
int chimeDuration = 500;
int numberOfChimes = 0;
bool isMajorChime = false;
time_t rawtime;
struct tm * timeinfo;
char buffer[10];
string temp;
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 10, "%I", timeinfo);
temp = string(buffer);
int hour = stoi(temp); //01-12
strftime(buffer, 10, "%M", timeinfo);
temp = string(buffer);
int minute = stoi(temp); //00-59
if (minute < 5) { //Top of the hour chime
isMajorChime = true;
numberOfChimes = hour;
}
else if (minute < 22) { //Quarter hour chime
numberOfChimes = 1;
}
else if (minute < 40) { //half hour chime
numberOfChimes = 2;
}
else { //third quarter chime
numberOfChimes = 3;
}
//***TESTING
numberOfChimes = 4;
isMajorChime = false;
for (int i = 0; i < numberOfChimes; i++) {
bulb.turnOff(chimeDuration / 2);
this_thread::sleep_for(chrono::milliseconds(chimeDuration/2));
if (isMajorChime) {
bulb.setHSB(majorChime);
}
else {
if(i==0)
bulb.setHSB(firstMinorChime, chimeDuration);
else if(i==1)
bulb.setHSB(secondMinorChime, chimeDuration);
else if(i==2)
bulb.setHSB(thirdMinorChime, chimeDuration);
else
bulb.setHSB(fourthMinorChime, chimeDuration);
}
this_thread::sleep_for(chrono::milliseconds(chimeDuration));
}
bulb.turnOff(chimeDuration / 2);
this_thread::sleep_for(chrono::milliseconds(chimeDuration/2));
/*
auto then = chrono::steady_clock::now();
while (!bulb.scheduleFinished()) {
auto now = chrono::steady_clock::now();
auto delta = now - then;
then = now;
//bulb.updateBySchedule(chrono::duration_cast<chrono::milliseconds>(delta).count(), false);
this_thread::sleep_for(chrono::milliseconds(100));
}
*/
bulb.restoreState(initialState);
}