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/09 16:42] – [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 select | + | import select, time |
| import sys, tty, termios | import sys, tty, termios | ||
| import os | import os | ||
| Ligne 114: | Ligne 114: | ||
| from subprocess import Popen, PIPE | 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() | ||
| Ligne 126: | Ligne 133: | ||
| 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() # | ||
| - | |||
| - | 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): | ||
| - | | + | |
| + | image = pygame.image.load("/ | ||
| + | ecran.blit(image, | ||
| + | pygame.display.flip() # | ||
| #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([' |
| - | out, err = p.communicate() | + | |
| - | + | ||
| - | #Listing des process | + | |
| - | for line in out.splitlines(): | + | |
| - | #On recherche si le lecteur video est en route | + | |
| - | if ' | + | |
| - | pid = int(line.split(None, | + | |
| - | #On Kill le process | + | |
| - | os.kill(pid, | + | |
| - | #Lencement d'un sous process pour lancer le clip | + | |
| - | p = subprocess.Popen([' | + | |
| - | .mp4' | + | |
| #Vérifie si le process se termine naturellement | #Vérifie si le process se termine naturellement | ||
| - | | + | |
| - | + | if dev.read_one() is not None: | |
| - | if retcode | + | os.killpg(p.pid, |
| - | accueil() | + | break |
| + | if p.poll() | ||
| + | accueil() | ||
| # | # | ||
| - | GPIO.add_event_detect(17, | + | #GPIO.add_event_detect(17, |
| - | GPIO.add_event_detect(23, | + | #GPIO.add_event_detect(23, |
| - | + | accueil() | |
| - | done = False | + | for event in dev.read_loop(): |
| - | while not done: | + | if (event.code |
| - | print (" | + | fct_movie(' |
| - | if getch() == " | + | if (event.code == ecodes.KEY_B and event.value == 0): |
| - | print(" | + | fct_movie(2) |
| - | | + | if (event.code == ecodes.KEY_C and event.value == 0): |
| - | if getch() == " | + | fct_movie(3) |
| - | print(" | + | if (event.code == ecodes.KEY_D and event.value == 0): |
| - | fct_movie(23) | + | fct_movie(' |
| - | + | ||
| - | # | + | |
| - | # | + | |
| - | # keys = pygame.key.get_pressed() | + | |
| - | # | + | |
| - | # if (keys[K_a]): | + | |
| - | # print(" | + | |
| - | # fct_movie(17) | + | |
| - | # if (keys[K_b]): | + | |
| - | # print(" | + | |
| - | # fct_movie(23) | + | |
| - | # if (event.key == K_ESCAPE): | + | |
| - | # done = True | + | |
| - | + | ||
| pygame.display.quit() | pygame.display.quit() | ||
| pygame.quit() | pygame.quit() | ||
| </ | </ | ||
| - | |||
| - | |||
evenements/obc2012/dikogeek.1368110543.txt.gz · Dernière modification : 2024/04/26 14:48 (modification externe)
