소스 검색

Better overrate command protection

Zachary Kotlarek 13 년 전
부모
커밋
3f9fedead7
1개의 변경된 파일과 15개의 추가작업 그리고 1개의 파일을 삭제
  1. 15 1
      dmx/projectorPower.pl

+ 15 - 1
dmx/projectorPower.pl

@@ -13,6 +13,7 @@ use DMX;
 my $TIMEOUT   = 900;
 my $TIMEOUT   = 900;
 my $COUNTDOWN = 300;
 my $COUNTDOWN = 300;
 my $OFF_DELAY = 15;
 my $OFF_DELAY = 15;
+my $CMD_DELAY = 5;
 
 
 # App config
 # App config
 my $DATA_DIR     = DMX::dataDir();
 my $DATA_DIR     = DMX::dataDir();
@@ -180,6 +181,17 @@ while (1) {
 
 
 	# Only allow updates to "ON" or "OFF" -- the projector knows no other states
 	# Only allow updates to "ON" or "OFF" -- the projector knows no other states
 	if ($update && ($state ne 'ON' && $state ne 'OFF')) {
 	if ($update && ($state ne 'ON' && $state ne 'OFF')) {
+		if ($DEBUG) {
+			print STDERR 'Ignoring update state other than ON/OFF: ' . $state . "\n";
+		}
+		$update = 0;
+	}
+
+	# Only allow updates every few seconds
+	if ($update && time() < $pushLast + $CMD_DELAY) {
+		if ($DEBUG) {
+			print STDERR 'Ignoring overrate update: ' . $state . "\n";
+		}
 		$update = 0;
 		$update = 0;
 	}
 	}
 
 
@@ -192,10 +204,12 @@ while (1) {
 		}
 		}
 
 
 		# Send master power state
 		# Send master power state
-		say('Projector ' . $state);
 		$proj->send($state)
 		$proj->send($state)
 		  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
+		say('Projector ' . $state);
+
 		# No output file
 		# No output file
 
 
 		# Update the push time
 		# Update the push time