Repository navigation
Expand file tree
/
Copy pathradio_screen.py
More file actions
189 lines (162 loc) · 6.04 KB
/
Copy pathradio_screen.py
File metadata and controls
189 lines (162 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import RPi.GPIO as GPIO
import time
import sys
import time
import atexit
import traceback
import Adafruit_GPIO as GPIO
import os
import atexit
from time import sleep
import Image
import Adafruit_GPIO.SPI as SPI
import pygame
from pygame.locals import*
stderr = sys.stderr.write;
DC = 22
RST = 23
SPI_PORT = 0
SPI_DEVICE = 0
gpio = GPIO.get_platform_gpio()
gpio.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
gpio.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for Bluetooth
gpio.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for Aux
gpio.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Switch for RPi
state = 0
btaux = 0
white = (255, 255, 255)
w = 1024
h = 768
screen = pygame.display.set_mode((1024,768),pygame.FULLSCREEN)
screen.fill((white))
# Initialize display.
pygame.init()
# Execute system command sub-routine
def exec_command(cmd):
result = ""
p = os.popen(cmd)
for line in p.readline().split('\n'):
result = result + line
return result
def image():
station = exec_command("mpc current").split(" ")
if station[0] == "KSUA" and btaux == 0:
#print station[0]
image = Image.open('/home/pi/radio/images/ksua.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
screen.fill((white))
screen.blit(image,(0,0))
pygame.display.flip()
elif station[0] == "Radio":
#print station[0]
image = Image.open('/home/pi/radio/images/rfb.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "KEXP.ORG":
#print station[0]
image = Image.open('/home/pi/radio/images/kexp.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "KCRW":
#print station[0]
image = Image.open('/home/pi/radio/images/kcrw.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "WNYC":
#print station[0]
image = Image.open('/home/pi/radio/images/wnyc.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "KUAC":
#print station[0]
image = Image.open('/home/pi/radio/images/kuac.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "WFMU":
#print station[0]
image = Image.open('/home/pi/radio/images/wfmu.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "KRUA":
#print station[0]
image = Image.open('/home/pi/radio/images/krua.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "KUTX":
#print station[0]
image = Image.open('/home/pi/radio/images/kutx.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "WICB":
#print station[0]
image = Image.open('/home/pi/radio/images/wicb.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
elif station[0] == "WMUA":
#print station[0]
image = Image.open('/home/pi/radio/images/wmua.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
def bt():
exec_command("mpc stop")
image = Image.open('/home/pi/radio/images/bluetooth.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
def aux():
exec_command("mpc stop")
image = Image.open('/home/pi/radio/images/aux.jpg') # Load an image.
image = image.rotate(90).resize((240, 320)) # Resize the image and rotate it so it's 240x320 pixels.
disp.display(image) # Draw the image
### Main routine ###
if __name__ == "__main__":
exec_command("service mpd start")
exec_command("mpc clear")
exec_command("mpc load feblist") #Put name of playlist here, but leave off the .m3u part
exec_command("mpc play")
exec_command("mpc volume 100")
disp.clear()
print "Use Ctl-C to exit"
while True:
try:
station = exec_command("mpc current").split(" ")
print station[0]
image()
input_state = gpio.input(26)
if input_state == False:
exec_command("mpc next")
time.sleep(0.2)
input_state2 = gpio.input(19)
if input_state2 == False:
exec_command("mpc prev")
time.sleep(0.2)
#input_state3 = gpio.input(13)
#if input_state3 == False and state == 0:
# exec_command("mpc pause")
# state = 1
# print "paused"
# time.sleep(0.5)
#input_state4 = gpio.input(13)
#if input_state4 == False and state == 1:
# exec_command("mpc play")
# state = 0
# print "play"
# time.sleep(0.5)
input_state5 = gpio.input(21)
if input_state5 == False:
bt()
time.sleep(0.5)
input_state6 = gpio.input(20)
if input_state6 == False:
aux()
time.sleep(0.5)
input_state6 = gpio.input(16)
if input_state6 == False:
exec_command("mpc play")
time.sleep(0.5)
except KeyboardInterrupt:
exec_command("mpc stop")
disp.clear()
print "\nExit"
sys.exit(0)