Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import os.path
- import ST7789 #v0.0.6
- import sys
- import signal
- import RPi.GPIO as GPIO
- import json
- from signal import *
- from time import sleep, strftime, gmtime # v.0.0.4
- import time # v.0.0.4
- display_state = "on"
- timeout = 300
- blanktime = time.time() + timeout
- # get the path of the script
- script_path = os.path.dirname(os.path.abspath(__file__))
- # set script path as current directory
- os.chdir(script_path)
- # Create ST7789 LCD display class.
- disp = ST7789.ST7789(
- height=240, #v0.0.6
- width=240, #v0.0.6
- rotation=90, # Needed to display the right way up on Pirate Audio
- port=0, # SPI port
- cs=1, # SPI port Chip-select channel
- dc=9, # BCM pin used for data/command
- backlight=13,
- spi_speed_hz=80 * 1000 * 1000,
- offset_left=0, #v0.0.6
- offset_top=0 #v0.0.6
- )
- # read json file (plugin values)
- with open('/data/configuration/miscellanea/pirateaudio/config.json', 'r') as myfile:
- data = myfile.read()
- obj = json.loads(data) # parse file
- BUTTONS = [5, 6, 16, obj['gpio_ybutton']['value']]
- # LABELS = ['A', 'B', 'X', 'Y']
- GPIO.setmode(GPIO.BCM) # Set up RPi.GPIO with the "BCM" numbering scheme
- def button_press(pin):
- global blanktime, timeout, display_state
- disp.set_backlight(True)
- display_state = "on"
- blanktime = time.time() + timeout
- def setup_channel(channel):
- try:
- GPIO.setup(channel, GPIO.IN, GPIO.PUD_UP)
- GPIO.add_event_detect(channel, GPIO.FALLING, button_press, bouncetime=400)
- except (ValueError, RuntimeError) as e:
- print('ERROR:', e)
- for x in BUTTONS:
- setup_channel(x)
- while True:
- now = time.time()
- if now > blanktime and display_state == "on":
- display_state = "off"
- disp.set_backlight(False)
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement