Skip to content

Commit

Permalink
Move display drawing to a separate thread
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Apr 15, 2024
1 parent 0f4c192 commit 8f26bb3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/yaroc/sources/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import re
import time
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from typing import Dict

Expand Down Expand Up @@ -30,6 +31,7 @@ def __init__(
self.meshtastic_channel = meshtastic_channel
self.handler = MessageHandler.new(dns, meshtastic_mac_addr)
self.drawer = StatusDrawer(self.handler, display_model)
self.executor = ThreadPoolExecutor(max_workers=1)

@staticmethod
def _payload_to_bytes(payload: PayloadType) -> bytes:
Expand Down Expand Up @@ -119,7 +121,7 @@ async def draw_table(self):
await asyncio.sleep(20.0)
while True:
time_start = time.time()
self.drawer.draw_status() # Move to another thread
self.executor.submit(self.drawer.draw_status)
await asyncio.sleep(60 - (time.time() - time_start))

async def loop(self):
Expand Down

0 comments on commit 8f26bb3

Please sign in to comment.