소스 검색

First pass at VR power control

Zachary Kotlarek 10 년 전
부모
커밋
33ae116f38
4개의 변경된 파일과 135개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 1
      dmx/channels.txt
  2. 24 0
      dmx/launchd/com.uberzach.ola.vr.plist
  3. 1 1
      dmx/reset.sh
  4. 105 0
      dmx/vr.pl

+ 5 - 1
dmx/channels.txt

@@ -11,7 +11,7 @@
 #       9  => Behind screen (track)
 #       10 => Behind screen (LED)
 #       11 => Fan (Switch)
-#       12 => <Unused> (Switch)
+#       12 => VR Front (Switch)
 #	13 => Blue
 #	14 => Red (+14%)
 #	15 => Green (+19%)
@@ -24,3 +24,7 @@
 #	22 => Garage Red (+23%)
 #	23 => Garage Blue
 #	24 => Garage Shelf
+#	64 => Rumble
+#	65 => <Unused>
+#	66 => VR Back (Switch)
+#	67 => <Unused> (Switch)

+ 24 - 0
dmx/launchd/com.uberzach.ola.vr.plist

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>LimitLoadToSessionType</key>
+	<string>Aqua</string>
+	<key>RunAtLoad</key>
+	<true/>
+	<key>Label</key>
+	<string>com.uberzach.ola.vr</string>
+	<key>KeepAlive</key>
+	<dict>
+		<key>OtherJobEnabled</key>
+		<dict>
+			<key>com.uberzach.ola.dmx</key>
+			<true/>
+		</dict>
+	</dict>
+	<key>ProgramArguments</key>
+	<array>
+		<string>/Users/tv/bin/video/dmx/vr.pl</string>
+	</array>
+</dict>
+</plist>

+ 1 - 1
dmx/reset.sh

@@ -1,5 +1,5 @@
 #!/bin/bash
-PROCS="amplifierPower.pl audio.pl bias.pl color.pl debug.pl door.pl fan.pl garage.pl garage_leds.pl garage_shelf.pl leds.pl oil.pl overhead.pl projectorPower.pl rave.pl rifftrax.pl rope.pl frontApp stairs.pl announce.pl rumbleCtl.pl HDMIctrl.pl"
+PROCS="amplifierPower.pl audio.pl bias.pl color.pl debug.pl door.pl fan.pl garage.pl garage_leds.pl garage_shelf.pl leds.pl oil.pl overhead.pl projectorPower.pl rave.pl rifftrax.pl rope.pl frontApp stairs.pl announce.pl rumbleCtl.pl HDMIctrl.pl vr.pl"
 
 # Find the PID for each named process
 PIDS=""

+ 105 - 0
dmx/vr.pl

@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+# Local modules
+use Cwd qw(abs_path);
+use File::Basename qw(dirname);
+use lib dirname(abs_path($0));
+use DMX;
+
+# User config
+my %DIM = (
+	'OFF' => [ { 'channel' => 12, 'value' => 0,   'time' => 0 }, { 'channel' => 66, 'value' => 0,   'time' => 0 }, ],
+	'ON'  => [ { 'channel' => 12, 'value' => 255, 'time' => 0 }, { 'channel' => 66, 'value' => 255, 'time' => 0 }, ],
+);
+
+# App config
+my $DATA_DIR     = DMX::dataDir();
+my $STATE_SOCK   = 'VR';
+my $OUTPUT_FILE  = $DATA_DIR . $STATE_SOCK;
+my $PUSH_TIMEOUT = 20;
+my $PULL_TIMEOUT = $PUSH_TIMEOUT * 3;
+my $DELAY        = $PULL_TIMEOUT / 2;
+
+# Debug
+my $DEBUG = 0;
+if ($ENV{'DEBUG'}) {
+	$DEBUG = 1;
+}
+
+# State
+my $state       = 'OFF';
+my $stateLast   = $state;
+my $masterState = 'OFF';
+my %exists      = ();
+my %mtime       = ();
+my $pushLast    = 0;
+my $pullLast    = time();
+my $update      = 0;
+
+# Always force the heater into OFF at launch
+$state = 'OFF';
+DMX::applyDataset($DIM{$state}, $state, $OUTPUT_FILE);
+
+# Sockets
+DMX::stateSocket($STATE_SOCK);
+DMX::stateSubscribe($STATE_SOCK);
+
+# Loop forever
+while (1) {
+
+	# Wait for state updates
+	my $cmdState = DMX::readState($DELAY, \%exists, \%mtime, undef());
+
+	# Avoid repeated calls to time()
+	my $now = time();
+
+	# Record only valid states
+	if (defined($cmdState)) {
+		$masterState = $cmdState;
+		$pullLast    = $now;
+	}
+
+	# Die if we don't see regular updates
+	if ($now - $pullLast > $PULL_TIMEOUT) {
+		die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
+	}
+
+	# Calculate the new state
+	$stateLast = $state;
+	if ($exists{'GAME'}) {
+		$state = 'ON';
+	} else {
+		$state = 'OFF';
+	}
+
+	# Force updates on a periodic basis
+	if (!$update && $now - $pushLast > $PUSH_TIMEOUT) {
+		if ($DEBUG) {
+			print STDERR "Forcing periodic update\n";
+		}
+		$update = 1;
+	}
+
+	# Force updates on any state change
+	if (!$update && $stateLast ne $state) {
+		if ($DEBUG) {
+			print STDERR 'State change: ' . $stateLast . ' => ' . $state . "\n";
+		}
+		$update = 1;
+	}
+
+	# Update the DMX chain
+	if ($update) {
+
+		# Update
+		DMX::applyDataset($DIM{$state}, $state, $OUTPUT_FILE);
+
+		# Update the push time
+		$pushLast = $now;
+
+		# Clear the update flag
+		$update = 0;
+	}
+}