Updates to Cresnet OccSensor Classes

Addresses #292
This commit is contained in:
Trevor Payne
2020-06-30 15:25:20 -05:00
parent b694f7640a
commit ac379763ce
2 changed files with 169 additions and 88 deletions

View File

@@ -55,11 +55,27 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
} }
} }
public GlsOccupancySensorBaseController(string key, string name, GlsOccupancySensorBase sensor) public GlsOccupancySensorBaseController(string key, Func<DeviceConfig, GlsOccupancySensorBase> preActivationFunc,
: base(key, name, sensor) DeviceConfig config)
: base(key, config.Name)
{ {
OccSensor = sensor;
AddPreActivationAction(() =>
{
OccSensor = preActivationFunc(config);
RegisterCrestronGenericBase(OccSensor);
RegisterGlsOdtSensorBaseController();
});
}
public GlsOccupancySensorBaseController(string key, string name) : base(key, name) {}
protected void RegisterGlsOdtSensorBaseController()
{
RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc); RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc);
PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PirEnabledFeedback.BoolValue); PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PirEnabledFeedback.BoolValue);
@@ -68,15 +84,18 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue); ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue);
PirSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.PirSensitivityInVacantStateFeedback.UShortValue); PirSensitivityInVacantStateFeedback =
new IntFeedback(() => OccSensor.PirSensitivityInVacantStateFeedback.UShortValue);
PirSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue); PirSensitivityInOccupiedStateFeedback =
new IntFeedback(() => OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue);
CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue); CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue);
LocalTimoutFeedback = new IntFeedback(() => OccSensor.LocalTimeoutFeedback.UShortValue); LocalTimoutFeedback = new IntFeedback(() => OccSensor.LocalTimeoutFeedback.UShortValue);
GraceOccupancyDetectedFeedback = new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue); GraceOccupancyDetectedFeedback =
new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue);
RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyFeedback.BoolValue); RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyFeedback.BoolValue);
@@ -86,7 +105,7 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
OccSensor.BaseEvent += new Crestron.SimplSharpPro.BaseEventHandler(OccSensor_BaseEvent); OccSensor.BaseEvent += new Crestron.SimplSharpPro.BaseEventHandler(OccSensor_BaseEvent);
OccSensor.GlsOccupancySensorChange += new GlsOccupancySensorChangeEventHandler(OccSensor_GlsOccupancySensorChange); OccSensor.GlsOccupancySensorChange += OccSensor_GlsOccupancySensorChange;
} }
@@ -97,40 +116,56 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
/// <param name="args"></param> /// <param name="args"></param>
protected virtual void OccSensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args) protected virtual void OccSensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args)
{ {
if (args.EventId == GlsOccupancySensorBase.PirEnabledFeedbackEventId) switch (args.EventId)
{
case GlsOccupancySensorBase.PirEnabledFeedbackEventId:
PirSensorEnabledFeedback.FireUpdate(); PirSensorEnabledFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId) break;
case GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId:
LedFlashEnabledFeedback.FireUpdate(); LedFlashEnabledFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId) break;
case GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId:
ShortTimeoutEnabledFeedback.FireUpdate(); ShortTimeoutEnabledFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId) break;
case GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId:
PirSensitivityInOccupiedStateFeedback.FireUpdate(); PirSensitivityInOccupiedStateFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId) break;
case GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId:
PirSensitivityInVacantStateFeedback.FireUpdate(); PirSensitivityInVacantStateFeedback.FireUpdate();
break;
}
} }
protected virtual void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args) protected virtual void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args)
{ {
Debug.Console(2, this, "GlsOccupancySensorChange EventId: {0}", args.EventId); Debug.Console(2, this, "GlsOccupancySensorChange EventId: {0}", args.EventId);
if (args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomOccupiedFeedbackEventId switch (args.EventId)
|| args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomVacantFeedbackEventId)
{ {
case Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomVacantFeedbackEventId:
case Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomOccupiedFeedbackEventId:
Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue); Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue);
RoomIsOccupiedFeedback.FireUpdate(); RoomIsOccupiedFeedback.FireUpdate();
} break;
else if (args.EventId == GlsOccupancySensorBase.TimeoutFeedbackEventId) case GlsOccupancySensorBase.TimeoutFeedbackEventId:
CurrentTimeoutFeedback.FireUpdate(); CurrentTimeoutFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.TimeoutLocalFeedbackEventId) break;
case GlsOccupancySensorBase.TimeoutLocalFeedbackEventId:
LocalTimoutFeedback.FireUpdate(); LocalTimoutFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId) break;
case GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId:
GraceOccupancyDetectedFeedback.FireUpdate(); GraceOccupancyDetectedFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.RawOccupancyFeedbackEventId) break;
case GlsOccupancySensorBase.RawOccupancyFeedbackEventId:
RawOccupancyFeedback.FireUpdate(); RawOccupancyFeedback.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId) break;
case GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId:
InternalPhotoSensorValue.FireUpdate(); InternalPhotoSensorValue.FireUpdate();
else if (args.EventId == GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId) break;
case GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId:
ExternalPhotoSensorValue.FireUpdate(); ExternalPhotoSensorValue.FireUpdate();
break;
}
} }
public void SetTestMode(bool mode) public void SetTestMode(bool mode)
@@ -373,7 +408,32 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
{ {
LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge);
} }
#region PreActivation
private static GlsOirCCn GetGlsOirCCn(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 GlsOirCCn");
return new GlsOirCCn(cresnetId, Global.ControlSystem);
} }
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge;
if (cresnetBridge != null)
{
Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOirCCn");
return new GlsOirCCn(cresnetId, cresnetBridge.Branches[branchId]);
}
Debug.Console(0, "Device {0} is not a valid cresnet master", branchId);
return null;
}
#endregion
public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory<GlsOccupancySensorBaseController> public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory<GlsOccupancySensorBaseController>
{ {
@@ -382,18 +442,17 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
TypeNames = new List<string>() { "glsoirccn" }; TypeNames = new List<string>() { "glsoirccn" };
} }
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device");
var key = dc.Key; return new GlsOccupancySensorBaseController(dc.Key, GetGlsOirCCn, dc);
var name = dc.Name;
var comm = CommFactory.GetControlPropertiesConfig(dc);
GlsOccupancySensorBase occSensor = new GlsOirCCn(comm.CresnetIdInt, Global.ControlSystem);
return new GlsOccupancySensorBaseController(key, name, occSensor);
}
} }
}
}
} }

