mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Merge pull request #127 from PepperDash/feature/comPortController-post-activation-add
Adds ctor for ComPortController and CecPortController
This commit is contained in:
@@ -20,6 +20,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
ICec Port;
|
ICec Port;
|
||||||
|
|
||||||
|
public CecPortController(string key, Func<EssentialsControlPropertiesConfig, ICec> postActivationFunc,
|
||||||
|
EssentialsControlPropertiesConfig config):base(key)
|
||||||
|
{
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
Port = postActivationFunc(config);
|
||||||
|
|
||||||
|
Port.StreamCec.CecChange += StreamCec_CecChange;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public CecPortController(string key, ICec port)
|
public CecPortController(string key, ICec port)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,19 @@ namespace PepperDash.Essentials.Core
|
|||||||
ComPort Port;
|
ComPort Port;
|
||||||
ComPort.ComPortSpec Spec;
|
ComPort.ComPortSpec Spec;
|
||||||
|
|
||||||
|
public ComPortController(string key, Func<EssentialsControlPropertiesConfig, ComPort> postActivationFunc,
|
||||||
|
ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key)
|
||||||
|
{
|
||||||
|
Spec = spec;
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
Port = postActivationFunc(config);
|
||||||
|
|
||||||
|
ConfigureComPort();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
|
public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
@@ -45,16 +58,21 @@ namespace PepperDash.Essentials.Core
|
|||||||
return; // false
|
return; // false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var specResult = Port.SetComPortSpec(Spec);
|
ConfigureComPort();
|
||||||
if (specResult != 0)
|
|
||||||
{
|
|
||||||
Debug.Console(0, this, "WARNING: Cannot set comspec");
|
|
||||||
return; // false
|
|
||||||
}
|
|
||||||
Port.SerialDataReceived += new ComPortDataReceivedEvent(Port_SerialDataReceived);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~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;
|
Port.SerialDataReceived -= Port_SerialDataReceived;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ namespace PepperDash.Essentials.Core
|
|||||||
switch (controlConfig.Method)
|
switch (controlConfig.Method)
|
||||||
{
|
{
|
||||||
case eControlMethod.Com:
|
case eControlMethod.Com:
|
||||||
comm = new ComPortController(deviceConfig.Key + "-com", GetComPort(controlConfig), controlConfig.ComParams);
|
comm = new ComPortController(deviceConfig.Key + "-com", GetComPort, controlConfig.ComParams, controlConfig);
|
||||||
break;
|
break;
|
||||||
case eControlMethod.Cec:
|
case eControlMethod.Cec:
|
||||||
comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort(controlConfig));
|
comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort, controlConfig);
|
||||||
break;
|
break;
|
||||||
case eControlMethod.IR:
|
case eControlMethod.IR:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user