Skip to content

Commit

Permalink
Merge pull request #1030 from princemaxwell/patch-4
Browse files Browse the repository at this point in the history
Add "same_id_delay" to settings + Add option to ignore control cards (volume, skip, seek, etc.)
  • Loading branch information
MiczFlor authored Jul 16, 2020
2 parents e42963e + 63e4af7 commit c9a7f7d
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 3 deletions.
2 changes: 2 additions & 0 deletions htdocs/inc.header.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function fileGetContentOrDefault($filename, $defaultValue)
$Audio_Folders_Path = $globalConf['AUDIOFOLDERSPATH'];
$Playlists_Folders_Path = $globalConf['PLAYLISTSFOLDERPATH'];
$Second_Swipe = $globalConf['SECONDSWIPE'];
$Second_Swipe_Pause = $globalConf['SECONDSWIPEPAUSE'];
$Second_Swipe_Pause_Controls = $globalConf['SECONDSWIPEPAUSECONTROLS'];
$VolumeManager = $globalConf['VOLUMEMANAGER'];
$ShowCover = $globalConf['SHOWCOVER'];
$WlanIpReadYN = $globalConf['READWLANIPYN'];
Expand Down
186 changes: 186 additions & 0 deletions htdocs/inc.setSecondSwipePause.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<!--
Set Second Swipe Pause
What if the cards is swiped again too fast? Here you can set a pause time.
-->
<?php
if(isset($_POST['secondSwipePause']) && trim($_POST['secondSwipePause']) != "") {
/*
* make sure it is a value we can accept, do not just write whatever is in the POST
*/
if(trim($_POST['secondSwipePause']) == "0") {
$Second_Swipe_Pause = "0";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "1") {
$Second_Swipe_Pause = "1";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "2") {
$Second_Swipe_Pause = "2";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "3") {
$Second_Swipe_Pause = "3";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "4") {
$Second_Swipe_Pause = "4";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "5") {
$Second_Swipe_Pause = "5";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "6") {
$Second_Swipe_Pause = "6";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "7") {
$Second_Swipe_Pause = "7";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "8") {
$Second_Swipe_Pause = "8";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "9") {
$Second_Swipe_Pause = "9";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePause']) == "10") {
$Second_Swipe_Pause = "10";
$exec = 'echo "'.$Second_Swipe_Pause.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause';
if($debug == "true") {
print $exec;
}
exec($exec);
}
// execute shell to create config file
exec("sudo ".$conf['scripts_abs']."/inc.writeGlobalConfig.sh");
}
?>
<!-- input-group -->
<div class="row" style="margin-bottom:1em;">
<div class="col-md-6 col-xs-12">
<h4><?php print $lang['settingsSecondSwipePauseInfo']; ?></h4>
<form name='secondSwipePause' method='post' action='<?php print $_SERVER['PHP_SELF']; ?>'>
<div class="input-group my-group">
<select id="secondSwipePause" name="secondSwipePause" class="selectpicker form-control">
<?php
print "
<option value='0'";
if($Second_Swipe_Pause == "0") {
print " selected";
}
print ">OFF</option>\n";
print "
<option value='1'";
if($Second_Swipe_Pause == "1") {
print " selected";
}
print ">1 ".$lang['second'];
print "</option>\n";
print "
<option value='2'";
if($Second_Swipe_Pause == "2") {
print " selected";
}
print ">2 ".$lang['seconds'];
print "</option>\n";
print "
<option value='3'";
if($Second_Swipe_Pause == "3") {
print " selected";
}
print ">3 ".$lang['seconds'];
print "</option>\n";
print "
<option value='4'";
if($Second_Swipe_Pause == "4") {
print " selected";
}
print ">4 ".$lang['seconds'];
print "</option>\n";
print "
<option value='5'";
if($Second_Swipe_Pause == "5") {
print " selected";
}
print ">5 ".$lang['seconds'];
print "</option>\n";
print "
<option value='6'";
if($Second_Swipe_Pause == "6") {
print " selected";
}
print ">6 ".$lang['seconds'];
print "</option>\n";
print "
<option value='7'";
if($Second_Swipe_Pause == "7") {
print " selected";
}
print ">7 ".$lang['seconds'];
print "</option>\n";
print "
<option value='8'";
if($Second_Swipe_Pause == "8") {
print " selected";
}
print ">8 ".$lang['seconds'];
print "</option>\n";
print "
<option value='9'";
if($Second_Swipe_Pause == "9") {
print " selected";
}
print ">9 ".$lang['seconds'];
print "</option>\n";
print "
<option value='10'";
if($Second_Swipe_Pause == "10") {
print " selected";
}
print ">10 ".$lang['seconds'];
print "</option>\n";
?>
</select>
<span class="input-group-btn">
<input type='submit' class="btn btn-default" name='submit' value='<?php print $lang['globalSet']; ?>'/>
</span>
</div>
</form>
</div>

