mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 18:24:13 +01:00
Scan length for AddressableScanEffect (#608)
* Added scan_length to AddressableScanEffect (allow more than one LED) * Added check for scan length being longer than addressable light * Added config option 'scan_length' to AddressableScanEffect (default: 1) * Renamed scan_length to scan_width, removed erroneous length check * Fixed indentation issue in addressable_light_effect.h Co-Authored-By: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
0a21816a5a
commit
970838ed09
2 changed files with 11 additions and 2 deletions
|
@ -143,14 +143,19 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||||
public:
|
public:
|
||||||
explicit AddressableScanEffect(const std::string &name) : AddressableLightEffect(name) {}
|
explicit AddressableScanEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||||
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
||||||
|
void set_scan_width(uint32_t scan_width) { this->scan_width_ = scan_width; }
|
||||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||||
it.all() = ESPColor::BLACK;
|
it.all() = ESPColor::BLACK;
|
||||||
it[this->at_led_] = current_color;
|
|
||||||
|
for (auto i = 0; i < this->scan_width_; i++) {
|
||||||
|
it[this->at_led_ + i] = current_color;
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t now = millis();
|
const uint32_t now = millis();
|
||||||
if (now - this->last_move_ > this->move_interval_) {
|
if (now - this->last_move_ > this->move_interval_) {
|
||||||
if (direction_) {
|
if (direction_) {
|
||||||
this->at_led_++;
|
this->at_led_++;
|
||||||
if (this->at_led_ == it.size() - 1)
|
if (this->at_led_ == it.size() - this->scan_width_)
|
||||||
this->direction_ = false;
|
this->direction_ = false;
|
||||||
} else {
|
} else {
|
||||||
this->at_led_--;
|
this->at_led_--;
|
||||||
|
@ -163,6 +168,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t move_interval_{};
|
uint32_t move_interval_{};
|
||||||
|
uint32_t scan_width_{1};
|
||||||
uint32_t last_move_{0};
|
uint32_t last_move_{0};
|
||||||
int at_led_{0};
|
int at_led_{0};
|
||||||
bool direction_{true};
|
bool direction_{true};
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .types import LambdaLightEffect, RandomLightEffect, StrobeLightEffect, \
|
||||||
CONF_ADD_LED_INTERVAL = 'add_led_interval'
|
CONF_ADD_LED_INTERVAL = 'add_led_interval'
|
||||||
CONF_REVERSE = 'reverse'
|
CONF_REVERSE = 'reverse'
|
||||||
CONF_MOVE_INTERVAL = 'move_interval'
|
CONF_MOVE_INTERVAL = 'move_interval'
|
||||||
|
CONF_SCAN_WIDTH = 'scan_width'
|
||||||
CONF_TWINKLE_PROBABILITY = 'twinkle_probability'
|
CONF_TWINKLE_PROBABILITY = 'twinkle_probability'
|
||||||
CONF_PROGRESS_INTERVAL = 'progress_interval'
|
CONF_PROGRESS_INTERVAL = 'progress_interval'
|
||||||
CONF_SPARK_PROBABILITY = 'spark_probability'
|
CONF_SPARK_PROBABILITY = 'spark_probability'
|
||||||
|
@ -179,10 +180,12 @@ def addressable_color_wipe_effect_to_code(config, effect_id):
|
||||||
|
|
||||||
@register_effect('addressable_scan', AddressableScanEffect, "Scan", {
|
@register_effect('addressable_scan', AddressableScanEffect, "Scan", {
|
||||||
cv.Optional(CONF_MOVE_INTERVAL, default='0.1s'): cv.positive_time_period_milliseconds,
|
cv.Optional(CONF_MOVE_INTERVAL, default='0.1s'): cv.positive_time_period_milliseconds,
|
||||||
|
cv.Optional(CONF_SCAN_WIDTH, default=1): cv.int_range(min=1),
|
||||||
})
|
})
|
||||||
def addressable_scan_effect_to_code(config, effect_id):
|
def addressable_scan_effect_to_code(config, effect_id):
|
||||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||||
cg.add(var.set_move_interval(config[CONF_MOVE_INTERVAL]))
|
cg.add(var.set_move_interval(config[CONF_MOVE_INTERVAL]))
|
||||||
|
cg.add(var.set_scan_width(config[CONF_SCAN_WIDTH]))
|
||||||
yield var
|
yield var
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue