diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs index bd6893ee..fc8ed0e2 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxAnalogAuxMixerController.cs @@ -1,4 +1,4 @@ -using System; +using Crestron.SimplSharp; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM; using PepperDash.Core; @@ -20,36 +20,72 @@ namespace PepperDash_Essentials_DM.Chassis Mixer = chassis.AnalogAuxiliaryMixer[mixer]; Mixer.AuxMixerPropertyChange += OnAuxMixerPropertyChange; + Mixer.AuxiliaryMuteControl.MuteAndVolumeControlPropertyChange += OnMuteAndVolumeControlPropertyChange; - VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); - MuteFeedback = new BoolFeedback(MuteFeedbackFunc); - } + VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); + MuteFeedback = new BoolFeedback(() => IsMuted); - private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) - { - Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.ToString(), args.Index, args.EventId); + VolumeLevel = Mixer.VolumeFeedback.ShortValue; + IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } #region Volume - public IntFeedback VolumeLevelFeedback { get; private set; } - - protected Func VolumeFeedbackFunc + private void OnAuxMixerPropertyChange(object sender, GenericEventArgs args) { - get { return () => Mixer.VolumeFeedback.UShortValue; } + Debug.Console(2, this, "AuxMixerPropertyChange: {0} > Index-{1}, EventId-{2}", sender.GetType().ToString(), args.Index, args.EventId); + + switch (args.EventId) + { + case (3): + { + VolumeLevel = Mixer.VolumeFeedback.ShortValue; + break; + } + } } + private const ushort CrestronLevelMin = 0; + private const ushort CrestronLevelMax = 65535; + + private const int DeviceLevelMin = -800; + private const int DeviceLevelMax = 200; + + private const int RampTime = 5000; + + private int _volumeLevel; + + public int VolumeLevel + { + get { return _volumeLevel; } + set + { + var level = value; + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); + + Debug.Console(1, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); + + VolumeLevelFeedback.FireUpdate(); + } + } + + public IntFeedback VolumeLevelFeedback { get; private set; } + public void SetVolume(ushort level) { - Mixer.Volume.UShortValue = level; + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, + DeviceLevelMin); + + Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); + + Mixer.Volume.ShortValue = (short)scaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - var remainingRatio = (65535 - Mixer.Volume.UShortValue)/65535; - Mixer.Volume.CreateRamp(65535, 400); + Mixer.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { @@ -61,8 +97,10 @@ namespace PepperDash_Essentials_DM.Chassis { if (pressRelease) { - var remainingRatio = Mixer.Volume.UShortValue/65535; - Mixer.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + //var remainingRatio = Mixer.Volume.UShortValue/CrestronLevelMax; + //Mixer.Volume.CreateRamp(CrestronLevelMin, (uint)(RampTime * remainingRatio)); + + Mixer.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { @@ -73,17 +111,42 @@ namespace PepperDash_Essentials_DM.Chassis #endregion + + #region Mute + private void OnMuteAndVolumeControlPropertyChange(MuteControl device, GenericEventArgs args) + { + Debug.Console(2, this, "OnMuteAndVolumeControlPropertyChange: {0} > Index-{1}, EventId-{2}", device.ToString(), args.Index, args.EventId); + + switch (args.EventId) + { + case (1): + case (2): + { + IsMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; + break; + } + } + } + private bool _isMuted; - public BoolFeedback MuteFeedback { get; private set; } - - protected Func MuteFeedbackFunc + public bool IsMuted { - get { return () => _isMuted = Mixer.AuxiliaryMuteControl.MuteOnFeedback.BoolValue; } + get { return _isMuted; } + set + { + _isMuted = value; + + Debug.Console(1, this, "IsMuted: _isMuted-'{0}'", _isMuted); + + MuteFeedback.FireUpdate(); + } } + public BoolFeedback MuteFeedback { get; private set; } + public void MuteOn() { Mixer.AuxiliaryMuteControl.MuteOn(); @@ -96,7 +159,7 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteToggle() { - if (_isMuted) + if (IsMuted) MuteOff(); else MuteOn(); diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs index 9716ba1e..d8583f19 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/HdPsXxxOutputAudioController.cs @@ -1,47 +1,76 @@ -using System; +using Crestron.SimplSharp; using Crestron.SimplSharpPro.DM; using PepperDash.Core; using PepperDash.Essentials.Core; namespace PepperDash_Essentials_DM.Chassis { - public class HdPsXxxOutputAudioController : IKeyed, + public class HdPsXxxOutputAudioController : IKeyed, IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback // || IBasicVolumeWithFeedback { public string Key { get; private set; } - + public HdPsXxxOutputPort Port { get; private set; } - + public HdPsXxxOutputAudioController(string parent, uint output, HdPsXxx chassis) { Key = string.Format("{0}-audioOut{1}", parent, output); - + Port = chassis.HdmiDmLiteOutputs[output].OutputPort; - VolumeLevelFeedback = new IntFeedback(VolumeFeedbackFunc); - MuteFeedback = new BoolFeedback(MuteFeedbackFunc); + VolumeLevelFeedback = new IntFeedback(() => VolumeLevel); + MuteFeedback = new BoolFeedback(() => IsMuted); + + //if(Port.AudioOutput.Volume != null) + // VolumeLevel = Port.AudioOutput.VolumeFeedback.UShortValue; + + IsMuted = Port.MuteOnFeedback.BoolValue; } #region Volume - public IntFeedback VolumeLevelFeedback { get; private set; } + private const ushort CrestronLevelMin = 0; + private const ushort CrestronLevelMax = 65535; - protected Func VolumeFeedbackFunc + private const int DeviceLevelMin = -800; + private const int DeviceLevelMax = 200; + + private const int RampTime = 5000; + + private int _volumeLevel; + + public int VolumeLevel { - get { return () => Port.AudioOutput.VolumeFeedback.UShortValue; } + get { return _volumeLevel; } + set + { + var level = value; + //_volumeLevel = CrestronEnvironment.ScaleWithLimits(level, DeviceLevelMax, DeviceLevelMin, CrestronLevelMax, CrestronLevelMin); + _volumeLevel = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, DeviceLevelMin); + + Debug.Console(2, this, "VolumeFeedback: level-'{0}', scaled-'{1}'", level, _volumeLevel); + + VolumeLevelFeedback.FireUpdate(); + } } + public IntFeedback VolumeLevelFeedback { get; private set; } + public void SetVolume(ushort level) { - Port.AudioOutput.Volume.UShortValue = level; + var scaled = CrestronEnvironment.ScaleWithLimits(level, CrestronLevelMax, CrestronLevelMin, DeviceLevelMax, + DeviceLevelMin); + + Debug.Console(1, this, "SetVolume: level-'{0}', scaled-'{1}'", level, scaled); + + Port.AudioOutput.Volume.ShortValue = (short)scaled; } public void VolumeUp(bool pressRelease) { if (pressRelease) { - var remainingRatio = (65535 - Port.AudioOutput.Volume.UShortValue)/65535; - Port.AudioOutput.Volume.CreateRamp(65535, 400); + Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMax, RampTime); } else { @@ -52,9 +81,8 @@ namespace PepperDash_Essentials_DM.Chassis public void VolumeDown(bool pressRelease) { if (pressRelease) - { - var remainingRatio = Port.AudioOutput.Volume.UShortValue/65535; - Port.AudioOutput.Volume.CreateRamp(0, (uint)(400 * remainingRatio)); + { + Port.AudioOutput.Volume.CreateSignedRamp(DeviceLevelMin, RampTime); } else { @@ -65,17 +93,27 @@ namespace PepperDash_Essentials_DM.Chassis #endregion + + #region Mute private bool _isMuted; - public BoolFeedback MuteFeedback { get; private set; } + public bool IsMuted + { + get { return _isMuted; } + set + { + _isMuted = value; - protected Func MuteFeedbackFunc - { - get { return () => _isMuted = Port.MuteOnFeedback.BoolValue; } + Debug.Console(1, this, "IsMuted: _isMuted-'{0}'", _isMuted); + + MuteFeedback.FireUpdate(); + } } + public BoolFeedback MuteFeedback { get; private set; } + public void MuteOn() { Port.MuteOn(); @@ -88,7 +126,7 @@ namespace PepperDash_Essentials_DM.Chassis public void MuteToggle() { - if (_isMuted) + if (IsMuted) MuteOff(); else MuteOn();