Fixing 2 issues in LifxLightBulb driver: 1) Detached thread handling (need to pass...
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LifxLightBulb.cpp
1 #include <iostream>
2 #include <string>
3 #include <thread>
4
5 #include <pthread.h>
6
7 #include "LifxLightBulb.hpp"
8 #include "IoTSet.hpp"
9 #include "IoTDeviceAddress.hpp"
10
11 using namespace std;
12
13 void run(LifxLightBulb *llb) {
14
15         llb->init();
16 }
17
18
19 void *prun(void *llb) {
20
21         ((LifxLightBulb*)llb)->init();
22 }
23
24
25 void onOff(LifxLightBulb *llb) {
26
27         for (int i = 0; i < 5; i++) {
28                 llb->turnOff();
29                 cout << "Turning off!" << endl;
30                 this_thread::sleep_for (chrono::milliseconds(1000));
31                 llb->turnOn();
32                 cout << "Turning on!" << endl;
33                 this_thread::sleep_for (chrono::milliseconds(1000));
34         }
35 }
36
37
38 void adjustTemp(LifxLightBulb *llb) {
39
40         for (int i = 2500; i < 9000; i += 100) {
41                 cout << "Adjusting Temp: " << i << endl;
42                 llb->setTemperature(i);
43                 this_thread::sleep_for (chrono::milliseconds(100));
44         }
45         cout << "Adjusted temperature to 9000!" << endl;
46         for (int i = 9000; i > 2500; i -= 100) {
47                 cout << "Adjusting Temp: " << i << endl;
48                 llb->setTemperature(i);
49                 this_thread::sleep_for (chrono::milliseconds(100));
50         }
51         cout << "Adjusted temperature to 2500!" << endl;
52 }
53
54
55 void adjustBright(LifxLightBulb *llb) {
56         for (int i = 100; i > 0; i -= 10) {
57                 cout << "Adjusting Brightness: " << i << endl;
58                 llb->setColor(llb->getHue(), llb->getSaturation(), i);
59                 this_thread::sleep_for (chrono::milliseconds(100));
60         }
61         cout << "Adjusted brightness to 0!" << endl;
62         for (int i = 0; i < 100; i += 10) {
63                 cout << "Adjusting Brightness: " << i << endl;
64                 llb->setColor(llb->getHue(), llb->getSaturation(), i);
65                 this_thread::sleep_for (chrono::milliseconds(100));
66         }
67         cout << "Adjusting brightness to 100!" << endl;
68 }
69
70
71 int main(int argc, char *argv[])
72 {
73         string macAddress = "D073D5128E300000";
74         //string macAddress = "D073D50241DA0000";
75         string devIPAddress = "192.168.2.126";
76         //string devIPAddress = "192.168.2.232";
77         //IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false);
78         IoTDeviceAddress* devAddress = new IoTDeviceAddress(devIPAddress, 12345, 56700, false, false);
79         unordered_set<IoTDeviceAddress*> myset = { devAddress };
80
81         IoTSet<IoTDeviceAddress*> setDevAddress(myset);
82         LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress);
83         llb->init();
84         llb->turnOn();
85         cout << "Generated LifxLightBulb object!" << endl;
86         onOff(llb);
87         adjustTemp(llb);
88         adjustBright(llb);
89         llb->turnOff();
90
91         delete devAddress;
92         delete llb;
93
94         return 0;
95 }