#!/usr/bin/env python import subprocess import time import itertools import glob import sensor PLAYER = "/home/pi/show/omxplayer-simple" landscapes = glob.glob("/home/pi/videos/L*") persons = glob.glob("/home/pi/videos/P*") videofiles = zip(landscapes, persons) oldprocess = None print sensor.state() for landscapefile, personfile in itertools.cycle(videofiles): process = subprocess.Popen([PLAYER, landscapefile], stdin=subprocess.PIPE) while process.poll() == None: time.sleep(0.1) if sensor.state(): personprocess = subprocess.Popen([PLAYER, personfile], stdin=subprocess.PIPE) time.sleep(2.7) if oldprocess and not oldprocess.poll(): oldprocess.terminate() oldprocess = process
formatter = logging.Formatter('%(asctime)s %(name)s: %(levelname)s %(message)s', '%b %e %H:%M:%S') handler.setFormatter(formatter) logger.addHandler(handler) return logger # configure logging logger = configure_logging() try: while True: time.sleep(0.1) # re-read the distance config (config.ini) to make tuning easier sensor.read_config() event = None new_sensor_state = sensor.state() if last_sensor_state != new_sensor_state: if new_sensor_state == True: event = EVENT_INCOMING else: event = EVENT_OUTGOING last_sensor_state = new_sensor_state new_player_state = gapless_player.is_stopped() if last_player_state != new_player_state: logger.info("player_state changed: %s", new_player_state) if new_player_state == False: pass else: logger.info("player_state finished: %s", new_player_state) event = EVENT_FINISHED
handler.setFormatter(formatter) logger.addHandler(handler) return logger # configure logging logger = configure_logging() try: while True: time.sleep(0.1) # re-read the distance config (config.ini) to make tuning easier sensor.read_config() event = None new_sensor_state = sensor.state() if last_sensor_state != new_sensor_state: if new_sensor_state == True: event = EVENT_INCOMING else: event = EVENT_OUTGOING last_sensor_state = new_sensor_state new_player_state = gapless_player.is_stopped() if last_player_state != new_player_state: logger.info("player_state changed: %s", new_player_state) if new_player_state == False: pass else: logger.info("player_state finished: %s", new_player_state) event = EVENT_FINISHED