Skip to content

Commit

Permalink
Merge pull request #39 from ArendJan/fix-oled
Browse files Browse the repository at this point in the history
Fix oled by using thread safe run_coroutine_threadsafe
  • Loading branch information
mklomp authored Oct 27, 2023
2 parents 8b3e56c + 0406ed5 commit b91d972
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mirte_telemetrix/scripts/ROS_telemetrix_aio_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3.8
import asyncio
import nest_asyncio
import os, os.path
import sys
import time
Expand All @@ -13,7 +12,6 @@
from tmx_pico_aio import tmx_pico_aio
from telemetrix_aio import telemetrix_aio

nest_asyncio.apply()

# Import the right Telemetrix AIO
devices = rospy.get_param("/mirte/device")
Expand Down Expand Up @@ -53,9 +51,6 @@ async def analog_write(board, pin, value):
font = ImageFont.load_default()

from adafruit_ssd1306 import _SSD1306
from concurrent.futures import ThreadPoolExecutor

executor = ThreadPoolExecutor(10)


import mappings.default
Expand Down Expand Up @@ -681,7 +676,12 @@ def set_oled_image_service(self, req):
return SetOLEDImageResponse(False)

try:
self.loop.run_until_complete(self.set_oled_image_service_async(req))
# the ros service is started on a different thread than the asyncio loop
# When using the normal loop.run_until_complete() function, both threads join in and the oled communication will get broken faster
future = asyncio.run_coroutine_threadsafe(
self.set_oled_image_service_async(req), self.loop
)
future.result() # wait for it to be done
except Exception as e:
print(e)
return SetOLEDImageResponse(True)
Expand Down

0 comments on commit b91d972

Please sign in to comment.