diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs new file mode 100644 index 00000000..1fd909e6 --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmpsAudioOutputController.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; + +using Crestron.SimplSharpPro.DM; +using Crestron.SimplSharpPro.DM.Cards; + +using PepperDash.Core; +using PepperDash.Essentials.Core; + +using PepperDash.Essentials.DM.Config; + +namespace PepperDash.Essentials.DM +{ + public class DmpsAudioOutputController : Device, IHasFeedback + { + Card.Dmps3OutputBase Card; + + public DmpsAudioOutput MasterVolumeLevel { get; private set; } + public DmpsAudioOutput SourceVolumeLevel { get; private set; } + public DmpsAudioOutput Codec1VolumeLevel { get; private set; } + public DmpsAudioOutput Codec2VolumeLevel { get; private set; } + public Dictionary MicVolumeLevels { get; private set; } + + public DmpsAudioOutputController(string key, string name, Card.Dmps3OutputBase card) + : base(key, name) + { + Card = card; + + MasterVolumeLevel = new DmpsAudioOutput(card, eDmpsLevelType.Master); + SourceVolumeLevel = new DmpsAudioOutput(card, eDmpsLevelType.Source); + + if (card is Card.Dmps3ProgramOutput) + { + Codec1VolumeLevel = new DmpsAudioOutput(card, eDmpsLevelType.Codec1); + } + } + + #region IHasFeedback Members + + public FeedbackCollection Feedbacks + { + get { throw new NotImplementedException(); } + } + + #endregion + } + + public class DmpsAudioOutput : IBasicVolumeWithFeedback + { + Card.Dmps3OutputBase Output; + + UShortInputSig Level; + + eDmpsLevelType Type; + + public BoolFeedback MuteFeedback { get; private set; } + public IntFeedback VolumeLevelFeedback { get; private set; } + + Action MuteOnAction; + Action MuteOffAction; + Action VolumeUpAction; + Action VolumeDownAction; + + public DmpsAudioOutput(Card.Dmps3OutputBase output, eDmpsLevelType type) + { + Output = output; + + switch (type) + { + case eDmpsLevelType.Master: + { + Level = output.MasterVolume; + + MuteFeedback = new BoolFeedback( new Func (() => Output.MasterMuteOnFeedBack.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => Output.MasterVolumeFeedBack.UShortValue)); + MuteOnAction = new Action(Output.MasterMuteOn); + MuteOffAction = new Action(Output.MasterMuteOff); + VolumeUpAction = new Action((b) => Output.MasterVolumeUp.BoolValue = b); + VolumeDownAction = new Action((b) => Output.MasterVolumeDown.BoolValue = b); + break; + } + case eDmpsLevelType.Source: + { + Level = output.SourceLevel; + + MuteFeedback = new BoolFeedback(new Func(() => Output.SourceMuteOnFeedBack.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => Output.SourceLevelFeedBack.UShortValue)); + MuteOnAction = new Action(Output.SourceMuteOn); + MuteOffAction = new Action(Output.SourceMuteOff); + VolumeUpAction = new Action((b) => Output.SourceLevelUp.BoolValue = b); + VolumeDownAction = new Action((b) => Output.SourceLevelDown.BoolValue = b); + break; + } + case eDmpsLevelType.Codec1: + { + var programOutput = output as Card.Dmps3ProgramOutput; + + if (programOutput != null) + { + Level = programOutput.Codec1Level; + + MuteFeedback = new BoolFeedback(new Func(() => programOutput.CodecMute1OnFeedback.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => programOutput.Codec1LevelFeedback.UShortValue)); + MuteOnAction = new Action(programOutput.Codec1MuteOn); + MuteOffAction = new Action(programOutput.Codec1MuteOff); + VolumeUpAction = new Action((b) => programOutput.Codec1LevelUp.BoolValue = b); + VolumeDownAction = new Action((b) => programOutput.Codec1LevelDown.BoolValue = b); + + } + else + { + var auxOutput = output as Card.Dmps3Aux2Output; + + Level = auxOutput.Codec1Level; + + MuteFeedback = new BoolFeedback(new Func(() => auxOutput.CodecMute1OnFeedback.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => auxOutput.Codec1LevelFeedback.UShortValue)); + MuteOnAction = new Action(auxOutput.Codec1MuteOn); + MuteOffAction = new Action(auxOutput.Codec1MuteOff); + VolumeUpAction = new Action((b) => auxOutput.Codec1LevelUp.BoolValue = b); + VolumeDownAction = new Action((b) => auxOutput.Codec1LevelDown.BoolValue = b); + } + break; + } + case eDmpsLevelType.Codec2: + { + var programOutput = output as Card.Dmps3ProgramOutput; + + if (programOutput != null) + { + Level = programOutput.Codec2Level; + + MuteFeedback = new BoolFeedback(new Func(() => programOutput.CodecMute1OnFeedback.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => programOutput.Codec2LevelFeedback.UShortValue)); + MuteOnAction = new Action(programOutput.Codec2MuteOn); + MuteOffAction = new Action(programOutput.Codec2MuteOff); + VolumeUpAction = new Action((b) => programOutput.Codec2LevelUp.BoolValue = b); + VolumeDownAction = new Action((b) => programOutput.Codec2LevelDown.BoolValue = b); + + } + else + { + var auxOutput = output as Card.Dmps3Aux1Output; + + Level = auxOutput.Codec2Level; + + MuteFeedback = new BoolFeedback(new Func(() => auxOutput.CodecMute2OnFeedback.BoolValue)); + VolumeLevelFeedback = new IntFeedback(new Func(() => auxOutput.Codec2LevelFeedback.UShortValue)); + MuteOnAction = new Action(auxOutput.Codec2MuteOn); + MuteOffAction = new Action(auxOutput.Codec2MuteOff); + VolumeUpAction = new Action((b) => auxOutput.Codec2LevelUp.BoolValue = b); + VolumeDownAction = new Action((b) => auxOutput.Codec2LevelDown.BoolValue = b); + } + break; + } + } + } + + #region IBasicVolumeWithFeedback Members + + public void SetVolume(ushort level) + { + Level.UShortValue = level; + } + + public void MuteOn() + { + MuteOnAction(); + } + + public void MuteOff() + { + MuteOffAction(); + } + + #endregion + + #region IBasicVolumeControls Members + + public void VolumeUp(bool pressRelease) + { + VolumeUpAction(pressRelease); + } + + public void VolumeDown(bool pressRelease) + { + VolumeDownAction(pressRelease); + } + + public void MuteToggle() + { + if (MuteFeedback.BoolValue) + MuteOff(); + else + MuteOn(); + } + + #endregion + } + + public enum eDmpsLevelType + { + Master, + Source, + MicsMaster, + Codec1, + Codec2 + } +} \ No newline at end of file