</div><!-- ./row -->
<!-- /input-group -->
61 changes: 61 additions & 0 deletions htdocs/inc.setSecondSwipePauseControls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
Set Second Swipe Pause Controls
Some Controls cards are useful without an delay
-->
<?php
if(isset($_POST['secondSwipePauseControls']) && trim($_POST['secondSwipePauseControls']) != "") {
/*
* make sure it is a value we can accept, do not just write whatever is in the POST
*/
if(trim($_POST['secondSwipePauseControls']) == "ON") {
$Second_Swipe_Pause_Controls = "ON";
$exec = 'echo "'.$Second_Swipe_Pause_Controls.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause_Controls';
if($debug == "true") {
print $exec;
}
exec($exec);
} elseif(trim($_POST['secondSwipePauseControls']) == "OFF") {
$Second_Swipe_Pause_Controls = "OFF";
$exec = 'echo "'.$Second_Swipe_Pause_Controls.'" > '.$conf['settings_abs'].'/Second_Swipe_Pause_Controls';
if($debug == "true") {
print $exec;
}
exec($exec);
}
// execute shell to create config file
exec("sudo ".$conf['scripts_abs']."/inc.writeGlobalConfig.sh");
}
?>
<!-- input-group -->
<div class="row" style="margin-bottom:1em;">
<div class="col-md-6 col-xs-12">
<h4><?php print $lang['settingsSecondSwipePauseControlsInfo']; ?></h4>
<form name='secondSwipe' method='post' action='<?php print $_SERVER['PHP_SELF']; ?>'>
<div class="input-group my-group">
<select id="secondSwipePauseControls" name="secondSwipePauseControls" class="selectpicker form-control">
<?php
print "
<option value='ON'";
if($Second_Swipe_Pause_Controls == "ON") {
print " selected";
}
print ">".$lang['settingsSecondSwipePauseControlsOn'];
print "</option>\n";
print "
<option value='OFF'";
if($Second_Swipe_Pause_Controls == "OFF") {
print " selected";
}
print ">".$lang['settingsSecondSwipePauseControlsOff'];
print "</option>\n";
?>
</select>
<span class="input-group-btn">
<input type='submit' class="btn btn-default" name='submit' value='<?php print $lang['globalSet']; ?>'/>
</span>
</div>
</form>
</div>

