Przeglądaj źródła

Standardize "say" usage

Zachary Kotlarek 13 lat temu
rodzic
commit
7da2a91001
3 zmienionych plików z 24 dodań i 21 usunięć
  1. 17 0
      dmx/DMX.pm
  2. 4 0
      dmx/fan.pl
  3. 3 21
      dmx/projectorPower.pl

+ 17 - 0
dmx/DMX.pm

@@ -293,5 +293,22 @@ sub readState($$$$) {
 	return $cmdState;
 	return $cmdState;
 }
 }
 
 
+# Speak
+sub say($) {
+	my ($str) = @_;
+
+	if ($DEBUG) {
+		print STDERR 'Say: ' . $str . "\n";
+	}
+
+	my $pid = fork();
+	if (!defined($pid)) {
+		die('Unable to fork: ' . $! . "\n");
+	}
+	if (!$pid) {
+		exec('say', $str);
+	}
+}
+
 # Always return true
 # Always return true
 1;
 1;

+ 4 - 0
dmx/fan.pl

@@ -46,6 +46,9 @@ DMX::dim({ 'channel' => 11, 'value' => 0, 'time' => 0 });
 # 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;
 
 
@@ -83,6 +86,7 @@ while (1) {
 			print STDERR 'State change: ' . $stateLast . ' => ' . $state . "\n";
 			print STDERR 'State change: ' . $stateLast . ' => ' . $state . "\n";
 		}
 		}
 		$update = 1;
 		$update = 1;
+		DMX::say('Fan ' . $state);
 	}
 	}
 
 
 	# Update the fan
 	# Update the fan

+ 3 - 21
dmx/projectorPower.pl

@@ -28,7 +28,6 @@ my $PULL_TIMEOUT = $PUSH_TIMEOUT * 3;
 my $DELAY        = $PULL_TIMEOUT / 2;
 my $DELAY        = $PULL_TIMEOUT / 2;
 
 
 # Prototypes
 # Prototypes
-sub say($);
 sub sayShutdown($);
 sub sayShutdown($);
 
 
 # Debug
 # Debug
@@ -58,7 +57,7 @@ my $color        = $COLOR_LOW;
 # Loop forever
 # Loop forever
 while (1) {
 while (1) {
 
 
-	# Reap zombie children
+	# Reap zombie children (from say)
 	while (waitpid(-1, WNOHANG) > 0) { }
 	while (waitpid(-1, WNOHANG) > 0) { }
 
 
 	# State is calculated; use newState to gather data
 	# State is calculated; use newState to gather data
@@ -245,7 +244,7 @@ while (1) {
 		  or die('Unable to write command to proj socket: ' . $state . ": ${!}\n");
 		  or die('Unable to write command to proj socket: ' . $state . ": ${!}\n");
 
 
 		# Annouce the state change, after the fact
 		# Annouce the state change, after the fact
-		say('Projector ' . $state);
+		DMX::say('Projector ' . $state);
 
 
 		# No output file
 		# No output file
 
 
@@ -258,24 +257,7 @@ while (1) {
 		# Clear the update flag
 		# Clear the update flag
 		$update = 0;
 		$update = 0;
 	}
 	}
-}
-
-# Speak
-sub say($) {
-	my ($str) = @_;
-
-	if ($DEBUG) {
-		print STDERR 'Say: ' . $str . "\n";
-	}
 
 
-	my $pid = fork();
-	if (!defined($pid)) {
-		die('Unable to fork: ' . $! . "\n");
-	}
-	if (!$pid) {
-		exec('say', $str);
-	}
-}
 
 
 sub sayShutdown($) {
 sub sayShutdown($) {
 	my ($minutesLeft) = @_;
 	my ($minutesLeft) = @_;
@@ -305,5 +287,5 @@ sub sayShutdown($) {
 	$unit .= $plural;
 	$unit .= $plural;
 
 
 	# Speak
 	# Speak
-	say('Projector shutdown in about ' . $timeLeft . ' ' . $unit);
+	DMX::say('Projector shutdown in about ' . $timeLeft . ' ' . $unit);
 }
 }