mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +01:00
Fix light partition (#584)
* Fix light partition Fixes https://github.com/esphome/issues/issues/365 * Lint
This commit is contained in:
parent
8be733efee
commit
a72c3ea9d7
9 changed files with 44 additions and 9 deletions
|
@ -5,8 +5,7 @@ from esphome.const import CONF_OUTPUT_ID, CONF_NUM_LEDS, CONF_RGB_ORDER, CONF_MA
|
||||||
from esphome.core import coroutine
|
from esphome.core import coroutine
|
||||||
|
|
||||||
fastled_base_ns = cg.esphome_ns.namespace('fastled_base')
|
fastled_base_ns = cg.esphome_ns.namespace('fastled_base')
|
||||||
FastLEDLightOutput = fastled_base_ns.class_('FastLEDLightOutput', cg.Component,
|
FastLEDLightOutput = fastled_base_ns.class_('FastLEDLightOutput', light.AddressableLight)
|
||||||
light.AddressableLight)
|
|
||||||
|
|
||||||
RGB_ORDERS = [
|
RGB_ORDERS = [
|
||||||
'RGB',
|
'RGB',
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace fastled_base {
|
namespace fastled_base {
|
||||||
|
|
||||||
class FastLEDLightOutput : public Component, public light::AddressableLight {
|
class FastLEDLightOutput : public light::AddressableLight {
|
||||||
public:
|
public:
|
||||||
/// Only for custom effects: Get the internal controller.
|
/// Only for custom effects: Get the internal controller.
|
||||||
CLEDController *get_controller() const { return this->controller_; }
|
CLEDController *get_controller() const { return this->controller_; }
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace light {
|
namespace light {
|
||||||
|
|
||||||
|
static const char *TAG = "light.addressable";
|
||||||
|
|
||||||
const ESPColor ESPColor::BLACK = ESPColor(0, 0, 0, 0);
|
const ESPColor ESPColor::BLACK = ESPColor(0, 0, 0, 0);
|
||||||
const ESPColor ESPColor::WHITE = ESPColor(255, 255, 255, 255);
|
const ESPColor ESPColor::WHITE = ESPColor(255, 255, 255, 255);
|
||||||
|
|
||||||
|
@ -92,5 +94,24 @@ int32_t HOT interpret_index(int32_t index, int32_t size) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddressableLight::call_setup() {
|
||||||
|
this->setup_internal_();
|
||||||
|
this->setup();
|
||||||
|
|
||||||
|
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
||||||
|
this->set_interval(5000, [this]() {
|
||||||
|
const char *name = this->state_parent_ == nullptr ? "" : this->state_parent_->get_name().c_str();
|
||||||
|
ESP_LOGVV(TAG, "Addressable Light '%s' (effect_active=%s next_show=%s)", name, YESNO(this->effect_active_),
|
||||||
|
YESNO(this->next_show_));
|
||||||
|
for (int i = 0; i < this->size(); i++) {
|
||||||
|
auto color = this->get(i);
|
||||||
|
ESP_LOGVV(TAG, " [%2d] Color: R=%3u G=%3u B=%3u W=%3u", i, color.get_red_raw(), color.get_green_raw(),
|
||||||
|
color.get_blue_raw(), color.get_white_raw());
|
||||||
|
}
|
||||||
|
ESP_LOGVV(TAG, "");
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace light
|
} // namespace light
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -335,13 +335,21 @@ class ESPColorView : public ESPColorSettable {
|
||||||
void darken(uint8_t delta) override { this->set(this->get().darken(delta)); }
|
void darken(uint8_t delta) override { this->set(this->get().darken(delta)); }
|
||||||
ESPColor get() const { return ESPColor(this->get_red(), this->get_green(), this->get_blue(), this->get_white()); }
|
ESPColor get() const { return ESPColor(this->get_red(), this->get_green(), this->get_blue(), this->get_white()); }
|
||||||
uint8_t get_red() const { return this->color_correction_->color_uncorrect_red(*this->red_); }
|
uint8_t get_red() const { return this->color_correction_->color_uncorrect_red(*this->red_); }
|
||||||
|
uint8_t get_red_raw() const { return *this->red_; }
|
||||||
uint8_t get_green() const { return this->color_correction_->color_uncorrect_green(*this->green_); }
|
uint8_t get_green() const { return this->color_correction_->color_uncorrect_green(*this->green_); }
|
||||||
|
uint8_t get_green_raw() const { return *this->green_; }
|
||||||
uint8_t get_blue() const { return this->color_correction_->color_uncorrect_blue(*this->blue_); }
|
uint8_t get_blue() const { return this->color_correction_->color_uncorrect_blue(*this->blue_); }
|
||||||
|
uint8_t get_blue_raw() const { return *this->blue_; }
|
||||||
uint8_t get_white() const {
|
uint8_t get_white() const {
|
||||||
if (this->white_ == nullptr)
|
if (this->white_ == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
return this->color_correction_->color_uncorrect_white(*this->white_);
|
return this->color_correction_->color_uncorrect_white(*this->white_);
|
||||||
}
|
}
|
||||||
|
uint8_t get_white_raw() const {
|
||||||
|
if (this->white_ == nullptr)
|
||||||
|
return 0;
|
||||||
|
return *this->white_;
|
||||||
|
}
|
||||||
uint8_t get_effect_data() const {
|
uint8_t get_effect_data() const {
|
||||||
if (this->effect_data_ == nullptr)
|
if (this->effect_data_ == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -475,7 +483,7 @@ class ESPRangeView : public ESPColorSettable {
|
||||||
int32_t end_;
|
int32_t end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddressableLight : public LightOutput {
|
class AddressableLight : public LightOutput, public Component {
|
||||||
public:
|
public:
|
||||||
virtual int32_t size() const = 0;
|
virtual int32_t size() const = 0;
|
||||||
ESPColorView operator[](int32_t index) const { return this->get_view_internal(interpret_index(index, this->size())); }
|
ESPColorView operator[](int32_t index) const { return this->get_view_internal(interpret_index(index, this->size())); }
|
||||||
|
@ -530,13 +538,18 @@ class AddressableLight : public LightOutput {
|
||||||
this->correction_.set_max_brightness(ESPColor(uint8_t(roundf(red * 255.0f)), uint8_t(roundf(green * 255.0f)),
|
this->correction_.set_max_brightness(ESPColor(uint8_t(roundf(red * 255.0f)), uint8_t(roundf(green * 255.0f)),
|
||||||
uint8_t(roundf(blue * 255.0f)), uint8_t(roundf(white * 255.0f))));
|
uint8_t(roundf(blue * 255.0f)), uint8_t(roundf(white * 255.0f))));
|
||||||
}
|
}
|
||||||
void setup_state(LightState *state) override { this->correction_.calculate_gamma_table(state->get_gamma_correct()); }
|
void setup_state(LightState *state) override {
|
||||||
|
this->correction_.calculate_gamma_table(state->get_gamma_correct());
|
||||||
|
this->state_parent_ = state;
|
||||||
|
}
|
||||||
void schedule_show() { this->next_show_ = true; }
|
void schedule_show() { this->next_show_ = true; }
|
||||||
|
|
||||||
#ifdef USE_POWER_SUPPLY
|
#ifdef USE_POWER_SUPPLY
|
||||||
void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
|
void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void call_setup() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool should_show_() const { return this->effect_active_ || this->next_show_; }
|
bool should_show_() const { return this->effect_active_ || this->next_show_; }
|
||||||
void mark_shown_() {
|
void mark_shown_() {
|
||||||
|
@ -559,6 +572,7 @@ class AddressableLight : public LightOutput {
|
||||||
#ifdef USE_POWER_SUPPLY
|
#ifdef USE_POWER_SUPPLY
|
||||||
power_supply::PowerSupplyRequester power_;
|
power_supply::PowerSupplyRequester power_;
|
||||||
#endif
|
#endif
|
||||||
|
LightState *state_parent_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace light
|
} // namespace light
|
||||||
|
|
|
@ -7,7 +7,7 @@ LightState = light_ns.class_('LightState', cg.Nameable, cg.Component)
|
||||||
# Fake class for addressable lights
|
# Fake class for addressable lights
|
||||||
AddressableLightState = light_ns.class_('LightState', LightState)
|
AddressableLightState = light_ns.class_('LightState', LightState)
|
||||||
LightOutput = light_ns.class_('LightOutput')
|
LightOutput = light_ns.class_('LightOutput')
|
||||||
AddressableLight = light_ns.class_('AddressableLight')
|
AddressableLight = light_ns.class_('AddressableLight', cg.Component)
|
||||||
AddressableLightRef = AddressableLight.operator('ref')
|
AddressableLightRef = AddressableLight.operator('ref')
|
||||||
LightColorValues = light_ns.class_('LightColorValues')
|
LightColorValues = light_ns.class_('LightColorValues')
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from esphome.const import CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_METHOD, CONF_NUM_L
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
|
|
||||||
neopixelbus_ns = cg.esphome_ns.namespace('neopixelbus')
|
neopixelbus_ns = cg.esphome_ns.namespace('neopixelbus')
|
||||||
NeoPixelBusLightOutputBase = neopixelbus_ns.class_('NeoPixelBusLightOutputBase', cg.Component,
|
NeoPixelBusLightOutputBase = neopixelbus_ns.class_('NeoPixelBusLightOutputBase',
|
||||||
light.AddressableLight)
|
light.AddressableLight)
|
||||||
NeoPixelRGBLightOutput = neopixelbus_ns.class_('NeoPixelRGBLightOutput', NeoPixelBusLightOutputBase)
|
NeoPixelRGBLightOutput = neopixelbus_ns.class_('NeoPixelRGBLightOutput', NeoPixelBusLightOutputBase)
|
||||||
NeoPixelRGBWLightOutput = neopixelbus_ns.class_('NeoPixelRGBWLightOutput',
|
NeoPixelRGBWLightOutput = neopixelbus_ns.class_('NeoPixelRGBWLightOutput',
|
||||||
|
|
|
@ -48,7 +48,7 @@ enum class ESPNeoPixelOrder {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T_METHOD, typename T_COLOR_FEATURE>
|
template<typename T_METHOD, typename T_COLOR_FEATURE>
|
||||||
class NeoPixelBusLightOutputBase : public Component, public light::AddressableLight {
|
class NeoPixelBusLightOutputBase : public light::AddressableLight {
|
||||||
public:
|
public:
|
||||||
NeoPixelBus<T_COLOR_FEATURE, T_METHOD> *get_controller() const { return this->controller_; }
|
NeoPixelBus<T_COLOR_FEATURE, T_METHOD> *get_controller() const { return this->controller_; }
|
||||||
|
|
||||||
|
|
|
@ -33,4 +33,5 @@ def to_code(config):
|
||||||
conf[CONF_TO] - conf[CONF_FROM] + 1))
|
conf[CONF_TO] - conf[CONF_FROM] + 1))
|
||||||
|
|
||||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID], segments)
|
var = cg.new_Pvariable(config[CONF_OUTPUT_ID], segments)
|
||||||
|
yield cg.register_component(var, config)
|
||||||
yield light.register_light(var, config)
|
yield light.register_light(var, config)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class AddressableSegment {
|
||||||
int32_t dst_offset_;
|
int32_t dst_offset_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PartitionLightOutput : public light::AddressableLight, public Component {
|
class PartitionLightOutput : public light::AddressableLight {
|
||||||
public:
|
public:
|
||||||
explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(segments) {
|
explicit PartitionLightOutput(std::vector<AddressableSegment> segments) : segments_(segments) {
|
||||||
int32_t off = 0;
|
int32_t off = 0;
|
||||||
|
|
Loading…
Reference in a new issue