Files
Flipdot-display/src/esp32/logic/stopwatch.h
T
mangavalkandClaude Opus 5.5 fc6fa1a180 Add scrolling, countdown, stopwatch, images, seconds, multiplier and degree sign
- Text elements can scroll in a window at a set speed; clock, countdown and
  stopwatch can show seconds. Moving pages are sent as instant frames (new
  Nano command D1) and paced by the estimated flip time.
- Countdown to a date and time (smart, days, days + time, with seconds),
  stopwatch (web UI, HA switch and reset button), image element (fixed or
  by Home Assistant state), multiplier for HA values, degree sign (char 127)
  in all fonts and the font converter.
- Page format version 2; version 1 pages are converted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 21:01:14 +02:00

38 lines
753 B
C++

#pragma once
#include <stdint.h>
// The stopwatch of the dynamic pages, started and stopped in the web UI and Home Assistant.
// Times are millis(). Pure logic, tested in test/test_esp32.
class Stopwatch
{
public:
void start(uint32_t now)
{
if (_running)
return;
_running = true;
_started = now;
}
void stop(uint32_t now)
{
if (!_running)
return;
_before += now - _started;
_running = false;
}
// Back to 0, stopped
void reset()
{
_running = false;
_before = 0;
}
bool running() const { return _running; }
uint32_t elapsed(uint32_t now) const { return _before + (_running ? now - _started : 0); }
private:
bool _running = false;
uint32_t _started = 0;
uint32_t _before = 0; // ms counted before the last start
};