diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/IRPortHelper.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/IRPortHelper.cs index c75630e4..80ee2a2c 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/IRPortHelper.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Comm and IR/IRPortHelper.cs @@ -224,12 +224,18 @@ namespace PepperDash.Essentials.Core /// public class IrOutPortConfig { + [JsonProperty("port")] public IROutputPort Port { get; set; } + + [JsonProperty("fileName")] public string FileName { get; set; } + [JsonProperty("useBridgeJoinMap")] + public bool UseBridgeJoinMap { get; set; } + public IrOutPortConfig() { - FileName = ""; + FileName = ""; } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index 409562a2..959b334b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; using Crestron.SimplSharpPro.DeviceSupport; using Newtonsoft.Json; using PepperDash.Core; -using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; +using PepperDash_Essentials_Core.Bridges.JoinMaps; namespace PepperDash.Essentials.Core.Devices { @@ -21,9 +21,12 @@ namespace PepperDash.Essentials.Core.Devices public string[] IrCommands {get { return _port.IrFileCommands; }} + public Dictionary BridgeJoins; + public GenericIrController(string key, string name, IrOutputPortController irPort) : base(key, name) { _port = irPort; + if(_port.UseBridgeJoinMap) BridgeJoins = new Dictionary(); if (_port == null) { @@ -71,23 +74,39 @@ namespace PepperDash.Essentials.Core.Devices if (!string.IsNullOrEmpty(joinMapSerialized)) joinMap = JsonConvert.DeserializeObject(joinMapSerialized); - for (uint i = 0; i < _port.IrFileCommands.Length; i++) - { - var cmd = _port.IrFileCommands[i]; - var joinData = new JoinDataComplete(new JoinData {JoinNumber = i, JoinSpan = 1}, - new JoinMetadata - { - Description = cmd, - JoinCapabilities = eJoinCapabilities.FromSIMPL, - JoinType = eJoinType.Digital - }); + if (_port.UseBridgeJoinMap) + { + Debug.Console(0, this, "Using new IR bridge join map"); - joinData.SetJoinOffset(joinStart); + var joins = BridgeJoins.Where((kv) => _port.IrFileCommands.Any(cmd => cmd == kv.Key)).ToDictionary(kv => kv.Key, kv=> kv.Value); + foreach (var join in joins) + { + Debug.Console(0, this, "_useBridgeJoinMap: {0}: {1}", join.Key, join.Value); + } + //joinMap.Joins = joins.Select(kv => kv.Value.SetJoinOffset(joinStart)).ToString(); + } + else + { + Debug.Console(0, this, "Using legacy IR join mapping based on available IR commands"); - joinMap.Joins.Add(cmd,joinData); + for (uint i = 0; i < _port.IrFileCommands.Length; i++) + { + var cmd = _port.IrFileCommands[i]; + var joinData = new JoinDataComplete(new JoinData { JoinNumber = i, JoinSpan = 1 }, + new JoinMetadata + { + Description = cmd, + JoinCapabilities = eJoinCapabilities.FromSIMPL, + JoinType = eJoinType.Digital + }); - trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(cmd, b)); - } + joinData.SetJoinOffset(joinStart); + + joinMap.Joins.Add(cmd, joinData); + + trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(cmd, b)); + } + } joinMap.PrintJoinMapInfo(); @@ -109,13 +128,6 @@ namespace PepperDash.Essentials.Core.Devices } } - public sealed class GenericIrControllerJoinMap : JoinMapBaseAdvanced - { - public GenericIrControllerJoinMap(uint joinStart) : base(joinStart) - { - } - } - public class GenericIrControllerFactory : EssentialsDeviceFactory { public GenericIrControllerFactory() diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs index cce1d46e..5ce7a779 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs @@ -29,6 +29,8 @@ namespace PepperDash.Essentials.Core public string[] IrFileCommands { get { return IrPort.AvailableStandardIRCmds(IrPortUid); } } + public bool UseBridgeJoinMap { get; private set; } + /// /// Constructor for IrDevice base class. If a null port is provided, this class will /// still function without trying to talk to a port. @@ -62,6 +64,8 @@ namespace PepperDash.Essentials.Core Debug.Console(0, this, "WARNING No valid IR Port assigned to controller. IR will not function"); return; } + + UseBridgeJoinMap = config.Properties["control"]["useBridgeJoinMap"].Value(); var filePath = Global.FilePathPrefix + "ir" + Global.DirectorySeparator + config.Properties["control"]["irFile"].Value(); Debug.Console(1, "*************Attempting to load IR file: {0}***************", filePath); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 75d4626d..c1445edb 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -127,6 +127,7 @@ +