5 #include "Lifxtest.hpp"
6 #include "LifxLightBulb.cpp"
9 // External create, destroy, and init functions
10 extern "C" void* createLifxtest(void** params) {
11 // Arguments: IoTSet<void*>* lifx_light_bulb, IoTSet<void*>* lab_room, IoTRelation<void*,void*> roomLightRelation
12 return new Lifxtest((IoTSet<void*>*) params[0], (IoTSet<void*>*) params[1], (IoTRelation<void*,void*>*) params[2]);
16 extern "C" void destroyLifxtest(void* t) {
17 Lifxtest* lt = (Lifxtest*) t;
22 extern "C" void initLifxtest(void* t) {
23 Lifxtest* lt = (Lifxtest*) t;
28 // Empty constructor (for testing)
29 Lifxtest::Lifxtest() {
33 // Constructor with 2 IoTSet and 1 IoTRelation objects
34 Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation) {
36 log.open("/home/iotuser/iot2/bin/iotruntime/log/Lifxtest_object_cpp.log");
37 lifx_light_bulb = _lifx_light_bulb;
39 roomLightRelation = _roomLightRelation;
40 log << "lifx_light_bulb initialized!" << endl;
43 Lifxtest::~Lifxtest() {
46 void Lifxtest::init() {
48 unordered_set<void*>* bulbSet = lifx_light_bulb->values();
49 unordered_set<void*>* roomSet = lab_room->values();
50 unordered_multimap<void*,void*>* roomLightRel = roomLightRelation->values();
51 log << "Size of map: " << roomLightRel->size() << endl;
53 for (auto itr = roomSet->begin(); itr != roomSet->end(); ++itr) {
54 RoomSmart* rs = (RoomSmart*) *itr;
55 log << "Now turning on lights in room with ID: " << rs->getRoomID() << endl;
56 auto itrLight = roomLightRel->find(rs);
58 if (itrLight == roomLightRel->end())
59 log << "No matching light! - should not get here at all!" << endl;
61 log << "Getting LightBulb!" << endl;
62 LightBulbTest* lifx = (LightBulbTest*) itrLight->second;
63 log << "Executing init!" << endl;
65 for (int i = 0; i < 10; i++) {
67 log << "Turning off!" << endl;
68 this_thread::sleep_for (chrono::milliseconds(1000));
70 log << "Turning on!" << i << endl;
71 this_thread::sleep_for (chrono::milliseconds(1000));
73 /* Note: The bottom part has not yet been heavily tested and
74 this might get the execution stuck at some point.
75 We are suspecting that this is due to the complex interaction
76 of the multiple threads that we have.
77 for (int i = 2500; i < 9000; i += 100) {
78 log << "Adjusting Temp: " << i << endl;
79 lifx->setTemperature(i);
80 this_thread::sleep_for (chrono::milliseconds(100));
83 for (int i = 9000; i > 2500; i -= 100) {
84 log << "Adjusting Temp: " << i << endl;
85 lifx->setTemperature(i);
86 this_thread::sleep_for (chrono::milliseconds(100));
89 double hue = lifx->getHue();
90 double saturation = lifx->getSaturation();
92 for (int i = 100; i > 0; i -= 10) {
93 log << "Adjusting Brightness: " << i << endl;
94 lifx->setColor(hue, saturation, i);
95 this_thread::sleep_for (chrono::milliseconds(500));
98 for (int i = 0; i < 100; i += 10) {
99 log << "Adjusting Brightness: " << i << endl;
100 lifx->setColor(hue, saturation, i);
101 this_thread::sleep_for (chrono::milliseconds(500));
105 log << "End of one LightBulb!" << endl << endl;
108 log << "End of iteration.. closing!" << endl;
110 //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave"