first pass at handling display lock/unlock

This commit is contained in:
Sundog Jones 2020-08-02 09:20:39 -07:00
parent 3e46566f4d
commit be449fc957
2 changed files with 21 additions and 4 deletions

View File

@ -20,6 +20,7 @@ class SoundslabDisplay:
backlight=13,
spi_speed_hz=self.spi_speed_mhz * 1000 * 1000
)
self.displayOn = True
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))
@ -34,6 +35,22 @@ class SoundslabDisplay:
# track currently playing song's art path to eliminate unnecessary reloads of the same image file
self.current_art_path = None
def _displayOff(self):
self.st7789.set_backlight(0) # turn off the backlight
self.st7789.command(0x28) # turn off the display itself
self.displayOn = False
def _displayOn(self):
self.st7789.command(0x29) # turn on the display itself
self.st7789.set_backlight(1) # turn on the backlight
self.displayOn = True
def toggleDisplayOnOff(self):
if self.displayOn:
self._displayOff()
else:
self._displayOn()
def getBatteryState(self):
bus = smbus.SMBus(1)

View File

@ -9,6 +9,9 @@ from math import floor
player_client = musicpd.MPDClient()
player_client.connect()
# initialize connection to display
display = SoundslabDisplay(player_client)
# The buttons on Pirate Audio are connected to pins 5, 6, 16 and 24
# Boards prior to 23 January 2020 used 5, 6, 16 and 20
# try changing 24 to 20 if your Y button doesn't work.
@ -94,7 +97,7 @@ def RT():
def SELECT():
# display lock/unlock
pass
display.toggleDisplayOnOff()
# This is a dictionary of the combination of pins and labels
LABELLED_BUTTONS = {
@ -123,9 +126,6 @@ def handle_button(pin):
for pin in BUTTONS:
GPIO.add_event_detect(pin, GPIO.FALLING, handle_button, bouncetime=100)
# initialize the display
display = SoundslabDisplay(player_client)
while True:
# test album art
display.updateAlbumArt()