Bladeren bron

New LED tuning

Zachary Kotlarek 11 jaren geleden
bovenliggende
commit
b5ec0e4c03
4 gewijzigde bestanden met toevoegingen van 50 en 35 verwijderingen
  1. 3 3
      dmx/DMX.pm
  2. 2 2
      dmx/channels.txt
  3. 32 22
      dmx/garage_leds.pl
  4. 13 8
      dmx/leds.pl

+ 3 - 3
dmx/DMX.pm

@@ -28,9 +28,9 @@ my %CHANNEL_ADJ = (
 	'13' => 1.00,
 	'13' => 1.00,
 	'14' => 1.14,
 	'14' => 1.14,
 	'15' => 1.19,
 	'15' => 1.19,
-	'21' => 1.00,
-	'22' => 1.14,
-	'23' => 1.19,
+	'21' => 1.19,
+	'22' => 1.23,
+	'23' => 1.00,
 );
 );
 
 
 # Sanity check
 # Sanity check

+ 2 - 2
dmx/channels.txt

@@ -20,7 +20,7 @@
 #	18 => <Unused>
 #	18 => <Unused>
 #	19 => <Unused> (Swtich)
 #	19 => <Unused> (Swtich)
 #	20 => Oil Heater (Switch)
 #	20 => Oil Heater (Switch)
-#	21 => Garage Red
-#	22 => Garage Green
+#	21 => Garage Green (+19%)
+#	22 => Garage Red (+23%)
 #	23 => Garage Blue
 #	23 => Garage Blue
 #	24 => Garage Shelf
 #	24 => Garage Shelf

+ 32 - 22
dmx/garage_leds.pl

@@ -1,6 +1,8 @@
 #!/usr/bin/perl
 #!/usr/bin/perl
 use strict;
 use strict;
 use warnings;
 use warnings;
+use POSIX;
+use Math::Random;
 
 
 # Local modules
 # Local modules
 use Cwd qw(abs_path);
 use Cwd qw(abs_path);
@@ -9,7 +11,7 @@ use lib dirname(abs_path($0));
 use DMX;
 use DMX;
 
 
 # User config
 # User config
-my $COLOR_TIMEOUT  = 30;
+my $COLOR_TIMEOUT  = 10;
 my $COLOR_TIME_MIN = int($COLOR_TIMEOUT / 2);
 my $COLOR_TIME_MIN = int($COLOR_TIMEOUT / 2);
 my %COLOR_VAR      = (
 my %COLOR_VAR      = (
 	'PREMOTION'  => 0.75,
 	'PREMOTION'  => 0.75,
@@ -25,9 +27,9 @@ my %DIM                = (
 			{ 'channel' => 23, 'value' => 0,   'time' => 60000 },
 			{ 'channel' => 23, 'value' => 0,   'time' => 60000 },
 	],
 	],
 	'PREMOTION'  => [
 	'PREMOTION'  => [
-			{ 'channel' => 21, 'value' => 32,  'time' => 2500 },
-			{ 'channel' => 22, 'value' => 32,  'time' => 2500 },
-			{ 'channel' => 23, 'value' => 32,  'time' => 2500 },
+			{ 'channel' => 21, 'value' => 5,   'time' => 2500 },
+			{ 'channel' => 22, 'value' => 5,   'time' => 2500 },
+			{ 'channel' => 23, 'value' => 5,   'time' => 2500 },
 			],
 			],
 	'MOTION'     => [
 	'MOTION'     => [
 			{ 'channel' => 21, 'value' => 128,  'time' => 750 },
 			{ 'channel' => 21, 'value' => 128,  'time' => 750 },
@@ -35,9 +37,9 @@ my %DIM                = (
 			{ 'channel' => 23, 'value' => 128,  'time' => 750 },
 			{ 'channel' => 23, 'value' => 128,  'time' => 750 },
 	],
 	],
 	'POSTMOTION' => [
 	'POSTMOTION' => [
-			{ 'channel' => 21, 'value' => 32,   'time' => $POSTMOTION_TIMEOUT * 1000 },
-			{ 'channel' => 22, 'value' => 32,   'time' => $POSTMOTION_TIMEOUT * 1000 },
-			{ 'channel' => 23, 'value' => 32,   'time' => $POSTMOTION_TIMEOUT * 1000 },
+			{ 'channel' => 21, 'value' => 8,   'time' => $POSTMOTION_TIMEOUT * 1000 },
+			{ 'channel' => 22, 'value' => 8,   'time' => $POSTMOTION_TIMEOUT * 1000 },
+			{ 'channel' => 23, 'value' => 8,   'time' => $POSTMOTION_TIMEOUT * 1000 },
 	],
 	],
 	'BRIGHT'     => [
 	'BRIGHT'     => [
 			{ 'channel' => 21, 'value' => 255,  'time' => 1000 },
 			{ 'channel' => 21, 'value' => 255,  'time' => 1000 },
@@ -45,9 +47,9 @@ my %DIM                = (
 			{ 'channel' => 23, 'value' => 255,  'time' => 1000 },
 			{ 'channel' => 23, 'value' => 255,  'time' => 1000 },
 	],
 	],
 	'ERROR'      => [
 	'ERROR'      => [
-			{ 'channel' => 21, 'value' => 144,  'time' => 100 },
+			{ 'channel' => 21, 'value' => 112,  'time' => 100 },
 			{ 'channel' => 22, 'value' => 255,  'time' => 100 },
 			{ 'channel' => 22, 'value' => 255,  'time' => 100 },
-			{ 'channel' => 23, 'value' => 144,  'time' => 100 },
+			{ 'channel' => 23, 'value' => 112,  'time' => 100 },
 	],
 	],
 );
 );
 
 
@@ -74,16 +76,16 @@ if ($DELAY > $COLOR_TIMEOUT / 2) {
 }
 }
 
 
 # State
 # State
