From a618fff822d3b6116742641012dca674f15da5d0 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 19 Jul 2020 18:39:01 +0200 Subject: [PATCH] sw: Implement SPI transmissions --- software/webradio.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/software/webradio.py b/software/webradio.py index c0f27ec..23eaf75 100644 --- a/software/webradio.py +++ b/software/webradio.py @@ -3,6 +3,7 @@ from PIL import Image, ImageDraw, ImageFont import asyncio from mpd import MPDClient +import spidev IO_DELAY = (1.0 / 20.0) MPD_DELAY = 0.5 @@ -17,7 +18,6 @@ class display(object): self.img = Image.new('1', (self.width, self.height), color = not self.fg) self.d = ImageDraw.Draw(self.img) self.bar_redraw = True - self.dbg = 0 def render(self): print("render NYI") @@ -26,9 +26,8 @@ class display(object): print("animate NYI") def get_image(self): - self.img.save("/tmp/wr/frame%d.png" % self.dbg) - self.dbg += 1 - return self.img.tobytes() + temp = self.img + return temp.rotate(-90,expand=True).tobytes() class display_playback(display): def __init__(self): @@ -133,8 +132,8 @@ class radioserv: while True: self.disp_mgr.animate(1) self.disp_mgr.render() - self.disp_mgr.get_image() - print("x") + data = list(self.disp_mgr.get_image()) + self.spi.xfer(data) await self.io_event.wait() self.io_event.clear() @@ -193,6 +192,12 @@ class radioserv: await asyncio.sleep(MPD_DELAY) async def main(self): + # Connect to SPI + self.spi = spidev.SpiDev() + self.spi.open(0, 0) + self.spi.max_speed_hz = 500000 + self.spi.mode = 0b00 + # Connect to MPD self.mpd = MPDClient() self.mpd.connect("yuki", 6600) @@ -212,7 +217,7 @@ class radioserv: mpd_task = asyncio.create_task(self.mpd_main()) # TODO: Wait for exit condition (shutdown command) - await asyncio.sleep(10) + await asyncio.sleep(60) io_timer_task.cancel() io_task.cancel()