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)
return;
uint16_t now = Kaleidoscope.millisAtCycleStart();
if ((now - last_update_) < parent_->update_delay_) {
if (!Kaleidoscope.hasTimeExpired(last_update_, parent_->update_delay_)) {
return;
}
last_update_ = now;
last_update_ += parent_->update_delay_;
// The red LED is at `pos_`; the blue one follows behind. `direction_` is
// either +1 or -1; `distance_` is the gap between them.

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

Loading…
Cancel
Save