News:

LATEST RELEASE:  FPP 6.3 - Download from here - https://github.com/FalconChristmas/fpp/releases/tag/6.3

+-+-

+-User

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+-Site Stats

Members
Total Members: 15659
Latest: PaulDzRGB
New This Month: 9
New This Week: 3
New Today: 1
Stats
Total Posts: 128431
Total Topics: 15791
Most Online Today: 48
Most Online Ever: 7634
(January 21, 2020, 02:14:03 AM)
Users Online
Members: 4
Guests: 29
Total: 33

Check if Playing Script - ignore extra gpio inputs if something is already playi

Started by richie4540, October 14, 2015, 06:44:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

richie4540

Hi, so I have had some issues with triggering events from GPIO's and while mostly sorted can still get issues if during an event the trigger is sent multiple times it tends to cause FPP to go to Stopped status causing everything to stop.

A check if playing script was added to the repository but I cant quite make sense of it -

the script asks for two scripts in the definitions and depending on if there is already a script playing or not playing will chose one of these scripts to fire.

All I want is when a trigger is sent to a GPIO that the system checks that something is or isn't already playing and then send the action.

i.e.  if a trigger is sent then it will check if there is anything playing - if there isnt then it will start the Playlist, if there is already a playlist running then it will do nothing and ignore the button press.

Will this do the trick ?

#!/bin/sh
###########################################################
# CheckIfPlaying.sh - Run scripts based on whether or not #
# FPP is currently playing a sequence of some sort.       #
###########################################################

# Edit this line to hold the script name to run if nothing is currently being played
SCRIPT_IF_NOT_PLAYING="PUT YOUR SCRIPT NAME HERE (NOT PlAYING)"

# Edit this line to hold the script name to run if something is currently playing
# Edit out this line for only the one action
# SCRIPT_IF_PLAYING="PUT YOUR SCRIPT NAME HERE (PLAYING)"



###########################################################
# Guts of the script.  You probably don't need to edit    #
# anything below this block                               #
###########################################################

# Get our current status
STATUS=$(fpp -s | cut -d',' -f2)

# Check that we got something meaningful
if [ -z "${STATUS}" ]; then
   echo "Error with status value" >&2
   exit 1
fi

# Act on the current status
case ${STATUS} in
   # IDLE
   0)
      if [ -e "${MEDIADIR}/scripts/${SCRIPT_IF_NOT_PLAYING}" ]; then
         eventScript "${MEDIADIR}/scripts/${SCRIPT_IF_NOT_PLAYING}"
      fi
      ;;
   # PLAYING
   1)
      # Do nothing
      ;;
   # STOPPING GRACEFULLY
   2|*)
      # Do nothing for stopping gracefully for now, or unknown
      ;;
esac






Regards Richard.

CaptainMurdoch

-
Chris

richie4540

Chris, I have been trying to run the modified script, but it results in no action taken, triggering the input does not start the event even when the system is idle.

the overall system is working though as I have another standard event script which runs and plays a vid, although if you send multiple triggers through the same input while the video is playing the system hangs at a point and you are left with a frozen still of the video, which sometimes will reset at a later point if a trigger is sent later. interestingly also while the system is about to hang the status page goes to idle even though the video still plays for a time and then hangs.
Regards Richard.

CaptainMurdoch

Modify your script to add a line in the middle to make it look like this:


###########################################################
# Guts of the script.  You probably don't need to edit    #
# anything below this block                               #
###########################################################

. /opt/fpp/scripts/common

# Get our current status


Add that line that references scripts/common.  This will setup some environment variables
for FPP and set the path to include FPP's bin and script directories.   I think the eventScript
wrapper is not in the path so it isn't being found.  I had to add this line in order to test the
script from the command line.

Normally your script would be called via the eventScript wrapper, so I don't think you need to
add this, but it is a good idea to have it and it may fix your problem.
-
Chris

Materdaddy

