evenements:obc2012:dikogeek
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
obc2012:dikogeek [2013/05/03 16:40] – [Interaction homme/machine] florianh | obc2012:dikogeek [2013/05/09 16:42] – [Code source] florianh | ||
---|---|---|---|
Ligne 107: | Ligne 107: | ||
#Import des librairies nécessaires | #Import des librairies nécessaires | ||
+ | import select | ||
+ | import sys, tty, termios | ||
import os | import os | ||
+ | import pygame | ||
import subprocess, signal | import subprocess, signal | ||
+ | from subprocess import Popen, PIPE | ||
+ | from pygame.locals import * | ||
import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||
GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||
- | from subprocess import Popen, PIPE | + | |
# | # | ||
GPIO.setup(23, | GPIO.setup(23, | ||
GPIO.setup(17, | GPIO.setup(17, | ||
- | #Création d'une fonction de rappel | + | pygame.init() |
- | def my_callback(channel): | + | pygame.display.init() |
- | print (" | + | def accueil(): |
+ | ecran = pygame.display.set_mode((0, | ||
+ | image = pygame.image.load("./ | ||
+ | ecran.blit(image, | ||
+ | pygame.display.flip() # | ||
+ | |||
+ | def getch(): | ||
+ | fd = sys.stdin.fileno() | ||
+ | old_settings = termios.tcgetattr(fd) | ||
+ | try: | ||
+ | tty.setraw(sys.stdin.fileno()) | ||
+ | ch = sys.stdin.read(1) | ||
+ | finally: | ||
+ | termios.tcsetattr(fd, | ||
+ | return ch | ||
+ | |||
+ | # | ||
+ | |||
+ | #Fonction appelé lors d'un appuie bouton | ||
+ | def fct_movie(channel): | ||
+ | print ('Lancement clip', channel) | ||
#Lancement d'un sous process pour récuperer la liste des processes en cours | #Lancement d'un sous process pour récuperer la liste des processes en cours | ||
p = subprocess.Popen([' | p = subprocess.Popen([' | ||
Ligne 127: | Ligne 151: | ||
#Listing des process | #Listing des process | ||
for line in out.splitlines(): | for line in out.splitlines(): | ||
- | #On recherche si le lecteur video est en route | + | |
- | if ' | + | if ' |
pid = int(line.split(None, | pid = int(line.split(None, | ||
- | #On Kill le process | + | |
os.kill(pid, | os.kill(pid, | ||
#Lencement d'un sous process pour lancer le clip | #Lencement d'un sous process pour lancer le clip | ||
- | p = subprocess.Popen([' | + | p = subprocess.Popen([' |
- | ocess.PIPE, | + | .mp4' |
#Vérifie si le process se termine naturellement | #Vérifie si le process se termine naturellement | ||
retcode = p.wait() | retcode = p.wait() | ||
- | #Si le process c'est terminé naturellement, | ||
if retcode is not None: | if retcode is not None: | ||
- | print " | + | accueil() |
- | os.system(" | + | |
- | + | ||
- | def my_callback2(channel): | + | |
- | print (" | + | |
- | p = subprocess.Popen([' | + | |
- | out, err = p.communicate() | + | |
- | for line in out.splitlines(): | + | # |
- | if ' | + | GPIO.add_event_detect(17, GPIO.FALLING, callback=fct_movie, |
- | | + | GPIO.add_event_detect(23, GPIO.FALLING, callback=fct_movie, bouncetime=600) |
- | os.kill(pid, signal.SIGKILL) | + | |
- | p = subprocess.Popen([' | + | |
- | rocess.PIPE,stderr=subprocess.PIPE, | + | |
- | retcode = p.wait() | + | |
- | if retcode is not None: | + | done = False |
- | print "Lancement navigateur" | + | while not done: |
- | | + | |
- | + | if getch() == " | |
- | + | | |
- | # | + | fct_movie(17) |
- | GPIO.add_event_detect(17, GPIO.FALLING, | + | if getch() |
- | GPIO.add_event_detect(23, GPIO.FALLING, | + | |
+ | fct_movie(23) | ||
- | #Permet de bloquer le programme pour éviter qu'il se termine tout seul | + | # for event in pygame.event.get(): |
- | raw_input("> ") | + | # if event.type == KEYDOWN: |
+ | # keys = pygame.key.get_pressed() | ||
+ | # | ||
+ | # if (keys[K_a]): | ||
+ | # print("touche a") | ||
+ | # fct_movie(17) | ||
+ | # if (keys[K_b]): | ||
+ | # print(" | ||
+ | # fct_movie(23) | ||
+ | # if (event.key == K_ESCAPE): | ||
+ | # done = True | ||
+ | |||
+ | pygame.display.quit() | ||
+ | pygame.quit() | ||
</ | </ | ||
evenements/obc2012/dikogeek.txt · Dernière modification : 2024/04/26 14:48 de 127.0.0.1