From 741f69473348ec5b3ab8198d8c8064f8c8f578b2 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 2 Sep 2020 16:54:01 -0600 Subject: [PATCH 1/6] add genericIrController class --- .../Devices/GenericIRController.cs | 50 +++++++++++++++++++ .../Devices/IrOutputPortController.cs | 2 + essentials-framework/pepperdashcore-builds | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs new file mode 100644 index 00000000..7dcac922 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using Crestron.SimplSharpPro.DeviceSupport; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash_Essentials_Core.Devices +{ + public class GenericIRController: EssentialsBridgeableDevice + { + private readonly IrOutputPortController _port; + + public GenericIRController(string key, string name, IrOutputPortController irPort) : base(key, name) + { + _port = irPort; + + DeviceManager.AddDevice(_port); + } + + #region Overrides of EssentialsBridgeableDevice + + public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) + { + throw new System.NotImplementedException(); + } + + #endregion + } + + public class GenericIrControllerFactory : EssentialsDeviceFactory + { + public GenericIrControllerFactory() + { + TypeNames = new List {"genericIrController"}; + } + #region Overrides of EssentialsDeviceFactory + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic IR Controller Device"); + + var irPort = IRPortHelper.GetIrOutputPortController(dc); + + return new GenericIRController(dc.Key, dc.Name, irPort); + } + + #endregion + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs index ff884007..49d4b7f3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs @@ -35,6 +35,8 @@ namespace PepperDash.Essentials.Core : base(key) { //if (port == null) throw new ArgumentNullException("port"); + + DriverLoaded = new BoolFeedback(() => DriverIsLoaded); IrPort = port; if (port == null) { diff --git a/essentials-framework/pepperdashcore-builds b/essentials-framework/pepperdashcore-builds index 18cb0c27..b64665a6 160000 --- a/essentials-framework/pepperdashcore-builds +++ b/essentials-framework/pepperdashcore-builds @@ -1 +1 @@ -Subproject commit 18cb0c273eb8b750f657d74160ad82eff1b24bca +Subproject commit b64665a60ebfa8cd4dc680acccb3ef0d94cbbf82 From 9526b9b6febe85a424ee2214b6f3895188520eb0 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 2 Sep 2020 17:18:08 -0600 Subject: [PATCH 2/6] added feedback for IrOutputController and added join map --- .../Devices/GenericIRController.cs | 85 +++++++++++++++++-- .../Devices/IrOutputPortController.cs | 8 +- .../PepperDash_Essentials_Core.csproj | 1 + 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index 7dcac922..13d851f2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Crestron.SimplSharpPro.DeviceSupport; +using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; @@ -7,28 +9,97 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash_Essentials_Core.Devices { - public class GenericIRController: EssentialsBridgeableDevice + public class GenericIrController: EssentialsBridgeableDevice { - private readonly IrOutputPortController _port; + //data storage for bridging + private BasicTriList _trilist; + private uint _joinStart; + private string _joinMapKey; + private EiscApiAdvanced _bridge; - public GenericIRController(string key, string name, IrOutputPortController irPort) : base(key, name) + private readonly IrOutputPortController _port; + + public GenericIrController(string key, string name, IrOutputPortController irPort) : base(key, name) { _port = irPort; DeviceManager.AddDevice(_port); + + _port.DriverLoaded.OutputChange += DriverLoadedOnOutputChange; + } + + private void DriverLoadedOnOutputChange(object sender, FeedbackEventArgs args) + { + if (!args.BoolValue) + { + return; + } + + LinkToApi(_trilist, _joinStart, _joinMapKey, _bridge); } #region Overrides of EssentialsBridgeableDevice public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { - throw new System.NotImplementedException(); + //if driver isn't loaded yet, store the variables until it is loaded, then call the LinkToApi method again + if (!_port.DriverIsLoaded) + { + _trilist = trilist; + _joinStart = joinStart; + _joinMapKey = joinMapKey; + _bridge = bridge; + return; + } + + var joinMap = new GenericIrControllerJoinMap(joinStart); + + var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); + + if (!string.IsNullOrEmpty(joinMapSerialized)) + joinMap = JsonConvert.DeserializeObject(joinMapSerialized); + + for (uint i = 0; i < _port.IrFileCommands.Length; i++) + { + joinMap.Joins.Add(_port.IrFileCommands[i], + new JoinDataComplete(new JoinData {JoinNumber = i + joinStart, JoinSpan = 1}, + new JoinMetadata + { + Description = _port.IrFileCommands[i], + JoinCapabilities = eJoinCapabilities.FromSIMPL, + JoinType = eJoinType.Digital + })); + + var index = i; + trilist.SetBoolSigAction(i + joinStart, (b) => Press(_port.IrFileCommands[index], b)); + } + + if (bridge != null) + { + bridge.AddJoinMap(Key, joinMap); + } + else + { + Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); + } } #endregion + + public void Press(string command, bool pressRelease) + { + _port.PressRelease(command, pressRelease); + } } - public class GenericIrControllerFactory : EssentialsDeviceFactory + public sealed class GenericIrControllerJoinMap : JoinMapBaseAdvanced + { + public GenericIrControllerJoinMap(uint joinStart) : base(joinStart) + { + } + } + + public class GenericIrControllerFactory : EssentialsDeviceFactory { public GenericIrControllerFactory() { @@ -42,7 +113,7 @@ namespace PepperDash_Essentials_Core.Devices var irPort = IRPortHelper.GetIrOutputPortController(dc); - return new GenericIRController(dc.Key, dc.Name, irPort); + return new GenericIrController(dc.Key, dc.Name, irPort); } #endregion diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs index 49d4b7f3..5099f7d0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs @@ -21,6 +21,8 @@ namespace PepperDash.Essentials.Core uint IrPortUid; IROutputPort IrPort; + public BoolFeedback DriverLoaded { get; private set; } + public ushort StandardIrPulseTime { get; set; } public string DriverFilepath { get; private set; } public bool DriverIsLoaded { get; private set; } @@ -93,13 +95,15 @@ namespace PepperDash.Essentials.Core DriverFilepath = path; StandardIrPulseTime = 200; DriverIsLoaded = true; + + DriverLoaded.FireUpdate(); } catch { DriverIsLoaded = false; var message = string.Format("WARNING IR Driver '{0}' failed to load", path); - Debug.Console(0, this, message); - ErrorLog.Error(message); + Debug.Console(0, this, Debug.ErrorLogLevel.Error, message); + DriverLoaded.FireUpdate(); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index c31a46b8..06978313 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -200,6 +200,7 @@ + From 8a98924ad7c045ce9a43e902656cb572c0f490e5 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 2 Sep 2020 21:03:24 -0600 Subject: [PATCH 3/6] Use joinData methods to set offset to get joins in the right spot --- .../Devices/GenericIRController.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index 13d851f2..f8486b76 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -61,17 +61,20 @@ namespace PepperDash_Essentials_Core.Devices for (uint i = 0; i < _port.IrFileCommands.Length; i++) { - joinMap.Joins.Add(_port.IrFileCommands[i], - new JoinDataComplete(new JoinData {JoinNumber = i + joinStart, JoinSpan = 1}, - new JoinMetadata - { - Description = _port.IrFileCommands[i], - JoinCapabilities = eJoinCapabilities.FromSIMPL, - JoinType = eJoinType.Digital - })); + var joinData = new JoinDataComplete(new JoinData {JoinNumber = i + joinStart, JoinSpan = 1}, + new JoinMetadata + { + Description = _port.IrFileCommands[i], + JoinCapabilities = eJoinCapabilities.FromSIMPL, + JoinType = eJoinType.Digital + }); + + joinData.SetJoinOffset(joinStart); + + joinMap.Joins.Add(_port.IrFileCommands[i],joinData); var index = i; - trilist.SetBoolSigAction(i + joinStart, (b) => Press(_port.IrFileCommands[index], b)); + trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(_port.IrFileCommands[index], b)); } if (bridge != null) From ceef883ad8d059d223120b4f9824b255235da243 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 2 Sep 2020 23:59:26 -0600 Subject: [PATCH 4/6] fixed some null refs and got join map being created correctly --- .../Devices/GenericIRController.cs | 22 ++++++++++++++----- .../Devices/IrOutputPortController.cs | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index f8486b76..f942a0f2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -23,6 +23,11 @@ namespace PepperDash_Essentials_Core.Devices { _port = irPort; + if (_port == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "IR Port is null, device will not function"); + return; + } DeviceManager.AddDevice(_port); _port.DriverLoaded.OutputChange += DriverLoadedOnOutputChange; @@ -35,6 +40,11 @@ namespace PepperDash_Essentials_Core.Devices return; } + if (_trilist == null || _bridge == null) + { + return; + } + LinkToApi(_trilist, _joinStart, _joinMapKey, _bridge); } @@ -61,22 +71,24 @@ namespace PepperDash_Essentials_Core.Devices for (uint i = 0; i < _port.IrFileCommands.Length; i++) { - var joinData = new JoinDataComplete(new JoinData {JoinNumber = i + joinStart, JoinSpan = 1}, + var cmd = _port.IrFileCommands[i]; + var joinData = new JoinDataComplete(new JoinData {JoinNumber = i, JoinSpan = 1}, new JoinMetadata { - Description = _port.IrFileCommands[i], + Description = cmd, JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital }); joinData.SetJoinOffset(joinStart); - joinMap.Joins.Add(_port.IrFileCommands[i],joinData); + joinMap.Joins.Add(cmd,joinData); - var index = i; - trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(_port.IrFileCommands[index], b)); + trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(cmd, b)); } + joinMap.PrintJoinMapInfo(); + if (bridge != null) { bridge.AddJoinMap(Key, joinMap); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs index 5099f7d0..cce1d46e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs @@ -52,6 +52,7 @@ namespace PepperDash.Essentials.Core DeviceConfig config) : base(key) { + DriverLoaded = new BoolFeedback(() => DriverIsLoaded); AddPostActivationAction(() => { IrPort = postActivationFunc(config); @@ -63,7 +64,7 @@ namespace PepperDash.Essentials.Core } var filePath = Global.FilePathPrefix + "ir" + Global.DirectorySeparator + config.Properties["control"]["irFile"].Value(); - Debug.Console(1, "*************Attemting to load IR file: {0}***************", filePath); + Debug.Console(1, "*************Attempting to load IR file: {0}***************", filePath); LoadDriver(filePath); From 7248e907626f82708dbb903beefd69b876528ca6 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 3 Sep 2020 00:01:25 -0600 Subject: [PATCH 5/6] add property to get IR Commands for Essentials --- .../PepperDashEssentialsBase/Devices/GenericIRController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index f942a0f2..bf4544de 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -19,6 +19,8 @@ namespace PepperDash_Essentials_Core.Devices private readonly IrOutputPortController _port; + public string[] IrCommands {get { return _port.IrFileCommands; }} + public GenericIrController(string key, string name, IrOutputPortController irPort) : base(key, name) { _port = irPort; From 7cd3a143a002e2e22cefc5f8b16bd39d60d50a3c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 3 Sep 2020 08:00:16 -0600 Subject: [PATCH 6/6] Adds Essentials core as a project reference --- PepperDashEssentials/PepperDashEssentials.csproj | 8 ++++---- .../Essentials Devices Common.csproj | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/PepperDashEssentials/PepperDashEssentials.csproj b/PepperDashEssentials/PepperDashEssentials.csproj index ed178abc..cd8062ce 100644 --- a/PepperDashEssentials/PepperDashEssentials.csproj +++ b/PepperDashEssentials/PepperDashEssentials.csproj @@ -75,10 +75,6 @@ False ..\packages\PepperDashCore\lib\net35\PepperDash_Core.dll - - False - ..\essentials-framework\Essentials DM\Essentials_DM\bin\PepperDash_Essentials_DM.dll - False ..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll @@ -215,6 +211,10 @@ {892B761C-E479-44CE-BD74-243E9214AF13} Essentials Devices Common + + {9199CE8A-0C9F-4952-8672-3EED798B284F} + PepperDash_Essentials_DM + diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index 7c978bd8..00612bab 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -71,10 +71,6 @@ False ..\..\..\packages\PepperDashCore\lib\net35\PepperDash_Core.dll - - False - ..\..\Essentials Core\PepperDashEssentialsBase\bin\PepperDash_Essentials_Core.dll - False ..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll @@ -187,6 +183,12 @@ + + + {A49AD6C8-FC0A-4CC0-9089-DFB4CF92D2B5} + PepperDash_Essentials_Core + +