The course of common scripts isn't needed.  What is needed is a script to run.  You didn't need to remove the section for "PLAYING" like you did, you only need to put another event script in the SCRIPT_IF_NOT_PLAYING variable.

For example, if you have a script called "StartMyShow.sh" that you were using previously for your GPIO trigger, and you want to make sure it only runs if nothing is already playing, you need to change your GPIO to trigger the new CheckIfPlaying.sh script instead of the old one, and then put "StartMyShow.sh" in the SCRIPT_IF_NOT_PLAYING variable of the CheckIfPlaying.sh script.

As Chris said, the script is run from the eventScript wrapper, so you don't need that line he mentioned.

CaptainMurdoch

Quote from: Materdaddy on October 15, 2015, 09:48:30 AM
You didn't need to remove the section for "PLAYING" like you did, you only need to put another event script in the SCRIPT_IF_NOT_PLAYING variable.

I forgot to mention that I modified that line for my test. :)  I did also confirm that it does work without using the common script line when run properly via the eventScript wrapper.
-
Chris

richie4540

OK, I must be missing something - I have the following in the FPP - I also at this point thankyou for your help - I am really new at bash scripting so don't understand the syntax to use but normally able to follow logic steps - can you recommend a programming manual to increase my learning?

Playlists loaded -

PL4 - plays one movie
PL5- plays one movie
PL7- plays one sequence
PL8- plays one sequence

Scripts loaded -

Checkifplay4.sh
PL4.sh
PL5.sh

GPIO configured

GPio BCM 23 - on low calls Event 1/1
GPio BCM 24 - on low calls Event 1/4

Events loaded

1/1 - calls PL5.sh
1/2 - calls PL5.sh
1/4 - calls Checkifplay4.sh

I have tried various versions of checkifplay4.sh as per your responses but none of the attempts trigger the script - in fact if I go to the events sections and try a manual trigger of PL5.sh it plays the correct movie but if I try to manually trigger the Checkifplay4.sh nothing happens.



the Checkifplay4.sh is as follows ----------

#!/bin/sh
###########################################################
# CheckIfPlaying.sh - Run scripts based on whether or not #
# FPP is currently playing a sequence of some sort.       #
###########################################################

# Edit this line to hold the script name to run if nothing is currently being played
SCRIPT_IF_NOT_PLAYING="PL4.sh (NOT PLAYING)"

# Edit this line to hold the script name to run if something is currently playing
# Edit out this line for only the one action
#SCRIPT_IF_PLAYING="NIL.sh (PLAYING)"



###########################################################
# Guts of the script.  You probably don't need to edit    #
# anything below this block                               #
###########################################################

. /opt/fpp/scripts/common

# Get our current status
STATUS=$(fpp -s | cut -d',' -f2)

# Check that we got something meaningful
if [ -z "${STATUS}" ]; then
   echo "Error with status value" >&2
   exit 1
fi

# Act on the current status
case ${STATUS} in
   # IDLE
   0)
      if [ -e "${MEDIADIR}/scripts/${SCRIPT_IF_NOT_PLAYING}" ]; then
         eventScript "${MEDIADIR}/scripts/${SCRIPT_IF_NOT_PLAYING}"
      fi
      ;;
   # PLAYING
   1)
      # Do nothing
      ;;
   # STOPPING GRACEFULLY
   2|*)
      # Do nothing for stopping gracefully for now, or unknown
      ;;
esac



Regards Richard.

richie4540

AHHHHH -  I have finally worked out what was wrong -

the line

SCRIPT_IF_NOT_PLAYING="PL4.sh (NOT PLAYING)"

should just be

SCRIPT_IF_NOT_PLAYING="PL4.sh"



Happy to report - that once a video is playing you can bang away on the input and nothing happens no matter how many times the input is triggered, where previously the FPP would either lock up or if it was just a couple of extra triggers would stop the playing file and restart it.

The action now is just to play the video once - just like the traffic signal switches - Little Johnny can press all he likes now :)
Regards Richard.

Materdaddy

I was scrolling through and was about to reply to tell you to *only* include the new script in the quotes, but you figured it out yourself, nice work!

Glad to hear you're up and running.

micropuller

I thought this script was the answer to my question, but I noticed it isn't quite.
What I'd like, is for a button to trigger an event, but first to check if the event isn't already active.
The idea is, that the playlist can't be interrupted or restarted by pushing another button or the same button a second time while it's playing.
Is this possible?

Materdaddy

I'm confused by your question because what you're describing is exactly what this script is for.

There are two scenarios in this script.
1) If FPP is not idle, run a script.
2) If FPP is idle, run a script.

What you want to do is set up your button to call this script as the GPIO event.  Next you will configure this script's "SCRIPT_IF_NOT_PLAYING" variable with another script that is to start your playlist.  Make sure you leave the other variable alone.

This will make it such that when your button is pressed and FPP is idle, your script that starts the playlist will run, starting the playlist.  Subsequent presses of the button (while the playlist is still going) will see that FPP is not idle, and will not run the other script because you didn't configure scenario 2.

micropuller

Maybe I'm reading the code wrong, but how I understand it is:
Richie has 2 buttons, one on GPIO bcm 23 and one on GPIO bcm 24
The first button triggers PL5.sh, the second button checks if there's something running and if not, triggers PL4.sh

I agree that it should work with just the second button, but I tried just uploading the script and replacing
SCRIPT_IF_NOT_PLAYING="PL4.sh"

with:
SCRIPT_IF_NOT_PLAYING="Test2"
(where Test2 is a playlist I already had triggered by another button)

I also changed the name of the script that's being triggered by the event , but the playlist doesn't start?

I'm not at my computer right now, but I'll upload a couple of screenshots when I get a chance.

micropuller

Ok, I figured out what I did wrong. I had the name of the playlist in "CheckIfPlaying.sh" Instead, I needed to put in the name of the script that should be triggered when the button is pressed (in my case "StartShow2")

The only problem I have now is, that if my second show is triggered and playing (by the CheckIfPlaying-script), and I trigger the first show, it stops the second show, then starts the second show again and after that the buttons are non-responsive (even the button that triggers the StopShow event), until the playlist is completed.

micropuller

Ah, I made a "CheckIfPlaying1.sh" to always trigger the first show, no matter if there is something playing or not, and now everything is working fine!

Materdaddy

Instead of "CheckIfPlaying1.sh" you should just call the start playlist1 script directly if that one doesn't care about the status of playing or not.  By having it start no matter if there's something playing or not defeats the purpose of the CheckIfPlaying button.  :D

Support FPP

+- Recent Topics

Warning/Error: Network incomplete frames hit 250. by JonD
February 06, 2023, 04:10:22 PM

F16V3 with 2 expansion boards at 40 fps MAX PIXELS per output? by tbone321
February 06, 2023, 10:51:55 AM

F48V4-NS at 40 fps using all 48 pixel output ports? by Poporacer
February 06, 2023, 10:27:09 AM

Unable to update RPi 5.5 to latest version by JonB256
February 05, 2023, 07:23:16 PM

help getting started, next step? by rayster
February 05, 2023, 04:24:09 PM

F48v4NS - Pi or No Pi? by joeyblasko
February 05, 2023, 09:15:33 AM

Huidu Controllers LED matrix by CaptainMurdoch
February 04, 2023, 10:18:47 AM

FPP6.2 universes by darylc
February 03, 2023, 08:48:57 PM

F16v4 Ports vs Universe Configuration Question by k6ccc
February 03, 2023, 09:32:48 AM

Need Expert Advise on F16v4 Ports vs Universe Configuration by Kairus
February 03, 2023, 09:32:33 AM

Powered by EzPortal
Powered by SMFPacks Menu Editor Mod