mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 22:28:14 +00:00
Renamed scan_length to scan_width, removed erroneous length check
This commit is contained in:
parent
028436673a
commit
e8714fb69b
@ -143,12 +143,11 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
public:
|
||||
explicit AddressableScanEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
||||
void set_scan_length(uint32_t scan_length) { this->scan_length_ = scan_length; }
|
||||
void set_scan_width(uint32_t scan_width) { this->scan_width_ = scan_width; }
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
it.all() = ESPColor::BLACK;
|
||||
|
||||
const uint32_t scan_length_limited = (scan_length_ < it.size()) ? scan_length_ : it.size();
|
||||
for (auto i = 0; i < scan_length_limited; i++) {
|
||||
for (auto i = 0; i < this->scan_width_; i++) {
|
||||
it[this->at_led_ + i] = current_color;
|
||||
}
|
||||
|
||||
@ -156,7 +155,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
if (now - this->last_move_ > this->move_interval_) {
|
||||
if (direction_) {
|
||||
this->at_led_++;
|
||||
if (this->at_led_ == it.size() - scan_length_limited)
|
||||
if (this->at_led_ == it.size() - this->scan_width_)
|
||||
this->direction_ = false;
|
||||
} else {
|
||||
this->at_led_--;
|
||||
@ -169,7 +168,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
|
||||
protected:
|
||||
uint32_t move_interval_{};
|
||||
uint32_t scan_length_{1};
|
||||
uint32_t scan_width_{1};
|
||||
uint32_t last_move_{0};
|
||||
int at_led_{0};
|
||||
bool direction_{true};
|
||||
|
@ -16,7 +16,7 @@ from .types import LambdaLightEffect, RandomLightEffect, StrobeLightEffect, \
|
||||
CONF_ADD_LED_INTERVAL = 'add_led_interval'
|
||||
CONF_REVERSE = 'reverse'
|
||||
CONF_MOVE_INTERVAL = 'move_interval'
|
||||
CONF_SCAN_LENGTH = 'scan_length'
|
||||
CONF_SCAN_WIDTH = 'scan_width'
|
||||
CONF_TWINKLE_PROBABILITY = 'twinkle_probability'
|
||||
CONF_PROGRESS_INTERVAL = 'progress_interval'
|
||||
CONF_SPARK_PROBABILITY = 'spark_probability'
|
||||
@ -180,12 +180,12 @@ def addressable_color_wipe_effect_to_code(config, effect_id):
|
||||
|
||||
@register_effect('addressable_scan', AddressableScanEffect, "Scan", {
|
||||
cv.Optional(CONF_MOVE_INTERVAL, default='0.1s'): cv.positive_time_period_milliseconds,
|
||||
cv.Optional(CONF_SCAN_LENGTH, default=1): cv.All(cv.uint32_t, cv.Range(min=1))
|
||||
cv.Optional(CONF_SCAN_WIDTH, default=1): cv.int_range(min=1),
|
||||
})
|
||||
def addressable_scan_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_move_interval(config[CONF_MOVE_INTERVAL]))
|
||||
cg.add(var.set_scan_length(config[CONF_SCAN_LENGTH]))
|
||||
cg.add(var.set_scan_width(config[CONF_SCAN_WIDTH]))
|
||||
yield var
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user