Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import subprocess
- import datetime
- import os
- import time
- import signal
- import threading
- # set PIN 2 (mode BCM) sebagai input
- GPIO.setmode(GPIO.BCM)
- CHANNEL = 2
- GPIO.setup(CHANNEL, GPIO.IN)
- is_playing = False
- # Mengeksekusi perintah dalam interval waktu tertentu. Jika interval sudah dilewati, eksekusi perintah tsb dimatikan
- def timeout_cmd(command, timeout):
- global is_playing
- cmd = command.split(" ")
- start = datetime.datetime.now()
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- is_playing = True
- while proc.poll() is None:
- time.sleep(0.1)
- now = datetime.datetime.now()
- if (now-start).seconds > timeout:
- os.kill(prod.pid, signal.SIGKILL)
- os.waitpid(-1, os.WNOHANG)
- is_playing = False
- return None
- while 1:
- if GPIO.input(CHANNEL):
- if not is_playing:
- timeout_cmd("omxplayer /home/pi/video/blablabla.mp4", 15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement