Changes to CrestronGenericBase

Refactor RfGatewayController

new IHasReady interface

Updates to Hrxx0WirelessRemoteController

merge in development

Addresses #292
This commit is contained in:
Trevor Payne
2020-07-01 16:03:32 -05:00
parent bfa49b4772
commit 2fea151089
4 changed files with 62 additions and 49 deletions

View File

@@ -13,7 +13,7 @@ namespace PepperDash.Essentials.Core
/// </summary>
public abstract class CrestronGenericBaseDevice : EssentialsDevice, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
{
public virtual GenericBase Hardware { get; protected set; }
protected GenericBase Hardware;
/// <summary>
/// Returns a list containing the Outputs that we want to expose.

View File

@@ -6,25 +6,19 @@ using Crestron.SimplSharp;
namespace PepperDash_Essentials_Core
{
public delegate void IsReadyEventHandler(object source, IsReadyEventArgs e);
public class IsReadyEventArgs : EventArgs
{
private readonly bool _EventData;
public bool IsReady { get; set; }
public IsReadyEventArgs(bool data)
{
_EventData = data;
}
public bool GetData()
{
return _EventData;
IsReady = data;
}
}
public interface IHasReady
{
event IsReadyEventHandler IsReady;
event EventHandler<IsReadyEventArgs> IsReadyEvent;
bool IsReady { get; }
}
}

View File

@@ -20,7 +20,9 @@ namespace PepperDash.Essentials.Core
[Description("Wrapper class for Crestron Infinet-EX Gateways")]
public class CenRfgwController : CrestronGenericBaseDevice, IHasReady
{
public event IsReadyEventHandler IsReady;
public event EventHandler<IsReadyEventArgs> IsReadyEvent;
public bool IsReady { get; private set; }
private GatewayBase _gateway;
@@ -34,23 +36,27 @@ namespace PepperDash.Essentials.Core
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
/// <param name="gateway"></param>
public CenRfgwController(string key, string name, GatewayBase gateway) :
base(key, name, gateway)
{
_gateway = gateway;
IsReady(this, new IsReadyEventArgs(true));
IsReady = true;
FireIsReadyEvent(IsReady);
}
public CenRfgwController(string key, Func<DeviceConfig, GatewayBase> preActivationFunc, DeviceConfig config) :
base(key, config.Name)
{
IsReady(this, new IsReadyEventArgs(false));
IsReady = false;
FireIsReadyEvent(IsReady);
AddPreActivationAction(() =>
{
_gateway = preActivationFunc(config);
IsReady = true;
RegisterCrestronGenericBase(_gateway);
IsReady(this, new IsReadyEventArgs(true));
FireIsReadyEvent(IsReady);
});
}
@@ -58,9 +64,7 @@ namespace PepperDash.Essentials.Core
public static GatewayBase GetNewIpRfGateway(DeviceConfig dc)
{
var control = CommFactory.GetControlPropertiesConfig(dc);
var name = dc.Name;
var type = dc.Type;
var key = dc.Key;
var ipId = control.IpIdInt;
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
@@ -74,6 +78,15 @@ namespace PepperDash.Essentials.Core
return null;
}
private void FireIsReadyEvent(bool data)
{
var handler = IsReadyEvent;
if (handler == null) return;
handler(this, new IsReadyEventArgs(data));
}
public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc)
{
var control = CommFactory.GetControlPropertiesConfig(dc);
@@ -135,7 +148,7 @@ namespace PepperDash.Essentials.Core
public enum eExGatewayType
public enum EExGatewayType
{
Ethernet,
EthernetShared,
@@ -159,22 +172,17 @@ namespace PepperDash.Essentials.Core
var props = JsonConvert.DeserializeObject<EssentialsRfGatewayConfig>(dc.Properties.ToString());
var type = dc.Type.ToLower();
var control = props.Control;
var ipid = control.IpIdInt;
var cresnetId = control.CresnetIdInt;
eExGatewayType gatewayType =
(eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true);
EExGatewayType gatewayType =
(EExGatewayType) Enum.Parse(typeof (EExGatewayType), props.GatewayType, true);
switch (gatewayType)
{
case (eExGatewayType.Ethernet):
return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc));
case (eExGatewayType.EthernetShared):
return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc));
case (eExGatewayType.Cresnet):
return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc);
case (EExGatewayType.Ethernet):
return new CenRfgwController(dc.Key, dc.Name, GetNewIpRfGateway(dc));
case (EExGatewayType.EthernetShared):
return new CenRfgwController(dc.Key, dc.Name, GetNewSharedIpRfGateway(dc));
case (EExGatewayType.Cresnet):
return new CenRfgwController(dc.Key, GetCenRfgwCresnetController, dc);
}
return null;
}

