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édente | ||
| obc2012:dikogeek [2013/05/08 14:02] – [Code source] florianh | evenements:obc2012:dikogeek [2024/04/26 14:48] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 107: | Ligne 107: | ||
| #Import des librairies nécessaires | #Import des librairies nécessaires | ||
| - | import sys | + | import select, time |
| + | 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) |
| + | from evdev import InputDevice, | ||
| + | dev = InputDevice('/ | ||
| + | fpid = os.fork() | ||
| + | if fpid!=0: | ||
| + | # | ||
| + | sys.exit(0) | ||
| + | |||
| # | # | ||
| - | GPIO.setup(23, | + | #GPIO.setup(23, |
| - | GPIO.setup(17, | + | #GPIO.setup(17, |
| pygame.init() | pygame.init() | ||
| - | pygame.mixer.quit() | ||
| pygame.display.init() | pygame.display.init() | ||
| - | |||
| - | played = 0 | ||
| def accueil(): | def accueil(): | ||
| ecran = pygame.display.set_mode((0, | ecran = pygame.display.set_mode((0, | ||
| - | image = pygame.image.load(" | + | image = pygame.image.load(" |
| ecran.blit(image, | ecran.blit(image, | ||
| pygame.display.flip() # | pygame.display.flip() # | ||
| - | |||
| - | accueil() | ||
| #Fonction appelé lors d'un appuie bouton | #Fonction appelé lors d'un appuie bouton | ||
| def fct_movie(channel): | def fct_movie(channel): | ||
| - | | + | |
| - | global played | + | |
| - | + | | |
| - | if played == 1: | + | pygame.display.flip() |
| - | global movie | + | |
| - | movie.stop() | + | p = subprocess.Popen([' |
| - | pygame.time.delay(2000) | + | #Vérifie si le process se termine naturellement |
| - | + | while (p.poll() is None): | |
| - | played = 1 | + | if dev.read_one() is not None: |
| - | fchannel = " | + | os.killpg(p.pid, signal.SIGKILL) |
| - | movie = pygame.movie.Movie(fchannel) | + | break |
| - | screen | + | if p.poll() is not None: |
| - | | + | |
| - | | + | |
| - | pygame.time.set_timer(USEREVENT, 1000) | + | |
| - | pygame.display.flip() | + | |
| - | | + | |
| - | while movie.get_busy(): | + | |
| - | evt = pygame.event.wait() | + | |
| - | if evt.type == QUIT: | + | |
| - | | + | |
| - | if evt.type == KEYDOWN and evt.unicode == QUIT_CHAR: | + | |
| - | break | + | |
| - | if movie.get_busy() == 0: | + | |
| - | movie.stop() | + | |
| accueil() | accueil() | ||
| - | pygame.time.set_timer(USEREVENT, | ||
| # | # | ||
| - | GPIO.add_event_detect(17, | + | #GPIO.add_event_detect(17, |
| - | GPIO.add_event_detect(23, | + | #GPIO.add_event_detect(23, |
| + | accueil() | ||
| + | for event in dev.read_loop(): | ||
| + | if (event.code == ecodes.KEY_A and event.value == 0): | ||
| + | fct_movie(' | ||
| + | if (event.code == ecodes.KEY_B and event.value == 0): | ||
| + | fct_movie(2) | ||
| + | if (event.code == ecodes.KEY_C and event.value == 0): | ||
| + | fct_movie(3) | ||
| + | if (event.code == ecodes.KEY_D and event.value == 0): | ||
| + | fct_movie(' | ||
| - | #Permet de bloquer le programme pour éviter qu'il se termine tout seul | + | pygame.display.quit() |
| - | raw_input("> ") | + | pygame.quit() |
| </ | </ | ||
| - | |||
| - | |||
evenements/obc2012/dikogeek.1368014539.txt.gz · Dernière modification : 2024/04/26 14:48 (modification externe)
