first pass at python module for handling display updates
This commit is contained in:
parent
ffaf3ed961
commit
59cf00c9fa
60
SoundslabDisplay.py
Normal file
60
SoundslabDisplay.py
Normal file
@ -0,0 +1,60 @@
|
||||
import time
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
from ST7789 import ST7789
|
||||
from glob import glob
|
||||
import struct
|
||||
import smbus
|
||||
import sys
|
||||
|
||||
class SoundslabDisplay:
|
||||
def __init__(self):
|
||||
self.screen_size = 240, 240
|
||||
self.spi_speed_mhz = 80
|
||||
self.st7789 = ST7789(
|
||||
rotation=90,
|
||||
port=0,
|
||||
cs=1,
|
||||
dc=9,
|
||||
backlight=13,
|
||||
spi_speed_hz=self.spi_speed_mhz * 1000 * 1000
|
||||
)
|
||||
self.current_background = Image.new("RGBA", self.screen_size, (0, 0, 255, 255))
|
||||
self.current_overlay = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
|
||||
self.current_menu = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
|
||||
self.fg_color = (255, 255, 255, 211)
|
||||
self.bg_color = (0, 0, 0, 78)
|
||||
|
||||
def updateOverlay(self, current_track_number, total_track_number, battery_level_percent, track_progress_percent):
|
||||
# initialize overlay
|
||||
im_overlay = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
|
||||
font = ImageFont.truetype(font='/usr/share/fonts/truetype/hack/Hack-Bold.ttf', size=18)
|
||||
overlay = ImageDraw.Draw(im_overlay)
|
||||
|
||||
# draw four rects on edges of screen_size
|
||||
overlay.rectangle([(0, 0), (self.screen_size[0], 20)], self.bg_color) # top bar
|
||||
overlay.rectangle([(0, self.screen_size[1] - 20), (self.screen_size[0], self.screen_size[1])], self.bg_color) # bottom bar
|
||||
overlay.rectangle([(0, 20), (20, self.screen_size[1] - 20)], self.bg_color) # left bar
|
||||
overlay.rectangle([(self.screen_size[0] - 20, 20), (self.screen_size[0], self.screen_size[1] - 20)], self.bg_color) # right bar
|
||||
|
||||
# add track # / total #
|
||||
track_and_queue = str(current_track_number) + " of " + str(total_track_number)
|
||||
overlay.text((10, 0), track_and_queue, font=font, fill=self.fg_color)
|
||||
|
||||
# add battery level
|
||||
battery_display = '{:02.2f}'.format(battery_level_percent) + '%'
|
||||
overlay.text((self.screen_size[0] - 70, 0), battery_display, font=font, fill=self.fg_color)
|
||||
|
||||
# add progress meter
|
||||
overlay.rectangle([(10, self.screen_size[1] - 15), (self.screen_size[0] - 10, self.screen_size[1] - 5)], fill=(0, 0, 0, 0), outline=self.fg_color, width=1)
|
||||
overlay.rectangle([(10, self.screen_size[1] - 15), (int((self.screen_size[0] - 20) * (track_progress_percent / 100)) + 10, self.screen_size[1] - 5)], fill=self.fg_color, outline=self.fg_color, width=1)
|
||||
|
||||
self.current_overlay = im_overlay.copy()
|
||||
|
||||
def updateAlbumArt(self, cover_image_file):
|
||||
im = Image.open(cover_image_file).convert("RGBA")
|
||||
image = im.resize(self.screen_size)
|
||||
self.current_background = image.copy()
|
||||
|
||||
def updateDisplay(self):
|
||||
tempoutput = Image.alpha_composite(self.current_background, self.current_overlay)
|
||||
self.st7789.display(Image.alpha_composite(tempoutput, self.current_menu))
|
Loading…
Reference in New Issue
Block a user