Advertisement
Hanner72

radio.py

Feb 23rd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. # +---------------------------------------------------+
  2. # | Webradio                                          |
  3. # | Autor: Johann Danner                              |
  4. # | Datum: 03/2016                                    |
  5. # | Version: V1.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. TEST_MPD_HOST     = "localhost"
  23. TEST_MPD_PORT     = "6600"
  24. #TEST_MPD_PASSWORD = "<Password>"
  25. POWEROFF_TIME     = 10
  26. POWER_PIN         = 16
  27. SWITCH_PIN        = 22
  28. PAUSE_PIN         = 23
  29.  
  30. # set up GPIO input channel
  31. gpio.setup(SWITCH_PIN, gpio.IN, pull_up_down=gpio.PUD_DOWN)
  32. gpio.setup(PAUSE_PIN, gpio.IN, pull_up_down=gpio.PUD_DOWN)
  33.  
  34. # Connect with MPD
  35. client = mpd.MPDClient()
  36. connected = False
  37. while connected == False:
  38.         connected = True
  39.         try:
  40.              client.connect("localhost","6600")
  41.         except SocketError as e:
  42.              connected = False
  43.         if connected == False:
  44.                 print "Couldn't connect. Retrying..."
  45.                 time.sleep(5)
  46. os.system('clear')             
  47. print("Connected!")
  48. sleep (2)
  49.  
  50. # Beginn Radio
  51. os.system('mpc load sender')
  52. os.system('sudo killall fbi')
  53. os.system('clear')
  54. print 'Hallo, bei meinem Webradio.'
  55. sleep(2)
  56. os.system('mpc play')
  57. os.system('clear')
  58. os.system('mpc -f "[%name%]" current')
  59. os.system('mpc -f "[%title%]" current')
  60.  
  61. counter = 0
  62. pause = 0
  63.  
  64.  
  65. try:
  66.     while(True):
  67.    
  68.         if gpio.input(SWITCH_PIN):
  69.             pause = 0
  70.             os.system('mpc next')
  71.             os.system('mpc play')
  72.             os.system('clear')
  73.             counter = 30
  74.         if gpio.input(PAUSE_PIN):
  75.             if pause == 0:
  76.                 os.system('mpc stop')
  77.                 pause = 1
  78.                 os.system('clear')
  79.                 print 'Pause'
  80.             else:
  81.                 os.system('mpc play')
  82.                 os.system('clear')
  83.                 os.system('mpc current')
  84.                 pause = 0
  85.  
  86.         sleep (0.1)
  87.         if counter == 40 and pause == 0:
  88.             radiosender = os.system('mpc -f "[%name%]" current')
  89.             #radiosender = client.currentsong()['name']
  90.             os.system('sudo killall fbi')
  91.             os.system('clear')
  92.             #os.system('mpc current')
  93.             if radiosender == "Bayern 3":
  94.                 os.system('clear')
  95.                 #os.system('mpc -f "[%name%]" current'
  96.                 #os.system('mpc -f "[%title%]" current')
  97.                 os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a bayern3.png')
  98.                 #sleep(20)
  99.             if radiosender == "886":
  100.                 os.system('clear')
  101.                 #os.system('mpc -f "[%name%]" current'
  102.                 #os.system('mpc -f "[%title%]" current')
  103.                 os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a 886.jpg')
  104.                 #sleep(20)
  105.             else:
  106.                 #print 'NEIN'
  107.                 os.system('sudo killall fbi')
  108.                 os.system('clear')
  109.                 os.system('mpc -f "[%name%]" current')
  110.                 os.system('mpc -f "[%title%]" current')
  111.             counter = 0
  112.         counter = counter + 1
  113.  
  114. except KeyboardInterrupt:
  115.     gpio.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement