Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Radio Bas
- """
- import RPi.GPIO as GPIO
- import time
- import subprocess
- import os
- import signal
- # -----
- # Variables
- # -----
- sleep_stop = .1
- channels = [{'pin': 7, 'url': 'http://pub1.diforfree.org:8000/di_club_dubstep', 'name': 'DubStep'},
- {'pin': 8, 'url': '', 'name': ''},
- {'pin': 12, 'url': '', 'name': ''},
- {'pin': 16, 'url': '', 'name': ''},
- {'pin': 20, 'url': '', 'name': ''},
- {'pin': 21, 'action': stop(), 'name': 'STOP'},
- {'pin': 24, 'url': '', 'name': ''},
- {'pin': 25, 'url': '', 'name': ''}]
- # -----
- # Activamos los pines del GPIO
- # -----
- GPIO.setmode(GPIO.BCM)
- for channel in channels:
- GPIO.setup(channel['pin'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
- def stop():
- os.killpg(p.pid,signal.SIGTERM)
- time.sleep(sleep_stop)
- while True:
- for channel in channels:
- input_state = GPIO.input(channel['pin'])
- if input_state == False:
- # Si tiene nombre, mostramos la pulsación por consola
- if 'name' in channel and channel['name']!='':
- print('Boton ' + channel['name'] + " pulsado')
- # Si tiene acción, ejecuto la función
- if 'action' in channel:
- channel['action']
- # Si tiene URL, sintonizamos canal
- if 'url' in channel and channel['url']!='':
- stop()
- url = "mplay " + channel['url']
- p = subprocess.Popen(url, shell=True, preexec_fn=os.setsid)
- time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement