Refactoring: Improve event_loop.

Improve the event loop architecture by making it set the divecomputer in
the constructor - using the same loop for multiple dive computers is not
intended to work.
Also change `next()` in `divemode_loop` to `at()` to make the name more
aligned with its function.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-09-03 19:48:49 +12:00 committed by bstoeger
parent 33bb39f1ca
commit ee25e8a1db
11 changed files with 28 additions and 33 deletions

View file

@ -200,17 +200,17 @@ void fake_dc(struct divecomputer *dc)
}
divemode_loop::divemode_loop(const struct divecomputer &dc) :
dc(dc), last(dc.divemode), loop("modechange")
last(dc.divemode), loop("modechange", dc)
{
/* on first invocation, get first event (if any) */
ev = loop.next(dc);
ev = loop.next();
}
divemode_t divemode_loop::next(int time)
divemode_t divemode_loop::at(int time)
{
while (ev && ev->time.seconds <= time) {
last = static_cast<divemode_t>(ev->value);
ev = loop.next(dc);
ev = loop.next();
}
return last;
}