commit c6c636ae0415a4592826760725dc31ab9cc1644f Author: Tim Date: Sun Aug 11 11:50:32 2024 +0200 Init diff --git a/reload.sh b/reload.sh new file mode 100644 index 0000000..e3c0237 --- /dev/null +++ b/reload.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +GREEN='\033[0;32m' +NOCOLOR='\033[0m' +SERVICE_NAME="pivideo.service" + +echo -e "${GREEN}======== Stoppe Dienst =========${NOCOLOR}" +sudo systemctl stop $SERVICE_NAME + + +echo -e "${GREEN}======== Starte Dienst =========${NOCOLOR}" +sudo systemctl start $SERVICE_NAME + +exit 0 \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..d68702a --- /dev/null +++ b/setup.sh @@ -0,0 +1,80 @@ +#! /bin/bash + +GREEN='\033[0;32m' +NOCOLOR='\033[0m' + +echo -e "${GREEN}======== Starte Installation =========${NOCOLOR}" + +CURRENT_USER=$(whoami) +SERVICE_NAME="pivideo.service" + +PYTHON_SCRIPT="/home/$CURRENT_USER/PiVideo/video.py" + + + +echo $CURRENT_USER +echo $PYTHON_SCRIPT + +echo -e "${GREEN}======== Führe Update durch =========${NOCOLOR}" + +sudo apt update && sudo apt upgrade -y + +echo -e "${GREEN}======== Installiere Abhängigkeiten =========${NOCOLOR}" +sduo apt install vlc python3-rpi.gpio git -y + + +echo -e "${GREEN}======== Holle Datein ========${NOCOLOR}" + +mkdir ~/PiVideo/ ~/PiVideo/videos/ +cd ~/PiVideo/ + +wget -L "https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/video.py" + + +echo -e "${GREEN}======== Holle Videos========${NOCOLOR}" + +cd videos/ +wget -L "https://github.com/miT-nib-hcI/PiVideo/raw/main/loop.mp4" +wget -L "https://github.com/miT-nib-hcI/PiVideo/raw/main/trigger.mp4" + +cd .. + +echo -e "${GREEN}======== Erestele Systemd Service ========${NOCOLOR}" + +SERVICE_CONTENT="[Unit] +Description=Video Control Script +After=network.target + +[Service] +ExecStart=/usr/bin/python3 $PYTHON_SCRIPT +WorkingDirectory=$(dirname $PYTHON_SCRIPT) +StandardOutput=inherit +StandardError=inherit +Restart=always +User=$CURRENT_USER + +[Install] +WantedBy=multi-user.target +" + +echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null + +# Lade die Systemd-Dienste neu +echo -e "${GREEN}======== Lade Dienste neu ========${NOCOLOR}" +sudo systemctl daemon-reload + +# Aktiviere den Service, damit er beim Booten gestartet wird +echo -e "${GREEN}======== Aktiviern des Dienstes ========${NOCOLOR}" +sudo systemctl enable $SERVICE_NAME + +# Starten des Services +echo -e "${GREEN}======== Starente des Dienstes ========${NOCOLOR}" +sudo systemctl start $SERVICE_NAME + + + +echo -e "${GREEN}=========================================================${NOCOLOR}" +echo -e "${GREEN}======== Das Script wurde Erfolgreich Ausgeführt ========${NOCOLOR}" +echo -e "${GREEN}=========================================================${NOCOLOR}" + +exit 0 \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..2c9783e --- /dev/null +++ b/start.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +GREEN='\033[0;32m' +NOCOLOR='\033[0m' +SERVICE_NAME="pivideo.service" + +echo -e "${GREEN}======== Starte Dienst =========${NOCOLOR}" +sudo systemctl start $SERVICE_NAME + + +echo -e "${GREEN}======== Starte Autostart des Diensts =========${NOCOLOR}" +sudo systemctl enable $SERVICE_NAME + +exit 0 \ No newline at end of file diff --git a/stop.sh b/stop.sh new file mode 100644 index 0000000..ed81c70 --- /dev/null +++ b/stop.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +GREEN='\033[0;32m' +NOCOLOR='\033[0m' +SERVICE_NAME="pivideo.service" + +echo -e "${GREEN}======== Stoppe Dienst =========${NOCOLOR}" +sudo systemctl stop $SERVICE_NAME + + +echo -e "${GREEN}======== Stoppe Autostart des Diensts =========${NOCOLOR}" +sudo systemctl disable $SERVICE_NAME + +exit 0 \ No newline at end of file diff --git a/video.py b/video.py new file mode 100755 index 0000000..16b0966 --- /dev/null +++ b/video.py @@ -0,0 +1,41 @@ +#! /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/videos/loop.mp4 b/videos/loop.mp4 new file mode 100644 index 0000000..337b9e2 Binary files /dev/null and b/videos/loop.mp4 differ diff --git a/videos/trigger.mp4 b/videos/trigger.mp4 new file mode 100644 index 0000000..9af497f Binary files /dev/null and b/videos/trigger.mp4 differ