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: 13 additions & 9 deletions selfdrive/ui/tests/diff/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@


@dataclass
class DummyEvent:
class Event:
click: bool = False
# TODO: add some kind of intensity
swipe_left: bool = False
swipe_right: bool = False
swipe_down: bool = False
delay: float = 1.0 # seconds to wait after event


SCRIPT = [
(0, DummyEvent()),
(FPS * 1, DummyEvent(click=True)),
(FPS * 2, DummyEvent(click=True)),
(FPS * 3, DummyEvent()),
Event(), # wait for initialization
Event(click=True), # open settings
Event(click=True), # open toggles
]


Expand All @@ -61,7 +61,7 @@ def inject_click(coords):
gui_app._mouse._events.extend(events)


def handle_event(event: DummyEvent):
def handle_event(event: Event):
if event.click:
inject_click([(gui_app.width // 2, gui_app.height // 2)])
if event.swipe_left:
Expand Down Expand Up @@ -90,21 +90,25 @@ def run_replay():

frame = 0
script_index = 0
elapsed_time = 0.0
next_event_time = 0.0

for should_render in gui_app.render():
while script_index < len(SCRIPT) and SCRIPT[script_index][0] == frame:
_, event = SCRIPT[script_index]
while script_index < len(SCRIPT) and elapsed_time >= next_event_time:
event = SCRIPT[script_index]
handle_event(event)
next_event_time += event.delay
script_index += 1

ui_state.update()

if should_render:
main_layout.render()

elapsed_time += 1.0 / FPS
frame += 1

if script_index >= len(SCRIPT):
if script_index >= len(SCRIPT) and elapsed_time >= next_event_time:
break

gui_app.close()
Expand Down
Loading