Skip to content

Commit

Permalink
allow loop counter to count things that happen more than once per loop
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed May 25, 2024
1 parent f10c78f commit 5c1edfe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions common/loop_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ class LoopCounter {
millis_sum_ = 0;
last_millis_ = 0;
}
void Update() {
void Update(uint32_t v) {
uint32_t m = millis();
if (last_millis_) {
millis_sum_ += m - last_millis_;
updates_++;
if (updates_ > 1000) {
updates_+=v;
if (millis_sum_ > 10000) {
updates_ /= 2;
millis_sum_ /= 2;
}
}
last_millis_ = m;
}
void Update() { Update(1); }
private:
int updates_ = 0;
int millis_sum_ = 0;
Expand Down

0 comments on commit 5c1edfe

Please sign in to comment.