Commit c6b560fb5a62144d24530a661b59c0fbbdf032a4
Committed by
Moritz Wirger
1 parent
fd5fa01a
Change LightsOff to turn off the lights individually.
Showing
2 changed files
with
10 additions
and
12 deletions
examples/CMakeLists.txt
| @@ -10,4 +10,4 @@ target_link_libraries(lights_off hueplusplusstatic) | @@ -10,4 +10,4 @@ target_link_libraries(lights_off hueplusplusstatic) | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | add_custom_target(hueplusplus_examples) | 12 | add_custom_target(hueplusplus_examples) |
| 13 | -add_dependencies(hueplusplus_examples bridge_setup) | ||
| 14 | \ No newline at end of file | 13 | \ No newline at end of file |
| 14 | +add_dependencies(hueplusplus_examples bridge_setup lights_off) | ||
| 15 | \ No newline at end of file | 15 | \ No newline at end of file |
examples/LightsOff.cpp
| 1 | +#include <thread> | ||
| 1 | 2 | ||
| 2 | #include <hueplusplus/Bridge.h> | 3 | #include <hueplusplus/Bridge.h> |
| 3 | 4 | ||
| @@ -60,13 +61,17 @@ void lightsOff(hue::Bridge& hue) | @@ -60,13 +61,17 @@ void lightsOff(hue::Bridge& hue) | ||
| 60 | 61 | ||
| 61 | // Save current on state of the lights | 62 | // Save current on state of the lights |
| 62 | std::map<int, bool> onMap; | 63 | std::map<int, bool> onMap; |
| 63 | - for (const hue::Light& l : lights) | 64 | + for (hue::Light& l : lights) |
| 64 | { | 65 | { |
| 65 | onMap.emplace(l.getId(), l.isOn()); | 66 | onMap.emplace(l.getId(), l.isOn()); |
| 67 | + l.Off(); | ||
| 66 | } | 68 | } |
| 67 | - | 69 | + |
| 70 | + // This would be preferrable, but does not work because it also resets the brightness of all lights | ||
| 68 | // Group 0 contains all lights, turn all off with a transition of 1 second | 71 | // Group 0 contains all lights, turn all off with a transition of 1 second |
| 69 | - hue.groups().get(0).setOn(false, 10); | 72 | + // hue.groups().get(0).setOn(false, 10); |
| 73 | + // ------------------------------------- | ||
| 74 | + | ||
| 70 | std::cout << "Turned off all lights\n"; | 75 | std::cout << "Turned off all lights\n"; |
| 71 | 76 | ||
| 72 | std::this_thread::sleep_for(std::chrono::seconds(20)); | 77 | std::this_thread::sleep_for(std::chrono::seconds(20)); |
| @@ -76,12 +81,6 @@ void lightsOff(hue::Bridge& hue) | @@ -76,12 +81,6 @@ void lightsOff(hue::Bridge& hue) | ||
| 76 | { | 81 | { |
| 77 | if (onMap[l.getId()]) | 82 | if (onMap[l.getId()]) |
| 78 | { | 83 | { |
| 79 | - // Refresh, because the state change from the group is not updated in the light. | ||
| 80 | - // This is not strictly necessary in this case, because the state is updated | ||
| 81 | - // automatically every 10 seconds. | ||
| 82 | - // However, when the sleep above is shorter, no refresh can cause the on request | ||
| 83 | - // to be removed, because the light thinks it is still on. | ||
| 84 | - l.refresh(true); | ||
| 85 | l.on(); | 84 | l.on(); |
| 86 | } | 85 | } |
| 87 | } | 86 | } |
| @@ -101,8 +100,7 @@ int main(int argc, char** argv) | @@ -101,8 +100,7 @@ int main(int argc, char** argv) | ||
| 101 | lightsOff(hue); | 100 | lightsOff(hue); |
| 102 | } | 101 | } |
| 103 | catch (...) | 102 | catch (...) |
| 104 | - { | ||
| 105 | - } | 103 | + { } |
| 106 | 104 | ||
| 107 | std::cout << "Press enter to exit\n"; | 105 | std::cout << "Press enter to exit\n"; |
| 108 | std::cin.get(); | 106 | std::cin.get(); |