Advertisement
DarrenHill

Volumio PirateAudio Screensaver

Jan 5th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import os
  4. import os.path
  5. import ST7789 #v0.0.6
  6. import sys
  7. import signal
  8. import RPi.GPIO as GPIO
  9. import json
  10. from signal import *
  11. from time import sleep, strftime, gmtime # v.0.0.4
  12. import time # v.0.0.4
  13.  
  14. display_state = "on"
  15. timeout = 300
  16. blanktime = time.time() + timeout
  17.  
  18. # get the path of the script
  19. script_path = os.path.dirname(os.path.abspath(__file__))
  20. # set script path as current directory
  21. os.chdir(script_path)
  22.  
  23. # Create ST7789 LCD display class.
  24. disp = ST7789.ST7789(
  25.     height=240, #v0.0.6
  26.     width=240, #v0.0.6
  27.     rotation=90, # Needed to display the right way up on Pirate Audio
  28.     port=0, # SPI port
  29.     cs=1, # SPI port Chip-select channel
  30.     dc=9, # BCM pin used for data/command
  31.     backlight=13,
  32.     spi_speed_hz=80 * 1000 * 1000,
  33.     offset_left=0, #v0.0.6
  34.     offset_top=0 #v0.0.6
  35. )
  36.  
  37. # read json file (plugin values)
  38. with open('/data/configuration/miscellanea/pirateaudio/config.json', 'r') as myfile:
  39.     data = myfile.read()
  40. obj = json.loads(data) # parse file
  41.  
  42. BUTTONS = [5, 6, 16, obj['gpio_ybutton']['value']]
  43. # LABELS = ['A', 'B', 'X', 'Y']
  44.  
  45. GPIO.setmode(GPIO.BCM) # Set up RPi.GPIO with the "BCM" numbering scheme
  46.  
  47. def button_press(pin):
  48.     global blanktime, timeout, display_state
  49.     disp.set_backlight(True)
  50.     display_state = "on"
  51.     blanktime = time.time() + timeout
  52.  
  53. def setup_channel(channel):
  54.     try:
  55.         GPIO.setup(channel, GPIO.IN, GPIO.PUD_UP)
  56.         GPIO.add_event_detect(channel, GPIO.FALLING, button_press, bouncetime=400)
  57.     except (ValueError, RuntimeError) as e:
  58.         print('ERROR:', e)
  59.  
  60. for x in BUTTONS:
  61.     setup_channel(x)
  62.  
  63. while True:
  64.     now = time.time()
  65.     if now > blanktime and display_state == "on":
  66.         display_state = "off"
  67.         disp.set_backlight(False)
  68.     sleep(1)
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement