瀏覽代碼

Do play monitoring in state.pl

Zachary Kotlarek 13 年之前
父節點
當前提交
5ed8aa725f
共有 2 個文件被更改,包括 25 次插入 和 25 次删除
  1. 25 13
      dmx/state.pl
  2. 0 12
      plexMonitor/plexMonitor.pl

+ 25 - 13
dmx/state.pl

@@ -18,12 +18,11 @@ sub mtime($);
 # User config
 my $STATE_TIMEOUT = 180;
 my %MON_FILES     = (
-	'PLAYING'     => 'MTIME',
 	'GUI'         => 'MTIME',
 	'MOTION'      => 'MTIME',
 	'PROJECTOR'   => 'STATUS',
 	'AMPLIFIER'   => 'STATUS_NOMTIME',
-	'PLAY_STATUS' => 'STATUS',
+	'PLAYING'     => 'PLAYING',
 	'LIGHTS'      => 'EXISTS',
 	'FAN_CMD'     => 'EXISTS',
 	'RAVE'        => 'EXISTS_OFF',
@@ -63,7 +62,6 @@ my @subscribers = ();
 # State
 my $state      = 'INIT';
 my $stateLast  = $state;
-my $playing    = 0;
 my $updateLast = 0;
 my $pushLast   = 0;
 
@@ -151,20 +149,34 @@ while (1) {
 		# Record the last update
 		if ($file->{'type'} eq '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";
 			}
 		}
 
-		# Grab the new status and save the old one
-		if ($file->{'type'} =~ /^STATUS/) {
-			my $fh;
-			open($fh, $file->{'path'})
-			  or die('Unable to open ' . $file->{'path'} . "\n");
-			my $text = <$fh>;
-			close($fh);
-			if ($text =~ /1/) {
-				$file->{'status'} = 1;
+		# Grab the new status
+		if ($file->{'type'} =~ /^STATUS/ || $file->{'type'} eq 'PLAYING') {
+			my $text = undef();
+			{
+				my $fh;
+				open($fh, $file->{'path'})
+				  or die('Unable to open ' . $file->{'path'} . "\n");
+				local $/;
+				$text = <$fh>;
+				close($fh);
+			}
+
+			if ($file->{'type'} =~ /^STATUS/) {
+				if ($text =~ /1/) {
+					$file->{'status'} = 1;
+				}
+			} else {
+				if ($text =~ /PlayStatus\:Playing/) {
+					$file->{'status'} = 1;
+				}
 			}
 			if ($DEBUG) {
 				print STDERR 'Status: ' . $file->{'name'} . ': ' . $file->{'status'} . "\n";
@@ -208,7 +220,7 @@ while (1) {
 	if ($files{'PROJECTOR'}->{'status'}) {
 
 		# We are always either playing or paused if the projector is on
-		if ($files{'PLAY_STATUS'}->{'status'}) {
+		if ($files{'PLAYING'}->{'status'}) {
 			$state = 'PLAY';
 		} else {
 			$state = 'PAUSE';

+ 0 - 12
plexMonitor/plexMonitor.pl

@@ -75,18 +75,6 @@ do {
 		rename($tmp, $DATA_DIR . '/' . $MODE);
 	}
 
-	# Special handling for PLAYING mode -- it's a bit of a hack, but it saves a lot of code other places
-	if ($changed && $MODE eq 'PLAYING') {
-		my $playing = 0;
-		if ($data =~ /PlayStatus\:Playing/) {
-			$playing = 1;
-		}
-		my ($fh, $tmp) = tempfile($DATA_DIR . '/PLAY_STATUS.XXXXXXXX', 'UNLINK' => 0);
-		print $fh $playing . "\n";
-		close($fh);
-		rename($tmp, $DATA_DIR . '/PLAY_STATUS');
-	}
-
 	# Delay and loop
 	usleep($DELAY);
 } until ($DELAY == 0);