Mercurial > code > home > repos > front-door-display
annotate lcd_simulator.py @ 14:899f12179b85
upgrade lit
author | drewp@bigasterisk.com |
---|---|
date | Thu, 06 Jun 2024 17:51:38 -0700 |
parents | 47795c3121f1 |
children |
rev | line source |
---|---|
4 | 1 import asyncio |
2 import struct | |
3 | |
5 | 4 import aiomqtt |
5 import pygame | |
4 | 6 |
8
47795c3121f1
bufferless updates! mqtt message is sent over SPI and everything works
drewp@bigasterisk.com
parents:
5
diff
changeset
|
7 screen = pygame.display.set_mode((320, 480)) |
4 | 8 clock = pygame.time.Clock() |
9 | |
10 | |
5 | 11 async def on_message(client): |
12 await client.subscribe('display/squib/updates') | |
13 async for message in client.messages: | |
14 payload = bytes(message.payload) | |
15 head, x, y, w, h = struct.unpack("HHHHH", payload[:10]) | |
16 buf = payload[10:] | |
17 pygame.draw.rect(screen, (255, 255, 0), (x, y, w, h)) | |
18 pygame.display.flip() | |
19 await asyncio.sleep(.02) | |
20 for dy in range(h): | |
21 for dx in range(w): | |
22 off = w * dy + dx | |
23 r, g, b = buf[off * 3:off * 3 + 3] | |
24 screen.set_at((x + dx, y + dy), (r, g, b)) | |
25 pygame.display.flip() | |
4 | 26 |
27 | |
28 async def main(): | |
29 async with aiomqtt.Client("mqtt2.bigasterisk.com") as client: | |
5 | 30 asyncio.create_task(on_message(client)) |
4 | 31 |
32 while True: | |
33 for event in pygame.event.get(): | |
5 | 34 pass |
35 await asyncio.sleep(1 / 30) | |
4 | 36 |
37 | |
38 asyncio.run(main()) |