Use standard timeout checker for LEDEffect-Chase

Also, change `update_delay_` from two bytes to one, and use a more consistent
interval by adding it to `last_update_` after each update, rather than using the
current time.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/642/head
Michael Richters 6 years ago
parent c5b8eddaae
commit 2bcfe8a0ea

@ -23,11 +23,10 @@ void LEDChaseEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Kaleidoscope.has_leds)
return; return;
uint16_t now = Kaleidoscope.millisAtCycleStart(); if (!Kaleidoscope.hasTimeExpired(last_update_, parent_->update_delay_)) {
if ((now - last_update_) < parent_->update_delay_) {
return; return;
} }
last_update_ = now; last_update_ += parent_->update_delay_;
// The red LED is at `pos_`; the blue one follows behind. `direction_` is // The red LED is at `pos_`; the blue one follows behind. `direction_` is
// either +1 or -1; `distance_` is the gap between them. // either +1 or -1; `distance_` is the gap between them.

@ -25,10 +25,10 @@ class LEDChaseEffect : public Plugin,
public: public:
LEDChaseEffect(void) {} LEDChaseEffect(void) {}
uint16_t update_delay() { uint8_t update_delay() {
return update_delay_; return update_delay_;
} }
void update_delay(uint16_t delay) { void update_delay(uint8_t delay) {
update_delay_ = delay; update_delay_ = delay;
} }
uint8_t distance() { uint8_t distance() {
@ -48,7 +48,7 @@ class LEDChaseEffect : public Plugin,
// members of their parent class. Most LED modes can do without. // members of their parent class. Most LED modes can do without.
// //
TransientLEDMode(const LEDChaseEffect *parent) TransientLEDMode(const LEDChaseEffect *parent)
: parent_(parent) {} : parent_(parent), last_update_(Kaleidoscope.millisAtCycleStart()) {}
protected: protected:
@ -60,12 +60,12 @@ class LEDChaseEffect : public Plugin,
int8_t pos_ = 0; int8_t pos_ = 0;
int8_t direction_ = 1; int8_t direction_ = 1;
uint16_t last_update_ = 0; uint16_t last_update_;
}; };
private: private:
uint8_t distance_ = 5; uint8_t distance_ = 5;
uint16_t update_delay_ = 150; uint8_t update_delay_ = 150;
}; };
} }
} }

Loading…
Cancel
Save