Ich bin gerade dabei alle meine Bauteile zu verbauen.
Dazu habe ich mir ein kleines py Programm gebaut.
kann mir einer sagen warum im Thread mailholen() das displaytext nicht angezeit wird?
Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import os
import sys
import time
import pygame
import subprocess
import threading
import feedparser
time_stamp_prev=0
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEODRIVER']="fbcon"
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
up = 18
down = 23
left = 17
rechts = 22
textsize = 20
GPIO.setup(up, GPIO.IN)
GPIO.setup(down, GPIO.IN)
GPIO.setup(left, GPIO.IN)
GPIO.setup(rechts, GPIO.IN)
def mailholen():
global mailtext
global newmails
USERNAME = "username"
PASSWORD = "pass"
NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, yours might
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds
while True:
newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])
str_mails = str(newmails)
mailtext = "You have", newmails, "new emails!"
displaytext("Hallo",10,100,80,(0,0,0),True)
time.sleep(MAIL_CHECK_FREQ)
def anzeige():
global screen
startvolmume = 65
str_x = str(startvolmume)
os.system("mpc volume " + str_x)
altvolume = startvolmume
text1 = subprocess.Popen(['mpc', 'volume'], stdout=subprocess.PIPE).stdout.read().strip().decode('utf-8')
text2 = subprocess.Popen(['mpc', 'current'], stdout=subprocess.PIPE).stdout.read().strip().decode('utf-8')
pygame.init()
pygame.mouse.set_visible(0)
size = width,height = 128,160
screen = pygame.display.set_mode(size)
while True:
if GPIO.input(up):
newvolume = altvolume +1
str_a = str(newvolume)
os.system("mpc volume " + str_a)
altvolume = newvolume
text1 = subprocess.Popen(['mpc', 'volume'], stdout=subprocess.PIPE).stdout.read().strip().decode('utf-8')
if GPIO.input(down):
newvolume = altvolume -1
str_a = str(newvolume)
os.system("mpc volume " + str_a)
altvolume = newvolume
text1 = subprocess.Popen(['mpc', 'volume'], stdout=subprocess.PIPE).stdout.read().strip().decode('utf-8')
if GPIO.input(left):
os.system("mpc play")
if GPIO.input(rechts):
os.system("mpc stop")
displaytext(time.strftime("%d.%m.%Y",time.localtime()),textsize,30,5,(0,0,0),True)
displaytext(time.strftime("%H:%M:%S",time.localtime()),textsize,22,20,(0,0,0),False)
displaytext(text2 ,14,50,35,(0,0,128),False)
displaytext(text1 ,textsize,50,50,(0,0,0),False)
pygame.display.flip()
time.sleep(1)
def displaytext(text,size,textx,texty,color,clearscreen):
if clearscreen:
screen.fill((255,255,255))
font = pygame.font.Font(None,size)
text = font.render(text,0,color)
rotated = pygame.transform.rotate(text,0)
textpos = rotated.get_rect()
textpos.centery = texty
textpos.centerx = textx
screen.blit(rotated,textpos)
def main():
th1=threading.Thread(target=mailholen)
th2=threading.Thread(target=anzeige)
th1.start()
th2.start()
if __name__ == '__main__':
main()
Alles anzeigen