Zachary Kotlarek пре 13 година
родитељ
комит
3cab4306ea
3 измењених фајлова са 80 додато и 19 уклоњено
  1. 51 5
      dmx/amplifierPower.pl
  2. 26 13
      dmx/leds.pl
  3. 3 1
      dmx/reset.sh

+ 51 - 5
dmx/amplifierPower.pl

@@ -8,6 +8,12 @@ use File::Basename qw(dirname);
 use lib dirname(abs_path($0));
 use lib dirname(abs_path($0));
 use DMX;
 use DMX;
 
 
+# Config
+my $USB_DEV     = 'USB Audio CODEC ';
+my $AMP_DEV     = 'Built-in Output';
+my $DEFAULT_DEV = $USB_DEV;
+my $RAVE_DEV    = $AMP_DEV;
+
 # App config
 # App config
 my $DATA_DIR     = DMX::dataDir();
 my $DATA_DIR     = DMX::dataDir();
 my $OUTPUT_FILE  = $DATA_DIR . 'AMPLIFIER_POWER';
 my $OUTPUT_FILE  = $DATA_DIR . 'AMPLIFIER_POWER';
@@ -16,6 +22,8 @@ my $AMP_SOCK     = $DATA_DIR . 'AMPLIFIER.socket';
 my $PUSH_TIMEOUT = 20;
 my $PUSH_TIMEOUT = 20;
 my $PULL_TIMEOUT = $PUSH_TIMEOUT * 3;
 my $PULL_TIMEOUT = $PUSH_TIMEOUT * 3;
 my $DELAY        = $PULL_TIMEOUT / 2;
 my $DELAY        = $PULL_TIMEOUT / 2;
+my $START_DELAY  = 3.5;
+my @AUDIO_SET    = ('SwitchAudioSource', '-s');
 
 
 # Debug
 # Debug
 my $DEBUG = 0;
 my $DEBUG = 0;
