forked from tperamun2/Phillips-Hue-Lighting-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Light.cpp
143 lines (128 loc) · 3.55 KB
/
Light.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
/**
* @brief The light class which represents a Hue light with it's associated state
* @author Gurkiran Tatla
* @author Jake Schindler
* @author Justine Kim
* @author Paul Salvatore
* @author Timal Peramune
*/
#include "Light.hpp"
#include <Wt/WApplication>
#include <Wt/WEvent>
#include <iostream>
/**
* Light::Light(std::string id, std::string name, HomePage *page)
* @brief Constructor; Initialization function to create a Light
*
* @param id: an ID number for the Light
* @param name: a name for the Light
* @param HomePage *page: link to homepage
* @return N/A
*/
Light::Light(std::string id, std::string name, HomePage *page)
: Wt::WPushButton(name) {
this->id = id;
this->name = name;
this->page = page;
}
/**
* Light::Light(std::string id, std::string name, HomePage *page, State *state)
* @brief Constructor; Initialization function to create a Light
*
* @param id: an ID number for the light
* @param name: a name for the light
* @param page: homepage
* @param State: light state
* @return N/A
*/
Light::Light(std::string id, std::string name, State *state, HomePage *page)
: Wt::WPushButton(name) {
this->id = id;
this->name = name;
this->page = page;
this->state = state;
}
/**
* Light::~Light()
* @brief Deconstructor
*
* @param N/A
* @return N/A
*/
Light::~Light() {
delete this->state;
delete this->page;
}
/**
* Light::getState()
* @brief Returns the State of the Light; must always be called with every light object created
*
* @param N/A
* @return State: state of the light
*/
State *Light::getState() { return this->state; }
/**
* Light::setName(std::string name)
* @brief sets the name of the light
*
* @param name: name of the light
* @return N/A
*/
void Light::setName(std::string name, std::string ip, std::string port) {
Wt::WIOService *ioservice = new Wt::WIOService();
ioservice->start();
Wt::Http::Client *client = new Wt::Http::Client(*ioservice);
Wt::Http::Message message = Wt::Http::Message();
message.addHeader("Content-type", "application/json");
message.addBodyText("{\"name\": " + name + "}");
client->put(ip + ":" + port + "/api/newdeveloper/lights/" + this->id, message);
ioservice->stop();
this->name = name;
}
/**
* Light::getName()
* @brief Returns the name of the Light
*
* @param N/A
* @return std::string: name of the light
*/
std::string Light::getName() { return this->name; }
/**
* Light::getID()
* @brief Returns the ID of the Light
*
* @param N/A
* @return std::string: ID of the light
*/
std::string Light::getID() { return this->id; }
/**
* Light::turnONorOFF()
* @brief Turns the light on or off
*
* @param N/A
* @return N/A
*/
void Light::turnONorOFF() {
if (this->state->isON()) {
this->state->setOFF(this->page->getCurrentBridge()->getIP(), this->page->getCurrentBridge()->getPort());
} else
this->state->setON(this->page->getCurrentBridge()->getIP(), this->page->getCurrentBridge()->getPort());
}
/**
* Light::setHue(long long hue)
* @brief Sets the hue of the Light
*
* @param hue: a long to represent the hue of the light
* @return N/A
*/
void Light::setHue(long long hue) { this->state->setHue(hue, this->page->getCurrentBridge()->getIP(), this->page->getCurrentBridge()->getPort()); }
/**
* Light::setBrightness(int brightness)
* @brief Sets the brightness of the Light
*
* @param brightness: an int to represent the brightness of the light
* @return N/A
*/
void Light::setBrightness(int brightness) {
this->state->setBrightness(brightness, this->page->getCurrentBridge()->getIP(), this->page->getCurrentBridge()->getPort());
}