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/08 14:02] – [Code source] florianh | obc2012:dikogeek [2013/05/15 01:00] – [Code source] florianh | ||
---|---|---|---|
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: | ||
+ | # Running as daemon now. PID is fpid | ||
+ | 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(): | ||
Ligne 129: | Ligne 136: | ||
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) | + | process.PIPE, |
- | + | #Vérifie si le process se termine naturellement | |
- | played = 1 | + | while (p.poll() is None): |
- | fchannel = " | + | if dev.read_one() is not None: |
- | movie = pygame.movie.Movie(fchannel) | + | os.killpg(p.pid, signal.SIGKILL) |
- | screen | + | break |
- | | + | 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_Q and event.value == 0): | ||
+ | fct_movie(17) | ||
+ | if (event.code == ecodes.KEY_B and event.value == 0): | ||
+ | fct_movie(23) | ||
+ | |||
+ | pygame.display.quit() | ||
+ | pygame.quit() | ||
- | #Permet de bloquer le programme pour éviter qu'il se termine tout seul | ||
- | raw_input("> | ||
</ | </ | ||
- | |||
- | |||
evenements/obc2012/dikogeek.txt · Dernière modification : 2024/04/26 14:48 de 127.0.0.1