Merge pull request #144 from PepperDash/feature/update-Display-Joinmap

resolves #143 - Joinmap and Bridge updated
This commit is contained in:
Neil Dorin
2020-05-05 16:49:03 -06:00
committed by GitHub
4 changed files with 490 additions and 521 deletions

View File

@@ -1,117 +1,77 @@
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.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Bridges namespace PepperDash.Essentials.Core.Bridges
{ {
public class DisplayControllerJoinMap : JoinMapBase public class DisplayControllerJoinMap : JoinMapBaseAdvanced
{ {
#region Digitals [JoinName("Name")]
/// <summary> public JoinDataComplete Name = new JoinDataComplete(new JoinData() { JoinNumber = 1, JoinSpan = 1 },
/// Turns the display off and reports power off feedback new JoinMetadata() { Label = "Name", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Serial });
/// </summary>
public uint PowerOff { get; set; } [JoinName("PowerOff")]
/// <summary> public JoinDataComplete PowerOff = new JoinDataComplete(new JoinData() { JoinNumber = 1, JoinSpan = 1 },
/// Turns the display on and repots power on feedback new JoinMetadata() { Label = "Power Off", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint PowerOn { get; set; } [JoinName("PowerOn")]
/// <summary> public JoinDataComplete PowerOn = new JoinDataComplete(new JoinData() { JoinNumber = 2, JoinSpan = 1 },
/// Indicates that the display device supports two way communication when high new JoinMetadata() { Label = "Power On", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint IsTwoWayDisplay { get; set; } [JoinName("IsTwoWayDisplay")]
/// <summary> public JoinDataComplete IsTwoWayDisplay = new JoinDataComplete(new JoinData() { JoinNumber = 3, JoinSpan = 1 },
/// Increments the volume while high new JoinMetadata() { Label = "Is Two Way Display", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint VolumeUp { get; set; } [JoinName("VolumeUp")]
/// <summary> public JoinDataComplete VolumeUp = new JoinDataComplete(new JoinData() { JoinNumber = 5, JoinSpan = 1 },
/// Decrements teh volume while high new JoinMetadata() { Label = "Volume Up", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint VolumeDown { get; set; } [JoinName("VolumeLevel")]
/// <summary> public JoinDataComplete VolumeLevel = new JoinDataComplete(new JoinData() { JoinNumber = 5, JoinSpan = 1 },
/// Toggles the mute state. Feedback is high when volume is muted new JoinMetadata() { Label = "Volume Level", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Analog });
/// </summary>
public uint VolumeMute { get; set; } [JoinName("VolumeDown")]
/// <summary> public JoinDataComplete VolumeDown = new JoinDataComplete(new JoinData() { JoinNumber = 6, JoinSpan = 1 },
/// Range of digital joins to select inputs and report current input as feedback new JoinMetadata() { Label = "Volume Down", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint InputSelectOffset { get; set; } [JoinName("VolumeMute")]
/// <summary> public JoinDataComplete VolumeMute = new JoinDataComplete(new JoinData() { JoinNumber = 7, JoinSpan = 1 },
/// Range of digital joins to report visibility for input buttons new JoinMetadata() { Label = "Volume Mute", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint ButtonVisibilityOffset { get; set; } [JoinName("VolumeMuteOn")]
/// <summary> public JoinDataComplete VolumeMuteOn = new JoinDataComplete(new JoinData() { JoinNumber = 8, JoinSpan = 1 },
/// High if the device is online new JoinMetadata() { Label = "Volume Mute On", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Digital });
/// </summary>
public uint IsOnline { get; set; } [JoinName("VolumeMuteOff")]
#endregion public JoinDataComplete VolumeMuteOff = new JoinDataComplete(new JoinData() { JoinNumber = 9, JoinSpan = 1 },
new JoinMetadata() { Label = "Volume Mute Off", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Digital });
#region Analogs
/// <summary> [JoinName("InputSelectOffset")]
/// Analog join to set the input and report current input as feedback public JoinDataComplete InputSelectOffset = new JoinDataComplete(new JoinData() { JoinNumber = 11, JoinSpan = 10 },
/// </summary> new JoinMetadata() { Label = "Input Select", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Digital });
public uint InputSelect { get; set; }
/// <summary> [JoinName("InputNamesOffset")]
/// Sets the volume level and reports the current level as feedback public JoinDataComplete InputNamesOffset = new JoinDataComplete(new JoinData() { JoinNumber = 11, JoinSpan = 10 },
/// </summary> new JoinMetadata() { Label = "Input Names Offset", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Serial });
public uint VolumeLevel { get; set; }
#endregion [JoinName("InputSelect")]
public JoinDataComplete InputSelect = new JoinDataComplete(new JoinData() { JoinNumber = 11, JoinSpan = 1 },
#region Serials new JoinMetadata() { Label = "Input Select", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.Analog });
/// <summary>
/// Reports the name of the display as defined in config as feedback [JoinName("ButtonVisibilityOffset")]
/// </summary> public JoinDataComplete ButtonVisibilityOffset = new JoinDataComplete(new JoinData() { JoinNumber = 41, JoinSpan = 10 },
public uint Name { get; set; } new JoinMetadata() { Label = "Button Visibility Offset", JoinCapabilities = eJoinCapabilities.ToFromSIMPL, JoinType = eJoinType.DigitalSerial });
/// <summary>
/// Range of serial joins that reports the names of the inputs as feedback [JoinName("IsOnline")]
/// </summary> public JoinDataComplete IsOnline = new JoinDataComplete(new JoinData() { JoinNumber = 50, JoinSpan = 1 },
public uint InputNamesOffset { get; set; } new JoinMetadata() { Label = "Is Online", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital });
#endregion
public DisplayControllerJoinMap(uint joinStart)
public DisplayControllerJoinMap() : base(joinStart, typeof(CameraControllerJoinMap))
{ {
// Digital }
IsOnline = 50; }
PowerOff = 1;
PowerOn = 2;
IsTwoWayDisplay = 3;
VolumeUp = 5;
VolumeDown = 6;
VolumeMute = 7;
ButtonVisibilityOffset = 40;
InputSelectOffset = 10;
// Analog
InputSelect = 11;
VolumeLevel = 5;
// Serial
Name = 1;
InputNamesOffset = 10;
}
public override void OffsetJoinNumbers(uint joinStart)
{
var joinOffset = joinStart - 1;
IsOnline = IsOnline + joinOffset;
PowerOff = PowerOff + joinOffset;
PowerOn = PowerOn + joinOffset;
IsTwoWayDisplay = IsTwoWayDisplay + joinOffset;
ButtonVisibilityOffset = ButtonVisibilityOffset + joinOffset;
Name = Name + joinOffset;
InputNamesOffset = InputNamesOffset + joinOffset;
InputSelectOffset = InputSelectOffset + joinOffset;
InputSelect = InputSelect + joinOffset;
VolumeUp = VolumeUp + joinOffset;
VolumeDown = VolumeDown + joinOffset;
VolumeMute = VolumeMute + joinOffset;
VolumeLevel = VolumeLevel + joinOffset;
}
}
} }

View File

@@ -1,11 +1,11 @@
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.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Bridges namespace PepperDash.Essentials.Core.Bridges
{ {
public class IBasicCommunicationJoinMap : JoinMapBaseAdvanced public class IBasicCommunicationJoinMap : JoinMapBaseAdvanced
{ {
@@ -38,5 +38,5 @@ namespace PepperDash.Essentials.Core.Bridges
: base(joinStart, typeof(IBasicCommunicationJoinMap)) : base(joinStart, typeof(IBasicCommunicationJoinMap))
{ {
} }
} }
} }

View File

@@ -1,124 +1,124 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp.CrestronSockets; using Crestron.SimplSharp.CrestronSockets;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Devices; using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports /// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
/// </summary> /// </summary>
[Description("Generic communication wrapper class for any IBasicCommunication type")] [Description("Generic communication wrapper class for any IBasicCommunication type")]
public class GenericComm : ReconfigurableBridgableDevice public class GenericComm : ReconfigurableBridgableDevice
{ {
EssentialsControlPropertiesConfig PropertiesConfig; EssentialsControlPropertiesConfig PropertiesConfig;
public IBasicCommunication CommPort { get; private set; } public IBasicCommunication CommPort { get; private set; }
public GenericComm(DeviceConfig config) public GenericComm(DeviceConfig config)
: base(config) : base(config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
CommPort = CommFactory.CreateCommForDevice(config);
}
public static IKeyed BuildDevice(DeviceConfig dc)
{
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc);
}
public void SetPortConfig(string portConfig)
{
// TODO: Deserialize new EssentialsControlPropertiesConfig and handle as necessary
try
{
PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
(portConfig);
}
catch (Exception e)
{
Debug.Console(2, this, "Error deserializing port config: {0}", e);
}
}
protected override void CustomSetConfig(DeviceConfig config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
ConfigWriter.UpdateDeviceConfig(config);
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{ {
var joinMap = new IBasicCommunicationJoinMap(joinStart); PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); CommPort = CommFactory.CreateCommForDevice(config);
if (!string.IsNullOrEmpty(joinMapSerialized)) }
joinMap = JsonConvert.DeserializeObject<IBasicCommunicationJoinMap>(joinMapSerialized);
public static IKeyed BuildDevice(DeviceConfig dc)
if (CommPort == null) {
{ Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
Debug.Console(1, this, "Unable to link device '{0}'. CommPort is null", Key); return new GenericComm(dc);
return; }
}
public void SetPortConfig(string portConfig)
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); {
// TODO: Deserialize new EssentialsControlPropertiesConfig and handle as necessary
// this is a permanent event handler. This cannot be -= from event try
CommPort.TextReceived += (s, a) => {
{ PropertiesConfig = JsonConvert.DeserializeObject<EssentialsControlPropertiesConfig>
Debug.Console(2, this, "RX: {0}", a.Text); (portConfig);
trilist.SetString(joinMap.TextReceived.JoinNumber, a.Text); }
catch (Exception e)
{
Debug.Console(2, this, "Error deserializing port config: {0}", e);
}
}
protected override void CustomSetConfig(DeviceConfig config)
{
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
ConfigWriter.UpdateDeviceConfig(config);
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
var joinMap = new IBasicCommunicationJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<IBasicCommunicationJoinMap>(joinMapSerialized);
if (CommPort == null)
{
Debug.Console(1, this, "Unable to link device '{0}'. CommPort is null", Key);
return;
}
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
// this is a permanent event handler. This cannot be -= from event
CommPort.TextReceived += (s, a) =>
{
Debug.Console(2, this, "RX: {0}", a.Text);
trilist.SetString(joinMap.TextReceived.JoinNumber, a.Text);
}; };
trilist.SetStringSigAction(joinMap.SendText.JoinNumber, s => CommPort.SendText(s)); trilist.SetStringSigAction(joinMap.SendText.JoinNumber, s => CommPort.SendText(s));
trilist.SetStringSigAction(joinMap.SetPortConfig.JoinNumber, SetPortConfig); trilist.SetStringSigAction(joinMap.SetPortConfig.JoinNumber, SetPortConfig);
var sComm = this as ISocketStatus; var sComm = this as ISocketStatus;
if (sComm == null) return; if (sComm == null) return;
sComm.ConnectionChange += (s, a) => sComm.ConnectionChange += (s, a) =>
{ {
trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)(a.Client.ClientStatus)); trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)(a.Client.ClientStatus));
trilist.SetBool(joinMap.Connected.JoinNumber, a.Client.ClientStatus == trilist.SetBool(joinMap.Connected.JoinNumber, a.Client.ClientStatus ==
SocketStatus.SOCKET_STATUS_CONNECTED); SocketStatus.SOCKET_STATUS_CONNECTED);
}; };
trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, b => trilist.SetBoolSigAction(joinMap.Connect.JoinNumber, b =>
{ {
if (b) if (b)
{ {
sComm.Connect(); sComm.Connect();
} }
else else
{ {
sComm.Disconnect(); sComm.Disconnect();
} }
}); });
} }
} }
public class GenericCommFactory : EssentialsDeviceFactory<GenericComm> public class GenericCommFactory : EssentialsDeviceFactory<GenericComm>
{ {
public GenericCommFactory() public GenericCommFactory()
{ {
TypeNames = new List<string>() { "genericComm" }; TypeNames = new List<string>() { "genericComm" };
} }
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
return new GenericComm(dc); return new GenericComm(dc);
} }
} }
} }

