mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
sm2135: add separate_modes option to support different chip variants (#6152)
This commit is contained in:
parent
b0db7319f9
commit
98466cb7f5
3 changed files with 26 additions and 11 deletions
|
@ -15,6 +15,7 @@ SM2135 = sm2135_ns.class_("SM2135", cg.Component)
|
|||
|
||||
CONF_RGB_CURRENT = "rgb_current"
|
||||
CONF_CW_CURRENT = "cw_current"
|
||||
CONF_SEPARATE_MODES = "separate_modes"
|
||||
|
||||
SM2135Current = sm2135_ns.enum("SM2135Current")
|
||||
|
||||
|
@ -51,6 +52,7 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_RGB_CURRENT, "20mA"): cv.enum(DRIVE_STRENGTHS_RGB),
|
||||
cv.Optional(CONF_CW_CURRENT, "10mA"): cv.enum(DRIVE_STRENGTHS_CW),
|
||||
cv.Optional(CONF_SEPARATE_MODES, default=True): cv.boolean,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
@ -66,3 +68,4 @@ async def to_code(config):
|
|||
|
||||
cg.add(var.set_rgb_current(config[CONF_RGB_CURRENT]))
|
||||
cg.add(var.set_cw_current(config[CONF_CW_CURRENT]))
|
||||
cg.add(var.set_separate_modes(config[CONF_SEPARATE_MODES]))
|
||||
|
|
|
@ -97,23 +97,32 @@ void SM2135::loop() {
|
|||
this->write_byte_(SM2135_ADDR_MC);
|
||||
this->write_byte_(current_mask_);
|
||||
|
||||
if (this->update_channel_ == 3 || this->update_channel_ == 4) {
|
||||
// No color so must be Cold/Warm
|
||||
if (this->separate_modes_) {
|
||||
if (this->update_channel_ == 3 || this->update_channel_ == 4) {
|
||||
// No color so must be Cold/Warm
|
||||
|
||||
this->write_byte_(SM2135_CW);
|
||||
this->sm2135_stop_();
|
||||
delay(1);
|
||||
this->sm2135_start_();
|
||||
this->write_byte_(SM2135_ADDR_C);
|
||||
this->write_byte_(this->pwm_amounts_[4]); // Warm
|
||||
this->write_byte_(this->pwm_amounts_[3]); // Cold
|
||||
this->write_byte_(SM2135_CW);
|
||||
this->sm2135_stop_();
|
||||
delay(1);
|
||||
this->sm2135_start_();
|
||||
this->write_byte_(SM2135_ADDR_C);
|
||||
this->write_byte_(this->pwm_amounts_[4]); // Warm
|
||||
this->write_byte_(this->pwm_amounts_[3]); // Cold
|
||||
} else {
|
||||
// Color
|
||||
|
||||
this->write_byte_(SM2135_RGB);
|
||||
this->write_byte_(this->pwm_amounts_[1]); // Green
|
||||
this->write_byte_(this->pwm_amounts_[0]); // Red
|
||||
this->write_byte_(this->pwm_amounts_[2]); // Blue
|
||||
}
|
||||
} else {
|
||||
// Color
|
||||
|
||||
this->write_byte_(SM2135_RGB);
|
||||
this->write_byte_(this->pwm_amounts_[1]); // Green
|
||||
this->write_byte_(this->pwm_amounts_[0]); // Red
|
||||
this->write_byte_(this->pwm_amounts_[2]); // Blue
|
||||
this->write_byte_(this->pwm_amounts_[4]); // Warm
|
||||
this->write_byte_(this->pwm_amounts_[3]); // Cold
|
||||
}
|
||||
|
||||
this->sm2135_stop_();
|
||||
|
|
|
@ -39,6 +39,8 @@ class SM2135 : public Component {
|
|||
this->current_mask_ = (this->rgb_current_ << 4) | this->cw_current_;
|
||||
}
|
||||
|
||||
void set_separate_modes(bool separate_modes) { this->separate_modes_ = separate_modes; }
|
||||
|
||||
void setup() override;
|
||||
|
||||
void dump_config() override;
|
||||
|
@ -78,6 +80,7 @@ class SM2135 : public Component {
|
|||
uint8_t current_mask_;
|
||||
SM2135Current rgb_current_;
|
||||
SM2135Current cw_current_;
|
||||
bool separate_modes_;
|
||||
uint8_t update_channel_;
|
||||
std::vector<uint8_t> pwm_amounts_;
|
||||
bool update_{true};
|
||||
|
|
Loading…
Reference in a new issue