Skip to content

Commit

Permalink
Update all camera views
Browse files Browse the repository at this point in the history
  • Loading branch information
OloFuchs committed Dec 4, 2023
1 parent 0935efa commit 4ea3254
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class KivyVirtualJoystick(App):
amiga_speed = StringProperty("???")
amiga_rate = StringProperty("???")

STREAM_NAMES = ["rgb", "disparity", "left", "right"]


def __init__(self, service_config: EventServiceConfig, stream_every_n: int) -> None:
super().__init__()
Expand All @@ -63,6 +65,9 @@ def __init__(self, service_config: EventServiceConfig, stream_every_n: int) -> N
self.async_tasks: list[asyncio.Task] = []

self.image_decoder = ImageDecoder()
self.view_name = 'rgb'

print(EventServiceConfigList)

# self.image_decoder = TurboJPEG('/mnt/managed_home/farm-ng-user-oliverfuchs/virtual-joystick-kivy/venv/lib/python3.8/site-packages/turbojpeg.py')

Expand All @@ -72,6 +77,10 @@ def build(self):
def on_exit_btn(self) -> None:
"""Kills the running kivy application."""
App.get_running_app().stop()

def update_view(self, view_name: str):
print(view_name)
self.view_name = view_name

async def app_func(self):
async def run_wrapper() -> None:
Expand All @@ -82,8 +91,10 @@ async def run_wrapper() -> None:
task.cancel()

# Camera task
self.async_tasks: list[asyncio.Task] = [
asyncio.create_task(self.stream_camera("rgb"))
print(self.view_name)
self.async_tasks: list[asyncio.Task] = [
asyncio.create_task(self.stream_camera(view_name))
for view_name in self.STREAM_NAMES
]

return await asyncio.gather(run_wrapper(), *self.async_tasks)
Expand All @@ -94,13 +105,16 @@ async def stream_camera(
"""Subscribes to the camera service and populates the tabbed panel with all 4 image streams."""
while self.root is None:
await asyncio.sleep(0.01)

print("how often does this happen")
async for _, message in EventClient(self.service_config).subscribe(
SubscribeRequest(
uri=Uri(path=f"/{view_name}"), every_n=self.stream_every_n
),
decode=True,
):
print("can you read this: " + self.view_name)
print(f"/{view_name}")

try:
img = self.image_decoder.decode(message.image_data)
except Exception as e:
Expand Down Expand Up @@ -151,6 +165,7 @@ def find_config_by_name(
)

oak_service_config = find_config_by_name(service_config_list, args.camera_name)
# print(oak_service_config)
if oak_service_config is None:
raise RuntimeError(f"Could not find service config for {args.camera_name}")

Expand Down
2 changes: 2 additions & 0 deletions src/res/main.kv
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ RelativeLayout:
do_default_tab: False
TabbedPanelItem:
text: "Rgb"
on_press: app.update_view('rgb')
Image:
id: rgb
TabbedPanelItem:
text: "Disparity"
on_press: app.update_view('disparity')
Image:
id: disparity
TabbedPanelItem:
Expand Down

0 comments on commit 4ea3254

Please sign in to comment.