Hallo zusammen, ich mag euch mal vorstellen was ich bisher zusammel gekramt habe...
( JA, ich stell das Netz auf den Kopf und schau ob mir irgendwelche Codeschnipsel weiterhelfen könnten...)
Grundlage für mein Projekt war der Python Quellcode von Adafruit,
=>R-PI + TFT - Webradio
Also:
Bisher hab ich es geschaft meinem PI zu erklären er soll über das WLAN online zu gehen.
auf Tastendruck (bzw touchscreen) die folgenden Funktionen anzusteuern:
( prev / stop / play / next / Vol- / Vol+ )
Er gibt mir auch Rückmeldung : Online/Ofline , Play/stop , Sendername & Titel.....
Und auch die Uhrzeit mittig im Display in XXL
- aber da kommt schon das erste Problem:
er aktualisiert das Display immer nur dann wenn er ein "event" registriert also einen druck auf dem touchscreen...
Mein Ziel ist es mein alten Radiowecker in Rente zu schicken ( + ein Paar extras)
Soweit hab ich es schon mal geschafft:
Derzeit stockt es an der aktualisierung des Displays
=> "ne aktuelle Uhrzeit gibt´s nur, wenn du mich drückst "
Ich hab halt keinen plan wo ich im programm hinterlegen muss
"aktualisiere die zeit alle Sekunde"
Alle Minute könnte ich auch mit leben, dann schmeiss ich die Sekunden halt aus der Anzeige raus.
Am Ende möchte ich die Weckzeit definieren können:
und das non-plus-ultra wäre das das Hintergrundbild
je nach Wettervorhersage aufgerufen wird:
=> Wettervorhersage gut => Sonne im Hintergrund
=> Wettervorhersage schlecht => Wolke im Hintergrund
Die Tage bin ich über den Blog gestolpert :
http://blog.jacobean.net/?p=1016
Er hat mehrere Wettervorhersage quellen zur auswahl, wertet die Daten aus und bereitet sie für das Display aus.
ich brauch aus dem ganzen projekt ja nur :
=> Temperatur (entweder die aktuelle oder halt 3: Morgens/ Mittags/ Abends)
=>und die Tendenz (wird schön / bleibt wolkig / schüttet aus Kübeln...)
Zum Stand der Dinge:
import sys, pygame
from pygame.locals import *
import time, datetime
import subprocess
import os
import glob
os.environ["SDL_FBDEV"] = "/dev/fb1" #define output to R-PI-TFT (adafruit 2,8" 320x240 )
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen" #define input
os.environ["SDL_MOUSEDRV"] = "TSLIB"#define input
pygame.init()
#define function that checks for mouse location
def on_click():
click_pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
#check to see if exit has been pressed
if 270 <= click_pos[0] <= 319 and 10 <= click_pos[1] <=50:
print "You pressed exit"
button(0)
#now check to see if previous was pressed
if 1 <= click_pos[0] <= 50 and 185 <= click_pos[1] <=239:
print "You pressed button PREV"
button(1)
#now check to see if PLAY was pressed <5 >
if 55 <= click_pos[0] <= 105 and 185 <= click_pos[1] <=239:
print "You pressed button STOP"
button(2)
#now check to see if STOP was pressed <5 >
if 110 <= click_pos[0] <= 160 and 185 <= click_pos[1] <=239:
print "You pressed button PLAY"
button(3)
#now check to see if NEXT was pressed
if 165 <= click_pos[0] <= 215 and 185 <= click_pos[1] <=239:
print "You pressed NEXT"
button(4)
#now check to see if VOL DOWN was pressed
if 220 <= click_pos[0] <= 270 and 185 <= click_pos[1] <=239:
print "You pressed volume DOWN"
button(5)
#now check to see if VOL UP was pressed
if 275 <= click_pos[0] <= 319 and 185 <= click_pos[1] <=239:
print "You pressed volume UP"
button(6)
#now check to see if TIME was pressed
if 1 <= click_pos[0] <= 319 and 50 <= click_pos[1] <=185:
print "You pressed TIME"
#button(7)
#define action on pressing buttons
def button(number):
print "You pressed button ",number
if number == 0: #specific script when exiting
screen.fill(black)
font=pygame.font.Font(None,60)
label=font.render(" Bye `,..,` Bye ", 1, (red))# Bye Bye
screen.blit(label,(20,90))
pygame.display.flip()
time.sleep(5)
subprocess.call("mpc stop ", shell=True) # end of playback + this prog.
sys.exit()
if number == 1:
subprocess.call("mpc prev ", shell=True)
refresh_menu_screen()
if number == 2:
subprocess.call("mpc stop ", shell=True)
refresh_menu_screen()
if number == 3:
subprocess.call("mpc play ", shell=True)
refresh_menu_screen()
if number == 4:
subprocess.call("mpc next ", shell=True)
refresh_menu_screen()
if number == 5:
subprocess.call("mpc volume -5 ", shell=True)
refresh_menu_screen()
if number == 6:
subprocess.call("mpc volume +5 ", shell=True)
refresh_menu_screen()
if number == 7: #big center where the time is displayed
#there should come a submeue for alarm settings, waiting for ideas...
refresh_menu_screen()
def refresh_menu_screen():
#set up the pictures for the menu
screen.fill(black) #change the colours if needed
font=pygame.font.Font(None,24)
title_font=pygame.font.Font(None,24)
station_font=pygame.font.Font(None,24)
drache=pygame.image.load("drache.tiff")
previous=pygame.image.load("previous.tiff")
stop=pygame.image.load("stop.tiff")
play=pygame.image.load("play.tiff")
next=pygame.image.load("next.tiff")
vol_down=pygame.image.load("volume_down.tiff")
vol_up=pygame.image.load("volume_up.tiff")
exit=pygame.image.load("exit.tiff")
# draw the main elements on the screen
screen.blit(drache,(1,1)) #Background
screen.blit(previous,(0,190)) # Posi Previous Button
screen.blit(stop,(55,190)) # Posi Stop Button
screen.blit(play,(110,190)) # Posi PLAY Button
screen.blit(next,(165,190)) # Posi NEXT Button
screen.blit(vol_down,(220,190)) # Posi VOL - Button
screen.blit(vol_up,(270,190)) # Posi Vol + Button
screen.blit(exit,(287,2)) # Posi EXIT Button
##### display the station name and split it into 2 parts :
station = subprocess.check_output("mpc current", shell=True )
lines=station.split(":")
length = len(lines)
if length==1:
line1 = lines[0]
line1 = line1[:-1]
line2 = "No additional info: "
else:
line1 = lines[0]
line2 = lines[1]
line2 = line2[:42]
line2 = line2[:-1]
#trap no station data
if line1 =="":
line2 = "Press PLAY or REFRESH"
station_status = "stopped |"
status_font = red
else:
station_status = "playing |"
status_font = gray
station_name=station_font.render(line1, 1, (gray))
additional_data=station_font.render(line2, 1, (gray))
station_label=title_font.render(station_status, 1, (status_font))
screen.blit(station_label,(70,5)) # POSI PLAY STOP status
screen.blit(station_name,(140,5)) # posi station Name
screen.blit(additional_data,(5,35)) # Posi station aditonal info / Songtitel
### ### add TIME
time = subprocess.check_output("date +%T ", shell=True ) # Check system time
time_font=pygame.font.Font(None,120)
time_tag=time_font.render(time, 1, (white))
screen.blit(time_tag,(2,70)) # Position TIME
### ### TIME finish
###### check to see if the Radio is connected to the internet
IP = subprocess.check_output("hostname -I", shell=True )
IP=IP[:3]
if IP =="192":
network_status = "online |"
status_font = gray
else:
network_status = "offline |"
status_font = red
network_status_label = font.render(network_status, 1, (status_font))
screen.blit(network_status_label, (10,5)) # POSI on/Ofline
pygame.display.flip()
def main():
while 1:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
print "screen pressed" #for debugging purposes
pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
print pos #for checking
pygame.draw.circle(screen, white, pos, 2, 0)
#for debugging purposes - adds a small dot where the screen is pressed
# to see them => kick the background.tiff
on_click()
#ensure there is always a safe way to end the program if the touch screen fails
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
time.sleep(0.5)
pygame.display.update()
#################### EVERTHING HAS NOW BEEN DEFINED ###########################
#set size of the screen
size = width, height = 320, 240
screen = pygame.display.set_mode(size)
#define colours
blue = 25, 25, 112
cream = 254, 255, 25
black = 0, 0, 0
white = 255, 255, 255
yellow = 255, 255, 0
red = 255, 0, 0
green = 0, 255, 0
brown = 51, 0, 0
gray = 51, 51, 51
refresh_menu_screen() #refresh the menu interface
main() #check for key presses and start emergency exit
station_name()
Alles anzeigen
Frage: wo hab ich den Knoten im Kopf, wo muss ich ihm sagen "aktualisier mal" ?
Vielleicht hat ja wer bock mit an der Aufgabe zu kniffeln..
( unten der Code und die Bilder)
Thx REMY
P.S. in der Dropbox hab ich auch noch mal den Code und die Bilder für die Buttons hinterlegt.
REMY´S-Dropbox