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édente | Prochaine révisionLes deux révisions suivantes | ||
obc2012:dikogeek [2013/05/08 14:02] – [Code source] 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 sys | + | import select |
+ | import sys, tty, termios | ||
import os | import os | ||
import pygame | import pygame | ||
+ | import subprocess, signal | ||
+ | from subprocess import Popen, PIPE | ||
from pygame.locals import * | from pygame.locals import * | ||
import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||
GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||
+ | |||
# | # | ||
GPIO.setup(23, | GPIO.setup(23, | ||
Ligne 119: | Ligne 122: | ||
pygame.init() | pygame.init() | ||
- | pygame.mixer.quit() | ||
pygame.display.init() | pygame.display.init() | ||
- | |||
- | played = 0 | ||
def accueil(): | def accueil(): | ||
Ligne 130: | Ligne 130: | ||
pygame.display.flip() # | pygame.display.flip() # | ||
- | accueil() | + | 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 | ||
+ | |||
+ | #accueil() | ||
#Fonction appelé lors d'un appuie bouton | #Fonction appelé lors d'un appuie bouton | ||
def fct_movie(channel): | def fct_movie(channel): | ||
print (' | print (' | ||
- | | + | |
+ | p = subprocess.Popen([' | ||
+ | out, err = p.communicate() | ||
- | | + | |
- | global movie | + | for line in out.splitlines(): |
- | movie.stop() | + | |
- | | + | if ' |
- | + | | |
- | | + | #On Kill le process |
- | fchannel = " | + | os.kill(pid, signal.SIGKILL) |
- | movie = pygame.movie.Movie(fchannel) | + | |
- | | + | |
- | | + | .mp4' |
- | | + | |
- | | + | |
- | pygame.display.flip() | + | |
- | | + | if retcode is not None: |
- | | + | accueil() |
- | evt = pygame.event.wait() | + | |
- | if evt.type == QUIT: | + | |
- | break | + | |
- | if evt.type == KEYDOWN and evt.unicode == QUIT_CHAR: | + | |
- | break | + | |
- | if movie.get_busy() == 0: | + | |
- | | + | |
- | accueil() | + | |
- | pygame.time.set_timer(USEREVENT, | + | |
# | # | ||
Ligne 166: | Ligne 169: | ||
GPIO.add_event_detect(23, | GPIO.add_event_detect(23, | ||
- | #Permet de bloquer le programme pour éviter qu'il se termine tout seul | + | done = False |
- | raw_input("> ") | + | while not done: |
+ | print (" | ||
+ | if getch() == " | ||
+ | | ||
+ | | ||
+ | if getch() == " | ||
+ | | ||
+ | | ||
+ | |||
+ | # for event in pygame.event.get(): | ||
+ | # 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