From 90bfa53e85faacdb9c3c5426ca0720a6f2ac0bcf Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 24 Jun 2020 16:39:39 -0600 Subject: [PATCH] Refactoring things to base class --- .../Room/Types/EssentialsHuddleSpaceRoom.cs | 165 ++++++----------- .../Room/Types/EssentialsHuddleVtc1Room.cs | 169 ++++++------------ .../Room/EssentialsRoomBase.cs | 72 +++++++- 3 files changed, 183 insertions(+), 223 deletions(-) diff --git a/PepperDashEssentials/Room/Types/EssentialsHuddleSpaceRoom.cs b/PepperDashEssentials/Room/Types/EssentialsHuddleSpaceRoom.cs index 3a717efd..29f24748 100644 --- a/PepperDashEssentials/Room/Types/EssentialsHuddleSpaceRoom.cs +++ b/PepperDashEssentials/Room/Types/EssentialsHuddleSpaceRoom.cs @@ -13,49 +13,9 @@ namespace PepperDash.Essentials { public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange, IRunRouteAction, IRunDefaultPresentRoute, IHasCurrentVolumeControls, IHasDefaultDisplay { - public event EventHandler CurrentVolumeDeviceChange; + // public event SourceInfoChangeHandler CurrentSourceChange; - protected override Func OnFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - var val = CurrentSourceInfo != null - && CurrentSourceInfo.Type == eSourceListItemType.Route - && disp != null; - //&& disp.PowerIsOnFeedback.BoolValue; - return val; - }; - } - } - - protected override Func IsWarmingFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - return disp != null && disp.IsWarmingUpFeedback.BoolValue; - }; - } - } - - protected override Func IsCoolingFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - return disp != null && disp.IsCoolingDownFeedback.BoolValue; - }; - } - } - public EssentialsHuddleRoomPropertiesConfig PropertiesConfig { get; private set; } public IRoutingSinkWithSwitching DefaultDisplay { get; private set; } @@ -74,33 +34,6 @@ namespace PepperDash.Essentials public bool EnablePowerOnToLastSource { get; set; } string _lastSourceKey; - /// - /// - /// - public IBasicVolumeControls CurrentVolumeControls - { - get { return _currentAudioDevice; } - set - { - if (value == _currentAudioDevice) return; - - var oldDev = _currentAudioDevice; - // derigister this room from the device, if it can - if (oldDev is IInUseTracking) - (oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio"); - var handler = CurrentVolumeDeviceChange; - if (handler != null) - CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange)); - _currentAudioDevice = value; - if (handler != null) - CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange)); - // register this room with new device, if it can - if (_currentAudioDevice is IInUseTracking) - (_currentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio"); - } - } - IBasicVolumeControls _currentAudioDevice; - /// /// The SourceListItem last run - containing names and icons /// @@ -152,7 +85,7 @@ namespace PepperDash.Essentials } } - void Initialize() + private void Initialize() { if (DefaultAudioDevice is IBasicVolumeControls) DefaultVolumeControls = DefaultAudioDevice as IBasicVolumeControls; @@ -160,46 +93,66 @@ namespace PepperDash.Essentials DefaultVolumeControls = (DefaultAudioDevice as IHasVolumeDevice).VolumeDevice; CurrentVolumeControls = DefaultVolumeControls; + SourceListKey = "default"; + EnablePowerOnToLastSource = true; + var disp = DefaultDisplay as DisplayBase; - if (disp != null) + if (disp == null) return; + + IsWarmingFeedbackFunc = () => disp.IsWarmingUpFeedback.BoolValue; + + IsCoolingFeedbackFunc = () => disp.IsCoolingDownFeedback.BoolValue; + + OnFeedbackFunc = () => CurrentSourceInfo != null + && CurrentSourceInfo.Type == eSourceListItemType.Route; + + InitializeDisplay(disp); + } + + + protected override void IsCoolingDownFeedbackOnOutputChange(object sender, FeedbackEventArgs feedbackEventArgs) + { + IsCoolingDownFeedback.FireUpdate(); + } + + protected override void PowerIsOnFeedbackOnOutputChange(object sender, FeedbackEventArgs feedbackEventArgs) + { + var display = sender as DisplayBase; + + if (display == null) return; + + if (display.PowerIsOnFeedback.BoolValue == OnFeedback.BoolValue) { - // Link power, warming, cooling to display - disp.PowerIsOnFeedback.OutputChange += (o, a) => - { - if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue) - { - if (!disp.PowerIsOnFeedback.BoolValue) - CurrentSourceInfo = null; - OnFeedback.FireUpdate(); - } - }; - - disp.IsWarmingUpFeedback.OutputChange += (o, a) => - { - IsWarmingUpFeedback.FireUpdate(); - - if (IsWarmingUpFeedback.BoolValue) - { - return; - } - - var display = DefaultDisplay as IBasicVolumeWithFeedback; - - if (display == null) - { - Debug.Console(0, this, Debug.ErrorLogLevel.Error, - "Default display {0} is not volume control control provider", DefaultDisplay.Key); - return; - } - - display.SetVolume(DefaultVolume); - }; - disp.IsCoolingDownFeedback.OutputChange += (o, a) => IsCoolingDownFeedback.FireUpdate(); + return; } - - SourceListKey = "default"; - EnablePowerOnToLastSource = true; - } + + if (!display.PowerIsOnFeedback.BoolValue) + { + CurrentSourceInfo = null; + } + OnFeedback.FireUpdate(); + } + + protected override void IsWarmingUpFeedbackOnOutputChange(object sender, FeedbackEventArgs feedbackEventArgs) + { + IsWarmingUpFeedback.FireUpdate(); + + if (IsWarmingUpFeedback.BoolValue) + { + return; + } + + var displayVolumeControl = DefaultDisplay as IBasicVolumeWithFeedback; + + if (displayVolumeControl == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, + "Default display {0} is not volume control control provider", DefaultDisplay.Key); + return; + } + + displayVolumeControl.SetVolume(DefaultVolume); + } protected override void CustomSetConfig(DeviceConfig config) { diff --git a/PepperDashEssentials/Room/Types/EssentialsHuddleVtc1Room.cs b/PepperDashEssentials/Room/Types/EssentialsHuddleVtc1Room.cs index 2e4f33a4..94b9bfb0 100644 --- a/PepperDashEssentials/Room/Types/EssentialsHuddleVtc1Room.cs +++ b/PepperDashEssentials/Room/Types/EssentialsHuddleVtc1Room.cs @@ -47,52 +47,7 @@ namespace PepperDash.Essentials public BoolFeedback IsSharingFeedback { get; private set; } //************************ - - - protected override Func OnFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - var val = CurrentSourceInfo != null - && CurrentSourceInfo.Type == eSourceListItemType.Route - && disp != null; - //&& disp.PowerIsOnFeedback.BoolValue; - return val; - }; - } - } - /// - /// - /// - protected override Func IsWarmingFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - return disp != null && disp.IsWarmingUpFeedback.BoolValue; - }; - } - } - /// - /// - /// - protected override Func IsCoolingFeedbackFunc - { - get - { - return () => - { - var disp = DefaultDisplay as DisplayBase; - return disp != null && disp.IsCoolingDownFeedback.BoolValue; - }; - } - } - + public EssentialsHuddleVtc1PropertiesConfig PropertiesConfig { get; private set; } public IRoutingSinkWithSwitching DefaultDisplay { get; private set; } @@ -115,34 +70,6 @@ namespace PepperDash.Essentials public bool EnablePowerOnToLastSource { get; set; } private string _lastSourceKey; - /// - /// Sets the volume control device, and attaches/removes InUseTrackers with "audio" - /// tag to device. - /// - public IBasicVolumeControls CurrentVolumeControls - { - get { return _currentAudioDevice; } - set - { - if (value == _currentAudioDevice) return; - - var oldDev = _currentAudioDevice; - // derigister this room from the device, if it can - if (oldDev is IInUseTracking) - (oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio"); - var handler = CurrentVolumeDeviceChange; - if (handler != null) - CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange)); - _currentAudioDevice = value; - if (handler != null) - CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange)); - // register this room with new device, if it can - if (_currentAudioDevice is IInUseTracking) - (_currentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio"); - } - } - IBasicVolumeControls _currentAudioDevice; - /// /// The SourceListItem last run - containing names and icons /// @@ -242,44 +169,6 @@ namespace PepperDash.Essentials return inAudioCall || inVideoCall; }); - var disp = DefaultDisplay as DisplayBase; - if (disp != null) - { - // Link power, warming, cooling to display - disp.PowerIsOnFeedback.OutputChange += (o, a) => - { - if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue) - { - if (!disp.PowerIsOnFeedback.BoolValue) - CurrentSourceInfo = null; - OnFeedback.FireUpdate(); - } - if (disp.PowerIsOnFeedback.BoolValue) - { - SetDefaultLevels(); - } - }; - - disp.IsWarmingUpFeedback.OutputChange += (o, a) => - { - IsWarmingUpFeedback.FireUpdate(); - if (IsWarmingUpFeedback.BoolValue) - { - return; - } - - var basicVolumeWithFeedback = CurrentVolumeControls as IBasicVolumeWithFeedback; - if (basicVolumeWithFeedback != null) - { - basicVolumeWithFeedback.SetVolume(DefaultVolume); - } - }; - disp.IsCoolingDownFeedback.OutputChange += (o, a) => IsCoolingDownFeedback.FireUpdate(); - - } - - - // Get Microphone Privacy object, if any MUST HAPPEN AFTER setting InCallFeedback MicrophonePrivacy = EssentialsRoomConfigHelper.GetMicrophonePrivacy(PropertiesConfig, this); @@ -307,6 +196,18 @@ namespace PepperDash.Essentials SourceListKey = "default"; EnablePowerOnToLastSource = true; + + var disp = DefaultDisplay as DisplayBase; + if (disp == null) + { + return; + } + + OnFeedbackFunc = () => CurrentSourceInfo != null + && CurrentSourceInfo.Type == eSourceListItemType.Route; + + InitializeDisplay(disp); + } catch (Exception e) { @@ -314,6 +215,50 @@ namespace PepperDash.Essentials } } + #region Overrides of EssentialsRoomBase + + protected override void PowerIsOnFeedbackOnOutputChange(object sender, FeedbackEventArgs args) + { + var disp = sender as DisplayBase; + + if (disp == null) return; + + if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue) + { + if (!disp.PowerIsOnFeedback.BoolValue) + CurrentSourceInfo = null; + OnFeedback.FireUpdate(); + } + if (disp.PowerIsOnFeedback.BoolValue) + { + SetDefaultLevels(); + } + } + + protected override void IsCoolingDownFeedbackOnOutputChange(object sender, FeedbackEventArgs args) + { + IsCoolingDownFeedback.FireUpdate(); + } + + protected override void IsWarmingUpFeedbackOnOutputChange(object sender, FeedbackEventArgs args) + { + IsWarmingUpFeedback.FireUpdate(); + + if (IsWarmingUpFeedback.BoolValue) + { + return; + } + + var basicVolumeWithFeedback = CurrentVolumeControls as IBasicVolumeWithFeedback; + if (basicVolumeWithFeedback != null) + { + basicVolumeWithFeedback.SetVolume(DefaultVolume); + } + } + + + #endregion + protected override void CustomSetConfig(DeviceConfig config) { var newPropertiesConfig = JsonConvert.DeserializeObject(config.Properties.ToString()); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/EssentialsRoomBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/EssentialsRoomBase.cs index 3a07994a..8f5c86e1 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/EssentialsRoomBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/EssentialsRoomBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Devices; @@ -11,6 +12,40 @@ namespace PepperDash.Essentials.Core /// public abstract class EssentialsRoomBase : ReconfigurableDevice { + public event EventHandler CurrentVolumeDeviceChange; + + /// + /// Sets the volume control device, and attaches/removes InUseTrackers with "audio" + /// tag to device. + /// + public IBasicVolumeControls CurrentVolumeControls + { + get { return CurrentAudioDevice; } + set + { + if (value == CurrentAudioDevice) + { + return; + } + + var handler = CurrentVolumeDeviceChange; + + if (handler != null) + { + CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(CurrentAudioDevice, value, ChangeType.WillChange)); + CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(CurrentAudioDevice, value, ChangeType.DidChange)); + } + + var oldDevice = value as IInUseTracking; + var newDevice = value as IInUseTracking; + + UpdateInUseTracking(oldDevice, newDevice); + + CurrentAudioDevice = value; + } + } + protected IBasicVolumeControls CurrentAudioDevice; + public BoolFeedback OnFeedback { get; private set; } /// @@ -25,9 +60,8 @@ namespace PepperDash.Essentials.Core public bool OccupancyStatusProviderIsRemote { get; private set; } - protected abstract Func IsWarmingFeedbackFunc { get; } - protected abstract Func IsCoolingFeedbackFunc { get; } - + protected Func IsWarmingFeedbackFunc; + protected Func IsCoolingFeedbackFunc; /// /// The config name of the source list /// @@ -65,7 +99,7 @@ namespace PepperDash.Essentials.Core /// /// /// - protected abstract Func OnFeedbackFunc { get; } + protected Func OnFeedbackFunc; protected Dictionary SavedVolumeLevels = new Dictionary(); @@ -116,7 +150,35 @@ namespace PepperDash.Essentials.Core }); } - void RoomVacancyShutdownPromptTimer_HasFinished(object sender, EventArgs e) + protected void InitializeDisplay(DisplayBase display) + { + // Link power, warming, cooling to display + display.PowerIsOnFeedback.OutputChange += PowerIsOnFeedbackOnOutputChange; + + display.IsWarmingUpFeedback.OutputChange += IsWarmingUpFeedbackOnOutputChange; + display.IsCoolingDownFeedback.OutputChange += IsCoolingDownFeedbackOnOutputChange; + } + + protected void UpdateInUseTracking(IInUseTracking oldDev, IInUseTracking newDev) + { + // derigister this room from the device, if it can + if (oldDev != null) + { + oldDev.InUseTracker.RemoveUser(this, "audio"); + } + + // register this room with new device, if it can + if (newDev != null) + { + newDev.InUseTracker.AddUser(this, "audio"); + } + } + + protected abstract void PowerIsOnFeedbackOnOutputChange(object sender, FeedbackEventArgs args); + protected abstract void IsWarmingUpFeedbackOnOutputChange(object sender, FeedbackEventArgs args); + protected abstract void IsCoolingDownFeedbackOnOutputChange(object sender, FeedbackEventArgs args); + + private void RoomVacancyShutdownPromptTimer_HasFinished(object sender, EventArgs e) { switch (VacancyMode) {