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 from PIL import Image, ImageDraw, ImageFont
import asyncio import asyncio
from mpd import MPDClient from mpd import MPDClient
import spidev
IO_DELAY = (1.0 / 20.0) IO_DELAY = (1.0 / 20.0)
MPD_DELAY = 0.5 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.img = Image.new('1', (self.width, self.height), color = not self.fg)
self.d = ImageDraw.Draw(self.img) self.d = ImageDraw.Draw(self.img)
self.bar_redraw = True self.bar_redraw = True
self.dbg = 0
def render(self): def render(self):
print("render NYI") print("render NYI")
@ -26,9 +26,8 @@ class display(object):
print("animate NYI") print("animate NYI")
def get_image(self): def get_image(self):
self.img.save("/tmp/wr/frame%d.png" % self.dbg) temp = self.img
self.dbg += 1 return temp.rotate(-90,expand=True).tobytes()
return self.img.tobytes()
class display_playback(display): class display_playback(display):
def __init__(self): def __init__(self):
@ -133,8 +132,8 @@ class radioserv:
while True: while True:
self.disp_mgr.animate(1) self.disp_mgr.animate(1)
self.disp_mgr.render() self.disp_mgr.render()
self.disp_mgr.get_image() data = list(self.disp_mgr.get_image())
print("x") self.spi.xfer(data)
await self.io_event.wait() await self.io_event.wait()
self.io_event.clear() self.io_event.clear()
@ -193,6 +192,12 @@ class radioserv:
await asyncio.sleep(MPD_DELAY) await asyncio.sleep(MPD_DELAY)
async def main(self): 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 # Connect to MPD
self.mpd = MPDClient() self.mpd = MPDClient()
self.mpd.connect("yuki", 6600) self.mpd.connect("yuki", 6600)
@ -212,7 +217,7 @@ class radioserv:
mpd_task = asyncio.create_task(self.mpd_main()) mpd_task = asyncio.create_task(self.mpd_main())
# TODO: Wait for exit condition (shutdown command) # TODO: Wait for exit condition (shutdown command)
await asyncio.sleep(10) await asyncio.sleep(60)
io_timer_task.cancel() io_timer_task.cancel()
io_task.cancel() io_task.cancel()