Mercurial > code > home > repos > front-door-display
view lcd_simulator.py @ 14:899f12179b85
upgrade lit
author | drewp@bigasterisk.com |
---|---|
date | Thu, 06 Jun 2024 17:51:38 -0700 |
parents | 47795c3121f1 |
children |
line wrap: on
line source
import asyncio import struct import aiomqtt import pygame screen = pygame.display.set_mode((320, 480)) clock = pygame.time.Clock() async def on_message(client): await client.subscribe('display/squib/updates') async for message in client.messages: payload = bytes(message.payload) head, x, y, w, h = struct.unpack("HHHHH", payload[:10]) buf = payload[10:] pygame.draw.rect(screen, (255, 255, 0), (x, y, w, h)) pygame.display.flip() await asyncio.sleep(.02) for dy in range(h): for dx in range(w): off = w * dy + dx r, g, b = buf[off * 3:off * 3 + 3] screen.set_at((x + dx, y + dy), (r, g, b)) pygame.display.flip() async def main(): async with aiomqtt.Client("mqtt2.bigasterisk.com") as client: asyncio.create_task(on_message(client)) while True: for event in pygame.event.get(): pass await asyncio.sleep(1 / 30) asyncio.run(main())