Improved step timeout calculation

Use a timeout calculation method that is not affected by overflow, and also
requires 16 bits less.

This likely fixes #8.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 7 years ago
parent b575a232be
commit 36333263ef

@ -24,7 +24,7 @@ namespace kaleidoscope {
uint8_t StalkerEffect::map_[ROWS][COLS];
StalkerEffect::ColorComputer *StalkerEffect::variant;
uint16_t StalkerEffect::step_length = 50;
uint32_t StalkerEffect::step_end_time_;
uint16_t StalkerEffect::step_start_time_;
void StalkerEffect::setup(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
@ -49,7 +49,8 @@ void StalkerEffect::update(void) {
if (!variant)
return;
bool time_out = millis() >= step_end_time_;
uint16_t now = millis();
bool time_out = (now - step_start_time_) > step_length;
for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) {
@ -70,7 +71,7 @@ void StalkerEffect::update(void) {
}
if (time_out)
step_end_time_ = millis() + step_length;
step_start_time_ = now;
}
namespace stalker {

@ -42,7 +42,7 @@ class StalkerEffect : public LEDMode {
void update(void) final;
private:
static uint32_t step_end_time_;
static uint16_t step_start_time_;
static uint8_t map_[ROWS][COLS];
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);

Loading…
Cancel
Save