1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 07:08:20 +00:00

Added config option 'scan_length' to AddressableScanEffect (default: 1)

This commit is contained in:
Major Péter 2019-06-03 17:07:44 +02:00
parent ba07df8c22
commit 028436673a
2 changed files with 5 additions and 1 deletions

View File

@ -143,6 +143,7 @@ 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_length(uint32_t scan_length) { this->scan_length_ = scan_length; }
void apply(AddressableLight &it, const ESPColor &current_color) override { void apply(AddressableLight &it, const ESPColor &current_color) override {
it.all() = ESPColor::BLACK; it.all() = ESPColor::BLACK;
@ -168,7 +169,7 @@ class AddressableScanEffect : public AddressableLightEffect {
protected: protected:
uint32_t move_interval_{}; uint32_t move_interval_{};
uint32_t scan_length_{10}; uint32_t scan_length_{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};

View File

@ -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_LENGTH = 'scan_length'
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_LENGTH, default=1): cv.All(cv.uint32_t, cv.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_length(config[CONF_SCAN_LENGTH]))
yield var yield var