Advertisement
Guest User

Radio Bas

a guest
Jul 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. Radio Bas
  6. """
  7.  
  8. import RPi.GPIO as GPIO
  9. import time
  10. import subprocess
  11. import os
  12. import signal
  13.  
  14. # -----
  15. # Variables
  16. # -----
  17. sleep_stop = .1
  18. channels = [{'pin': 7, 'url': 'http://pub1.diforfree.org:8000/di_club_dubstep', 'name': 'DubStep'},
  19. {'pin': 8, 'url': '', 'name': ''},
  20. {'pin': 12, 'url': '', 'name': ''},
  21. {'pin': 16, 'url': '', 'name': ''},
  22. {'pin': 20, 'url': '', 'name': ''},
  23. {'pin': 21, 'action': stop(), 'name': 'STOP'},
  24. {'pin': 24, 'url': '', 'name': ''},
  25. {'pin': 25, 'url': '', 'name': ''}]
  26. # -----
  27. # Activamos los pines del GPIO
  28. # -----
  29. GPIO.setmode(GPIO.BCM)
  30. for channel in channels:
  31. GPIO.setup(channel['pin'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
  32.  
  33.  
  34. def stop():
  35. os.killpg(p.pid,signal.SIGTERM)
  36. time.sleep(sleep_stop)
  37.  
  38. while True:
  39. for channel in channels:
  40. input_state = GPIO.input(channel['pin'])
  41. if input_state == False:
  42. # Si tiene nombre, mostramos la pulsación por consola
  43. if 'name' in channel and channel['name']!='':
  44. print('Boton ' + channel['name'] + " pulsado')
  45. # Si tiene acción, ejecuto la función
  46. if 'action' in channel:
  47. channel['action']
  48. # Si tiene URL, sintonizamos canal
  49. if 'url' in channel and channel['url']!='':
  50. stop()
  51. url = "mplay " + channel['url']
  52. p = subprocess.Popen(url, shell=True, preexec_fn=os.setsid)
  53. time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement