diff --git a/SoundslabDisplay.py b/SoundslabDisplay.py index 0a04c38..0e41a6b 100644 --- a/SoundslabDisplay.py +++ b/SoundslabDisplay.py @@ -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) diff --git a/SoundslabInput.py b/SoundslabInput.py index c2f12e8..88f1c2c 100644 --- a/SoundslabInput.py +++ b/SoundslabInput.py @@ -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()