mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 12:15:01 +00:00
Merge pull request #856 from PepperDash/feature/glspartition-sensor-sensitivity-configuration
GlsPartitionSensor Configuration of Device Specific Properties
This commit is contained in:
@@ -5,6 +5,9 @@ namespace PepperDash.Essentials.Core.Bridges.JoinMaps
|
|||||||
{
|
{
|
||||||
public class GlsPartitionSensorJoinMap : JoinMapBaseAdvanced
|
public class GlsPartitionSensorJoinMap : JoinMapBaseAdvanced
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#region Digital
|
||||||
|
|
||||||
[JoinName("IsOnline")]
|
[JoinName("IsOnline")]
|
||||||
public JoinDataComplete IsOnline = new JoinDataComplete(
|
public JoinDataComplete IsOnline = new JoinDataComplete(
|
||||||
new JoinData
|
new JoinData
|
||||||
@@ -19,19 +22,6 @@ namespace PepperDash.Essentials.Core.Bridges.JoinMaps
|
|||||||
JoinType = eJoinType.Digital
|
JoinType = eJoinType.Digital
|
||||||
});
|
});
|
||||||
|
|
||||||
[JoinName("Name")]
|
|
||||||
public JoinDataComplete Name = new JoinDataComplete(
|
|
||||||
new JoinData
|
|
||||||
{
|
|
||||||
JoinNumber = 1,
|
|
||||||
JoinSpan = 1
|
|
||||||
},
|
|
||||||
new JoinMetadata
|
|
||||||
{
|
|
||||||
Description = "Sensor Name",
|
|
||||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
|
||||||
JoinType = eJoinType.Serial
|
|
||||||
});
|
|
||||||
|
|
||||||
[JoinName("Enable")]
|
[JoinName("Enable")]
|
||||||
public JoinDataComplete Enable = new JoinDataComplete(
|
public JoinDataComplete Enable = new JoinDataComplete(
|
||||||
@@ -103,6 +93,10 @@ namespace PepperDash.Essentials.Core.Bridges.JoinMaps
|
|||||||
JoinType = eJoinType.Digital
|
JoinType = eJoinType.Digital
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Analog
|
||||||
|
|
||||||
[JoinName("Sensitivity")]
|
[JoinName("Sensitivity")]
|
||||||
public JoinDataComplete Sensitivity = new JoinDataComplete(
|
public JoinDataComplete Sensitivity = new JoinDataComplete(
|
||||||
new JoinData
|
new JoinData
|
||||||
@@ -117,6 +111,28 @@ namespace PepperDash.Essentials.Core.Bridges.JoinMaps
|
|||||||
JoinType = eJoinType.Analog
|
JoinType = eJoinType.Analog
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Serial
|
||||||
|
|
||||||
|
[JoinName("Name")]
|
||||||
|
public JoinDataComplete Name = new JoinDataComplete(
|
||||||
|
new JoinData
|
||||||
|
{
|
||||||
|
JoinNumber = 1,
|
||||||
|
JoinSpan = 1
|
||||||
|
},
|
||||||
|
new JoinMetadata
|
||||||
|
{
|
||||||
|
Description = "Sensor Name",
|
||||||
|
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||||
|
JoinType = eJoinType.Serial
|
||||||
|
});
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor to use when instantiating this Join Map without inheriting from it
|
/// Constructor to use when instantiating this Join Map without inheriting from it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharpPro.DeviceSupport;
|
using Crestron.SimplSharpPro.DeviceSupport;
|
||||||
using Crestron.SimplSharpPro.GeneralIO;
|
using Crestron.SimplSharpPro.GeneralIO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -9,15 +10,18 @@ using PepperDash.Essentials.Core.Bridges.JoinMaps;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
using PepperDash_Essentials_Core.PartitionSensor;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
[Description("Wrapper class for GLS Cresnet Partition Sensor")]
|
[Description("Wrapper class for GLS Cresnet Partition Sensor")]
|
||||||
public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice, IPartitionStateProvider
|
public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice, IPartitionStateProvider
|
||||||
{
|
{
|
||||||
private GlsPartCn _partitionSensor;
|
|
||||||
|
|
||||||
public StringFeedback NameFeedback { get; private set; }
|
public GlsPartitionSensorPropertiesConfig PropertiesConfig { get; private set; }
|
||||||
|
|
||||||
|
private GlsPartCn _partitionSensor;
|
||||||
|
|
||||||
public BoolFeedback EnableFeedback { get; private set; }
|
public BoolFeedback EnableFeedback { get; private set; }
|
||||||
public BoolFeedback PartitionPresentFeedback { get; private set; }
|
public BoolFeedback PartitionPresentFeedback { get; private set; }
|
||||||
public BoolFeedback PartitionNotSensedFeedback { get; private set; }
|
public BoolFeedback PartitionNotSensedFeedback { get; private set; }
|
||||||
@@ -32,23 +36,71 @@ namespace PepperDash.Essentials.Core
|
|||||||
public GlsPartitionSensorController(string key, Func<DeviceConfig, GlsPartCn> preActivationFunc, DeviceConfig config)
|
public GlsPartitionSensorController(string key, Func<DeviceConfig, GlsPartCn> preActivationFunc, DeviceConfig config)
|
||||||
: base(key, config.Name)
|
: base(key, config.Name)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var props = config.Properties.ToObject<GlsPartitionSensorPropertiesConfig>();
|
||||||
|
if (props != null)
|
||||||
|
{
|
||||||
|
PropertiesConfig = props;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "props are null. Unable to deserialize into GlsPartSensorPropertiesConfig");
|
||||||
|
}
|
||||||
|
|
||||||
AddPreActivationAction(() =>
|
AddPreActivationAction(() =>
|
||||||
{
|
{
|
||||||
_partitionSensor = preActivationFunc(config);
|
_partitionSensor = preActivationFunc(config);
|
||||||
|
|
||||||
RegisterCrestronGenericBase(_partitionSensor);
|
RegisterCrestronGenericBase(_partitionSensor);
|
||||||
|
|
||||||
NameFeedback = new StringFeedback(() => Name);
|
|
||||||
EnableFeedback = new BoolFeedback(() => InTestMode ? TestEnableFeedback : _partitionSensor.EnableFeedback.BoolValue);
|
EnableFeedback = new BoolFeedback(() => InTestMode ? TestEnableFeedback : _partitionSensor.EnableFeedback.BoolValue);
|
||||||
PartitionPresentFeedback = new BoolFeedback(() => InTestMode ? TestPartitionSensedFeedback : _partitionSensor.PartitionSensedFeedback.BoolValue);
|
PartitionPresentFeedback = new BoolFeedback(() => InTestMode ? TestPartitionSensedFeedback : _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||||
PartitionNotSensedFeedback = new BoolFeedback(() => InTestMode ? !TestPartitionSensedFeedback : _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
PartitionNotSensedFeedback = new BoolFeedback(() => InTestMode ? !TestPartitionSensedFeedback : _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||||
SensitivityFeedback = new IntFeedback(() => InTestMode ? TestSensitivityFeedback : _partitionSensor.SensitivityFeedback.UShortValue);
|
SensitivityFeedback = new IntFeedback(() => InTestMode ? TestSensitivityFeedback : _partitionSensor.SensitivityFeedback.UShortValue);
|
||||||
|
|
||||||
if (_partitionSensor != null) _partitionSensor.BaseEvent += PartitionSensor_BaseEvent;
|
if (_partitionSensor != null)
|
||||||
|
{
|
||||||
|
_partitionSensor.BaseEvent += PartitionSensor_BaseEvent;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
_partitionSensor.OnlineStatusChange += (o, a) =>
|
||||||
|
{
|
||||||
|
if (a.DeviceOnLine)
|
||||||
|
{
|
||||||
|
ApplySettingsToSensorFromConfig();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_partitionSensor.IsOnline)
|
||||||
|
{
|
||||||
|
ApplySettingsToSensorFromConfig();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PartitionSensor_BaseEvent(GenericBase device, BaseEventArgs args)
|
private void ApplySettingsToSensorFromConfig()
|
||||||
|
{
|
||||||
|
if (_partitionSensor.IsOnline == false) return;
|
||||||
|
|
||||||
|
Debug.Console(1, this, "Attempting to apply settings to sensor from config");
|
||||||
|
|
||||||
|
if (PropertiesConfig.Sensitivity != null)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Sensitivity found, attempting to set value '{0}' from config",
|
||||||
|
PropertiesConfig.Sensitivity);
|
||||||
|
_partitionSensor.Sensitivity.UShortValue = (ushort) PropertiesConfig.Sensitivity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Sensitivity null, no value specified in config");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PartitionSensor_BaseEvent(GenericBase device, BaseEventArgs args)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "EventId: {0}, Index: {1}", args.EventId, args.Index);
|
Debug.Console(2, this, "EventId: {0}, Index: {1}", args.EventId, args.Index);
|
||||||
|
|
||||||
@@ -61,11 +113,13 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
case (GlsPartCn.PartitionSensedFeedbackEventId):
|
case (GlsPartCn.PartitionSensedFeedbackEventId):
|
||||||
{
|
{
|
||||||
|
Debug.Console(1, this, "Partition Sensed State: {0}", _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||||
PartitionPresentFeedback.FireUpdate();
|
PartitionPresentFeedback.FireUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (GlsPartCn.PartitionNotSensedFeedbackEventId):
|
case (GlsPartCn.PartitionNotSensedFeedbackEventId):
|
||||||
{
|
{
|
||||||
|
Debug.Console(1, this, "Partition Not Sensed State: {0}", _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||||
PartitionNotSensedFeedback.FireUpdate();
|
PartitionNotSensedFeedback.FireUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -133,7 +187,22 @@ namespace PepperDash.Essentials.Core
|
|||||||
Debug.Console(1, this, "InTestMode: {0}, unable to set sensitivity value: {1}", InTestMode.ToString(), value);
|
Debug.Console(1, this, "InTestMode: {0}, unable to set sensitivity value: {1}", InTestMode.ToString(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEnableState(bool state)
|
public void GetSettings()
|
||||||
|
{
|
||||||
|
var dash = new string('*', 50);
|
||||||
|
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||||
|
|
||||||
|
Debug.Console(0, this, "Enabled State: {0}", _partitionSensor.EnableFeedback.BoolValue);
|
||||||
|
|
||||||
|
Debug.Console(0, this, "Partition Sensed State: {0}", _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||||
|
Debug.Console(0, this, "Partition Not Sensed State: {0}", _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||||
|
|
||||||
|
Debug.Console(0, this, "Sensitivity Value: {0}", _partitionSensor.SensitivityFeedback.UShortValue);
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetEnableState(bool state)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Sensor is {0}, SetEnableState: {1}", _partitionSensor == null ? "null" : "not null", state);
|
Debug.Console(2, this, "Sensor is {0}, SetEnableState: {1}", _partitionSensor == null ? "null" : "not null", state);
|
||||||
if (_partitionSensor == null)
|
if (_partitionSensor == null)
|
||||||
@@ -189,18 +258,20 @@ namespace PepperDash.Essentials.Core
|
|||||||
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||||
Debug.Console(0, this, "Linking to Bridge Type {0}", GetType().Name);
|
Debug.Console(0, this, "Linking to Bridge Type {0}", GetType().Name);
|
||||||
|
|
||||||
// link input from simpl
|
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||||
|
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = _partitionSensor.Name;
|
||||||
|
|
||||||
trilist.SetBoolSigAction(joinMap.Enable.JoinNumber, SetEnableState);
|
trilist.SetBoolSigAction(joinMap.Enable.JoinNumber, SetEnableState);
|
||||||
|
EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]);
|
||||||
|
|
||||||
|
PartitionPresentFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]);
|
||||||
|
PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]);
|
||||||
|
|
||||||
trilist.SetSigTrueAction(joinMap.IncreaseSensitivity.JoinNumber, IncreaseSensitivity);
|
trilist.SetSigTrueAction(joinMap.IncreaseSensitivity.JoinNumber, IncreaseSensitivity);
|
||||||
trilist.SetSigTrueAction(joinMap.DecreaseSensitivity.JoinNumber, DecreaseSensitivity);
|
trilist.SetSigTrueAction(joinMap.DecreaseSensitivity.JoinNumber, DecreaseSensitivity);
|
||||||
trilist.SetUShortSigAction(joinMap.Sensitivity.JoinNumber, SetSensitivity);
|
|
||||||
|
|
||||||
// link output to simpl
|
SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]);
|
||||||
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
trilist.SetUShortSigAction(joinMap.Sensitivity.JoinNumber, SetSensitivity);
|
||||||
EnableFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Enable.JoinNumber]);
|
|
||||||
PartitionPresentFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionSensed.JoinNumber]);
|
|
||||||
PartitionNotSensedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PartitionNotSensed.JoinNumber]);
|
|
||||||
SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]);
|
|
||||||
|
|
||||||
FeedbacksFireUpdates();
|
FeedbacksFireUpdates();
|
||||||
|
|
||||||
@@ -218,6 +289,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
if (a.DeviceOnLine)
|
if (a.DeviceOnLine)
|
||||||
{
|
{
|
||||||
|
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = _partitionSensor.Name;
|
||||||
FeedbacksFireUpdates();
|
FeedbacksFireUpdates();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -226,7 +298,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
private void FeedbacksFireUpdates()
|
private void FeedbacksFireUpdates()
|
||||||
{
|
{
|
||||||
IsOnline.FireUpdate();
|
IsOnline.FireUpdate();
|
||||||
NameFeedback.FireUpdate();
|
|
||||||
EnableFeedback.FireUpdate();
|
EnableFeedback.FireUpdate();
|
||||||
PartitionPresentFeedback.FireUpdate();
|
PartitionPresentFeedback.FireUpdate();
|
||||||
PartitionNotSensedFeedback.FireUpdate();
|
PartitionNotSensedFeedback.FireUpdate();
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace PepperDash_Essentials_Core.PartitionSensor
|
||||||
|
{
|
||||||
|
public class GlsPartitionSensorPropertiesConfig
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the sensor sensitivity
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The sensitivity range shall be between 1(lowest) to 10 (highest).
|
||||||
|
/// </remarks>
|
||||||
|
[JsonProperty("sensitivity")]
|
||||||
|
public ushort? Sensitivity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,6 +236,7 @@
|
|||||||
<Compile Include="Occupancy\GlsOccupancySensorPropertiesConfig.cs" />
|
<Compile Include="Occupancy\GlsOccupancySensorPropertiesConfig.cs" />
|
||||||
<Compile Include="Occupancy\GlsOirOccupancySensorController.cs" />
|
<Compile Include="Occupancy\GlsOirOccupancySensorController.cs" />
|
||||||
<Compile Include="PartitionSensor\EssentialsPartitionController.cs" />
|
<Compile Include="PartitionSensor\EssentialsPartitionController.cs" />
|
||||||
|
<Compile Include="PartitionSensor\GlsPartitionSensorPropertiesConfig.cs" />
|
||||||
<Compile Include="PartitionSensor\IPartitionStateProvider.cs" />
|
<Compile Include="PartitionSensor\IPartitionStateProvider.cs" />
|
||||||
<Compile Include="Occupancy\OccupancyAggregatorConfig.cs" />
|
<Compile Include="Occupancy\OccupancyAggregatorConfig.cs" />
|
||||||
<Compile Include="Queues\ComsMessage.cs" />
|
<Compile Include="Queues\ComsMessage.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user