WHAR-1436 - Add Vol control up/down buttons on the user page

This commit is contained in:
Jason T Alborough
2018-08-24 14:12:53 -04:00
parent 96e60f6eaf
commit 759635b364
2 changed files with 137 additions and 119 deletions

View File

@@ -1,119 +1,137 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.DM; using PepperDash.Essentials.DM;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Routing; using PepperDash.Essentials.Core.Routing;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.EthernetCommunication; using Crestron.SimplSharpPro.EthernetCommunication;
using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM;
namespace PepperDash.Essentials { namespace PepperDash.Essentials {
public class EssentialDsp : PepperDash.Core.Device { public class EssentialDsp : PepperDash.Core.Device {
public EssentialDspProperties Properties; public EssentialDspProperties Properties;
public List<BridgeApiEisc> BridgeApiEiscs; public List<BridgeApiEisc> BridgeApiEiscs;
private PepperDash.Essentials.Devices.Common.DSP.QscDsp Dsp; private PepperDash.Essentials.Devices.Common.DSP.QscDsp Dsp;
private EssentialDspApiMap ApiMap = new EssentialDspApiMap(); private EssentialDspApiMap ApiMap = new EssentialDspApiMap();
public EssentialDsp(string key, string name, JToken properties) public EssentialDsp(string key, string name, JToken properties)
: base(key, name) { : base(key, name) {
Properties = JsonConvert.DeserializeObject<EssentialDspProperties>(properties.ToString()); Properties = JsonConvert.DeserializeObject<EssentialDspProperties>(properties.ToString());
} }
public override bool CustomActivate() { public override bool CustomActivate() {
// Create EiscApis // Create EiscApis
try try
{ {
foreach (var device in DeviceManager.AllDevices) foreach (var device in DeviceManager.AllDevices)
{ {
if (device.Key == this.Properties.connectionDeviceKey) if (device.Key == this.Properties.connectionDeviceKey)
{ {
Debug.Console(2, "deviceKey {0} Matches", device.Key); Debug.Console(2, "deviceKey {0} Matches", device.Key);
Dsp = DeviceManager.GetDeviceForKey(device.Key) as PepperDash.Essentials.Devices.Common.DSP.QscDsp; Dsp = DeviceManager.GetDeviceForKey(device.Key) as PepperDash.Essentials.Devices.Common.DSP.QscDsp;
break; break;
} }
else else
{ {
Debug.Console(2, "deviceKey {0} doesn't match", device.Key); Debug.Console(2, "deviceKey {0} doesn't match", device.Key);
} }
} }
if (Properties.EiscApiIpids != null && Dsp != null) if (Properties.EiscApiIpids != null && Dsp != null)
{ {
foreach (string Ipid in Properties.EiscApiIpids) foreach (string Ipid in Properties.EiscApiIpids)
{ {
var ApiEisc = new BridgeApiEisc(Ipid); var ApiEisc = new BridgeApiEisc(Ipid);
Debug.Console(2, "Connecting EiscApi {0} to {1}", ApiEisc.Ipid, Dsp.Name); Debug.Console(2, "Connecting EiscApi {0} to {1}", ApiEisc.Ipid, Dsp.Name);
ushort x = 1; ushort x = 1;
foreach (var channel in Dsp.LevelControlPoints) foreach (var channel in Dsp.LevelControlPoints)
{ {
//var QscChannel = channel.Value as PepperDash.Essentials.Devices.Common.DSP.QscDspLevelControl; //var QscChannel = channel.Value as PepperDash.Essentials.Devices.Common.DSP.QscDspLevelControl;
Debug.Console(2, "QscChannel {0} connect", x); Debug.Console(2, "QscChannel {0} connect", x);
var QscChannel = channel.Value as IBasicVolumeWithFeedback; var QscChannel = channel.Value as IBasicVolumeWithFeedback;
QscChannel.MuteFeedback.LinkInputSig(ApiEisc.Eisc.BooleanInput[ApiMap.channelMuteToggle[x]]); QscChannel.MuteFeedback.LinkInputSig(ApiEisc.Eisc.BooleanInput[ApiMap.channelMuteToggle[x]]);
QscChannel.VolumeLevelFeedback.LinkInputSig(ApiEisc.Eisc.UShortInput[ApiMap.channelVolume[x]]); QscChannel.VolumeLevelFeedback.LinkInputSig(ApiEisc.Eisc.UShortInput[ApiMap.channelVolume[x]]);
ApiEisc.Eisc.SetSigTrueAction(ApiMap.channelMuteToggle[x], () => QscChannel.MuteToggle());
ApiEisc.Eisc.SetUShortSigAction(ApiMap.channelVolume[x], u => QscChannel.SetVolume(u)); ApiEisc.Eisc.SetSigTrueAction(ApiMap.channelMuteToggle[x], () => QscChannel.MuteToggle());
ApiEisc.Eisc.SetStringSigAction(ApiMap.presetString, s => Dsp.RunPreset(s)); ApiEisc.Eisc.SetSigTrueAction(ApiMap.channelMuteOn[x], () => QscChannel.MuteOn());
x++; ApiEisc.Eisc.SetSigTrueAction(ApiMap.channelMuteOff[x], () => QscChannel.MuteOff());
} ApiEisc.Eisc.SetBoolSigAction(ApiMap.channelVolumeUp[x], b => QscChannel.VolumeUp(b));
x = 1; ApiEisc.Eisc.SetBoolSigAction(ApiMap.channelVolumeDown[x], b => QscChannel.VolumeDown(b));
foreach (var preset in Dsp.PresetList)
{ ApiEisc.Eisc.SetUShortSigAction(ApiMap.channelVolume[x], u => QscChannel.SetVolume(u));
ApiEisc.Eisc.StringInput[ApiMap.presets[x]].StringValue = preset.label; ApiEisc.Eisc.SetStringSigAction(ApiMap.presetString, s => Dsp.RunPreset(s));
ApiEisc.Eisc.SetSigTrueAction(ApiMap.presets[x], () => Dsp.RunPresetNumber(x)); x++;
x++;
} }
x = 1;
} foreach (var preset in Dsp.PresetList)
} {
ApiEisc.Eisc.StringInput[ApiMap.presets[x]].StringValue = preset.label;
ApiEisc.Eisc.SetSigTrueAction(ApiMap.presets[x], () => Dsp.RunPresetNumber(x));
x++;
}
Debug.Console(2, "Name {0} Activated", this.Name);
return true; }
} }
catch (Exception e) {
Debug.Console(0, "Bridge {0}", e);
return false;
}
} Debug.Console(2, "Name {0} Activated", this.Name);
} return true;
public class EssentialDspProperties { }
public string connectionDeviceKey; catch (Exception e) {
public string[] EiscApiIpids; Debug.Console(0, "Bridge {0}", e);
return false;
}
} }
}
public class EssentialDspProperties {
public class EssentialDspApiMap { public string connectionDeviceKey;
public ushort presetString = 2000; public string[] EiscApiIpids;
public Dictionary<uint, ushort> channelMuteToggle;
public Dictionary<uint, ushort> channelVolume;
public Dictionary<uint, ushort> presets; }
public EssentialDspApiMap() {
channelMuteToggle = new Dictionary<uint, ushort>(); public class EssentialDspApiMap {
channelVolume = new Dictionary<uint, ushort>(); public ushort presetString = 2000;
presets = new Dictionary<uint, ushort>(); public Dictionary<uint, ushort> channelMuteToggle;
for (uint x = 1; x <= 100; x++) { public Dictionary<uint, ushort> channelMuteOn;
uint tempNum = x; public Dictionary<uint, ushort> channelMuteOff;
presets[tempNum] = (ushort)(tempNum + 100); public Dictionary<uint, ushort> channelVolume;
channelMuteToggle[tempNum] = (ushort)(tempNum + 400); public Dictionary<uint, ushort> channelVolumeUp;
channelVolume[tempNum] = (ushort)(tempNum + 200); public Dictionary<uint, ushort> channelVolumeDown;
public Dictionary<uint, ushort> presets;
}
} public EssentialDspApiMap() {
} channelMuteToggle = new Dictionary<uint, ushort>();
} channelMuteOn = new Dictionary<uint, ushort>();
channelMuteOff = new Dictionary<uint, ushort>();
channelVolume = new Dictionary<uint, ushort>();
presets = new Dictionary<uint, ushort>();
channelVolumeUp = new Dictionary<uint, ushort>();
channelVolumeDown = new Dictionary<uint, ushort>();
for (uint x = 1; x <= 100; x++) {
uint tempNum = x;
presets[tempNum] = (ushort)(tempNum + 100);
channelMuteToggle[tempNum] = (ushort)(tempNum + 400);
channelMuteOn[tempNum] = (ushort)(tempNum + 600);
channelMuteOff[tempNum] = (ushort)(tempNum + 800);
channelVolume[tempNum] = (ushort)(tempNum + 200);
channelVolumeUp[tempNum] = (ushort)(tempNum + 1000);
channelVolumeDown[tempNum] = (ushort)(tempNum + 1200);
}
}
}
}