diff web_to_mqtt.py @ 7:b46679798c51

mv esp code to this repo. still trying to get correct refreshes
author drewp@bigasterisk.com
date Sun, 10 Mar 2024 15:03:53 -0700
parents e36abecb48a1
children 47795c3121f1
line wrap: on
line diff
--- a/web_to_mqtt.py	Fri Mar 08 09:17:05 2024 -0800
+++ b/web_to_mqtt.py	Sun Mar 10 15:03:53 2024 -0700
@@ -30,8 +30,8 @@
         return Image.open(out.name).convert('RGB')
 
 
-blockX = 16
-blockY = 64
+blockX = 32
+blockY = 32
 msgDelay = .12
 dirtyQueue = {}
 
@@ -55,10 +55,12 @@
     while True:
         if dirtyQueue:
             # pos = random.choice(list(dirtyQueue.keys()))
-            pos = min(list(dirtyQueue.keys()))
+            # pos = min(list(dirtyQueue.keys()))
+            pos = random.choice(list(dirtyQueue.keys()))
             img = dirtyQueue.pop(pos)
             await tell_lcd(client, pos[0], pos[1], img)
-        await asyncio.sleep(msgDelay) # too fast and esp restarts
+        await asyncio.sleep(msgDelay)  # too fast and esp restarts
+
 
 framesSent = itertools.count()
 
@@ -66,8 +68,11 @@
 async def tell_lcd(client: aiomqtt.Client, x: int, y: int,
                    region: Image.Image):
     seq = next(framesSent) % 65535
-    msg = struct.pack('HHHHH', seq, x, y, region.width, region.height) + region.tobytes()
-    print(f'send {seq=} {x=} {y=} {region.width=} {region.height=}  ', end='\r', flush=True)
+    msg = struct.pack('HHHHH', seq, x, y, region.width,
+                      region.height) + region.tobytes()
+    print(f'send {seq=} {x=} {y=} {region.width=} {region.height=}  ',
+          end='\r',
+          flush=True)
     await client.publish('display/squib/updates', msg, qos=0)