Mercurial > code > home > repos > front-door-display
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:e36abecb48a1 | 7:b46679798c51 |
---|---|
28 stdout=subprocess.DEVNULL, | 28 stdout=subprocess.DEVNULL, |
29 stderr=subprocess.DEVNULL) | 29 stderr=subprocess.DEVNULL) |
30 return Image.open(out.name).convert('RGB') | 30 return Image.open(out.name).convert('RGB') |
31 | 31 |
32 | 32 |
33 blockX = 16 | 33 blockX = 32 |
34 blockY = 64 | 34 blockY = 32 |
35 msgDelay = .12 | 35 msgDelay = .12 |
36 dirtyQueue = {} | 36 dirtyQueue = {} |
37 | 37 |
38 | 38 |
39 async def check_for_changes(renderer, client, last_image): | 39 async def check_for_changes(renderer, client, last_image): |
53 | 53 |
54 async def sendDirty(client): | 54 async def sendDirty(client): |
55 while True: | 55 while True: |
56 if dirtyQueue: | 56 if dirtyQueue: |
57 # pos = random.choice(list(dirtyQueue.keys())) | 57 # pos = random.choice(list(dirtyQueue.keys())) |
58 pos = min(list(dirtyQueue.keys())) | 58 # pos = min(list(dirtyQueue.keys())) |
59 pos = random.choice(list(dirtyQueue.keys())) | |
59 img = dirtyQueue.pop(pos) | 60 img = dirtyQueue.pop(pos) |
60 await tell_lcd(client, pos[0], pos[1], img) | 61 await tell_lcd(client, pos[0], pos[1], img) |
61 await asyncio.sleep(msgDelay) # too fast and esp restarts | 62 await asyncio.sleep(msgDelay) # too fast and esp restarts |
63 | |
62 | 64 |
63 framesSent = itertools.count() | 65 framesSent = itertools.count() |
64 | 66 |
65 | 67 |
66 async def tell_lcd(client: aiomqtt.Client, x: int, y: int, | 68 async def tell_lcd(client: aiomqtt.Client, x: int, y: int, |
67 region: Image.Image): | 69 region: Image.Image): |
68 seq = next(framesSent) % 65535 | 70 seq = next(framesSent) % 65535 |
69 msg = struct.pack('HHHHH', seq, x, y, region.width, region.height) + region.tobytes() | 71 msg = struct.pack('HHHHH', seq, x, y, region.width, |
70 print(f'send {seq=} {x=} {y=} {region.width=} {region.height=} ', end='\r', flush=True) | 72 region.height) + region.tobytes() |
73 print(f'send {seq=} {x=} {y=} {region.width=} {region.height=} ', | |
74 end='\r', | |
75 flush=True) | |
71 await client.publish('display/squib/updates', msg, qos=0) | 76 await client.publish('display/squib/updates', msg, qos=0) |
72 | 77 |
73 | 78 |
74 async def main(): | 79 async def main(): |
75 # also listen for dirty msgs from the web page; see ts. | 80 # also listen for dirty msgs from the web page; see ts. |