Zachary Kotlarek 13 лет назад
Родитель
Сommit
77a49ff8bf
10 измененных файлов с 51 добавлено и 45 удалено
  1. 14 9
      dmx/DMX.pm
  2. 1 1
      dmx/amplifierPower.pl
  3. 1 1
      dmx/bias.pl
  4. 1 1
      dmx/fan.pl
  5. 1 1
      dmx/garage.pl
  6. 1 1
      dmx/leds.pl
  7. 1 1
      dmx/overhead.pl
  8. 13 17
      dmx/projectorPower.pl
  9. 1 1
      dmx/rope.pl
  10. 17 12
      dmx/state.pl

+ 14 - 9
dmx/DMX.pm

@@ -94,14 +94,18 @@ sub stateSocket($) {
 }
 
 # Parse the state->client comm string
-sub parseState($$) {
-	my ($text, $exists) = @_;
+sub parseState($$$) {
+	my ($text, $exists, $mtime) = @_;
 	my $cmdState    = undef();
 	my $exists_text = undef();
+	if (!defined($mtime)) {
+		my %tmp = ();
+		$mtime  = \%tmp;
+	}
 
 	# Parse the string
-	my %tmp = ();
 	%{$exists} = ();
+	%{$mtime}  = ();
 	($cmdState, $exists_text) = $text =~ /^(\w+)(?:\s+\(([^\)]+)\))?/;
 	if (!defined($cmdState)) {
 		print STDERR 'State parse error: ' . $text . "\n";
@@ -109,18 +113,19 @@ sub parseState($$) {
 	}
 	if (defined($exists_text)) {
 		foreach my $exists_val (split(/\s*,\s*/, $exists_text)) {
-			my ($name, $value) = $exists_val =~ /(\w+)\:(\d+)/;
-			if (!defined($name) || !defined($value)) {
+			my ($name, $value, $time) = $exists_val =~ /(\w+)\:(\d+)\:(\d+)/;
+			if (!defined($name) || !defined($value) || !defined($time)) {
 				print STDERR 'State parse error (exists): ' . $text . "\n";
 				next;
 			}
 			$exists->{$name} = $value;
+			$mtime->{$name}  = $time;
 		}
 	}
 	if ($DEBUG) {
 		my @exists_tmp = ();
 		foreach my $key (keys(%{$exists})) {
-			push(@exists_tmp, $key . ':' . $exists->{$key});
+			push(@exists_tmp, $key . ':' . $exists->{$key} . ':' . $mtime->{$key});
 		}
 		print STDERR 'Got state: ' . $cmdState . ' (' . join(', ', @exists_tmp) . ")\n";
 	}
@@ -220,8 +225,8 @@ sub applyDataset($$$) {
 	}
 }
 
-sub readState($$$) {
-	my ($delay, $exists, $valid) = @_;
+sub readState($$$$) {
+	my ($delay, $exists, $mtime, $valid) = @_;
 	my $cmdState = undef();
 
 	# Wait for state updates
@@ -235,7 +240,7 @@ sub readState($$$) {
 		while (defined($fh->recv(my $text, $MAX_CMD_LEN))) {
 
 			# Parse the string
-			my $state = parseState($text, $exists);
+			my $state = parseState($text, $exists, $mtime);
 
 			# Ignore invalid states
 			if (defined($valid)) {

+ 1 - 1
dmx/amplifierPower.pl

@@ -51,7 +51,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, undef());
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), undef());
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 1 - 1
dmx/bias.pl

@@ -58,7 +58,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, \%VALID);
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), \%VALID);
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 1 - 1
dmx/fan.pl

@@ -50,7 +50,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, undef());
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), undef());
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 1 - 1
dmx/garage.pl

@@ -52,7 +52,7 @@ while (1) {
 	my $newState = 'OFF';
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, undef());
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), undef());
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 1 - 1
dmx/leds.pl

@@ -134,7 +134,7 @@ while (1) {
 	}
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($delay, \%exists, \%VALID);
+	my $cmdState = DMX::readState($delay, \%exists, undef(), \%VALID);
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 1 - 1
dmx/overhead.pl

@@ -59,7 +59,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, \%VALID);
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), \%VALID);
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 13 - 17
dmx/projectorPower.pl

@@ -37,6 +37,7 @@ my $proj = DMX::clientSock($PROJ_SOCK);
 my $state     = 'OFF';
 my $stateLast = $state;
 my %exists    = ();
+my %mtime     = ();
 my $pushLast  = 0;
 my $pullLast  = time();
 my $update    = 0;
@@ -50,7 +51,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, undef());
+	my $cmdState = DMX::readState($DELAY, \%exists, \%mtime, undef());
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();
@@ -61,22 +62,17 @@ while (1) {
 		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
 	}
 
