Chase: Use timers for timing instead of counting cycles

Counting cycles is an incredibly unreliable way of timing animations. Use timers
instead.

Fixes #545.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/550/head
Gergely Nagy 6 years ago
parent e7a48497e7
commit 88abeacd53
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -18,15 +18,16 @@
namespace kaleidoscope {
namespace plugin {
void LEDChaseEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
// Check to see if it's time to change the positions of the red and blue lights
if (current_chase_counter++ < chase_threshold) {
uint16_t now = Kaleidoscope.millisAtCycleStart();
if ((now - last_update_) < update_delay_) {
return;
}
current_chase_counter = 0;
last_update_ = now;
// The red LED is at `pos`; the blue one follows behind. `chase_sign` is either +1 or
// -1; `chase_pixels` is the gap between them.

@ -24,6 +24,13 @@ class LEDChaseEffect : public LEDMode {
public:
LEDChaseEffect(void) {}
uint16_t update_delay() {
return update_delay_;
}
void update_delay(uint16_t delay) {
update_delay_ = delay;
}
protected:
void update(void) final;
@ -31,8 +38,8 @@ class LEDChaseEffect : public LEDMode {
int8_t pos = 0;
int8_t chase_sign = 1; //negative values when it's going backwar
uint8_t chase_pixels = 5;
uint8_t current_chase_counter = 0;
static const uint8_t chase_threshold = 150;
uint16_t update_delay_ = 150;
uint16_t last_update_ = 0;
};
}
}

Loading…
Cancel
Save