mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Changes to CrestronGenericBase
Refactor RfGatewayController new IHasReady interface Updates to Hrxx0WirelessRemoteController merge in development Addresses #292
This commit is contained in:
@@ -13,7 +13,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class CrestronGenericBaseDevice : EssentialsDevice, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
|
public abstract class CrestronGenericBaseDevice : EssentialsDevice, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
|
||||||
{
|
{
|
||||||
public virtual GenericBase Hardware { get; protected set; }
|
protected GenericBase Hardware;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list containing the Outputs that we want to expose.
|
/// Returns a list containing the Outputs that we want to expose.
|
||||||
|
|||||||
@@ -6,25 +6,19 @@ using Crestron.SimplSharp;
|
|||||||
|
|
||||||
namespace PepperDash_Essentials_Core
|
namespace PepperDash_Essentials_Core
|
||||||
{
|
{
|
||||||
public delegate void IsReadyEventHandler(object source, IsReadyEventArgs e);
|
|
||||||
|
|
||||||
public class IsReadyEventArgs : EventArgs
|
public class IsReadyEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
private readonly bool _EventData;
|
public bool IsReady { get; set; }
|
||||||
|
|
||||||
public IsReadyEventArgs(bool data)
|
public IsReadyEventArgs(bool data)
|
||||||
{
|
{
|
||||||
_EventData = data;
|
IsReady = data;
|
||||||
}
|
|
||||||
|
|
||||||
public bool GetData()
|
|
||||||
{
|
|
||||||
return _EventData;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IHasReady
|
public interface IHasReady
|
||||||
{
|
{
|
||||||
event IsReadyEventHandler IsReady;
|
event EventHandler<IsReadyEventArgs> IsReadyEvent;
|
||||||
|
bool IsReady { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,9 @@ namespace PepperDash.Essentials.Core
|
|||||||
[Description("Wrapper class for Crestron Infinet-EX Gateways")]
|
[Description("Wrapper class for Crestron Infinet-EX Gateways")]
|
||||||
public class CenRfgwController : CrestronGenericBaseDevice, IHasReady
|
public class CenRfgwController : CrestronGenericBaseDevice, IHasReady
|
||||||
{
|
{
|
||||||
public event IsReadyEventHandler IsReady;
|
public event EventHandler<IsReadyEventArgs> IsReadyEvent;
|
||||||
|
|
||||||
|
public bool IsReady { get; private set; }
|
||||||
|
|
||||||
private GatewayBase _gateway;
|
private GatewayBase _gateway;
|
||||||
|
|
||||||
@@ -34,23 +36,27 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
|
/// <param name="gateway"></param>
|
||||||
public CenRfgwController(string key, string name, GatewayBase gateway) :
|
public CenRfgwController(string key, string name, GatewayBase gateway) :
|
||||||
base(key, name, gateway)
|
base(key, name, gateway)
|
||||||
{
|
{
|
||||||
_gateway = gateway;
|
_gateway = gateway;
|
||||||
IsReady(this, new IsReadyEventArgs(true));
|
IsReady = true;
|
||||||
|
FireIsReadyEvent(IsReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CenRfgwController(string key, Func<DeviceConfig, GatewayBase> preActivationFunc, DeviceConfig config) :
|
public CenRfgwController(string key, Func<DeviceConfig, GatewayBase> preActivationFunc, DeviceConfig config) :
|
||||||
base(key, config.Name)
|
base(key, config.Name)
|
||||||
{
|
{
|
||||||
IsReady(this, new IsReadyEventArgs(false));
|
IsReady = false;
|
||||||
|
FireIsReadyEvent(IsReady);
|
||||||
AddPreActivationAction(() =>
|
AddPreActivationAction(() =>
|
||||||
{
|
{
|
||||||
_gateway = preActivationFunc(config);
|
_gateway = preActivationFunc(config);
|
||||||
|
|
||||||
|
IsReady = true;
|
||||||
RegisterCrestronGenericBase(_gateway);
|
RegisterCrestronGenericBase(_gateway);
|
||||||
IsReady(this, new IsReadyEventArgs(true));
|
FireIsReadyEvent(IsReady);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -58,9 +64,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
public static GatewayBase GetNewIpRfGateway(DeviceConfig dc)
|
public static GatewayBase GetNewIpRfGateway(DeviceConfig dc)
|
||||||
{
|
{
|
||||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||||
var name = dc.Name;
|
|
||||||
var type = dc.Type;
|
var type = dc.Type;
|
||||||
var key = dc.Key;
|
|
||||||
var ipId = control.IpIdInt;
|
var ipId = control.IpIdInt;
|
||||||
|
|
||||||
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
||||||
@@ -74,6 +78,15 @@ namespace PepperDash.Essentials.Core
|
|||||||
return null;
|
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)
|
public static GatewayBase GetNewSharedIpRfGateway(DeviceConfig dc)
|
||||||
{
|
{
|
||||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||||
@@ -135,7 +148,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public enum eExGatewayType
|
public enum EExGatewayType
|
||||||
{
|
{
|
||||||
Ethernet,
|
Ethernet,
|
||||||
EthernetShared,
|
EthernetShared,
|
||||||
@@ -159,22 +172,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var props = JsonConvert.DeserializeObject<EssentialsRfGatewayConfig>(dc.Properties.ToString());
|
var props = JsonConvert.DeserializeObject<EssentialsRfGatewayConfig>(dc.Properties.ToString());
|
||||||
|
|
||||||
var type = dc.Type.ToLower();
|
EExGatewayType gatewayType =
|
||||||
var control = props.Control;
|
(EExGatewayType) Enum.Parse(typeof (EExGatewayType), props.GatewayType, true);
|
||||||
var ipid = control.IpIdInt;
|
|
||||||
var cresnetId = control.CresnetIdInt;
|
|
||||||
|
|
||||||
eExGatewayType gatewayType =
|
|
||||||
(eExGatewayType) Enum.Parse(typeof (eExGatewayType), props.GatewayType, true);
|
|
||||||
|
|
||||||
switch (gatewayType)
|
switch (gatewayType)
|
||||||
{
|
{
|
||||||
case (eExGatewayType.Ethernet):
|
case (EExGatewayType.Ethernet):
|
||||||
return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewIpRfGateway(dc));
|
return new CenRfgwController(dc.Key, dc.Name, GetNewIpRfGateway(dc));
|
||||||
case (eExGatewayType.EthernetShared):
|
case (EExGatewayType.EthernetShared):
|
||||||
return new CenRfgwController(dc.Key, dc.Name, CenRfgwController.GetNewSharedIpRfGateway(dc));
|
return new CenRfgwController(dc.Key, dc.Name, GetNewSharedIpRfGateway(dc));
|
||||||
case (eExGatewayType.Cresnet):
|
case (EExGatewayType.Cresnet):
|
||||||
return new CenRfgwController(dc.Key, CenRfgwController.GetCenRfgwCresnetController, dc);
|
return new CenRfgwController(dc.Key, GetCenRfgwCresnetController, dc);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public CrestronCollection<Button> Buttons { get { return _remote.Button; } }
|
public CrestronCollection<Button> Buttons { get { return _remote.Button; } }
|
||||||
|
|
||||||
|
private DeviceConfig _config;
|
||||||
|
|
||||||
public Hrxx0WirelessRemoteController(string key, Func<DeviceConfig, Hr1x0WirelessRemoteBase> preActivationFunc,
|
public Hrxx0WirelessRemoteController(string key, Func<DeviceConfig, Hr1x0WirelessRemoteBase> preActivationFunc,
|
||||||
DeviceConfig config)
|
DeviceConfig config)
|
||||||
: base(key, config.Name)
|
: base(key, config.Name)
|
||||||
@@ -39,6 +41,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var type = config.Type;
|
var type = config.Type;
|
||||||
var rfId = (uint)props.Control.InfinetIdInt;
|
var rfId = (uint)props.Control.InfinetIdInt;
|
||||||
|
_config = config;
|
||||||
|
|
||||||
GatewayBase gateway;
|
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)
|
void _remote_BaseEvent(GenericBase device, BaseEventArgs args)
|
||||||
@@ -97,6 +97,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
Feedbacks["BatteryVoltage"].FireUpdate();
|
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)
|
void _remote_ButtonStateChange(GenericBase device, ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user