Zachary Kotlarek 13 лет назад
Родитель
Сommit
e22fb823fa
3 измененных файлов с 23 добавлено и 21 удалено
  1. 1 13
      dmx/projectorPower.pl
  2. 18 8
      dmx/rave.pl
  3. 4 0
      dmx/rifftrax.pl

+ 1 - 13
dmx/projectorPower.pl

@@ -1,7 +1,6 @@
 #!/usr/bin/perl
 #!/usr/bin/perl
 use strict;
 use strict;
 use warnings;
 use warnings;
-use POSIX;
 
 
 # Local modules
 # Local modules
 use Cwd qw(abs_path);
 use Cwd qw(abs_path);
@@ -57,27 +56,16 @@ my $color        = $COLOR_LOW;
 # Loop forever
 # Loop forever
 while (1) {
 while (1) {
 
 
-	# Reap zombie children (from say)
-	while (waitpid(-1, WNOHANG) > 0) { }
-
 	# State is calculated; use newState to gather data
 	# State is calculated; use newState to gather data
 	my $newState = $state;
 	my $newState = $state;
 
 
 	# Wait for state updates
 	# Wait for state updates
 	{
 	{
-		my %mtimeTmp  = ();
-		my %existsTmp = ();
-		my $cmdState  = DMX::readState($DELAY, \%existsTmp, \%mtimeTmp, undef());
+		my $cmdState = DMX::readState($DELAY, \%exists, \%mtime, undef());
 		if (defined($cmdState)) {
 		if (defined($cmdState)) {
 			$newState = $cmdState;
 			$newState = $cmdState;
 			$pullLast = time();
 			$pullLast = time();
 		}
 		}
-
-		# Only record valid exists/mtime hashes
-		if (scalar(keys(%existsTmp)) > 0) {
-			%mtime  = %mtimeTmp;
-			%exists = %existsTmp;
-		}
 	}
 	}
 
 
 	# Die if we don't see regular updates
 	# Die if we don't see regular updates

+ 18 - 8
dmx/rave.pl

@@ -25,7 +25,7 @@ my $MEDIA_PATH = `~/bin/video/mediaPath` . '/DMX';
 my @CHANNELS   = (1, 2, 4, 5, 6, 7, 8, 9, 13, 14, 15);
 my @CHANNELS   = (1, 2, 4, 5, 6, 7, 8, 9, 13, 14, 15);
 my %EFFECTS    = (
 my %EFFECTS    = (
 	'RED_ALERT' => { 'cmd' => \&red_alert },
 	'RED_ALERT' => { 'cmd' => \&red_alert },
-	'LSR'       => { 'cmd' => \&lsr_init, 'next' => \&lsr_run, 'loop' => \&lsr_loop },
+	'LSR'       => { 'cmd' => \&lsr_init, 'next' => \&lsr_run, 'loop' => \&lsr_loop, 'done' => \&lsr_done },
 );
 );
 my %FILES = (
 my %FILES = (
 	'RED_ALERT' => 'DMX/Red Alert.mp3',
 	'RED_ALERT' => 'DMX/Red Alert.mp3',
@@ -65,6 +65,7 @@ DMX::stateSubscribe($STATE_SOCK);
 
 
 # State
 # State
 my %exists   = ();
 my %exists   = ();
+my %last     = ();
 my $pullLast = time();
 my $pullLast = time();
 my $update   = 0;
 my $update   = 0;
 my $PID      = undef();
 my $PID      = undef();
@@ -85,6 +86,7 @@ while (1) {
 
 
 	# State is transient during a RAVE
 	# State is transient during a RAVE
 	my $newState = 'OFF';
 	my $newState = 'OFF';
+	%last = %exists;
 
 
 	# Reduce the select delay when we're processing background effects
 	# Reduce the select delay when we're processing background effects
 	# We don't want to hang waiting for event updates while we're running the show
 	# We don't want to hang waiting for event updates while we're running the show
@@ -97,17 +99,11 @@ while (1) {
 
 
 	# Wait for state updates
 	# Wait for state updates
 	{
 	{
-		my %existsTmp = ();
-		my $cmdState = DMX::readState($delay, \%existsTmp, undef(), undef());
+		my $cmdState = DMX::readState($delay, \%exists, undef(), undef());
 		if (defined($cmdState)) {
 		if (defined($cmdState)) {
 			$newState = $cmdState;
 			$newState = $cmdState;
 			$pullLast = time();
 			$pullLast = time();
 		}
 		}
-
-		# Only record valid exists hashes
-		if (scalar(keys(%existsTmp)) > 0) {
-			%exists = %existsTmp;
-		}
 	}
 	}
 
 
 	# Die if we don't see regular updates
 	# Die if we don't see regular updates
@@ -136,6 +132,11 @@ while (1) {
 				print STDERR 'Reaped child: ' . $PID . "\n";
 				print STDERR 'Reaped child: ' . $PID . "\n";
 			}
 			}
 
 
+			# Run the cleanup routine (if any)
+			if ($EFFECTS{$NAME}{'done'}) {
+				$EFFECTS{$NAME}{'done'}($NAME, \%exists, $EFFECTS{$NAME});
+			}
+
 			# Forget our local bypass state
 			# Forget our local bypass state
 			$PID      = undef();
 			$PID      = undef();
 			$NAME     = undef();
 			$NAME     = undef();
@@ -297,6 +298,7 @@ sub lsr_init($$$) {
 	}
 	}
 
 
 	# Initiate the RAVE state
 	# Initiate the RAVE state
+	DMX::say('Light switch rave: initiated');
 	touch($RAVE_FILE);
 	touch($RAVE_FILE);
 
 
 	# Save data for future runs
 	# Save data for future runs
@@ -427,3 +429,11 @@ sub lsr_loop($$$) {
 	# Wait for the fade interval
 	# Wait for the fade interval
 	usleep($wait * 1000);
 	usleep($wait * 1000);
 }
 }
+
+sub lsr_done($$$) {
+	my ($name, $exists, $params) = @_;
+	if ($DEBUG) {
+		print STDERR "lsr_done()\n";
+	}
+	DMX::say('Light switch rave: terminated');
+}

+ 4 - 0
dmx/rifftrax.pl

@@ -112,6 +112,7 @@ my $url       = '';
 my $urlLast   = $url;
 my $urlLast   = $url;
 my $nudge     = 0;
 my $nudge     = 0;
 my %exists    = ();
 my %exists    = ();
+my %last      = ();
 my $pullLast  = time();
 my $pullLast  = time();
 
 
 # Loop forever
 # Loop forever
@@ -120,6 +121,7 @@ while (1) {
 	# Save the last RIFF and state
 	# Save the last RIFF and state
 	$stateLast = $state;
 	$stateLast = $state;
 	$riffLast  = $riff;
 	$riffLast  = $riff;
+	%last      = %exists;
 
 
 	# Force a change if our riff is clearly invalid (first loop, reset, etc.)
 	# Force a change if our riff is clearly invalid (first loop, reset, etc.)
 	if ($riff < 0) {
 	if ($riff < 0) {
@@ -165,6 +167,7 @@ while (1) {
 			Audio::drop('RIFF');
 			Audio::drop('RIFF');
 			$riff  = 0;
 			$riff  = 0;
 			$nudge = 0;
 			$nudge = 0;
+			say('RiffTrax complete');
 		}
 		}
 
 
 		# Activate a new RIFF, if applicable
 		# Activate a new RIFF, if applicable
@@ -178,6 +181,7 @@ while (1) {
 				Audio::addLoad('RIFF', $RIFFS{$riff}->{'path'});
 				Audio::addLoad('RIFF', $RIFFS{$riff}->{'path'});
 				Audio::rate('RIFF', $RIFFS{$riff}->{'rate'});
 				Audio::rate('RIFF', $RIFFS{$riff}->{'rate'});
 				Audio::background('RIFF');
 				Audio::background('RIFF');
+				say('RiffTrax initiated');
 			}
 			}
 		}
 		}
 	}
 	}