From 3856a96e5fd8f78774b41f50e5a69417db8da7f3 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 6 Jul 2020 09:30:43 -0600 Subject: [PATCH] add dual display fusion controller --- PepperDashEssentials/ControlSystem.cs | 31 +++- .../EssentialsDualDisplayFusionController.cs | 172 ++++++++++++++++++ .../PepperDash_Essentials_Core.csproj | 2 + 3 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Fusion/EssentialsDualDisplayFusionController.cs diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index a182efbd..3dc62c43 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -429,15 +429,18 @@ namespace PepperDash.Essentials foreach (var roomConfig in ConfigReader.ConfigObject.Rooms) { var room = EssentialsRoomConfigHelper.GetRoomObject(roomConfig) as EssentialsRoomBase; - if (room != null) + if (room == null) { - if (room is EssentialsHuddleSpaceRoom) - { - DeviceManager.AddDevice(room); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create room from config, key '{0}'", roomConfig.Key);' + return; + } - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Room is EssentialsHuddleSpaceRoom, attempting to add to DeviceManager with Fusion"); - DeviceManager.AddDevice(new Core.Fusion.EssentialsHuddleSpaceFusionSystemControllerBase((EssentialsHuddleSpaceRoom)room, 0xf1)); + var huddleRoom = room as EssentialsHuddleSpaceRoom; + var vtcRoom = room as EssentialsHuddleVtc1Room; + if (huddleRoom != null) + { + DeviceManager.AddDevice(huddleRoom); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge..."); @@ -447,8 +450,11 @@ namespace PepperDash.Essentials { DeviceManager.AddDevice(room); - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Room is EssentialsHuddleVtc1Room, attempting to add to DeviceManager with Fusion"); - DeviceManager.AddDevice(new EssentialsHuddleVtc1FusionController((EssentialsHuddleVtc1Room)room, 0xf1)); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge..."); + // Mobile Control bridge + var bridge = new MobileControlEssentialsHuddleSpaceRoomBridge(huddleRoom); + AddBridgePostActivationHelper(bridge); // Lets things happen later when all devices are present + DeviceManager.AddDevice(bridge); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge..."); @@ -460,6 +466,15 @@ namespace PepperDash.Essentials DeviceManager.AddDevice(room); } + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Room is EssentialsHuddleVtc1Room, attempting to add to DeviceManager with Fusion"); + DeviceManager.AddDevice(new EssentialsHuddleVtc1FusionController(vtcRoom, 0xf1)); + + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge..."); + // Mobile Control bridge + var bridge = new MobileControlEssentialsHuddleSpaceRoomBridge(room); + AddBridgePostActivationHelper(bridge); // Lets things happen later when all devices are present + DeviceManager.AddDevice(bridge); + continue; } else Debug.Console(0, Debug.ErrorLogLevel.Notice, "Notice: Cannot create room from config, key '{0}' - Is this intentional? This may be a valid configuration.", roomConfig.Key); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Fusion/EssentialsDualDisplayFusionController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Fusion/EssentialsDualDisplayFusionController.cs new file mode 100644 index 00000000..a45168f5 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Fusion/EssentialsDualDisplayFusionController.cs @@ -0,0 +1,172 @@ +using System; +using System.Linq; +using Crestron.SimplSharpPro; +using PepperDash.Core; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash.Essentials.Core.Fusion +{ + public class EssentialsDualDisplayFusionController:EssentialsHuddleSpaceFusionSystemControllerBase + { + private BooleanSigData _codecIsInCall; + private readonly EssentialsDualDisplayRoom _room; + + public EssentialsDualDisplayFusionController(EssentialsDualDisplayRoom room, uint ipId) : base(room, ipId) + { + _room = room; + } + + #region Overrides of EssentialsHuddleSpaceFusionSystemControllerBase + + protected override void ExecuteCustomSteps() + { + SetUpCodec(); + base.ExecuteCustomSteps(); + } + + #endregion + + #region Overrides of EssentialsHuddleSpaceFusionSystemControllerBase + + protected override void SetUpDisplay() + { + base.SetUpDisplay(); + + + } + + #endregion + + /// + /// Creates a static asset for the codec and maps the joins to the main room symbol + /// + private void SetUpCodec() + { + try + { + var essentialsHuddleVtc1Room = Room as EssentialsHuddleVtc1Room; + if (essentialsHuddleVtc1Room == null) + { + return; + } + + var codec = essentialsHuddleVtc1Room.VideoCodec; + + if (codec == null) + { + Debug.Console(1, this, "Cannot link codec to Fusion because codec is null"); + return; + } + + codec.UsageTracker = new UsageTracking(codec) { UsageIsTracked = true }; + codec.UsageTracker.DeviceUsageEnded += UsageTracker_DeviceUsageEnded; + + var codecPowerOnAction = new Action(b => + { + if (!b) + { + codec.StandbyDeactivate(); + } + }); + var codecPowerOffAction = new Action(b => + { + if (!b) + { + codec.StandbyActivate(); + } + }); + + // Map FusionRoom Attributes: + + // Codec volume + var codecVolume = FusionRoom.CreateOffsetUshortSig(50, "Volume - Fader01", eSigIoMask.InputOutputSig); + codecVolume.OutputSig.UserObject = + new Action(b => (codec as IBasicVolumeWithFeedback).SetVolume(b)); + (codec as IBasicVolumeWithFeedback).VolumeLevelFeedback.LinkInputSig(codecVolume.InputSig); + + // In Call Status + _codecIsInCall = FusionRoom.CreateOffsetBoolSig(69, "Conf - VC 1 In Call", eSigIoMask.InputSigOnly); + codec.CallStatusChange += codec_CallStatusChange; + + // Online status + if (codec is ICommunicationMonitor) + { + var c = codec as ICommunicationMonitor; + var codecOnline = FusionRoom.CreateOffsetBoolSig(122, "Online - VC 1", eSigIoMask.InputSigOnly); + codecOnline.InputSig.BoolValue = c.CommunicationMonitor.Status == MonitorStatus.IsOk; + c.CommunicationMonitor.StatusChange += + (o, a) => { codecOnline.InputSig.BoolValue = a.Status == MonitorStatus.IsOk; }; + Debug.Console(0, this, "Linking '{0}' communication monitor to Fusion '{1}'", codec.Key, + "Online - VC 1"); + } + + // Codec IP Address + var codecHasIpInfo = false; + var codecComm = codec.Communication; + + var codecIpAddress = string.Empty; + var codecIpPort = 0; + + if (codecComm is GenericSshClient) + { + codecIpAddress = (codecComm as GenericSshClient).Hostname; + codecIpPort = (codecComm as GenericSshClient).Port; + codecHasIpInfo = true; + } + else if (codecComm is GenericTcpIpClient) + { + codecIpAddress = (codecComm as GenericTcpIpClient).Hostname; + codecIpPort = (codecComm as GenericTcpIpClient).Port; + codecHasIpInfo = true; + } + + if (codecHasIpInfo) + { + var codecIpAddressSig = FusionRoom.CreateOffsetStringSig(121, "IP Address - VC", + eSigIoMask.InputSigOnly); + codecIpAddressSig.InputSig.StringValue = codecIpAddress; + + var codecIpPortSig = FusionRoom.CreateOffsetStringSig(150, "IP Port - VC", + eSigIoMask.InputSigOnly); + codecIpPortSig.InputSig.StringValue = codecIpPort.ToString(); + } + + FusionAsset tempAsset; + + var deviceConfig = ConfigReader.ConfigObject.Devices.FirstOrDefault(c => c.Key.Equals(codec.Key)); + + if (FusionStaticAssets.ContainsKey(deviceConfig.Uid)) + { + tempAsset = FusionStaticAssets[deviceConfig.Uid]; + } + else + { + // Create a new asset + tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom), codec.Name, + "Codec", ""); + FusionStaticAssets.Add(deviceConfig.Uid, tempAsset); + } + + var codecAsset = FusionRoom.CreateStaticAsset(tempAsset.SlotNumber, tempAsset.Name, "Display", + tempAsset.InstanceId); + codecAsset.PowerOn.OutputSig.UserObject = codecPowerOnAction; + codecAsset.PowerOff.OutputSig.UserObject = codecPowerOffAction; + codec.StandbyIsOnFeedback.LinkComplementInputSig(codecAsset.PowerOn.InputSig); + + codecAsset.TrySetMakeModel(codec); + codecAsset.TryLinkAssetErrorToCommunication(codec); + } + catch (Exception e) + { + Debug.Console(1, this, "Error setting up codec in Fusion: {0}", e); + } + } + + private void codec_CallStatusChange(object sender, Devices.Codec.CodecCallStatusItemChangeEventArgs e) + { + var codec = _room.VideoCodec; + + _codecIsInCall.InputSig.BoolValue = codec.IsInCall; + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 29e2b91f..94e0e7a2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -238,7 +238,9 @@ + +