mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 20:24:57 +00:00
Added ConfigWriter class. Updated AV Funciton Driver UI classes to show shutdown prompt when room about to shut down for vacancy.
This commit is contained in:
67
PepperDashEssentials/Config/ConfigWriter.cs
Normal file
67
PepperDashEssentials/Config/ConfigWriter.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Essentials.Core;
|
||||||
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials
|
||||||
|
{
|
||||||
|
public class ConfigWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
public static bool WriteConfig()
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Writing Configuration to file");
|
||||||
|
|
||||||
|
var fileLock = new CCriticalSection();
|
||||||
|
|
||||||
|
|
||||||
|
var filePath = Global.FilePathPrefix + "LocalConfig" + Global.DirectorySeparator + "configurationFile.json";
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write config file: '{0}'", filePath);
|
||||||
|
|
||||||
|
var configData = JsonConvert.SerializeObject(ConfigReader.ConfigObject);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
if (fileLock.TryEnter())
|
||||||
|
{
|
||||||
|
using (StreamWriter sw = new StreamWriter(filePath))
|
||||||
|
{
|
||||||
|
sw.Write(configData);
|
||||||
|
sw.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to enter FileLock");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Config write failed: \r{0}", e);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fileLock != null && !fileLock.Disposed)
|
||||||
|
fileLock.Leave();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,8 @@ namespace PepperDash.Essentials
|
|||||||
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
|
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
|
||||||
// ConsoleAccessLevelEnum.AccessOperator);
|
// ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
|
CrestronConsole.AddNewConsoleCommand(S => { ConfigWriter.WriteConfig(); }, "writeconfig", "writes the current config to a file", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(s =>
|
CrestronConsole.AddNewConsoleCommand(s =>
|
||||||
{
|
{
|
||||||
foreach (var tl in TieLineCollection.Default)
|
foreach (var tl in TieLineCollection.Default)
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
<Compile Include="Configuration ORIGINAL\Factories\DisplayFactory.cs" />
|
<Compile Include="Configuration ORIGINAL\Factories\DisplayFactory.cs" />
|
||||||
<Compile Include="Configuration ORIGINAL\Factories\FactoryHelper.cs" />
|
<Compile Include="Configuration ORIGINAL\Factories\FactoryHelper.cs" />
|
||||||
<Compile Include="Config\ConfigReader.cs" />
|
<Compile Include="Config\ConfigReader.cs" />
|
||||||
|
<Compile Include="Config\ConfigWriter.cs" />
|
||||||
<Compile Include="Config\EssentialsConfig.cs" />
|
<Compile Include="Config\EssentialsConfig.cs" />
|
||||||
<Compile Include="Factory\DeviceFactory.cs" />
|
<Compile Include="Factory\DeviceFactory.cs" />
|
||||||
<Compile Include="Devices\Amplifier.cs" />
|
<Compile Include="Devices\Amplifier.cs" />
|
||||||
|
|||||||
@@ -273,8 +273,6 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CalculateAndSetAcknowledgeExpirationTimeout(ScheduledEvent schEvent, DateTime time1, DateTime time2)
|
void CalculateAndSetAcknowledgeExpirationTimeout(ScheduledEvent schEvent, DateTime time1, DateTime time2)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "time1.Hour = {0}", time1.Hour);
|
Debug.Console(1, this, "time1.Hour = {0}", time1.Hour);
|
||||||
@@ -421,7 +419,7 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for event that enables feature
|
/// Callback for event that enables feature. Enables feature if config property is true
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="SchEvent"></param>
|
/// <param name="SchEvent"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
@@ -437,7 +435,7 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for event that enables feature
|
/// Callback for event that enables feature. Disables feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="SchEvent"></param>
|
/// <param name="SchEvent"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
|
|||||||
@@ -1,468 +1,468 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using PepperDash.Essentials.Room.Config;
|
using PepperDash.Essentials.Room.Config;
|
||||||
|
|
||||||
namespace PepperDash.Essentials
|
namespace PepperDash.Essentials
|
||||||
{
|
{
|
||||||
public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange, IRunRouteAction, IRunDefaultPresentRoute
|
public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange, IRunRouteAction, IRunDefaultPresentRoute
|
||||||
{
|
{
|
||||||
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
|
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
|
||||||
public event SourceInfoChangeHandler CurrentSingleSourceChange;
|
public event SourceInfoChangeHandler CurrentSingleSourceChange;
|
||||||
|
|
||||||
protected override Func<bool> OnFeedbackFunc
|
protected override Func<bool> OnFeedbackFunc
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
var disp = DefaultDisplay as DisplayBase;
|
var disp = DefaultDisplay as DisplayBase;
|
||||||
var val = CurrentSourceInfo != null
|
var val = CurrentSourceInfo != null
|
||||||
&& CurrentSourceInfo.Type == eSourceListItemType.Route
|
&& CurrentSourceInfo.Type == eSourceListItemType.Route
|
||||||
&& disp != null;
|
&& disp != null;
|
||||||
//&& disp.PowerIsOnFeedback.BoolValue;
|
//&& disp.PowerIsOnFeedback.BoolValue;
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override Func<bool> IsWarmingFeedbackFunc
|
protected override Func<bool> IsWarmingFeedbackFunc
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
var disp = DefaultDisplay as DisplayBase;
|
var disp = DefaultDisplay as DisplayBase;
|
||||||
if (disp != null)
|
if (disp != null)
|
||||||
return disp.IsWarmingUpFeedback.BoolValue;
|
return disp.IsWarmingUpFeedback.BoolValue;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override Func<bool> IsCoolingFeedbackFunc
|
protected override Func<bool> IsCoolingFeedbackFunc
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
var disp = DefaultDisplay as DisplayBase;
|
var disp = DefaultDisplay as DisplayBase;
|
||||||
if (disp != null)
|
if (disp != null)
|
||||||
return disp.IsCoolingDownFeedback.BoolValue;
|
return disp.IsCoolingDownFeedback.BoolValue;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EssentialsRoomPropertiesConfig Config { get; private set; }
|
public EssentialsRoomPropertiesConfig Config { get; private set; }
|
||||||
|
|
||||||
public IRoutingSinkWithSwitching DefaultDisplay { get; private set; }
|
public IRoutingSinkWithSwitching DefaultDisplay { get; private set; }
|
||||||
public IRoutingSinkNoSwitching DefaultAudioDevice { get; private set; }
|
public IRoutingSinkNoSwitching DefaultAudioDevice { get; private set; }
|
||||||
public IBasicVolumeControls DefaultVolumeControls { get; private set; }
|
public IBasicVolumeControls DefaultVolumeControls { get; private set; }
|
||||||
|
|
||||||
public bool ExcludeFromGlobalFunctions { get; set; }
|
public bool ExcludeFromGlobalFunctions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The config name of the source list
|
/// The config name of the source list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SourceListKey { get; set; }
|
public string SourceListKey { get; set; }
|
||||||
|
|
||||||
public string DefaultSourceItem { get; set; }
|
public string DefaultSourceItem { get; set; }
|
||||||
|
|
||||||
public ushort DefaultVolume { get; set; }
|
public ushort DefaultVolume { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If room is off, enables power on to last source. Default true
|
/// If room is off, enables power on to last source. Default true
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnablePowerOnToLastSource { get; set; }
|
public bool EnablePowerOnToLastSource { get; set; }
|
||||||
string LastSourceKey;
|
string LastSourceKey;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IBasicVolumeControls CurrentVolumeControls
|
public IBasicVolumeControls CurrentVolumeControls
|
||||||
{
|
{
|
||||||
get { return _CurrentAudioDevice; }
|
get { return _CurrentAudioDevice; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == _CurrentAudioDevice) return;
|
if (value == _CurrentAudioDevice) return;
|
||||||
|
|
||||||
var oldDev = _CurrentAudioDevice;
|
var oldDev = _CurrentAudioDevice;
|
||||||
// derigister this room from the device, if it can
|
// derigister this room from the device, if it can
|
||||||
if (oldDev is IInUseTracking)
|
if (oldDev is IInUseTracking)
|
||||||
(oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio");
|
(oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio");
|
||||||
var handler = CurrentVolumeDeviceChange;
|
var handler = CurrentVolumeDeviceChange;
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange));
|
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange));
|
||||||
_CurrentAudioDevice = value;
|
_CurrentAudioDevice = value;
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange));
|
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange));
|
||||||
// register this room with new device, if it can
|
// register this room with new device, if it can
|
||||||
if (_CurrentAudioDevice is IInUseTracking)
|
if (_CurrentAudioDevice is IInUseTracking)
|
||||||
(_CurrentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio");
|
(_CurrentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IBasicVolumeControls _CurrentAudioDevice;
|
IBasicVolumeControls _CurrentAudioDevice;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The SourceListItem last run - containing names and icons
|
/// The SourceListItem last run - containing names and icons
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SourceListItem CurrentSourceInfo
|
public SourceListItem CurrentSourceInfo
|
||||||
{
|
{
|
||||||
get { return _CurrentSourceInfo; }
|
get { return _CurrentSourceInfo; }
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
if (value == _CurrentSourceInfo) return;
|
if (value == _CurrentSourceInfo) return;
|
||||||
|
|
||||||
var handler = CurrentSingleSourceChange;
|
var handler = CurrentSingleSourceChange;
|
||||||
// remove from in-use tracker, if so equipped
|
// remove from in-use tracker, if so equipped
|
||||||
if(_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
|
if(_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
|
||||||
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
|
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
|
||||||
|
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
handler(this, _CurrentSourceInfo, ChangeType.WillChange);
|
handler(this, _CurrentSourceInfo, ChangeType.WillChange);
|
||||||
|
|
||||||
_CurrentSourceInfo = value;
|
_CurrentSourceInfo = value;
|
||||||
|
|
||||||
// add to in-use tracking
|
// add to in-use tracking
|
||||||
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
|
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
|
||||||
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
|
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
handler(this, _CurrentSourceInfo, ChangeType.DidChange);
|
handler(this, _CurrentSourceInfo, ChangeType.DidChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SourceListItem _CurrentSourceInfo;
|
SourceListItem _CurrentSourceInfo;
|
||||||
|
|
||||||
public string CurrentSourceInfoKey { get; private set; }
|
public string CurrentSourceInfoKey { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
public EssentialsHuddleSpaceRoom(string key, string name, IRoutingSinkWithSwitching defaultDisplay,
|
public EssentialsHuddleSpaceRoom(string key, string name, IRoutingSinkWithSwitching defaultDisplay,
|
||||||
IRoutingSinkNoSwitching defaultAudio, EssentialsRoomPropertiesConfig config)
|
IRoutingSinkNoSwitching defaultAudio, EssentialsRoomPropertiesConfig config)
|
||||||
: base(key, name)
|
: base(key, name)
|
||||||
{
|
{
|
||||||
Config = config;
|
Config = config;
|
||||||
DefaultDisplay = defaultDisplay;
|
DefaultDisplay = defaultDisplay;
|
||||||
DefaultAudioDevice = defaultAudio;
|
DefaultAudioDevice = defaultAudio;
|
||||||
if (defaultAudio is IBasicVolumeControls)
|
if (defaultAudio is IBasicVolumeControls)
|
||||||
DefaultVolumeControls = defaultAudio as IBasicVolumeControls;
|
DefaultVolumeControls = defaultAudio as IBasicVolumeControls;
|
||||||
else if (defaultAudio is IHasVolumeDevice)
|
else if (defaultAudio is IHasVolumeDevice)
|
||||||
DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
|
DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
|
||||||
CurrentVolumeControls = DefaultVolumeControls;
|
CurrentVolumeControls = DefaultVolumeControls;
|
||||||
|
|
||||||
var disp = DefaultDisplay as DisplayBase;
|
var disp = DefaultDisplay as DisplayBase;
|
||||||
if (disp != null)
|
if (disp != null)
|
||||||
{
|
{
|
||||||
// Link power, warming, cooling to display
|
// Link power, warming, cooling to display
|
||||||
disp.PowerIsOnFeedback.OutputChange += (o, a) =>
|
disp.PowerIsOnFeedback.OutputChange += (o, a) =>
|
||||||
{
|
{
|
||||||
if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
|
if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
|
||||||
{
|
{
|
||||||
if (!disp.PowerIsOnFeedback.BoolValue)
|
if (!disp.PowerIsOnFeedback.BoolValue)
|
||||||
CurrentSourceInfo = null;
|
CurrentSourceInfo = null;
|
||||||
OnFeedback.FireUpdate();
|
OnFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
|
disp.IsWarmingUpFeedback.OutputChange += (o, a) =>
|
||||||
{
|
{
|
||||||
IsWarmingUpFeedback.FireUpdate();
|
IsWarmingUpFeedback.FireUpdate();
|
||||||
if (!IsWarmingUpFeedback.BoolValue)
|
if (!IsWarmingUpFeedback.BoolValue)
|
||||||
(DefaultDisplay as IBasicVolumeWithFeedback).SetVolume(DefaultVolume);
|
(DefaultDisplay as IBasicVolumeWithFeedback).SetVolume(DefaultVolume);
|
||||||
};
|
};
|
||||||
disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
|
disp.IsCoolingDownFeedback.OutputChange += (o, a) =>
|
||||||
{
|
{
|
||||||
IsCoolingDownFeedback.FireUpdate();
|
IsCoolingDownFeedback.FireUpdate();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceListKey = "default";
|
SourceListKey = "default";
|
||||||
EnablePowerOnToLastSource = true;
|
EnablePowerOnToLastSource = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void EndShutdown()
|
protected override void EndShutdown()
|
||||||
{
|
{
|
||||||
SetDefaultLevels();
|
SetDefaultLevels();
|
||||||
|
|
||||||
RunDefaultPresentRoute();
|
RunDefaultPresentRoute();
|
||||||
|
|
||||||
CrestronEnvironment.Sleep(1000);
|
CrestronEnvironment.Sleep(1000);
|
||||||
|
|
||||||
RunRouteAction("roomOff");
|
RunRouteAction("roomOff");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Routes the default source item, if any
|
/// Routes the default source item, if any
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override bool RunDefaultPresentRoute()
|
public override bool RunDefaultPresentRoute()
|
||||||
{
|
{
|
||||||
if (DefaultSourceItem == null)
|
if (DefaultSourceItem == null)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Unable to run default present route, DefaultSourceItem is null.");
|
Debug.Console(0, this, "Unable to run default present route, DefaultSourceItem is null.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RunRouteAction(DefaultSourceItem);
|
RunRouteAction(DefaultSourceItem);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="routeKey"></param>
|
/// <param name="routeKey"></param>
|
||||||
public void RunRouteAction(string routeKey)
|
public void RunRouteAction(string routeKey)
|
||||||
{
|
{
|
||||||
RunRouteAction(routeKey, null);
|
RunRouteAction(routeKey, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a source from config list SourceListKey and dynamically build and executes the
|
/// Gets a source from config list SourceListKey and dynamically build and executes the
|
||||||
/// route or commands
|
/// route or commands
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
public void RunRouteAction(string routeKey, Action successCallback)
|
public void RunRouteAction(string routeKey, Action successCallback)
|
||||||
{
|
{
|
||||||
// Run this on a separate thread
|
// Run this on a separate thread
|
||||||
new CTimer(o =>
|
new CTimer(o =>
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Run route action '{0}'", routeKey);
|
Debug.Console(1, this, "Run route action '{0}'", routeKey);
|
||||||
var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
|
var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
|
||||||
if(dict == null)
|
if(dict == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey);
|
Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the list item by it's string key
|
// Try to get the list item by it's string key
|
||||||
if (!dict.ContainsKey(routeKey))
|
if (!dict.ContainsKey(routeKey))
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'",
|
Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'",
|
||||||
routeKey, SourceListKey);
|
routeKey, SourceListKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = dict[routeKey];
|
var item = dict[routeKey];
|
||||||
//Debug.Console(2, this, "Action {0} has {1} steps",
|
//Debug.Console(2, this, "Action {0} has {1} steps",
|
||||||
// item.SourceKey, item.RouteList.Count);
|
// item.SourceKey, item.RouteList.Count);
|
||||||
|
|
||||||
// End usage timer on last source
|
// End usage timer on last source
|
||||||
if (!string.IsNullOrEmpty(LastSourceKey))
|
if (!string.IsNullOrEmpty(LastSourceKey))
|
||||||
{
|
{
|
||||||
var lastSource = dict[LastSourceKey].SourceDevice;
|
var lastSource = dict[LastSourceKey].SourceDevice;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (lastSource != null && lastSource is IUsageTracking)
|
if (lastSource != null && lastSource is IUsageTracking)
|
||||||
(lastSource as IUsageTracking).UsageTracker.EndDeviceUsage();
|
(lastSource as IUsageTracking).UsageTracker.EndDeviceUsage();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "*#* EXCEPTION in end usage tracking (257):\r{0}", e);
|
Debug.Console(1, this, "*#* EXCEPTION in end usage tracking (257):\r{0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's run it
|
// Let's run it
|
||||||
if (routeKey.ToLower() != "roomoff")
|
if (routeKey.ToLower() != "roomoff")
|
||||||
{
|
{
|
||||||
LastSourceKey = routeKey;
|
LastSourceKey = routeKey;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CurrentSourceInfoKey = null;
|
CurrentSourceInfoKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var route in item.RouteList)
|
foreach (var route in item.RouteList)
|
||||||
{
|
{
|
||||||
// if there is a $defaultAll on route, run two separate
|
// if there is a $defaultAll on route, run two separate
|
||||||
if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase))
|
if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// Going to assume a single-path route for now
|
// Going to assume a single-path route for now
|
||||||
var tempVideo = new SourceRouteListItem
|
var tempVideo = new SourceRouteListItem
|
||||||
{
|
{
|
||||||
DestinationKey = "$defaultDisplay",
|
DestinationKey = "$defaultDisplay",
|
||||||
SourceKey = route.SourceKey,
|
SourceKey = route.SourceKey,
|
||||||
Type = eRoutingSignalType.Video
|
Type = eRoutingSignalType.Video
|
||||||
};
|
};
|
||||||
DoRoute(tempVideo);
|
DoRoute(tempVideo);
|
||||||
|
|
||||||
//var tempAudio = new SourceRouteListItem
|
//var tempAudio = new SourceRouteListItem
|
||||||
//{
|
//{
|
||||||
// DestinationKey = "$defaultAudio",
|
// DestinationKey = "$defaultAudio",
|
||||||
// SourceKey = route.SourceKey,
|
// SourceKey = route.SourceKey,
|
||||||
// Type = eRoutingSignalType.Audio
|
// Type = eRoutingSignalType.Audio
|
||||||
//};
|
//};
|
||||||
//DoRoute(tempAudio);
|
//DoRoute(tempAudio);
|
||||||
//continue; -- not sure why this was here
|
//continue; -- not sure why this was here
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DoRoute(route);
|
DoRoute(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start usage timer on routed source
|
// Start usage timer on routed source
|
||||||
if (item.SourceDevice is IUsageTracking)
|
if (item.SourceDevice is IUsageTracking)
|
||||||
{
|
{
|
||||||
(item.SourceDevice as IUsageTracking).UsageTracker.StartDeviceUsage();
|
(item.SourceDevice as IUsageTracking).UsageTracker.StartDeviceUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Set volume control, using default if non provided
|
// Set volume control, using default if non provided
|
||||||
IBasicVolumeControls volDev = null;
|
IBasicVolumeControls volDev = null;
|
||||||
// Handle special cases for volume control
|
// Handle special cases for volume control
|
||||||
if (string.IsNullOrEmpty(item.VolumeControlKey)
|
if (string.IsNullOrEmpty(item.VolumeControlKey)
|
||||||
|| item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
|
|| item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
|
||||||
volDev = DefaultVolumeControls;
|
volDev = DefaultVolumeControls;
|
||||||
else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
|
else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
|
||||||
volDev = DefaultDisplay as IBasicVolumeControls;
|
volDev = DefaultDisplay as IBasicVolumeControls;
|
||||||
// Or a specific device, probably rarely used.
|
// Or a specific device, probably rarely used.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey);
|
var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey);
|
||||||
if (dev is IBasicVolumeControls)
|
if (dev is IBasicVolumeControls)
|
||||||
volDev = dev as IBasicVolumeControls;
|
volDev = dev as IBasicVolumeControls;
|
||||||
else if (dev is IHasVolumeDevice)
|
else if (dev is IHasVolumeDevice)
|
||||||
volDev = (dev as IHasVolumeDevice).VolumeDevice;
|
volDev = (dev as IHasVolumeDevice).VolumeDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (volDev != CurrentVolumeControls)
|
if (volDev != CurrentVolumeControls)
|
||||||
{
|
{
|
||||||
// zero the volume on the device we are leaving.
|
// zero the volume on the device we are leaving.
|
||||||
// Set the volume to default on device we are entering
|
// Set the volume to default on device we are entering
|
||||||
if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
|
if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
|
||||||
{
|
{
|
||||||
var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
||||||
SavedVolumeLevels[vd] = (uint)vd.VolumeLevelFeedback.IntValue;
|
SavedVolumeLevels[vd] = (uint)vd.VolumeLevelFeedback.IntValue;
|
||||||
vd.SetVolume(0);
|
vd.SetVolume(0);
|
||||||
}
|
}
|
||||||
CurrentVolumeControls = volDev;
|
CurrentVolumeControls = volDev;
|
||||||
if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
|
if (ZeroVolumeWhenSwtichingVolumeDevices && CurrentVolumeControls is IBasicVolumeWithFeedback)
|
||||||
{
|
{
|
||||||
var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
var vd = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
||||||
ushort vol = (SavedVolumeLevels.ContainsKey(vd) ? (ushort)SavedVolumeLevels[vd] : DefaultVolume);
|
ushort vol = (SavedVolumeLevels.ContainsKey(vd) ? (ushort)SavedVolumeLevels[vd] : DefaultVolume);
|
||||||
vd.SetVolume(vol);
|
vd.SetVolume(vol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// store the name and UI info for routes
|
// store the name and UI info for routes
|
||||||
if (item.SourceKey == "$off")
|
if (item.SourceKey == "$off")
|
||||||
{
|
{
|
||||||
CurrentSourceInfoKey = routeKey;
|
CurrentSourceInfoKey = routeKey;
|
||||||
CurrentSourceInfo = null;
|
CurrentSourceInfo = null;
|
||||||
}
|
}
|
||||||
else if (item.SourceKey != null)
|
else if (item.SourceKey != null)
|
||||||
{
|
{
|
||||||
CurrentSourceInfoKey = routeKey;
|
CurrentSourceInfoKey = routeKey;
|
||||||
CurrentSourceInfo = item;
|
CurrentSourceInfo = item;
|
||||||
}
|
}
|
||||||
// And finally, set the "control". This will trigger event
|
// And finally, set the "control". This will trigger event
|
||||||
//CurrentControlDevice = DeviceManager.GetDeviceForKey(item.SourceKey) as Device;
|
//CurrentControlDevice = DeviceManager.GetDeviceForKey(item.SourceKey) as Device;
|
||||||
|
|
||||||
OnFeedback.FireUpdate();
|
OnFeedback.FireUpdate();
|
||||||
|
|
||||||
// report back when done
|
// report back when done
|
||||||
if (successCallback != null)
|
if (successCallback != null)
|
||||||
successCallback();
|
successCallback();
|
||||||
|
|
||||||
}, 0); // end of CTimer
|
}, 0); // end of CTimer
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will power the room on with the last-used source
|
/// Will power the room on with the last-used source
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void PowerOnToDefaultOrLastSource()
|
public override void PowerOnToDefaultOrLastSource()
|
||||||
{
|
{
|
||||||
if (!EnablePowerOnToLastSource || LastSourceKey == null)
|
if (!EnablePowerOnToLastSource || LastSourceKey == null)
|
||||||
return;
|
return;
|
||||||
RunRouteAction(LastSourceKey);
|
RunRouteAction(LastSourceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Does what it says
|
/// Does what it says
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void SetDefaultLevels()
|
public override void SetDefaultLevels()
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Restoring default levels");
|
Debug.Console(1, this, "Restoring default levels");
|
||||||
var vc = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
var vc = CurrentVolumeControls as IBasicVolumeWithFeedback;
|
||||||
if (vc != null)
|
if (vc != null)
|
||||||
vc.SetVolume(DefaultVolume);
|
vc.SetVolume(DefaultVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="route"></param>
|
/// <param name="route"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool DoRoute(SourceRouteListItem route)
|
bool DoRoute(SourceRouteListItem route)
|
||||||
{
|
{
|
||||||
IRoutingSinkNoSwitching dest = null;
|
IRoutingSinkNoSwitching dest = null;
|
||||||
|
|
||||||
if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase))
|
if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase))
|
||||||
dest = DefaultAudioDevice;
|
dest = DefaultAudioDevice;
|
||||||
else if (route.DestinationKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
|
else if (route.DestinationKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
|
||||||
dest = DefaultDisplay;
|
dest = DefaultDisplay;
|
||||||
else
|
else
|
||||||
dest = DeviceManager.GetDeviceForKey(route.DestinationKey) as IRoutingSinkNoSwitching;
|
dest = DeviceManager.GetDeviceForKey(route.DestinationKey) as IRoutingSinkNoSwitching;
|
||||||
|
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Cannot route, unknown destination '{0}'", route.DestinationKey);
|
Debug.Console(1, this, "Cannot route, unknown destination '{0}'", route.DestinationKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (route.SourceKey.Equals("$off", StringComparison.OrdinalIgnoreCase))
|
if (route.SourceKey.Equals("$off", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
dest.ReleaseRoute();
|
dest.ReleaseRoute();
|
||||||
if (dest is IPower)
|
if (dest is IPower)
|
||||||
(dest as IPower).PowerOff();
|
(dest as IPower).PowerOff();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var source = DeviceManager.GetDeviceForKey(route.SourceKey) as IRoutingOutputs;
|
var source = DeviceManager.GetDeviceForKey(route.SourceKey) as IRoutingOutputs;
|
||||||
if (source == null)
|
if (source == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Cannot route unknown source '{0}' to {1}", route.SourceKey, route.DestinationKey);
|
Debug.Console(1, this, "Cannot route unknown source '{0}' to {1}", route.SourceKey, route.DestinationKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dest.ReleaseAndMakeRoute(source, route.Type);
|
dest.ReleaseAndMakeRoute(source, route.Type);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void RoomVacatedForTimeoutPeriod(object o)
|
public override void RoomVacatedForTimeoutPeriod(object o)
|
||||||
{
|
{
|
||||||
//Implement this
|
//Implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs "roomOff" action on all rooms not set to ExcludeFromGlobalFunctions
|
/// Runs "roomOff" action on all rooms not set to ExcludeFromGlobalFunctions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void AllRoomsOff()
|
public static void AllRoomsOff()
|
||||||
{
|
{
|
||||||
var allRooms = DeviceManager.AllDevices.Where(d =>
|
var allRooms = DeviceManager.AllDevices.Where(d =>
|
||||||
d is EssentialsHuddleSpaceRoom && !(d as EssentialsHuddleSpaceRoom).ExcludeFromGlobalFunctions);
|
d is EssentialsHuddleSpaceRoom && !(d as EssentialsHuddleSpaceRoom).ExcludeFromGlobalFunctions);
|
||||||
foreach (var room in allRooms)
|
foreach (var room in allRooms)
|
||||||
(room as EssentialsHuddleSpaceRoom).RunRouteAction("roomOff");
|
(room as EssentialsHuddleSpaceRoom).RunRouteAction("roomOff");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Submodule essentials-framework updated: 5c2202723f...bf9115f17b
Reference in New Issue
Block a user