@@ -51,12 +59,25 @@ while (1) {
 
 
 	# Calculate the new state
 	# Calculate the new state
 	$stateLast = $state;
 	$stateLast = $state;
-	if ($newState eq 'ON' || $exists{'RAVE'}) {
+	if ($newState eq 'ON') {
 		$state = 'ON';
 		$state = 'ON';
+	} elsif ($exists{'RAVE'}) {
+		$state = 'RAVE';
 	} else {
 	} else {
 		$state = 'OFF';
 		$state = 'OFF';
 	}
 	}
 
 
+	# Force updates when there is a physical state mistmatch
+	if ($state eq 'OFF') {
+		if ($exists{'AMPLIFIER'}) {
+			$update = 1;
+		}
+	} else {
+		if (!$exists{'AMPLIFIER'}) {
+			$update = 1;
+		}
+	}
+
 	# Force updates on a periodic basis
 	# Force updates on a periodic basis
 	if (time() - $pushLast > $PUSH_TIMEOUT) {
 	if (time() - $pushLast > $PUSH_TIMEOUT) {
 		# Not for the amp
 		# Not for the amp
@@ -85,21 +106,46 @@ while (1) {
 		}
 		}
 
 
 		# Send master power state
 		# Send master power state
+		my $cmd = undef();
 		if ($state eq 'OFF' || $state eq 'ON') {
 		if ($state eq 'OFF' || $state eq 'ON') {
-			$amp->send($state)
-			  or die('Unable to write command to amp socket: ' . $state . ": ${!}\n");
+			$cmd = $state;
+		} elsif ($state eq 'RAVE') {
+			$cmd = 'ON';
+		}
+		if (defined($cmd)) {
+			$amp->send($cmd)
+			  or die('Unable to write command to amp socket: ' . $cmd . ": ${!}\n");
 		}
 		}
 
 
 		# Reset to TV @ 5.1 at power on
 		# Reset to TV @ 5.1 at power on
-		if ($state eq 'ON') {
+		if (defined($cmd) && $cmd eq 'ON') {
+			# Set the audio source back to the default
+			my @CMD = @AUDIO_SET;
+			push(@CMD, $DEFAULT_DEV);
+			system(@CMD);
+
 			# Wait for the amp to boot
 			# Wait for the amp to boot
-			sleep($DELAY);
+			sleep($START_DELAY);
+
+			# Set the mode
 			$amp->send('TV')
 			$amp->send('TV')
 			  or die('Unable to write command to amp socket: TV' . ": ${!}\n");
 			  or die('Unable to write command to amp socket: TV' . ": ${!}\n");
 			$amp->send('SURROUND')
 			$amp->send('SURROUND')
 			  or die('Unable to write command to amp socket: SURROUND' . ": ${!}\n");
 			  or die('Unable to write command to amp socket: SURROUND' . ": ${!}\n");
 		}
 		}
 
 
+		# Rave through the main amp
+		if ($state eq 'RAVE') {
+			# Set the audio source to the RAVE device
+			my @CMD = @AUDIO_SET;
+			push(@CMD, $RAVE_DEV);
+			system(@CMD);
+
+			# Set the mode
+			$amp->send('STEREO')
+			  or die('Unable to write command to amp socket: STEREO' . ": ${!}\n");
+		}
+
 		# No output file
 		# No output file
 
 
 		# Update the push time
 		# Update the push time

+ 26 - 13
dmx/leds.pl

@@ -348,18 +348,16 @@ sub rave() {
 		print STDERR "rave()\n";
 		print STDERR "rave()\n";
 	}
 	}
 
 
-	my $file  = '/mnt/media/DMX/Rave.mp3';
-	my @sound = ('afplay', $file);
+	# Config
+	my $file      = '/mnt/media/DMX/Rave.mp3';
+	my @sound     = ('afplay', $file);
+	my $AMP_DELAY = 9;
 
 
 	# Stat the file to bring the network up-to-date
 	# Stat the file to bring the network up-to-date
 	stat($file);
 	stat($file);
 
 
-	# Play the sound in a child (i.e. in the background)
-	$PID = fork();
-	if (defined($PID) && $PID == 0) {
-		exec(@sound)
-		  or die('Unable to play sound: ' . join(' ', @sound) . "\n");
-	}
+	# Initiate the RAVE state
+	touch($RAVE_FILE);
 
 
 	# Setup our loop handler
 	# Setup our loop handler
 	$EFFECT = \&rave_loop;
 	$EFFECT = \&rave_loop;
@@ -368,9 +366,6 @@ sub rave() {
 	my %data = ();
 	my %data = ();
 	$PID_DATA = \%data;
 	$PID_DATA = \%data;
 
 
-	# Record our start time
-	$data{'start'} = Time::HiRes::time();
-
 	# Initialize the channels hash
 	# Initialize the channels hash
 	my %channels = (
 	my %channels = (
 		1  => 0,
 		1  => 0,
@@ -389,8 +384,26 @@ sub rave() {
 	$data{'num_channels'}  = scalar(keys(%channels));
 	$data{'num_channels'}  = scalar(keys(%channels));
 	$data{'live_channels'} = 0;
 	$data{'live_channels'} = 0;
 
 
-	# Initiate the RAVE state
-	touch($RAVE_FILE);
+	# Dim while we wait
+	my @data_set = ();
+	foreach my $chan (keys(%channels)) {
+		push(@data_set, { 'channel' => $chan, 'value' => 0, 'time' => $AMP_DELAY * 1000 });
+	}
+	DMX::applyDataset(\@data_set, 'RAVE', $OUTPUT_FILE);
+	$pushLast = time();
+
+	# Wait for the amp to boot
+	sleep($AMP_DELAY);
+
+	# Play the sound in a child (i.e. in the background)
+	$PID = fork();
+	if (defined($PID) && $PID == 0) {
+		exec(@sound)
+		  or die('Unable to play sound: ' . join(' ', @sound) . "\n");
+	}
+
+	# Record our start time
+	$data{'start'} = Time::HiRes::time();
 
 
 	# Do not pass GO, do not collect $200
 	# Do not pass GO, do not collect $200
 	return 1;
 	return 1;

+ 3 - 1
dmx/reset.sh

@@ -3,11 +3,13 @@
 ROPE="`ps -A -o pid=,command= | grep -v grep | grep rope.pl | awk '{print $1}'`"
 ROPE="`ps -A -o pid=,command= | grep -v grep | grep rope.pl | awk '{print $1}'`"
 LEDS="`ps -A -o pid=,command= | grep -v grep | grep leds.pl | awk '{print $1}'`"
 LEDS="`ps -A -o pid=,command= | grep -v grep | grep leds.pl | awk '{print $1}'`"
 BIAS="`ps -A -o pid=,command= | grep -v grep | grep bias.pl | awk '{print $1}'`"
 BIAS="`ps -A -o pid=,command= | grep -v grep | grep bias.pl | awk '{print $1}'`"
+PROJ="`ps -A -o pid=,command= | grep -v grep | grep projectorPower.pl | awk '{print $1}'`"
 FAN="`ps -A -o pid=,command= | grep -v grep | grep fan.pl | awk '{print $1}'`"
 FAN="`ps -A -o pid=,command= | grep -v grep | grep fan.pl | awk '{print $1}'`"
+AMP="`ps -A -o pid=,command= | grep -v grep | grep ampliferPower.pl | awk '{print $1}'`"
 OVERHEAD="`ps -A -o pid=,command= | grep -v grep | grep overhead.pl | awk '{print $1}'`"
 OVERHEAD="`ps -A -o pid=,command= | grep -v grep | grep overhead.pl | awk '{print $1}'`"
 GARAGE="`ps -A -o pid=,command= | grep -v grep | grep garage.pl | awk '{print $1}'`"
 GARAGE="`ps -A -o pid=,command= | grep -v grep | grep garage.pl | awk '{print $1}'`"
 
 
-for i in $ROPE $LEDS $FAN $BIAS $OVERHEAD $GARAGE; do
+for i in $ROPE $LEDS $FAN $BIAS $OVERHEAD $GARAGE $AMP $PROJ; do
 	if [ -n "${i}" ]; then
 	if [ -n "${i}" ]; then
 		kill $i
 		kill $i
 	fi
 	fi