From c2a439d20d2ce81a5c456bc883686cccbfc30b84 Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 14 Dec 2022 09:47:31 -0600 Subject: [PATCH] feat: Add DinIo8 --- .../Crestron IO/DinIo8/DinIo8Controller.cs | 80 +++++++++++++++++++ .../PepperDash_Essentials_Core.csproj | 1 + 2 files changed, 81 insertions(+) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/DinIo8/DinIo8Controller.cs diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/DinIo8/DinIo8Controller.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/DinIo8/DinIo8Controller.cs new file mode 100644 index 00000000..e3c2b094 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/DinIo8/DinIo8Controller.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DeviceSupport; +using Crestron.SimplSharpPro.GeneralIO; +using PepperDash.Core; +using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; + +namespace PepperDash.Essentials.Core.CrestronIO +{ + public class DinIo8Controller:CrestronGenericBaseDevice, IIOPorts + { + private DinIo8 _device; + + public DinIo8Controller(string key, Func preActivationFunc, DeviceConfig config):base(key, config.Name) + { + AddPreActivationAction(() => + { + _device = preActivationFunc(config); + + RegisterCrestronGenericBase(_device); + }); + } + + #region Implementation of IIOPorts + + public CrestronCollection VersiPorts + { + get { return _device.VersiPorts; } + } + + public int NumberOfVersiPorts + { + get { return _device.NumberOfVersiPorts; } + } + + #endregion + + + } + + public class DinIo8ControllerFactory : EssentialsDeviceFactory + { + public DinIo8ControllerFactory() + { + TypeNames = new List() { "DinIo8" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new C2N-IO Device"); + + return new DinIo8Controller(dc.Key, GetDinIo8Device, dc); + } + + static DinIo8 GetDinIo8Device(DeviceConfig dc) + { + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + var branchId = control.ControlPortNumber; + var parentKey = string.IsNullOrEmpty(control.ControlPortDevKey) ? "processor" : control.ControlPortDevKey; + + if (parentKey.Equals("processor", StringComparison.CurrentCultureIgnoreCase)) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new DinIo8", parentKey); + return new DinIo8(cresnetId, Global.ControlSystem); + } + var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches; + + if (cresnetBridge != null) + { + Debug.Console(0, "Device {0} is a valid cresnet master - creating new DinIo8", parentKey); + return new DinIo8(cresnetId, cresnetBridge.CresnetBranches[branchId]); + } + Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey); + return null; + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index dfa59b88..351c781c 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -179,6 +179,7 @@ +