|
@ -172,36 +172,41 @@ namespace bs2 { |
|
|
{ |
|
|
{ |
|
|
auto values = state->current_values; |
|
|
auto values = state->current_values; |
|
|
|
|
|
|
|
|
// Turn off the light when its state is 'off'. |
|
|
|
|
|
if (values.get_state() == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
ESP_LOGD(TAG, "Turn off the light"); |
|
|
|
|
|
red_->set_level(1.0f); |
|
|
|
|
|
green_->set_level(1.0f); |
|
|
|
|
|
blue_->set_level(1.0f); |
|
|
|
|
|
white_->set_level(0.0f); |
|
|
|
|
|
master2_->turn_off(); |
|
|
|
|
|
master1_->turn_off(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The color must either be set instantly, or the color is |
|
|
|
|
|
// transitioning to an end color. The transition handler |
|
|
|
|
|
// will do its own inspection to see if a transition is |
|
|
|
|
|
// currently active or not. Based on the outcome, use either |
|
|
|
|
|
// the instant or transition handler. |
|
|
GPIOOutputs *delegate; |
|
|
GPIOOutputs *delegate; |
|
|
if (transition_handler_->set_light_color_values(values)) { |
|
|
if (transition_handler_->set_light_color_values(values)) { |
|
|
transition_handler_->log("TRANSITION"); |
|
|
|
|
|
delegate = transition_handler_; |
|
|
delegate = transition_handler_; |
|
|
} else { |
|
|
} else { |
|
|
instant_handler_->set_light_color_values(values); |
|
|
instant_handler_->set_light_color_values(values); |
|
|
instant_handler_->log("INSTANT"); |
|
|
|
|
|
delegate = instant_handler_; |
|
|
delegate = instant_handler_; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
delegate->set_light_color_values(values); |
|
|
|
|
|
master2_->turn_on(); |
|
|
|
|
|
master1_->turn_on(); |
|
|
|
|
|
|
|
|
// Note: one might think that it is more logical to turn on |
|
|
|
|
|
// the LED circuitry master switch after setting the individual |
|
|
|
|
|
// channels, but this is the order that was used by the original |
|
|
|
|
|
// firmware. I tried to stay as close as possible to the original |
|
|
|
|
|
// behavior, so that's why these GPIOs are turned on at this point. |
|
|
|
|
|
if (values.get_state() != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
master2_->turn_on(); |
|
|
|
|
|
master1_->turn_on(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Apply the current GPIO output levels from the selected handler. |
|
|
red_->set_level(delegate->red); |
|
|
red_->set_level(delegate->red); |
|
|
green_->set_level(delegate->green); |
|
|
green_->set_level(delegate->green); |
|
|
blue_->set_level(delegate->blue); |
|
|
blue_->set_level(delegate->blue); |
|
|
white_->set_level(delegate->white); |
|
|
white_->set_level(delegate->white); |
|
|
|
|
|
|
|
|
|
|
|
if (values.get_state() == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
master2_->turn_off(); |
|
|
|
|
|
master1_->turn_off(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
@ -223,6 +228,8 @@ namespace bs2 { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/// This custom LightState class is used to provide access to the |
|
|
|
|
|
/// protected LightTranformer information in the LightState class. |
|
|
class YeelightBS2LightState : public light::LightState, public LightStateTransformerInspector |
|
|
class YeelightBS2LightState : public light::LightState, public LightStateTransformerInspector |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|