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 Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs new file mode 100644 index 00000000..bf4544de --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -0,0 +1,138 @@ +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; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash_Essentials_Core.Devices +{ + public class GenericIrController: EssentialsBridgeableDevice + { + //data storage for bridging + private BasicTriList _trilist; + private uint _joinStart; + private string _joinMapKey; + private EiscApiAdvanced _bridge; + + private readonly IrOutputPortController _port; + + public string[] IrCommands {get { return _port.IrFileCommands; }} + + public GenericIrController(string key, string name, IrOutputPortController irPort) : base(key, name) + { + _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; + } + + private void DriverLoadedOnOutputChange(object sender, FeedbackEventArgs args) + { + if (!args.BoolValue) + { + return; + } + + if (_trilist == null || _bridge == null) + { + return; + } + + LinkToApi(_trilist, _joinStart, _joinMapKey, _bridge); + } + + #region Overrides of EssentialsBridgeableDevice + + public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) + { + //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++) + { + 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 + }); + + joinData.SetJoinOffset(joinStart); + + joinMap.Joins.Add(cmd,joinData); + + trilist.SetBoolSigAction(joinData.JoinNumber, (b) => Press(cmd, b)); + } + + joinMap.PrintJoinMapInfo(); + + 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 sealed class GenericIrControllerJoinMap : JoinMapBaseAdvanced + { + public GenericIrControllerJoinMap(uint joinStart) : base(joinStart) + { + } + } + + 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..cce1d46e 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; } @@ -35,6 +37,8 @@ namespace PepperDash.Essentials.Core : base(key) { //if (port == null) throw new ArgumentNullException("port"); + + DriverLoaded = new BoolFeedback(() => DriverIsLoaded); IrPort = port; if (port == null) { @@ -48,6 +52,7 @@ namespace PepperDash.Essentials.Core DeviceConfig config) : base(key) { + DriverLoaded = new BoolFeedback(() => DriverIsLoaded); AddPostActivationAction(() => { IrPort = postActivationFunc(config); @@ -59,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); @@ -91,13 +96,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 077d46fa..ae420105 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 @@ + 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 22a1dc1d..d18cb6ce 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 + + 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