mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-28 11:54:57 +00:00
Refactoring things to base class
This commit is contained in:
@@ -13,49 +13,9 @@ namespace PepperDash.Essentials
|
||||
{
|
||||
public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange, IRunRouteAction, IRunDefaultPresentRoute, IHasCurrentVolumeControls, IHasDefaultDisplay
|
||||
{
|
||||
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
|
||||
//
|
||||
public event SourceInfoChangeHandler CurrentSourceChange;
|
||||
|
||||
protected override Func<bool> 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<bool> IsWarmingFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
var disp = DefaultDisplay as DisplayBase;
|
||||
return disp != null && disp.IsWarmingUpFeedback.BoolValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected override Func<bool> 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;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// The SourceListItem last run - containing names and icons
|
||||
/// </summary>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -47,52 +47,7 @@ namespace PepperDash.Essentials
|
||||
public BoolFeedback IsSharingFeedback { get; private set; }
|
||||
|
||||
//************************
|
||||
|
||||
|
||||
protected override Func<bool> OnFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
var disp = DefaultDisplay as DisplayBase;
|
||||
var val = CurrentSourceInfo != null
|
||||
&& CurrentSourceInfo.Type == eSourceListItemType.Route
|
||||
&& disp != null;
|
||||
//&& disp.PowerIsOnFeedback.BoolValue;
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override Func<bool> IsWarmingFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
var disp = DefaultDisplay as DisplayBase;
|
||||
return disp != null && disp.IsWarmingUpFeedback.BoolValue;
|
||||
};
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override Func<bool> 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;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the volume control device, and attaches/removes InUseTrackers with "audio"
|
||||
/// tag to device.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// The SourceListItem last run - containing names and icons
|
||||
/// </summary>
|
||||
@@ -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<EssentialsHuddleVtc1PropertiesConfig>(config.Properties.ToString());
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public abstract class EssentialsRoomBase : ReconfigurableDevice
|
||||
{
|
||||
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the volume control device, and attaches/removes InUseTrackers with "audio"
|
||||
/// tag to device.
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
@@ -25,9 +60,8 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
public bool OccupancyStatusProviderIsRemote { get; private set; }
|
||||
|
||||
protected abstract Func<bool> IsWarmingFeedbackFunc { get; }
|
||||
protected abstract Func<bool> IsCoolingFeedbackFunc { get; }
|
||||
|
||||
protected Func<bool> IsWarmingFeedbackFunc;
|
||||
protected Func<bool> IsCoolingFeedbackFunc;
|
||||
/// <summary>
|
||||
/// The config name of the source list
|
||||
/// </summary>
|
||||
@@ -65,7 +99,7 @@ namespace PepperDash.Essentials.Core
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected abstract Func<bool> OnFeedbackFunc { get; }
|
||||
protected Func<bool> OnFeedbackFunc;
|
||||
|
||||
protected Dictionary<IBasicVolumeWithFeedback, uint> SavedVolumeLevels = new Dictionary<IBasicVolumeWithFeedback, uint>();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user