Fixing 2 issues in LifxLightBulb driver: 1) Detached thread handling (need to pass...
[iot2.git] / benchmarks / drivers / Cpp / LifxLightBulb / LifxLightBulb.cpp
index 21b209c4f3955817724eca5bba5f6a35e1148dce..5a53d5e7b5f09d09de03dc6a3a61cda732d3e418 100644 (file)
@@ -1,24 +1,94 @@
 #include <iostream>
 #include <string>
+#include <thread>
+
+#include <pthread.h>
+
 #include "LifxLightBulb.hpp"
 #include "IoTSet.hpp"
 #include "IoTDeviceAddress.hpp"
 
 using namespace std;
 
+void run(LifxLightBulb *llb) {
+
+       llb->init();
+}
+
+
+void *prun(void *llb) {
+
+       ((LifxLightBulb*)llb)->init();
+}
+
+
+void onOff(LifxLightBulb *llb) {
+
+       for (int i = 0; i < 5; i++) {
+               llb->turnOff();
+               cout << "Turning off!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+               llb->turnOn();
+               cout << "Turning on!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+       }
+}
+
+
+void adjustTemp(LifxLightBulb *llb) {
+
+       for (int i = 2500; i < 9000; i += 100) {
+               cout << "Adjusting Temp: " << i << endl;
+               llb->setTemperature(i);
+               this_thread::sleep_for (chrono::milliseconds(100));
+       }
+       cout << "Adjusted temperature to 9000!" << endl;
+       for (int i = 9000; i > 2500; i -= 100) {
+               cout << "Adjusting Temp: " << i << endl;
+               llb->setTemperature(i);
+               this_thread::sleep_for (chrono::milliseconds(100));
+       }
+       cout << "Adjusted temperature to 2500!" << endl;
+}
+
+
+void adjustBright(LifxLightBulb *llb) {
+       for (int i = 100; i > 0; i -= 10) {
+               cout << "Adjusting Brightness: " << i << endl;
+               llb->setColor(llb->getHue(), llb->getSaturation(), i);
+               this_thread::sleep_for (chrono::milliseconds(100));
+       }
+       cout << "Adjusted brightness to 0!" << endl;
+       for (int i = 0; i < 100; i += 10) {
+               cout << "Adjusting Brightness: " << i << endl;
+               llb->setColor(llb->getHue(), llb->getSaturation(), i);
+               this_thread::sleep_for (chrono::milliseconds(100));
+       }
+       cout << "Adjusting brightness to 100!" << endl;
+}
+
+
 int main(int argc, char *argv[])
 {
        string macAddress = "D073D5128E300000";
+       //string macAddress = "D073D50241DA0000";
        string devIPAddress = "192.168.2.126";
-       IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false);
-       unordered_set<IoTDeviceAddress> myset = { devAddress };
+       //string devIPAddress = "192.168.2.232";
+       //IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false);
+       IoTDeviceAddress* devAddress = new IoTDeviceAddress(devIPAddress, 12345, 56700, false, false);
+       unordered_set<IoTDeviceAddress*> myset = { devAddress };
 
-       IoTSet<IoTDeviceAddress> setDevAddress(myset);
+       IoTSet<IoTDeviceAddress*> setDevAddress(myset);
        LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress);
        llb->init();
-
+       llb->turnOn();
        cout << "Generated LifxLightBulb object!" << endl;
+       onOff(llb);
+       adjustTemp(llb);
+       adjustBright(llb);
+       llb->turnOff();
 
+       delete devAddress;
        delete llb;
 
        return 0;