From 282ea62f83c459e2fd32a26bfe3b134807536a19 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 27 Apr 2020 18:21:55 -0600 Subject: [PATCH 1/3] adds new ctor to add post activation action for ComPortController --- .../Config/Comm and IR/ComPortController.cs | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ComPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ComPortController.cs index a5a5b14f..07260c7e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ComPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ComPortController.cs @@ -21,6 +21,19 @@ namespace PepperDash.Essentials.Core ComPort Port; ComPort.ComPortSpec Spec; + public ComPortController(string key, Func postActivationFunc, + ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key) + { + Spec = spec; + + AddPostActivationAction(() => + { + Port = postActivationFunc(config); + + ConfigureComPort(); + }); + } + public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec) : base(key) { @@ -45,16 +58,21 @@ namespace PepperDash.Essentials.Core return; // false } } - var specResult = Port.SetComPortSpec(Spec); - if (specResult != 0) - { - Debug.Console(0, this, "WARNING: Cannot set comspec"); - return; // false - } - Port.SerialDataReceived += new ComPortDataReceivedEvent(Port_SerialDataReceived); + ConfigureComPort(); } - ~ComPortController() + private void ConfigureComPort() + { + var specResult = Port.SetComPortSpec(Spec); + if (specResult != 0) + { + Debug.Console(0, this, "WARNING: Cannot set comspec"); + return; + } + Port.SerialDataReceived += Port_SerialDataReceived; + } + + ~ComPortController() { Port.SerialDataReceived -= Port_SerialDataReceived; } From d6d0e3cfda20ee2e2a4d771dfb230a56fb2d0c48 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 27 Apr 2020 18:22:23 -0600 Subject: [PATCH 2/3] adds new ctor to CecPortController to add post activation func --- .../Config/Comm and IR/CecPortController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CecPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CecPortController.cs index a2493e3c..1ab38d89 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CecPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CecPortController.cs @@ -20,6 +20,17 @@ namespace PepperDash.Essentials.Core ICec Port; + public CecPortController(string key, Func postActivationFunc, + EssentialsControlPropertiesConfig config):base(key) + { + AddPostActivationAction(() => + { + Port = postActivationFunc(config); + + Port.StreamCec.CecChange += StreamCec_CecChange; + }); + } + public CecPortController(string key, ICec port) : base(key) { From 0d33354f0838ebc8644a2104a79418de5f0ad976 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 27 Apr 2020 18:22:47 -0600 Subject: [PATCH 3/3] updates CommFactory to use new ctors for ComPortController and CecPortController --- .../Config/Comm and IR/CommFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CommFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CommFactory.cs index 23aea272..94110fd7 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CommFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/CommFactory.cs @@ -48,10 +48,10 @@ namespace PepperDash.Essentials.Core switch (controlConfig.Method) { case eControlMethod.Com: - comm = new ComPortController(deviceConfig.Key + "-com", GetComPort(controlConfig), controlConfig.ComParams); + comm = new ComPortController(deviceConfig.Key + "-com", GetComPort, controlConfig.ComParams, controlConfig); break; case eControlMethod.Cec: - comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort(controlConfig)); + comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort, controlConfig); break; case eControlMethod.IR: break;