View File

@@ -35,10 +35,17 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
public BoolFeedback RawOccupancyUsFeedback { get; private set; } public BoolFeedback RawOccupancyUsFeedback { get; private set; }
public GlsOdtOccupancySensorController(string key, string name, GlsOdtCCn sensor) public GlsOdtOccupancySensorController(string key, Func<DeviceConfig, GlsOdtCCn> preActivationFunc,
: base(key, name, sensor) DeviceConfig config)
: base(key, config.Name)
{ {
OccSensor = sensor; AddPreActivationAction(() =>
{
OccSensor = preActivationFunc(config);
RegisterCrestronGenericBase(OccSensor);
RegisterGlsOdtSensorBaseController();
AndWhenVacatedFeedback = new BoolFeedback(() => OccSensor.AndWhenVacatedFeedback.BoolValue); AndWhenVacatedFeedback = new BoolFeedback(() => OccSensor.AndWhenVacatedFeedback.BoolValue);
@@ -55,6 +62,8 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInVacantStateFeedback.UShortValue); UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInVacantStateFeedback.UShortValue);
UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInOccupiedStateFeedback.UShortValue); UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => OccSensor.UsSensitivityInOccupiedStateFeedback.UShortValue);
});
} }
/// <summary> /// <summary>
@@ -160,7 +169,32 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
{ {
LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge);
} }
#region PreActivation
private static GlsOdtCCn GetGlsOdtCCn(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 GlsOdtCCn");
return new GlsOdtCCn(cresnetId, Global.ControlSystem);
} }
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as ICresnetBridge;
if (cresnetBridge != null)
{
Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn");
return new GlsOdtCCn(cresnetId, cresnetBridge.Branches[branchId]);
}
Debug.Console(0, "Device {0} is not a valid cresnet master", branchId);
return null;
}
#endregion
public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory<GlsOdtOccupancySensorController> public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory<GlsOdtOccupancySensorController>
{ {
@@ -169,29 +203,17 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy
TypeNames = new List<string>() { "glsodtccn" }; TypeNames = new List<string>() { "glsodtccn" };
} }
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device");
var typeName = dc.Type.ToLower(); return new GlsOdtOccupancySensorController(dc.Key, GetGlsOdtCCn, dc);
var key = dc.Key;
var name = dc.Name;
var comm = CommFactory.GetControlPropertiesConfig(dc);
var occSensor = new GlsOdtCCn(comm.CresnetIdInt, Global.ControlSystem);
if (occSensor != null)
{
return new GlsOdtOccupancySensorController(key, name, occSensor);
} }
else
{
Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key);
return null;
}
} }
} }
} }