sw: Implement preliminary key press handlers

This commit is contained in:
Markus Koch 2020-08-08 16:52:57 +02:00
parent b92eb13f76
commit f369f88899

View File

@ -129,12 +129,39 @@ class display_manager(object):
# TODO: Consider also animating inactive screens... Might resolve some glitches when updating text while a screen is in the background (or pass `tick` to update funcs) # TODO: Consider also animating inactive screens... Might resolve some glitches when updating text while a screen is in the background (or pass `tick` to update funcs)
class radioserv: class radioserv:
def handle_rx(self, rdata):
# Handle key presses
key_id = rdata[0] & 0x0F
key_press_short = ((rdata[0] & 0xC0) == 128)
if (key_press_short):
print("Press key: {}".format(key_id))
if (key_id == 0): # Tune-
pass
elif (key_id == 1): # Tune+
self.mpd.previous()
elif (key_id == 2): # Power
self.kill_event.set()
elif (key_id == 4): # Wheel
self.mpd.pause()
elif (key_id == 5): # Source
pass
elif (key_id == 6): # Info / Menu
self.mpd.next()
elif (key_id == 7): # PRESET
pass
# Handle rotary input
rotary_delta = int(rdata[1])# - 128
if (rotary_delta > 0):
print("Rotary: {}".format(rdata[2]))
# self.mpd.volume(rotary_delta)
#print("Battery: {}".format(rdata[2]))
async def io_main(self): async def io_main(self):
while True: while True:
self.disp_mgr.animate(1) self.disp_mgr.animate(1)
self.disp_mgr.render() self.disp_mgr.render()
rdata = self.spi.xfer([100, 101, 102], 50000, 1000) rdata = self.spi.xfer([100, 101, 102], 50000, 1000)
print(rdata) self.handle_rx(rdata)
data = list(self.disp_mgr.get_image()) data = list(self.disp_mgr.get_image())
rdata = self.spi.xfer(data, SPI_SPEED, 10000) rdata = self.spi.xfer(data, SPI_SPEED, 10000)
await self.io_event.wait() await self.io_event.wait()
@ -214,13 +241,14 @@ class radioserv:
# Create main tasks # Create main tasks
self.io_event = asyncio.Event() self.io_event = asyncio.Event()
self.kill_event = asyncio.Event()
io_task = asyncio.create_task(self.io_main()) io_task = asyncio.create_task(self.io_main())
io_timer_task = asyncio.create_task(self.io_timer_main()) io_timer_task = asyncio.create_task(self.io_timer_main())
mpd_task = asyncio.create_task(self.mpd_main()) mpd_task = asyncio.create_task(self.mpd_main())
# TODO: Wait for exit condition (shutdown command) await self.kill_event.wait()
await asyncio.sleep(6000) self.kill_event.clear()
io_timer_task.cancel() io_timer_task.cancel()
io_task.cancel() io_task.cancel()