What problem are you trying to solve?
DovesLapTimer's reset() starts completely fresh. This is fine for a single
session, but real devices face two common scenarios where historical data needs
to survive:
SCENARIO A — Device restart mid-session:
The microcontroller reboots (power blip, watchdog reset, ...)
mid-session. If the user has saved laps/bestLapTime to SD or EEPROM, they
want to reload those values into the timer so the display shows the session's
running best, not "0". Without a way to inject this state, the user must
maintain their own parallel shadow copy of all timing state and avoid calling
the library's getters entirely.
SCENARIO B — "Best ever" mode:
At the start of a race day, the user loads their all-time best lap from
persistent storage so the delta display compares against the absolute best,
not just the current session's best. Currently impossible without hacking the
private bestLapTime member.
There is no API to set bestLapTime, laps, or lastLapTime from outside the
library. These are private state with no setter except through crossing events.
Proposed solution
Add a setLapsData() method that allows pre-loading core session state:
void setLapsData(
int readLaps,
unsigned long readLastLapTime,
unsigned long readBestLapTime
);
Implementation (3 lines):
this->laps = readLaps;
this->lastLapTime = readLastLapTime;
this->bestLapTime = readBestLapTime;
This is intentionally minimal — it sets the three fields most likely to be
restored from external storage. It does NOT set sector times, odometer, or
timestamps (those are session-specific and would be meaningless to restore).
OPTIONAL EXTENSION (could be a separate PR):
void setBestSectorTimes(
unsigned long s1, unsigned long s2, unsigned long s3
);
Allows restoring best sector times alongside lap times for the sector delta
display (Issue #31) to work correctly from session start.
SESSION NUMBER TRACKING (companion concept):
A session counter that increments each time the device starts and a circuit
is loaded — useful for SD log file naming and display. Example:
int currentSessionNumber = 1; // readable by user code
The session number is incremented externally (by SD logger, EEPROM, etc.) and
injected via a simple setter. The library just stores and exposes it:
void setSessionNumber(int n) { currentSessionNumber = n; }
int getSessionNumber() const { return currentSessionNumber; }
Alternatives considered
-
User maintains a separate "best lap" variable outside the library —
current workaround. Means the user can never rely on getBestLapTime() for
the true best; they need their own shadow variable. Defeats the purpose of
a library.
-
Make bestLapTime public — breaks encapsulation; no setter semantics.
-
Serialize/deserialize the entire timer state — complex, version-dependent,
not all state is meaningful to restore (odometer, position, buffer state).
setLapsData() is the minimal useful interface.
What problem are you trying to solve?
DovesLapTimer's reset() starts completely fresh. This is fine for a single
session, but real devices face two common scenarios where historical data needs
to survive:
SCENARIO A — Device restart mid-session:
The microcontroller reboots (power blip, watchdog reset, ...)
mid-session. If the user has saved laps/bestLapTime to SD or EEPROM, they
want to reload those values into the timer so the display shows the session's
running best, not "0". Without a way to inject this state, the user must
maintain their own parallel shadow copy of all timing state and avoid calling
the library's getters entirely.
SCENARIO B — "Best ever" mode:
At the start of a race day, the user loads their all-time best lap from
persistent storage so the delta display compares against the absolute best,
not just the current session's best. Currently impossible without hacking the
private bestLapTime member.
There is no API to set bestLapTime, laps, or lastLapTime from outside the
library. These are private state with no setter except through crossing events.
Proposed solution
Add a
setLapsData()method that allows pre-loading core session state:Implementation (3 lines):
this->laps = readLaps;
this->lastLapTime = readLastLapTime;
this->bestLapTime = readBestLapTime;
This is intentionally minimal — it sets the three fields most likely to be
restored from external storage. It does NOT set sector times, odometer, or
timestamps (those are session-specific and would be meaningless to restore).
OPTIONAL EXTENSION (could be a separate PR):
Allows restoring best sector times alongside lap times for the sector delta
display (Issue #31) to work correctly from session start.
SESSION NUMBER TRACKING (companion concept):
A session counter that increments each time the device starts and a circuit
is loaded — useful for SD log file naming and display. Example:
The session number is incremented externally (by SD logger, EEPROM, etc.) and
injected via a simple setter. The library just stores and exposes it:
Alternatives considered
User maintains a separate "best lap" variable outside the library —
current workaround. Means the user can never rely on getBestLapTime() for
the true best; they need their own shadow variable. Defeats the purpose of
a library.
Make bestLapTime public — breaks encapsulation; no setter semantics.
Serialize/deserialize the entire timer state — complex, version-dependent,
not all state is meaningful to restore (odometer, position, buffer state).
setLapsData() is the minimal useful interface.