5 #include "Lifxtest.hpp"
6 #include "LifxLightBulb.cpp"
7 #include "Iterator.hpp"
10 // External create, destroy, and init functions
11 extern "C" void* createLifxtest(void** params) {
12 // Arguments: IoTSet<void*>* lifx_light_bulb
13 return new Lifxtest((IoTSet<void*>*) params[0]);
17 extern "C" void destroyLifxtest(void* t) {
18 Lifxtest* lt = (Lifxtest*) t;
23 extern "C" void initLifxtest(void* t) {
24 Lifxtest* lt = (Lifxtest*) t;
28 Lifxtest::Lifxtest() {
29 log.open("Lifxtest_object_cpp.log");
30 log << "lifx_light_bulb initialized!" << endl;
33 Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
35 log.open("Lifxtest_object_cpp.log");
36 lifx_light_bulb = _lifx_light_bulb;
37 log << "lifx_light_bulb initialized!" << endl;
40 Lifxtest::Lifxtest(void** args) {
42 log.open("Lifxtest_object_cpp.log");
43 lifx_light_bulb = (IoTSet<void*>*) args[0];
44 log << "lifx_light_bulb initialized!" << endl;
48 Lifxtest::~Lifxtest() {
52 void Lifxtest::init() {
54 unordered_set<void*>* bulbSet = lifx_light_bulb->values();
55 //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
56 log << "Get into Lifxtest init()!" << endl;
57 for (auto itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
58 log << "Iteration init()!" << endl;
59 //LightBulb* lifx = (LightBulb*) *itr;
60 LightBulbTest* lifx = (LightBulbTest*) *itr;
61 log << "Getting object!" << endl;
63 log << "Executing init!" << endl;
64 this_thread::sleep_for (chrono::milliseconds(1000));
66 for (int i = 0; i < 5; i++) {
68 //cout << "Turning off!" << endl;
69 log << "Turning off!" << endl;
70 this_thread::sleep_for (chrono::milliseconds(1000));
72 //cout << "Turning on!" << endl;
73 log << "Turning on!" << i << endl;
74 this_thread::sleep_for (chrono::milliseconds(1000));
78 for (int i = 2500; i < 9000; i += 100) {
79 //cout << "Adjusting Temp: " << i << endl;
80 log << "Adjusting Temp: " << i << endl;
81 lifx->setTemperature(i);
82 this_thread::sleep_for (chrono::milliseconds(100));
85 for (int i = 9000; i > 2500; i -= 100) {
86 //cout << "Adjusting Temp: " << i << endl;
87 log << "Adjusting Temp: " << i << endl;
88 lifx->setTemperature(i);
89 this_thread::sleep_for (chrono::milliseconds(100));
92 for (int i = 100; i > 0; i -= 10) {
93 //cout << "Adjusting Brightness: " << i << endl;
94 log << "Adjusting Brightness: " << i << endl;
95 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
96 this_thread::sleep_for (chrono::milliseconds(500));
99 for (int i = 0; i < 100; i += 10) {
100 //cout << "Adjusting Brightness: " << i << endl;
101 log << "Adjusting Brightness: " << i << endl;
102 lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
103 this_thread::sleep_for (chrono::milliseconds(500));
108 log << "End of iteration.. closing!" << endl;
110 while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"
114 /*int main(int argc, char *argv[])
117 string macAddress1 = "D073D5128E300000";
118 string devIPAddress1 = "192.168.2.126";
119 IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
120 unordered_set<void*>* myset1 = new unordered_set<void*>();
121 myset1->insert(devAddress1);
122 IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
123 LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
124 //cout << "Generated LifxLightBulb object!" << endl;
127 string macAddress2 = "D073D50241DA0000";
128 string devIPAddress2 = "192.168.2.232";
129 IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false);
130 unordered_set<void*>* myset2 = new unordered_set<void*>();
131 myset2->insert(devAddress2);
132 IoTSet<void*>* setDevAddress2 = new IoTSet<void*>(myset2);
133 LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2);
136 unordered_set<void*>* setLb = new unordered_set<void*>();
139 IoTSet<void*>* lbSet = new IoTSet<void*>(setLb);
142 //args[0] = (void*) lbSet;
143 //Lifxtest *lt = new Lifxtest(args);
144 Lifxtest *lt = new Lifxtest(lbSet);
153 delete setDevAddress1;
154 delete setDevAddress2;