diff --git a/setup.sh b/setup.sh index 7b9ec69..55a8976 100755 --- a/setup.sh +++ b/setup.sh @@ -101,12 +101,6 @@ cd .. # Create the systemd service for autologin and video control echo -e "${GREEN}======== Creating systemd service ========${NOCOLOR}" -# Autologin service content -AUTOLOGIN_SERVICE_CONTENT="[Service] -ExecStart= -ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux -" - # Video control service content SERVICE_CONTENT="[Unit] Description=Video Control Script @@ -126,11 +120,10 @@ WantedBy=multi-user.target # If the user opted for autostart, create the service files if [ $SYSD -eq 0 ]; then - # Creating Service file for Autologin of the Current User - echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null - check_error "Failed to create autologin service." + # Disableing Login Promt for TTY1 + sudo systemctl disable getty@tty1.service - # Craating Service file for Video Playback + # Creating Service file for Video Playback echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null check_error "Failed to create PiVideo service." diff --git a/video-old.py b/video-old.py new file mode 100755 index 0000000..798fd58 --- /dev/null +++ b/video-old.py @@ -0,0 +1,42 @@ +#! /usr/bin/python3 + +import RPi.GPIO as GPIO +import subprocess +import time + +# GPIO-Setup +BUTTON_PIN = 17 # Ersetze dies durch den tatsächlichen GPIO-Pin, den du verwendest +GPIO.setmode(GPIO.BCM) +GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +loop_video = 'videos/loop.mp4' +trigger_video = 'videos/trigger.mp4' + +# Funktion zum Abspielen eines Videos +def play_video(video_file): + subprocess.run(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_file]) + +# Endlosschleife Video 1 starten +loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video]) + +try: + while True: + # Überprüfen, ob der Button gedrückt wurde + button_state = GPIO.input(BUTTON_PIN) + if button_state == GPIO.LOW: # Button gedrückt + # Stoppe das loop_video + loop_video.terminate() + + # Video 2 abspielen + play_video(trigger_video) + + # Nach dem Abspielen von Video 2 wieder Video 1 in Schleife starten + loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video]) + + time.sleep(0.1) # Entprellen des Buttons + +except KeyboardInterrupt: + # Bei einem Tastaturabbruch das laufende Video stoppen und GPIO reinigen + loop_video.terminate() + GPIO.cleanup() + \ No newline at end of file diff --git a/video.py b/video.py old mode 100755 new mode 100644 index 798fd58..8f7aac6 --- a/video.py +++ b/video.py @@ -1,42 +1,76 @@ -#! /usr/bin/python3 - -import RPi.GPIO as GPIO -import subprocess +import os import time +import RPi.GPIO as GPIO +from subprocess import Popen, call +import sys -# GPIO-Setup -BUTTON_PIN = 17 # Ersetze dies durch den tatsächlichen GPIO-Pin, den du verwendest +os.system('sudo chvt 1') + +# Pfade zu den Dateien +THUMBNAIL_IMAGE = "/home/tim/PiVideo/videos/thumb.jpeg" +TRIGGER_VIDEO = "/home/tim/PiVideo/videos/trigger.mp4" +LOG_FILE = "/home/tim/PiVideo/log.txt" + +# GPIO-Einstellungen +BUTTON_PIN = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) -loop_video = 'videos/loop.mp4' -trigger_video = 'videos/trigger.mp4' +# Umleitung der Ausgaben in eine Log-Datei +sys.stdout = open(LOG_FILE, "a") +sys.stderr = open(LOG_FILE, "a") -# Funktion zum Abspielen eines Videos -def play_video(video_file): - subprocess.run(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_file]) +def log_message(message): + """Schreibt eine Nachricht in die Log-Datei.""" + timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + print(f"{timestamp} - {message}") + sys.stdout.flush() -# Endlosschleife Video 1 starten -loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video]) +def show_thumbnail(image_path): + """Zeigt das Thumbnail an.""" + log_message(f"Displaying thumbnail: {image_path}") + call(['sudo', 'fbi', '-T', '1', '-d', '/dev/fb0', '-a','-noverbose', image_path]) -try: - while True: - # Überprüfen, ob der Button gedrückt wurde - button_state = GPIO.input(BUTTON_PIN) - if button_state == GPIO.LOW: # Button gedrückt - # Stoppe das loop_video - loop_video.terminate() +def close_thumbnail(): + """Beendet fbi, um das Thumbnail zu schließen.""" + log_message("Closing thumbnail.") + call(['sudo', 'killall', 'fbi']) - # Video 2 abspielen - play_video(trigger_video) +def play_video(video_path): + """Spielt das Trigger-Video ab.""" + log_message(f"Playing video: {video_path}") + p = Popen(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_path]) + p.wait() - # Nach dem Abspielen von Video 2 wieder Video 1 in Schleife starten - loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video]) - time.sleep(0.1) # Entprellen des Buttons -except KeyboardInterrupt: - # Bei einem Tastaturabbruch das laufende Video stoppen und GPIO reinigen - loop_video.terminate() - GPIO.cleanup() - \ No newline at end of file +def main(): + log_message("Starting main loop.") + try: + while True: + # Thumbnail anzeigen + show_thumbnail(THUMBNAIL_IMAGE) + + # Warten, bis der Button gedrückt wird + while GPIO.input(BUTTON_PIN) == GPIO.HIGH: + time.sleep(0.1) + + + # Video abspielen, wenn Button gedrückt wurde + log_message("Button pressed, playing trigger video.") + play_video(TRIGGER_VIDEO) + + # fbi schließen, bevor das Video abgespielt wird + close_thumbnail() + # Nach dem Video wieder Thumbnail anzeigen + log_message("Trigger video finished, displaying thumbnail again.") + + except KeyboardInterrupt: + log_message("Script interrupted by user.") + finally: + GPIO.cleanup() + log_message("GPIO cleanup completed. Exiting script.") + +if __name__ == "__main__": + log_message("Script started.") + main() diff --git a/videos/Thumb.jpeg b/videos/Thumb.jpeg new file mode 100644 index 0000000..9d57c26 Binary files /dev/null and b/videos/Thumb.jpeg differ diff --git a/videos/demo-loop.mp4 b/videos/demo-loop.mp4 index bbb96e2..337b9e2 100644 Binary files a/videos/demo-loop.mp4 and b/videos/demo-loop.mp4 differ diff --git a/videos/demo-trigger.webm b/videos/demo-trigger.webm index 8e594bf..7c68e75 100644 Binary files a/videos/demo-trigger.webm and b/videos/demo-trigger.webm differ diff --git a/videos/trigger.mp4 b/videos/trigger.mp4 deleted file mode 100644 index 7ecec28..0000000 --- a/videos/trigger.mp4 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:521fef707842b9686e5d1e8323e9616f1c8ccc6c5bf183572b396f058fcc0760 -size 378799509