-my $state      = 'OFF';
-my $stateLast  = $state;
-my %exists     = ();
-my %mtime      = ();
-my $pushLast   = 0;
-my $pullLast   = time();
-my $update     = 0;
-my $lastMotion = 0;
+my $state       = 'OFF';
+my $stateLast   = $state;
+my %exists      = ();
+my %mtime       = ();
+my $pushLast    = 0;
+my $pullLast    = time();
+my $update      = 0;
+my $lastMotion  = 0;
 my @COLOR       = ();
 my @COLOR       = ();
-my $colorChange = time();
+my $colorChange = 0;
 
 
 # Always force lights into ERROR at launch
 # Always force lights into ERROR at launch
 $state = 'ERROR';
 $state = 'ERROR';
@@ -135,7 +137,15 @@ while (1) {
 	$state = $newState;
 	$state = $newState;
 
 
 	# Color changes
 	# Color changes
-	if ($COLOR_VAR{$state} && time() - $colorChange > $COLOR_TIMEOUT) {
+	if ($COLOR_VAR{$state}) {
+		print STDERR "State is color eligible\n";
+	}
+	if ($now - $colorChange > $COLOR_TIMEOUT) {
+		print STDERR "Time is color eligibile\n";
+	} else {
+		print STDERR "Time to color change: " . ($now - $colorChange) . ' (' . $COLOR_TIMEOUT . ")\n";
+	}
+	if ($COLOR_VAR{$state} && $now - $colorChange > $COLOR_TIMEOUT) {
 		@COLOR = ();
 		@COLOR = ();
 
 
 		# Grab the default (white) data
 		# Grab the default (white) data
@@ -158,7 +168,7 @@ while (1) {
 
 
 		# Update
 		# Update
 		$update      = 1;
 		$update      = 1;
-		$colorChange = time();
+		$colorChange = $now;
 		if ($DEBUG) {
 		if ($DEBUG) {
 			print STDERR "New color\n";
 			print STDERR "New color\n";
 		}
 		}
@@ -189,7 +199,7 @@ while (1) {
 				print STDERR "Reset color sequence\n";
 				print STDERR "Reset color sequence\n";
 			}
 			}
 			@COLOR       = ();
 			@COLOR       = ();
-			$colorChange = time() + $COLOR_TIME_MIN;
+			$colorChange = $now + $COLOR_TIME_MIN;
 		}
 		}
 
 
 		# Select a data set (color or standard)
 		# Select a data set (color or standard)
@@ -203,7 +213,7 @@ while (1) {
 		}
 		}
 
 
 		# Update
 		# Update
