Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions api_drivers/common_api_drivers/frozen/other/task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
self._task_handler_ref = self._task_handler
self.max_scheduled = max_scheduled

self._start_time = time.ticks_ms() # NOQA
self._last_tick = time.ticks_ms() # NOQA
self._timer.init(
mode=Timer.PERIODIC,
period=self.duration,
Expand Down Expand Up @@ -126,16 +126,8 @@ def _task_handler(self, _):
else:
sys.print_exception(err) # NOQA

stop_time = time.ticks_ms() # NOQA

ticks_diff = time.ticks_diff(stop_time, self._start_time) # NOQA
self._start_time = stop_time
lv.tick_inc(ticks_diff)

if run_update:
lv.task_handler()
start_time = time.ticks_ms() # NOQA

for cb, evt, data in self._callbacks:
if not evt & TASK_HANDLER_FINISHED:
continue
Expand All @@ -151,10 +143,6 @@ def _task_handler(self, _):
else:
sys.print_exception(err) # NOQA

stop_time = time.ticks_ms() # NOQA
ticks_diff = time.ticks_diff(stop_time, start_time) # NOQA
lv.tick_inc(ticks_diff)

self._running = False

except Exception as e:
Expand All @@ -164,7 +152,13 @@ def _task_handler(self, _):
self.exception_hook(e)

def _timer_cb(self, _):
lv.tick_inc(self.duration)
# The only place LVGL time advances. Feed it the real elapsed time
# rather than the nominal period: timer callbacks are delivered via the
# scheduler and coalesce or drop under load, and _task_handler must not
# add ticks of its own or LVGL time runs ~2x faster than wall clock.
now = time.ticks_ms() # NOQA
lv.tick_inc(time.ticks_diff(now, self._last_tick)) # NOQA
self._last_tick = now
if self._running:
return

Expand Down