View File

@@ -29,6 +29,8 @@ namespace PepperDash.Essentials.Core
public CrestronCollection<Button> Buttons { get { return _remote.Button; } }
private DeviceConfig _config;
public Hrxx0WirelessRemoteController(string key, Func<DeviceConfig, Hr1x0WirelessRemoteBase> preActivationFunc,
DeviceConfig config)
: base(key, config.Name)
@@ -39,6 +41,7 @@ namespace PepperDash.Essentials.Core
var type = config.Type;
var rfId = (uint)props.Control.InfinetIdInt;
_config = config;
GatewayBase gateway;
@@ -62,29 +65,26 @@ namespace PepperDash.Essentials.Core
}
}
if (_gateway != null)
if (_gateway == null) return;
_gateway.IsReadyEvent += _gateway_IsReadyEvent;
if (_gateway.IsReady)
{
_gateway.IsReady += new PepperDash_Essentials_Core.IsReadyEventHandler(_gateway_IsReady);
AddPreActivationAction(() =>
{
_remote = preActivationFunc(config);
RegisterEvents();
});
}
AddPreActivationAction(() =>
{
_remote = preActivationFunc(config);
_remote.ButtonStateChange += new ButtonEventHandler(_remote_ButtonStateChange);
Feedbacks.Add(new BoolFeedback("BatteryCritical", () => _remote.BatteryCriticalFeedback.BoolValue));
Feedbacks.Add(new BoolFeedback("BatteryLow", () => _remote.BatteryLowFeedback.BoolValue));
Feedbacks.Add(new IntFeedback("BatteryVoltage", () => _remote.BatteryVoltageFeedback.UShortValue));
_remote.BaseEvent += new BaseEventHandler(_remote_BaseEvent);
});
}
void _gateway_IsReady(object source, PepperDash_Essentials_Core.IsReadyEventArgs e)
void _gateway_IsReadyEvent(object sender, PepperDash_Essentials_Core.IsReadyEventArgs e)
{
throw new NotImplementedException();
if (e.IsReady != true) return;
_remote = GetHr1x0WirelessRemote(_config);
RegisterEvents();
}
void _remote_BaseEvent(GenericBase device, BaseEventArgs args)
@@ -97,6 +97,17 @@ namespace PepperDash.Essentials.Core
Feedbacks["BatteryVoltage"].FireUpdate();
}
private void RegisterEvents()
{
_remote.ButtonStateChange += _remote_ButtonStateChange;
Feedbacks.Add(new BoolFeedback("BatteryCritical", () => _remote.BatteryCriticalFeedback.BoolValue));
Feedbacks.Add(new BoolFeedback("BatteryLow", () => _remote.BatteryLowFeedback.BoolValue));
Feedbacks.Add(new IntFeedback("BatteryVoltage", () => _remote.BatteryVoltageFeedback.UShortValue));
_remote.BaseEvent += _remote_BaseEvent;
}
void _remote_ButtonStateChange(GenericBase device, ButtonEventArgs args)
{
try