From c6b560fb5a62144d24530a661b59c0fbbdf032a4 Mon Sep 17 00:00:00 2001 From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com> Date: Sat, 23 Jan 2021 23:13:25 +0100 Subject: [PATCH] Change LightsOff to turn off the lights individually. --- examples/CMakeLists.txt | 2 +- examples/LightsOff.cpp | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c33b6d9..7dccbf0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -10,4 +10,4 @@ target_link_libraries(lights_off hueplusplusstatic) add_custom_target(hueplusplus_examples) -add_dependencies(hueplusplus_examples bridge_setup) \ No newline at end of file +add_dependencies(hueplusplus_examples bridge_setup lights_off) \ No newline at end of file diff --git a/examples/LightsOff.cpp b/examples/LightsOff.cpp index 79942a9..9c75a8f 100644 --- a/examples/LightsOff.cpp +++ b/examples/LightsOff.cpp @@ -1,3 +1,4 @@ +#include #include @@ -60,13 +61,17 @@ void lightsOff(hue::Bridge& hue) // Save current on state of the lights std::map onMap; - for (const hue::Light& l : lights) + for (hue::Light& l : lights) { onMap.emplace(l.getId(), l.isOn()); + l.Off(); } - + + // This would be preferrable, but does not work because it also resets the brightness of all lights // Group 0 contains all lights, turn all off with a transition of 1 second - hue.groups().get(0).setOn(false, 10); + // hue.groups().get(0).setOn(false, 10); + // ------------------------------------- + std::cout << "Turned off all lights\n"; std::this_thread::sleep_for(std::chrono::seconds(20)); @@ -76,12 +81,6 @@ void lightsOff(hue::Bridge& hue) { if (onMap[l.getId()]) { - // Refresh, because the state change from the group is not updated in the light. - // This is not strictly necessary in this case, because the state is updated - // automatically every 10 seconds. - // However, when the sleep above is shorter, no refresh can cause the on request - // to be removed, because the light thinks it is still on. - l.refresh(true); l.on(); } } @@ -101,8 +100,7 @@ int main(int argc, char** argv) lightsOff(hue); } catch (...) - { - } + { } std::cout << "Press enter to exit\n"; std::cin.get(); -- libgit2 0.21.4