-		DMX::applyDataset($DIM{$state}, $state, $OUTPUT_FILE);
+		DMX::applyDataset(\@data_set, $local_state, $OUTPUT_FILE);
 
 
 		# Update the push time
 		# Update the push time
 		$pushLast = $now;
 		$pushLast = $now;

+ 13 - 8
dmx/leds.pl

@@ -93,7 +93,7 @@ my $pushLast    = 0;
 my $pullLast    = time();
 my $pullLast    = time();
 my $update      = 0;
 my $update      = 0;
 my @COLOR       = ();
 my @COLOR       = ();
-my $colorChange = time();
+my $colorChange = 0;
 
 
 # Always force lights into ERROR at launch
 # Always force lights into ERROR at launch
 $state = 'ERROR';
 $state = 'ERROR';
@@ -111,13 +111,18 @@ while (1) {
 
 
 	# Wait for state updates
 	# Wait for state updates
 	my $cmdState = DMX::readState($DELAY, \%exists, undef(), \%VALID);
 	my $cmdState = DMX::readState($DELAY, \%exists, undef(), \%VALID);
+
+	# Avoid repeated calls to time()
+	my $now = time();
+
+	# Record only valid states
 	if (defined($cmdState)) {
 	if (defined($cmdState)) {
 		$newState = $cmdState;
 		$newState = $cmdState;
-		$pullLast = time();
+		$pullLast = $now;
 	}
 	}
 
 
 	# Die if we don't see regular updates
 	# Die if we don't see regular updates
-	if (time() - $pullLast > $PULL_TIMEOUT) {
+	if ($now - $pullLast > $PULL_TIMEOUT) {
 		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
 		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
 	}
 	}
 
 
@@ -144,7 +149,7 @@ while (1) {
 	$state = $newState;
 	$state = $newState;
 
 
 	# Color changes
 	# Color changes
-	if ($COLOR_VAR{$state} && time() - $colorChange > $COLOR_TIMEOUT) {
+	if ($COLOR_VAR{$state} && $now - $colorChange > $COLOR_TIMEOUT) {
 		@COLOR = ();
 		@COLOR = ();
 
 
 		# Grab the default (white) data
 		# Grab the default (white) data
@@ -167,14 +172,14 @@ while (1) {
 
 
 		# Update
 		# Update
 		$update      = 1;
 		$update      = 1;
-		$colorChange = time();
+		$colorChange = $now;
 		if ($DEBUG) {
 		if ($DEBUG) {
 			print STDERR "New color\n";
 			print STDERR "New color\n";
 		}
 		}
 	}
 	}
 
 
 	# Force updates on a periodic basis
 	# Force updates on a periodic basis
-	if (!$update && time() - $pushLast > $PUSH_TIMEOUT) {
+	if (!$update && $now - $pushLast > $PUSH_TIMEOUT) {
 		if ($DEBUG) {
 		if ($DEBUG) {
 			print STDERR "Forcing periodic update\n";
 			print STDERR "Forcing periodic update\n";
 		}
 		}
@@ -198,7 +203,7 @@ while (1) {
 				print STDERR "Reset color sequence\n";
 				print STDERR "Reset color sequence\n";
 			}
 			}
 			@COLOR       = ();
 			@COLOR       = ();
-			$colorChange = time() + $COLOR_TIME_MIN;
+			$colorChange = $now + $COLOR_TIME_MIN;
 		}
 		}
 
 
 		# Select a data set (color or standard)
 		# Select a data set (color or standard)
@@ -215,7 +220,7 @@ while (1) {
 		DMX::applyDataset(\@data_set, $local_state, $OUTPUT_FILE);
 		DMX::applyDataset(\@data_set, $local_state, $OUTPUT_FILE);
 
 
 		# Update the push time
 		# Update the push time
-		$pushLast = time();
+		$pushLast = $now;
 
 
 		# Clear the update flag
 		# Clear the update flag
 		$update = 0;
 		$update = 0;