Quellcode durchsuchen

ad gpio functioality

master
Andreas Demmelbauer vor 5 Jahren
Ursprung
Commit
e6a719ff95
1 geänderte Dateien mit 41 neuen und 24 gelöschten Zeilen
  1. +41
    -24
      Adafruit_Video_Looper/video_looper.py

+ 41
- 24
Adafruit_Video_Looper/video_looper.py Datei anzeigen

@@ -12,6 +12,9 @@ import time

import pygame

import wiringpi


from .model import Playlist


@@ -56,6 +59,9 @@ class VideoLooper:
self._osd = self._config.getboolean('video_looper', 'osd')
self._is_random = self._config.getboolean('video_looper', 'is_random')
self._keyboard_control = self._config.getboolean('video_looper', 'keyboard_control')
self._gpio_control = self._config.getboolean('video_looper', 'gpio_control')
self._gpio_control_pin = self._config.get('video_looper', 'gpio_control_pin')
self._gpio_control_upstate = self._config.get('video_looper', 'gpio_control_upstate') # 1 or 0
# Parse string of 3 comma separated values like "255, 255, 255" into
# list of ints for colors.
self._bgcolor = list(map(int, self._config.get('video_looper', 'bgcolor')
@@ -71,7 +77,8 @@ class VideoLooper:
# Initialize pygame and display a blank screen.
pygame.display.init()
pygame.font.init()
pygame.mouse.set_visible(False)
pygame.mouse.set_visible(False)/

size = self._size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
self._screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
self._bgimage = self._load_bgimage()
@@ -81,6 +88,11 @@ class VideoLooper:
self._small_font = pygame.font.Font(None, 50)
self._big_font = pygame.font.Font(None, 250)
self._running = True
# Set GPIO Pin to input mode
if self._gpio_control:
wiringpi.pinMode(self._gpio_control_pin, 0)


def _print(self, message):
"""Print message to standard output if console output is enabled."""
@@ -232,29 +244,34 @@ class VideoLooper:
self._prepare_to_run_playlist(playlist)
# Main loop to play videos in the playlist and listen for file changes.
while self._running:
# Load and play a new movie if nothing is playing.
if not self._player.is_playing():
movie = playlist.get_next()
if movie is not None:
# Start playing the first available movie.
self._print('Playing movie: {0}'.format(movie))
self._player.play(movie, loop=playlist.length() == 1, vol = self._sound_vol)
# Check for changes in the file search path (like USB drives added)
# and rebuild the playlist.
if self._reader.is_changed():
self._player.stop(3) # Up to 3 second delay waiting for old
# player to stop.
# Rebuild playlist and show countdown again (if OSD enabled).
playlist = self._build_playlist()
self._prepare_to_run_playlist(playlist)
# Event handling for key press, if keyboard control is enabled
if self._keyboard_control:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
# If pressed key is ESC quit program
if event.key == pygame.K_ESCAPE:
self.quit()
# Give the CPU some time to do other tasks.
if not self._gpio_control or wiringpi.digitalRead(self._gpio_control_pin) == self._gpio_control_upstate:
# Load and play a new movie if nothing is playing.
if not self._player.is_playing():
movie = playlist.get_next()
if if not self._player.is_playing(): movie is not None:
# Start playing the first available movie.
self._print('Playing movie: {0}'.format(movie))
self._player.play(movie, loop=playlist.length() == 1, vol = self._sound_vol)
# Check for changes in the file search path (like USB drives added)
# and rebuild the playlist.
if self._reader.is_changed():
self._player.stop(3) # Up to 3 second delay waiting for old
# player to stop.
# Rebuild playlist and show countdown again (if OSD enabled).
playlist = self._build_playlist()
self._prepare_to_run_playlist(playlist)
# Event handling for key press, if keyboard control is enabled
if self._keyboard_control:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
# If pressed key is ESC quit program
if event.key == pygame.K_ESCAPE:
self.quit()
else:
self._player.stop()
# Give the CPU some time to do other tasks.
time.sleep(0.002)

def quit(self):


Laden…
Abbrechen
Speichern