5 #include "Lifxtest.hpp"
6 #include "LifxLightBulb.cpp"
8 #include "Iterator.hpp"
11 // External create, destroy, and init functions
12 extern "C" void* createLifxtest(void** params) {
13 // Arguments: IoTSet<void*>* lifx_light_bulb
14 //return new Lifxtest((IoTSet<void*>*) params[0]);
15 return new Lifxtest((IoTSet<void*>*) params[0], (IoTSet<void*>*) params[1], (IoTRelation<void*,void*>*) params[2]);
19 extern "C" void destroyLifxtest(void* t) {
20 Lifxtest* lt = (Lifxtest*) t;
25 extern "C" void initLifxtest(void* t) {
26 Lifxtest* lt = (Lifxtest*) t;
31 // Empty constructor (for testing)
32 Lifxtest::Lifxtest() {
33 log.open("Lifxtest_object_cpp.log");
34 log << "lifx_light_bulb initialized!" << endl;
38 // Constructor with only 1 IoTSet object (lifx_light_bulb)
39 Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
41 log.open("Lifxtest_object_cpp.log");
42 lifx_light_bulb = _lifx_light_bulb;
43 log << "lifx_light_bulb initialized!" << endl;
47 // Constructor with 2 IoTSet and 1 IoTRelation objects
48 Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation) {
50 log.open("Lifxtest_object_cpp.log");
51 lifx_light_bulb = _lifx_light_bulb;
53 roomLightRelation = _roomLightRelation;
54 log << "lifx_light_bulb initialized!" << endl;
58 // Constructor with void** argument
59 Lifxtest::Lifxtest(void** args) {
61 log.open("Lifxtest_object_cpp.log");
62 lifx_light_bulb = (IoTSet<void*>*) args[0];
63 log << "lifx_light_bulb initialized!" << endl;
67 Lifxtest::~Lifxtest() {
71 /*void Lifxtest::init() {
73 unordered_set<void*>* bulbSet = lifx_light_bulb->values();
74 //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
75 log << "Get into Lifxtest init()!" << endl;
76 for (auto itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
77 log << "Iteration init()!" << endl;
78 //LightBulb* lifx = (LightBulb*) *itr;
79 LightBulbTest* lifx = (LightBulbTest*) *itr;
80 log << "Getting object!" << endl;
82 log << "Executing init!" << endl;
83 this_thread::sleep_for (chrono::milliseconds(1000));
85 for (int i = 0; i < 10; i++) {
89 //cout << "Turning off!" << endl;
90 log << "Turning off!" << endl;
91 this_thread::sleep_for (chrono::milliseconds(1000));
93 //cout << "Turning on!" << endl;
94 log << "Turning on!" << i << endl;
95 this_thread::sleep_for (chrono::milliseconds(1000));
99 /* for (int i = 2500; i < 9000; i += 100) {
100 //cout << "Adjusting Temp: " << i << endl;
101 log << "Adjusting Temp: " << i << endl;
102 lifx->setTemperature(i);
103 this_thread::sleep_for (chrono::milliseconds(100));
106 for (int i = 9000; i > 2500; i -= 100) {
107 //cout << "Adjusting Temp: " << i << endl;
108 log << "Adjusting Temp: " << i << endl;
109 lifx->setTemperature(i);
110 this_thread::sleep_for (chrono::milliseconds(100));
113 for (int i = 100; i > 0; i -= 10) {
114 //cout << "Adjusting Brightness: " << i << endl;
115 log << "Adjusting Brightness: " << i << endl;
116 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
117 this_thread::sleep_for (chrono::milliseconds(500));
120 for (int i = 0; i < 100; i += 10) {
121 //cout << "Adjusting Brightness: " << i << endl;
122 log << "Adjusting Brightness: " << i << endl;
123 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
124 this_thread::sleep_for (chrono::milliseconds(500));
129 log << "End of iteration.. closing!" << endl;
131 //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
135 void Lifxtest::init() {
137 unordered_set<void*>* bulbSet = lifx_light_bulb->values();
138 unordered_set<void*>* roomSet = lab_room->values();
139 unordered_multimap<void*,void*>* roomLightRel = roomLightRelation->values();
140 log << "Size of map: " << roomLightRel->size() << endl;
141 //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
142 for (auto itr = roomSet->begin(); itr != roomSet->end(); ++itr) {
143 log << "Getting Room!" << endl;
144 //Room* rs = (Room*) *itr;
145 RoomSmart* rs = (RoomSmart*) *itr;
146 log << "Getting Room! ID: " << rs->getRoomID() << endl;
147 auto itrLight = roomLightRel->find(rs);
149 if (itrLight == roomLightRel->end())
150 log << "No match!" << endl;
151 //while (itrLight != roomLightRel->end()) {
153 //LightBulb* lifx = (LightBulb*) itrLight->second;
154 log << "Getting LightBulb!" << endl;
155 LightBulbTest* lifx = (LightBulbTest*) itrLight->second;
156 log << "Executing init!" << endl;
158 for (int i = 0; i < 10; i++) {
160 //cout << "Turning off!" << endl;
161 log << "Turning off!" << endl;
162 this_thread::sleep_for (chrono::milliseconds(1000));
164 //cout << "Turning on!" << endl;
165 log << "Turning on!" << i << endl;
166 this_thread::sleep_for (chrono::milliseconds(1000));
168 for (int i = 2500; i < 9000; i += 100) {
169 //cout << "Adjusting Temp: " << i << endl;
170 log << "Adjusting Temp: " << i << endl;
171 lifx->setTemperature(i);
172 this_thread::sleep_for (chrono::milliseconds(100));
175 for (int i = 9000; i > 2500; i -= 100) {
176 //cout << "Adjusting Temp: " << i << endl;
177 log << "Adjusting Temp: " << i << endl;
178 lifx->setTemperature(i);
179 this_thread::sleep_for (chrono::milliseconds(100));
182 for (int i = 100; i > 0; i -= 10) {
183 //cout << "Adjusting Brightness: " << i << endl;
184 log << "Adjusting Brightness: " << i << endl;
185 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
186 this_thread::sleep_for (chrono::milliseconds(500));
189 for (int i = 0; i < 100; i += 10) {
190 //cout << "Adjusting Brightness: " << i << endl;
191 log << "Adjusting Brightness: " << i << endl;
192 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
193 this_thread::sleep_for (chrono::milliseconds(500));
197 log << "End of one LightBulb!" << endl << endl;
200 log << "End of iteration.. closing!" << endl;
202 //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
206 int main(int argc, char *argv[])
209 string macAddress1 = "D073D5128E300000";
210 string devIPAddress1 = "192.168.2.126";
211 IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
212 unordered_set<void*>* myset1 = new unordered_set<void*>();
213 myset1->insert(devAddress1);
214 IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
215 LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
216 //cout << "Generated LifxLightBulb object!" << endl;
219 string macAddress2 = "D073D50241DA0000";
220 string devIPAddress2 = "192.168.2.232";
221 IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false);
222 unordered_set<void*>* myset2 = new unordered_set<void*>();
223 myset2->insert(devAddress2);
224 IoTSet<void*>* setDevAddress2 = new IoTSet<void*>(myset2);
225 LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2);
228 unordered_set<void*>* setLb = new unordered_set<void*>();
231 IoTSet<void*>* lbSet = new IoTSet<void*>(setLb);
234 LabRoom *lr1 = new LabRoom();
235 LabRoom *lr2 = new LabRoom();
236 unordered_set<void*>* setLR = new unordered_set<void*>();
239 IoTSet<void*>* lrSet = new IoTSet<void*>(setLR);
241 pair<void*,void*>* pair1 = new pair<void*,void*>(lr1, llb1);
242 pair<void*,void*>* pair2 = new pair<void*,void*>(lr2, llb2);
243 unordered_multimap<void*,void*>* mmap = new unordered_multimap<void*,void*>();
244 mmap->insert(*pair1);
245 mmap->insert(*pair2);
246 IoTRelation<void*,void*>* rlRel = new IoTRelation<void*,void*>(mmap);
249 //args[0] = (void*) lbSet;
250 //Lifxtest *lt = new Lifxtest(args);
251 Lifxtest *lt = new Lifxtest(lbSet, lrSet, rlRel);
260 delete setDevAddress1;
261 delete setDevAddress2;