View File

@@ -1,281 +1,290 @@
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 Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM;
using Crestron.SimplSharpPro.DM.Endpoints; using Crestron.SimplSharpPro.DM.Endpoints;
using Crestron.SimplSharpPro.DM.Endpoints.Transmitters; using Crestron.SimplSharpPro.DM.Endpoints.Transmitters;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public abstract class DisplayBase : EssentialsBridgeableDevice, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling, IUsageTracking public abstract class DisplayBase : EssentialsBridgeableDevice, IHasFeedback, IRoutingSinkWithSwitching, IPower, IWarmingCooling, IUsageTracking
{ {
public event SourceInfoChangeHandler CurrentSourceChange; public event SourceInfoChangeHandler CurrentSourceChange;
public string CurrentSourceInfoKey { get; set; } public string CurrentSourceInfoKey { get; set; }
public SourceListItem CurrentSourceInfo public SourceListItem CurrentSourceInfo
{ {
get get
{ {
return _CurrentSourceInfo; return _CurrentSourceInfo;
} }
set set
{ {
if (value == _CurrentSourceInfo) return; if (value == _CurrentSourceInfo) return;
var handler = CurrentSourceChange; var handler = CurrentSourceChange;
if (handler != null) if (handler != null)
handler(_CurrentSourceInfo, ChangeType.WillChange); handler(_CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value; _CurrentSourceInfo = value;
if (handler != null) if (handler != null)
handler(_CurrentSourceInfo, ChangeType.DidChange); handler(_CurrentSourceInfo, ChangeType.DidChange);
} }
} }
SourceListItem _CurrentSourceInfo; SourceListItem _CurrentSourceInfo;
public BoolFeedback PowerIsOnFeedback { get; protected set; } public BoolFeedback PowerIsOnFeedback { get; protected set; }
public BoolFeedback IsCoolingDownFeedback { get; protected set; } public BoolFeedback IsCoolingDownFeedback { get; protected set; }
public BoolFeedback IsWarmingUpFeedback { get; private set; } public BoolFeedback IsWarmingUpFeedback { get; private set; }
public UsageTracking UsageTracker { get; set; } public UsageTracking UsageTracker { get; set; }
public uint WarmupTime { get; set; } public uint WarmupTime { get; set; }
public uint CooldownTime { get; set; } public uint CooldownTime { get; set; }
/// <summary> /// <summary>
/// Bool Func that will provide a value for the PowerIsOn Output. Must be implemented /// Bool Func that will provide a value for the PowerIsOn Output. Must be implemented
/// by concrete sub-classes /// by concrete sub-classes
/// </summary> /// </summary>
abstract protected Func<bool> PowerIsOnFeedbackFunc { get; } abstract protected Func<bool> PowerIsOnFeedbackFunc { get; }
abstract protected Func<bool> IsCoolingDownFeedbackFunc { get; } abstract protected Func<bool> IsCoolingDownFeedbackFunc { get; }
abstract protected Func<bool> IsWarmingUpFeedbackFunc { get; } abstract protected Func<bool> IsWarmingUpFeedbackFunc { get; }
protected CTimer WarmupTimer; protected CTimer WarmupTimer;
protected CTimer CooldownTimer; protected CTimer CooldownTimer;
#region IRoutingInputs Members #region IRoutingInputs Members
public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; } public RoutingPortCollection<RoutingInputPort> InputPorts { get; private set; }
#endregion #endregion
protected DisplayBase(string key, string name) protected DisplayBase(string key, string name)
: base(key, name) : base(key, name)
{ {
PowerIsOnFeedback = new BoolFeedback("PowerOnFeedback", PowerIsOnFeedbackFunc); PowerIsOnFeedback = new BoolFeedback("PowerOnFeedback", PowerIsOnFeedbackFunc);
IsCoolingDownFeedback = new BoolFeedback("IsCoolingDown", IsCoolingDownFeedbackFunc); IsCoolingDownFeedback = new BoolFeedback("IsCoolingDown", IsCoolingDownFeedbackFunc);
IsWarmingUpFeedback = new BoolFeedback("IsWarmingUp", IsWarmingUpFeedbackFunc); IsWarmingUpFeedback = new BoolFeedback("IsWarmingUp", IsWarmingUpFeedbackFunc);
InputPorts = new RoutingPortCollection<RoutingInputPort>(); InputPorts = new RoutingPortCollection<RoutingInputPort>();
PowerIsOnFeedback.OutputChange += PowerIsOnFeedback_OutputChange; PowerIsOnFeedback.OutputChange += PowerIsOnFeedback_OutputChange;
} }
void PowerIsOnFeedback_OutputChange(object sender, EventArgs e) void PowerIsOnFeedback_OutputChange(object sender, EventArgs e)
{ {
if (UsageTracker != null) if (UsageTracker != null)
{ {
if (PowerIsOnFeedback.BoolValue) if (PowerIsOnFeedback.BoolValue)
UsageTracker.StartDeviceUsage(); UsageTracker.StartDeviceUsage();
else else
UsageTracker.EndDeviceUsage(); UsageTracker.EndDeviceUsage();
} }
} }
public abstract void PowerOn(); public abstract void PowerOn();
public abstract void PowerOff(); public abstract void PowerOff();
public abstract void PowerToggle(); public abstract void PowerToggle();
public virtual FeedbackCollection<Feedback> Feedbacks public virtual FeedbackCollection<Feedback> Feedbacks
{ {
get get
{ {
return new FeedbackCollection<Feedback> return new FeedbackCollection<Feedback>
{ {
PowerIsOnFeedback, PowerIsOnFeedback,
IsCoolingDownFeedback, IsCoolingDownFeedback,
IsWarmingUpFeedback IsWarmingUpFeedback
}; };
} }
} }
public abstract void ExecuteSwitch(object selector); public abstract void ExecuteSwitch(object selector);
protected void LinkDisplayToApi(DisplayBase displayDevice, BasicTriList trilist, uint joinStart, string joinMapKey, protected void LinkDisplayToApi(DisplayBase displayDevice, BasicTriList trilist, uint joinStart, string joinMapKey,
EiscApiAdvanced bridge) EiscApiAdvanced bridge)
{ {
var inputNumber = 0; var inputNumber = 0;
var inputKeys = new List<string>(); var inputKeys = new List<string>();
var joinMap = new DisplayControllerJoinMap(); var joinMap = new DisplayControllerJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized)) if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<DisplayControllerJoinMap>(joinMapSerialized); joinMap = JsonConvert.DeserializeObject<DisplayControllerJoinMap>(joinMapSerialized);
joinMap.OffsetJoinNumbers(joinStart); Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
Debug.Console(0, "Linking to Display: {0}", displayDevice.Name);
Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
Debug.Console(0, "Linking to Display: {0}", displayDevice.Name); trilist.StringInput[joinMap.Name.JoinNumber].StringValue = displayDevice.Name;
trilist.StringInput[joinMap.Name].StringValue = displayDevice.Name; var commMonitor = displayDevice as ICommunicationMonitor;
if (commMonitor != null)
var commMonitor = displayDevice as ICommunicationMonitor; {
if (commMonitor != null) commMonitor.CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
{ }
commMonitor.CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline]);
} var inputNumberFeedback = new IntFeedback(() => inputNumber);
var inputNumberFeedback = new IntFeedback(() => inputNumber); // Two way feedbacks
var twoWayDisplay = displayDevice as TwoWayDisplayBase;
// Two way feedbacks
var twoWayDisplay = displayDevice as TwoWayDisplayBase; if (twoWayDisplay != null)
{
if (twoWayDisplay != null) trilist.SetBool(joinMap.IsTwoWayDisplay.JoinNumber, true);
{
trilist.SetBool(joinMap.IsTwoWayDisplay, true); twoWayDisplay.CurrentInputFeedback.OutputChange += (o, a) => Debug.Console(0, "CurrentInputFeedback_OutputChange {0}", a.StringValue);
twoWayDisplay.CurrentInputFeedback.OutputChange += (o, a) => Debug.Console(0, "CurrentInputFeedback_OutputChange {0}", a.StringValue);
inputNumberFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputSelect.JoinNumber]);
}
inputNumberFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputSelect]);
} // Power Off
trilist.SetSigTrueAction(joinMap.PowerOff.JoinNumber, () =>
// Power Off {
trilist.SetSigTrueAction(joinMap.PowerOff, () => inputNumber = 102;
{ inputNumberFeedback.FireUpdate();
inputNumber = 102; displayDevice.PowerOff();
inputNumberFeedback.FireUpdate(); });
displayDevice.PowerOff();
}); displayDevice.PowerIsOnFeedback.OutputChange += (o, a) =>
{
displayDevice.PowerIsOnFeedback.OutputChange += (o, a) => if (!a.BoolValue)
{ {
if (!a.BoolValue) inputNumber = 102;
{ inputNumberFeedback.FireUpdate();
inputNumber = 102;
inputNumberFeedback.FireUpdate(); }
else
} {
else inputNumber = 0;
{ inputNumberFeedback.FireUpdate();
inputNumber = 0; }
inputNumberFeedback.FireUpdate(); };
}
}; displayDevice.PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff.JoinNumber]);
displayDevice.PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff]); // PowerOn
trilist.SetSigTrueAction(joinMap.PowerOn.JoinNumber, () =>
// PowerOn {
trilist.SetSigTrueAction(joinMap.PowerOn, () => inputNumber = 0;
{ inputNumberFeedback.FireUpdate();
inputNumber = 0; displayDevice.PowerOn();
inputNumberFeedback.FireUpdate(); });
displayDevice.PowerOn();
});
displayDevice.PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn.JoinNumber]);
displayDevice.PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn]); for (int i = 0; i < displayDevice.InputPorts.Count; i++)
{
var count = 1; if (i < joinMap.InputNamesOffset.JoinSpan)
foreach (var input in displayDevice.InputPorts) {
{ inputKeys.Add(displayDevice.InputPorts[i].Key);
inputKeys.Add(input.Key); var tempKey = inputKeys.ElementAt(i);
var tempKey = inputKeys.ElementAt(count - 1); trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + i),
trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset + count), () => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector)); () => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector));
Debug.Console(2, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}", joinMap.InputSelectOffset + count, displayDevice.InputPorts[tempKey].Key.ToString()); Debug.Console(2, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}",
trilist.StringInput[(ushort)(joinMap.InputNamesOffset + count)].StringValue = input.Key.ToString(); joinMap.InputSelectOffset.JoinNumber + i, displayDevice.InputPorts[tempKey].Key.ToString());
count++; trilist.StringInput[(ushort)(joinMap.InputNamesOffset.JoinNumber + i)].StringValue = displayDevice.InputPorts[i].Key.ToString();
} }
else
Debug.Console(2, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect); Debug.Console(0, displayDevice, Debug.ErrorLogLevel.Warning, "Device has {0} inputs. The Join Map allows up to {1} inputs. Discarding inputs {2} - {3} from bridge.",
trilist.SetUShortSigAction(joinMap.InputSelect, (a) => displayDevice.InputPorts.Count, joinMap.InputNamesOffset.JoinSpan, i + 1, displayDevice.InputPorts.Count);
{ }
if (a == 0)
{ Debug.Console(2, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect);
displayDevice.PowerOff(); trilist.SetUShortSigAction(joinMap.InputSelect.JoinNumber, (a) =>
inputNumber = 0; {
} if (a == 0)
else if (a > 0 && a < displayDevice.InputPorts.Count && a != inputNumber) {
{ displayDevice.PowerOff();
displayDevice.ExecuteSwitch(displayDevice.InputPorts.ElementAt(a - 1).Selector); inputNumber = 0;
inputNumber = a; }
} else if (a > 0 && a < displayDevice.InputPorts.Count && a != inputNumber)
else if (a == 102) {
{ displayDevice.ExecuteSwitch(displayDevice.InputPorts.ElementAt(a - 1).Selector);
displayDevice.PowerToggle(); inputNumber = a;
}
} else if (a == 102)
if (twoWayDisplay != null) {
inputNumberFeedback.FireUpdate(); displayDevice.PowerToggle();
});
}
if (twoWayDisplay != null)
var volumeDisplay = displayDevice as IBasicVolumeControls; inputNumberFeedback.FireUpdate();
if (volumeDisplay == null) return; });
trilist.SetBoolSigAction(joinMap.VolumeUp, volumeDisplay.VolumeUp);
trilist.SetBoolSigAction(joinMap.VolumeDown, volumeDisplay.VolumeDown); var volumeDisplay = displayDevice as IBasicVolumeControls;
trilist.SetSigTrueAction(joinMap.VolumeMute, volumeDisplay.MuteToggle); if (volumeDisplay == null) return;
var volumeDisplayWithFeedback = volumeDisplay as IBasicVolumeWithFeedback; trilist.SetBoolSigAction(joinMap.VolumeUp.JoinNumber, volumeDisplay.VolumeUp);
trilist.SetBoolSigAction(joinMap.VolumeDown.JoinNumber, volumeDisplay.VolumeDown);
if (volumeDisplayWithFeedback == null) return; trilist.SetSigTrueAction(joinMap.VolumeMute.JoinNumber, volumeDisplay.MuteToggle);
trilist.SetUShortSigAction(joinMap.VolumeLevel, volumeDisplayWithFeedback.SetVolume); var volumeDisplayWithFeedback = volumeDisplay as IBasicVolumeWithFeedback;
volumeDisplayWithFeedback.VolumeLevelFeedback.LinkInputSig(trilist.UShortInput[joinMap.VolumeLevel]);
volumeDisplayWithFeedback.MuteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VolumeMute]); if (volumeDisplayWithFeedback == null) return;
} trilist.SetSigTrueAction(joinMap.VolumeMuteOn.JoinNumber, volumeDisplayWithFeedback.MuteOn);
} trilist.SetSigTrueAction(joinMap.VolumeMuteOff.JoinNumber, volumeDisplayWithFeedback.MuteOff);
/// <summary>
/// trilist.SetUShortSigAction(joinMap.VolumeLevel.JoinNumber, volumeDisplayWithFeedback.SetVolume);
/// </summary> volumeDisplayWithFeedback.VolumeLevelFeedback.LinkInputSig(trilist.UShortInput[joinMap.VolumeLevel.JoinNumber]);
public abstract class TwoWayDisplayBase : DisplayBase volumeDisplayWithFeedback.MuteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VolumeMute.JoinNumber]);
{ volumeDisplayWithFeedback.MuteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VolumeMuteOn.JoinNumber]);
public StringFeedback CurrentInputFeedback { get; private set; } volumeDisplayWithFeedback.MuteFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.VolumeMuteOff.JoinNumber]);
}
abstract protected Func<string> CurrentInputFeedbackFunc { get; } }
/// <summary>
public static MockDisplay DefaultDisplay ///
{ /// </summary>
get public abstract class TwoWayDisplayBase : DisplayBase
{ {
if (_DefaultDisplay == null) public StringFeedback CurrentInputFeedback { get; private set; }
_DefaultDisplay = new MockDisplay("default", "Default Display");
return _DefaultDisplay; abstract protected Func<string> CurrentInputFeedbackFunc { get; }
}
}
static MockDisplay _DefaultDisplay; public static MockDisplay DefaultDisplay
{
public TwoWayDisplayBase(string key, string name) get
: base(key, name) {
{ if (_DefaultDisplay == null)
CurrentInputFeedback = new StringFeedback(CurrentInputFeedbackFunc); _DefaultDisplay = new MockDisplay("default", "Default Display");
return _DefaultDisplay;
WarmupTime = 7000; }
CooldownTime = 15000; }
static MockDisplay _DefaultDisplay;
Feedbacks.Add(CurrentInputFeedback);
public TwoWayDisplayBase(string key, string name)
: base(key, name)
} {
CurrentInputFeedback = new StringFeedback(CurrentInputFeedbackFunc);
}
WarmupTime = 7000;
CooldownTime = 15000;
Feedbacks.Add(CurrentInputFeedback);
}
}
} }