</div><!-- ./row -->
<!-- /input-group -->
6 changes: 6 additions & 0 deletions htdocs/lang/lang-de-DE.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@
$lang['settingsSecondSwipePause'] = "Pause / Wiedergabe umschalten";
$lang['settingsSecondSwipePlay'] = "Wiedergabe fortsetzen";
$lang['settingsSecondSwipeNoAudioPlay'] = "Nur Systembefehle mehrfach ausführen";
$lang['settingsSecondSwipePauseInfo'] = "Ignoriere das erneute Scannen derselben Karte für:";
$lang['second'] = "Sekunde";
$lang['seconds'] = "Sekunden";
$lang['settingsSecondSwipePauseControlsInfo'] = "Bestimmte Funktionskarten (z.B. Lautstärke hoch/runter, Nächster/Voriger Titel, Vor-/Zurückspulen) sollen keine Verzögerung (wie in der Einstellung zuvor eingestellt) haben:";
$lang['settingsSecondSwipePauseControlsOn'] = "Funktionskarten ohne Verzögerung";
$lang['settingsSecondSwipePauseControlsOff'] = "Funktionskarten mit Verzögerung (Sekunden wie zuvor)";
$lang['settingsWebInterface'] = "Web-Oberfläche";
$lang['settingsCoverInfo'] = "Willst du Cover neben den Alben und Playlisten auf der Hauptseite anzeigen?";
$lang['settingsShowCoverON'] = "Cover anzeigen";
Expand Down
6 changes: 6 additions & 0 deletions htdocs/lang/lang-en-UK.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@
$lang['settingsSecondSwipePause'] = "Toggle pause / play";
$lang['settingsSecondSwipePlay'] = "Resume playback";
$lang['settingsSecondSwipeNoAudioPlay'] = "Ignore audio playout triggers, only system commands";
$lang['settingsSecondSwipePauseInfo'] = "Ignore rescanning of the same card for:";
$lang['second'] = "second";
$lang['seconds'] = "seconds";
$lang['settingsSecondSwipePauseControlsInfo'] = "Certain function cards (e.g. volume up / down, next / previous track, forward / rewind) should not have a delay (as set in the setting previously):";
$lang['settingsSecondSwipePauseControlsOn'] = "Function cards without delay";
$lang['settingsSecondSwipePauseControlsOff'] = "Function cards with delay (seconds as before)";
$lang['settingsWebInterface'] = "Web Interface";
$lang['settingsCoverInfo'] = "Do you want to show covers beside the albums and playlists on the main page?";
$lang['settingsShowCoverON'] = "Show cover";
Expand Down
6 changes: 6 additions & 0 deletions htdocs/lang/lang-nl-NL.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
$lang['settingsSecondSwipeSkipnext'] = "Ga naar het volgende nummer";
$lang['settingsSecondSwipePause'] = "Schakelen tussen pauze / afspelen";
$lang['settingsSecondSwipeNoAudioPlay'] = "Negeer audio playout-triggers, alleen systeemopdrachten";
$lang['settingsSecondSwipePauseInfo'] = "Negeer het opnieuw scannen van dezelfde kaart voor:";
$lang['second'] = "Seconde";
$lang['seconds'] = "Seconden";
$lang['settingsSecondSwipePauseControlsInfo'] = "Bepaalde functiekaarten (bijv. Volume omhoog / omlaag, volgende / vorige track, snel vooruit / terugspoelen) mogen geen vertraging hebben (zoals eerder ingesteld in de instelling):";
$lang['settingsSecondSwipePauseControlsOn'] = "Functiekaarten zonder vertraging";
$lang['settingsSecondSwipePauseControlsOff'] = "Functiekaarten met vertraging (seconden als voorheen)";
$lang['settingsWebInterface'] = "Web Interface";
$lang['settingsCoverInfo'] = "Wil je albumhoezen naast de albums en afspeellijsten op de hoofdpagina weergeven?";
$lang['settingsShowCoverON'] = "Albumhoes laten zien";
Expand Down
2 changes: 2 additions & 0 deletions htdocs/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
<div class="panel-body">
<?php
include("inc.setSecondSwipe.php");
include("inc.setSecondSwipePause.php");
include("inc.setSecondSwipePauseControls.php");
?>
</div><!-- /.panel-body -->

Expand Down
38 changes: 35 additions & 3 deletions scripts/daemon_rfid_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import subprocess
import time
import re

from Reader import Reader

Expand All @@ -21,11 +22,40 @@
dir_path = os.path.dirname(os.path.realpath(__file__))
logger.info('Dir_PATH: {dir_path}'.format(dir_path=dir_path))

# get control card ids
file_path = os.path.dirname(__file__)
if file_path != "":
os.chdir(file_path)

# vars for ensuring delay between same-card-swipes
same_id_delay = 0
ssp = open('../settings/Second_Swipe_Pause', 'r')
same_id_delay = ssp.read().strip()
sspc = open('../settings/Second_Swipe_Pause_Controls', 'r')
sspc_nodelay = sspc.readline().strip()
previous_id = ""
previous_time = time.time()

#create array for control card ids
cards = []

# open file and read the content in a list
with open('../settings/global.conf', 'r') as filehandle:
filecontents = filehandle.readlines()

for line in filecontents:
cids = line[:-1]
cards.append(cids)


extract = [s for s in cards if s.startswith('CMD')]
string = ''.join(extract)

# if controlcards delay is deactivated, let the cards pass, otherwise, they have to wait...
if sspc_nodelay == "ON":
ids = re.findall("(\d+)", string)
else:
ids = ""

while True:
# reading the card id
# NOTE: it's been reported that KKMOON Reader might need the following line altered.
Expand All @@ -40,16 +70,18 @@
# start the player script and pass on the cardid (but only if new card or otherwise
# "same_id_delay" seconds have passed)
if cardid is not None:
if cardid != previous_id or (time.time() - previous_time) >= same_id_delay:
if cardid != previous_id or (time.time() - previous_time) >= float(same_id_delay) or cardid in str(ids):
logger.info('Trigger Play Cardid={cardid}'.format(cardid=cardid))
subprocess.call([dir_path + '/rfid_trigger_play.sh --cardid=' + cardid], shell=True)
previous_id = cardid
previous_time = time.time()

else:
logger.debug('Ignoring Card id {cardid} due to same-card-delay, delay: {same_id_delay}'.format(
cardid=cardid,
same_id_delay=same_id_delay
))

previous_time = time.time()

except OSError as e:
logger.error('Execution failed: {e}'.format(e=e))
Loading

0 comments on commit c9a7f7d

Please sign in to comment.