Advertisement
Hanner72

radio5.py

Mar 15th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.28 KB | None | 0 0
  1. # +---------------------------------------------------+
  2. # | Webradio                                          |
  3. # | Autor: Johann Danner                              |
  4. # | Datum: 03/2016                                    |
  5. # | Version: V2.0                                     |
  6. # +---------------------------------------------------+
  7.  
  8. import RPi.GPIO as gpio
  9. import time
  10. from time import sleep, time
  11. import os
  12. import types
  13. import sys
  14. from socket import error as SocketError
  15. import mpd
  16.  
  17. gpio.setwarnings(False)
  18.  
  19. # to use Raspberry Pi board GPIO numbers
  20. gpio.setmode(gpio.BCM)
  21.  
  22. # to use Raspberry Pi board GPIO PIN numbers
  23. # gpio.setmode(gpio.Board)
  24.  
  25. # GPIO Pins festlegen
  26. NEXT_PIN        = 22
  27. PREV_PIN        = 13
  28. PAUSE_PIN       = 23
  29. VOLUMEUP_PIN    = 19
  30. VOLUMEDOWN_PIN  = 26
  31.  
  32. # set up GPIO input channel
  33. gpio.setup(NEXT_PIN, gpio.IN)
  34. gpio.setup(PREV_PIN, gpio.IN)
  35. gpio.setup(PAUSE_PIN, gpio.IN)
  36. gpio.setup(VOLUMEUP_PIN, gpio.IN)
  37. gpio.setup(VOLUMEDOWN_PIN, gpio.IN)
  38.  
  39.  
  40. # Host Einstellungen
  41. TEST_MPD_HOST     = "localhost"
  42. TEST_MPD_PORT     = "6600"
  43.  
  44. ### Beginn Radio
  45.  
  46. # mit MPD verbinden (hinter webradio.jpg)
  47. client = mpd.MPDClient()
  48. connected = False
  49. while connected == False:
  50.         connected = True
  51.         try:
  52.              client.connect("localhost","6600")
  53.         except SocketError as e:
  54.              connected = False
  55.         if connected == False:
  56.                 print "Couldn't connect. Retrying..."
  57.                 time.sleep(5)
  58. os.system('clear')            
  59. print("Connected!")
  60. sleep (0.2)
  61.  
  62. # Sprunghilfe einbauen
  63. def goto(linenum): # mit goto(x) kann zu line=x gesprungen werden
  64.     global line
  65.     line = linenum
  66.    
  67. # Sender laden
  68. os.system('mpc clear')
  69. os.system('mpc load sender')
  70.  
  71. def sender_laden_und_spielen():
  72. # alle Sender mal abspielen
  73.     os.system('mpc volume 0')
  74.     os.system('mpc play 1')
  75.     sleep (1)
  76.     os.system('mpc play 2')
  77.     sleep (1)
  78.     os.system('mpc play 3')
  79.     sleep (1)
  80.     os.system('mpc play 4')
  81.     sleep (1)
  82.     os.system('mpc play 5')
  83.     sleep (1)
  84.     os.system('mpc play 6')
  85.     sleep (1)
  86.     os.system('mpc play 7')
  87.     sleep (1)
  88.     os.system('mpc play 8')
  89.     sleep (1)
  90.     os.system('mpc play 9')
  91.     sleep (1)
  92.     os.system('mpc play 10')
  93.     sleep (1)
  94.     os.system('mpc play 11')
  95.     sleep (1)
  96.     os.system('mpc play 12')
  97.     sleep (1)
  98.     os.system('mpc play 13')
  99.     sleep (1)
  100.     os.system('mpc play 14')
  101.     sleep (1)
  102.     os.system('mpc play 15')
  103.     sleep (1)
  104.     os.system('mpc stop')
  105.  
  106. sender_laden_und_spielen()
  107.  
  108. os.system('mpc volume 100')
  109. os.system('mpc play 1')
  110. os.system('clear')
  111. os.system('mpc -f "[%name%]" current')
  112.  
  113. pause = 0
  114. line = 1
  115.  
  116. def print_aktuell():
  117.    
  118.     radiosender = os.system('mpc -f "[%name%]" current')
  119.    
  120.     if radiosender == "Bayern 3":
  121.         #os.system('sudo killall fbi')
  122.         #os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a bayern3.jpg')
  123.         os.system('clear')
  124.         print('Das ist der Bayern')
  125.     elif radiosender == '88.6 Radio Live Stream':
  126.         #os.system('sudo killall fbi')
  127.         #os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a 886.jpg')
  128.         os.system('clear')
  129.         print('Das ist der 88.6')
  130.     else:
  131.         os.system('clear')
  132.         os.system('mpc -f "[%name%]" current')
  133.         print('--> else')
  134.  
  135. try:
  136.     while True:
  137.        
  138.         if line == 1:
  139.             while line <= 39:
  140.                 if gpio.input(NEXT_PIN):
  141.                     os.system('mpc next')
  142.                     os.system('mpc play')
  143.                     print_aktuell()
  144.                     goto(50)
  145.                    
  146.                 if gpio.input(PREV_PIN):
  147.                     os.system('mpc prev')
  148.                     os.system('mpc play')
  149.                     print_aktuell()
  150.                     goto(50)
  151.                                
  152.                 if gpio.input(PAUSE_PIN):
  153.                     if pause == 0:
  154.                         os.system('mpc stop')
  155.                         pause = 1
  156.                         print('Pause')
  157.                     else:
  158.                         #os.system('clear')
  159.                         os.system('mpc play')
  160.                         print_aktuell()
  161.                         pause = 0
  162.                         #goto(40)
  163.                        
  164.                 if gpio.input(VOLUMEUP_PIN):
  165.                     os.system('mpc volume +5')
  166.                     os.system('clear')
  167.                     os.system('mpc volume')
  168.                     sleep(1)
  169.                     goto(50)
  170.                     print_aktuell()
  171.                    
  172.                 if gpio.input(VOLUMEDOWN_PIN):
  173.                     os.system('mpc volume -5')
  174.                     os.system('clear')
  175.                     os.system('mpc volume')
  176.                     sleep(1)
  177.                     goto(50)
  178.                     print_aktuell()
  179.                    
  180.                 sleep(0.2) 
  181.                 line = line + 1
  182.             goto(40)
  183.            
  184.         elif line == 40 and pause == 0:
  185.             print('Line 40')
  186.             sleep(3)
  187.             goto(50)
  188.            
  189.         elif line == 50:
  190.             print_aktuell()
  191.             goto(1)
  192.         goto(1)
  193.    
  194. except KeyboardInterrupt:
  195.     gpio.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement