sw: Implement SPI transmissions

This commit is contained in:
Markus Koch 2020-07-19 18:39:01 +02:00
parent a8d947544b
commit a618fff822
1 changed files with 12 additions and 7 deletions

View File

@ -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()