-	# Record the lastUser time -- last GUI update or last time we were playing
-	if ($lastUser < $exists{'GUI'}) {
-		$lastUser = $exists{'GUI'};
+	# Menu changes count as activity
+	if ($lastUser < $mtime{'GUI'}) {
+		$lastUser = $mtime{'GUI'};
 	}
-	my $now = time();
-	if ($lastUser < $now) {
-		if ($exists{'PLAYING'}) {
-			$lastUser = $now;
-		}
+	# Projector starts count as activity
+	if ($exists{'PROJECTOR'} && $lastUser < $mtime{'PROJECTOR'}) {
+		$lastUser = $mtime{'PROJECTOR'};
 	}
-
-	# Treat a transition from "OFF" to "PAUSE" as user activity (i.e. someone fired up the projector)
-	if ($lastUser < $now) {
-		if ($newState eq 'PAUSE' && $stateLast eq 'OFF') {
-			$lastUser = $now;
-		}
+	# Playing counts as activity
+	if ($exists{'PLAYING'} && $lastUser < time()) {
+		$lastUser = time();
 	}
 
 	# Calculate the elapsed time
@@ -136,8 +132,8 @@ while (1) {
 
 		# Send master power state
 		if ($state eq 'OFF' || $state eq 'ON') {
-			$proj->send($state)
-			  or die('Unable to write command to proj socket: ' . $state . ": ${!}\n");
+		#	$proj->send($state)
+		#	  or die('Unable to write command to proj socket: ' . $state . ": ${!}\n");
 		}
 
 		# No output file

+ 1 - 1
dmx/rope.pl

@@ -104,7 +104,7 @@ while (1) {
 	my $newState = $state;
 
 	# Wait for state updates
-	my $cmdState = DMX::readState($DELAY, \%exists, \%VALID);
+	my $cmdState = DMX::readState($DELAY, \%exists, undef(), \%VALID);
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$pullLast = time();

+ 17 - 12
dmx/state.pl

@@ -21,7 +21,7 @@ my %MON_FILES     = (
 	'GUI'       => 'MTIME',
 	'MOTION'    => 'MTIME',
 	'PROJECTOR' => 'STATUS',
-	'AMPLIFIER' => 'STATUS_NOMTIME',
+	'AMPLIFIER' => 'STATUS',
 	'PLAYING'   => 'STATUS_PLAYING',
 	'LIGHTS'    => 'EXISTS',
 	'FAN_CMD'   => 'EXISTS',
@@ -62,6 +62,8 @@ my @subscribers = ();
 # State
 my $state      = 'INIT';
 my $stateLast  = $state;
+my $status     = '';
+my $statusLast = $status;
 my $updateLast = 0;
 my $pushLast   = 0;
 
@@ -147,11 +149,8 @@ while (1) {
 		$file->{'status'} = 0;
 
 		# Record the last update
-		if ($file->{'type'} eq 'STATUS' || $file->{'type'} =~ /^MTIME/) {
+		if ($file->{'type'} =~ /^STATUS/ || $file->{'type'} =~ /^MTIME/) {
 			$file->{'update'} = mtime($file->{'path'});
-			if ($file->{'type'} =~ /^MTIME/) {
-				$file->{'status'} = $file->{'update'};
-			}
 			if ($DEBUG) {
 				print STDERR 'Last change: ' . $file->{'name'} . ': ' . localtime($file->{'update'}) . "\n";
 			}
@@ -201,6 +200,7 @@ while (1) {
 
 			if (-e $file->{'path'}) {
 				$file->{'status'} = 1;
+				$file->{'update'} = time();
 			}
 			if ($DEBUG) {
 				print STDERR 'Exists: ' . $file->{'name'} . ': ' . $file->{'status'} . "\n";
@@ -251,13 +251,18 @@ while (1) {
 		}
 	}
 
-	# Append the status of all files
+	# Calculate the new status
+	$statusLast     = $status;
+	my $statusMtime = '';
 	{
-		my @status = ();
+		my @statTime = ();
+		my @statOnly = ();
 		foreach my $file (values(%files)) {
-			push(@status, $file->{'name'} . ':' . $file->{'status'});
+			push(@statOnly, $file->{'name'} . ':' . $file->{'status'});
+			push(@statTime, $file->{'name'} . ':' . $file->{'status'} . ':' . $file->{'update'});
 		}
-		$state .= ' (' . join(', ', @status) . ')';
+		$status      = ' (' . join(', ', @statOnly) . ')';
+		$statusMtime = ' (' . join(', ', @statTime) . ')';
 	}
 
 	# Clear exists_clear files immediately (but after we append their status)
@@ -285,9 +290,9 @@ while (1) {
 	}
 
 	# Force updates on any state change
-	if ($stateLast ne $state) {
+	if ($stateLast ne $state || $statusLast ne $status) {
 		if ($DEBUG) {
-			print STDERR 'State change: ' . $stateLast . ' => ' . $state . "\n";
+			print STDERR 'State change: ' . $stateLast . $statusLast . ' => ' . $state . $status . "\n";
 		}
 		$update = 1;
 	}
@@ -302,7 +307,7 @@ while (1) {
 		foreach my $sub (@subscribers) {
 
 			# Drop subscribers that are not available
-			if (!eval { $sub->{'socket'}->send($state) }) {
+			if (!eval { $sub->{'socket'}->send($state . $statusMtime) }) {
 				print STDERR 'Dropping bad socket from subscriber list: ' . $sub->{'path'} . "\n";
 
 				my @new_subscribers = ();