mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-16 05:54:56 +00:00
Compare commits
5 Commits
developmen
...
2.0.0-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edefe0a0bf | ||
|
|
9b4a33f3b9 | ||
|
|
7f5e991921 | ||
|
|
48dd29ae83 | ||
|
|
154dbb8e2a |
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
{
|
||||
[Obsolete("This Device will be moved to a plugin in a future update")]
|
||||
public class DigitalLoggerJoinMap : JoinMapBase
|
||||
{
|
||||
public uint IsOnline { get; set; }
|
||||
public uint CircuitNames { get; set; }
|
||||
public uint CircuitState { get; set; }
|
||||
public uint CircuitCycle { get; set; }
|
||||
public uint CircuitIsCritical { get; set; }
|
||||
public uint CircuitOnCmd { get; set; }
|
||||
public uint CircuitOffCmd { get; set; }
|
||||
|
||||
public DigitalLoggerJoinMap()
|
||||
{
|
||||
// Digital
|
||||
IsOnline = 9;
|
||||
CircuitState = 0;
|
||||
CircuitCycle = 0;
|
||||
CircuitIsCritical = 10;
|
||||
CircuitOnCmd = 10;
|
||||
CircuitOffCmd = 20;
|
||||
// Serial
|
||||
CircuitNames = 0;
|
||||
// Analog
|
||||
}
|
||||
|
||||
public override void OffsetJoinNumbers(uint joinStart)
|
||||
{
|
||||
var joinOffset = joinStart - 1;
|
||||
|
||||
IsOnline = IsOnline + joinOffset;
|
||||
CircuitNames = CircuitNames + joinOffset;
|
||||
CircuitState = CircuitState + joinOffset;
|
||||
CircuitCycle = CircuitCycle + joinOffset;
|
||||
CircuitIsCritical = CircuitIsCritical + joinOffset;
|
||||
CircuitOnCmd = CircuitOnCmd + joinOffset;
|
||||
CircuitOffCmd = CircuitOffCmd + joinOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,146 +155,3 @@ namespace PepperDash.Essentials.Core.Bridges.JoinMaps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Bridges.JoinMaps
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Obsolete("use PepperDash.Essentials.Core.Bridges.JoinMaps version")]
|
||||
public class GlsPartitionSensorJoinMap:JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 1,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Is Online",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
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")]
|
||||
public JoinDataComplete Enable = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 2,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Enable",
|
||||
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("PartitionSensed")]
|
||||
public JoinDataComplete PartitionSensed = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 3,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Partition Sensed",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("PartitionNotSensed")]
|
||||
public JoinDataComplete PartitionNotSensed = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 4,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Partition Not Sensed",
|
||||
JoinCapabilities = eJoinCapabilities.ToSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("IncreaseSensitivity")]
|
||||
public JoinDataComplete IncreaseSensitivity = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 6,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Increase Sensitivity",
|
||||
JoinCapabilities = eJoinCapabilities.FromSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("DecreaseSensitivity")]
|
||||
public JoinDataComplete DecreaseSensitivity = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 7,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Decrease Sensitivity",
|
||||
JoinCapabilities = eJoinCapabilities.FromSIMPL,
|
||||
JoinType = eJoinType.Digital
|
||||
});
|
||||
|
||||
[JoinName("Sensitivity")]
|
||||
public JoinDataComplete Sensitivity = new JoinDataComplete(
|
||||
new JoinData
|
||||
{
|
||||
JoinNumber = 2,
|
||||
JoinSpan = 1
|
||||
},
|
||||
new JoinMetadata
|
||||
{
|
||||
Description = "Sensor Sensitivity",
|
||||
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
|
||||
JoinType = eJoinType.Analog
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to use when instantiating this Join Map without inheriting from it
|
||||
/// </summary>
|
||||
/// <param name="joinStart">Join this join map will start at</param>
|
||||
public GlsPartitionSensorJoinMap(uint joinStart)
|
||||
: this(joinStart, typeof(GlsPartitionSensorJoinMap))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to use when extending this Join map
|
||||
/// </summary>
|
||||
/// <param name="joinStart">Join this join map will start at</param>
|
||||
/// <param name="type">Type of the child join map</param>
|
||||
protected GlsPartitionSensorJoinMap(uint joinStart, Type type)
|
||||
: base(joinStart, type)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,106 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO
|
||||
{
|
||||
public class C2NIoController:CrestronGenericBaseDevice, IComPorts, IIROutputPorts, IRelayPorts
|
||||
{
|
||||
private C2nIo _device;
|
||||
|
||||
public C2NIoController(string key, Func<DeviceConfig, C2nIo> preActivationFunc, DeviceConfig config):base(key, config.Name)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_device = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_device);
|
||||
});
|
||||
}
|
||||
|
||||
#region Implementation of IComPorts
|
||||
|
||||
public CrestronCollection<ComPort> ComPorts
|
||||
{
|
||||
get { return _device.ComPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfComPorts
|
||||
{
|
||||
get { return _device.NumberOfComPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IIROutputPorts
|
||||
|
||||
public CrestronCollection<IROutputPort> IROutputPorts
|
||||
{
|
||||
get { return _device.IROutputPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfIROutputPorts
|
||||
{
|
||||
get { return _device.NumberOfIROutputPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IRelayPorts
|
||||
|
||||
public CrestronCollection<Relay> RelayPorts
|
||||
{
|
||||
get { return _device.RelayPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfRelayPorts
|
||||
{
|
||||
get { return _device.NumberOfRelayPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class C2NIoControllerFactory : EssentialsDeviceFactory<C2NIoController>
|
||||
{
|
||||
public C2NIoControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "c2nio" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new C2N-IO Device");
|
||||
|
||||
return new C2NIoController(dc.Key, GetC2NIoDevice, dc);
|
||||
}
|
||||
|
||||
static C2nIo GetC2NIoDevice(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 C2nIo", parentKey);
|
||||
return new C2nIo(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new C2nIo", parentKey);
|
||||
return new C2nIo(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO
|
||||
{
|
||||
[Description("Wrapper class for the C2N-RTHS sensor")]
|
||||
public class C2nRthsController : CrestronGenericBridgeableBaseDevice
|
||||
{
|
||||
private C2nRths _device;
|
||||
|
||||
public IntFeedback TemperatureFeedback { get; private set; }
|
||||
public IntFeedback HumidityFeedback { get; private set; }
|
||||
|
||||
public C2nRthsController(string key, Func<DeviceConfig, C2nRths> preActivationFunc,
|
||||
DeviceConfig config)
|
||||
: base(key, config.Name)
|
||||
{
|
||||
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_device = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_device);
|
||||
|
||||
TemperatureFeedback = new IntFeedback(() => _device.TemperatureFeedback.UShortValue);
|
||||
HumidityFeedback = new IntFeedback(() => _device.HumidityFeedback.UShortValue);
|
||||
|
||||
if (_device != null) _device.BaseEvent += DeviceOnBaseEvent;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void DeviceOnBaseEvent(GenericBase device, BaseEventArgs args)
|
||||
{
|
||||
switch (args.EventId)
|
||||
{
|
||||
case C2nRths.TemperatureFeedbackEventId:
|
||||
TemperatureFeedback.FireUpdate();
|
||||
break;
|
||||
case C2nRths.HumidityFeedbackEventId:
|
||||
HumidityFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTemperatureFormat(bool setToC)
|
||||
{
|
||||
_device.TemperatureFormat.BoolValue = setToC;
|
||||
}
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new C2nRthsControllerJoinMap(joinStart);
|
||||
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<C2nRthsControllerJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
|
||||
|
||||
trilist.SetBoolSigAction(joinMap.TemperatureFormat.JoinNumber, SetTemperatureFormat);
|
||||
|
||||
|
||||
|
||||
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
TemperatureFeedback.LinkInputSig(trilist.UShortInput[joinMap.Temperature.JoinNumber]);
|
||||
HumidityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Humidity.JoinNumber]);
|
||||
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = Name;
|
||||
|
||||
trilist.OnlineStatusChange += (d, args) =>
|
||||
{
|
||||
if (!args.DeviceOnLine) return;
|
||||
|
||||
UpdateFeedbacksWhenOnline();
|
||||
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = Name;
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateFeedbacksWhenOnline()
|
||||
{
|
||||
IsOnline.FireUpdate();
|
||||
TemperatureFeedback.FireUpdate();
|
||||
HumidityFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
#region PreActivation
|
||||
|
||||
private static C2nRths GetC2nRthsDevice(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 C2nRths", parentKey);
|
||||
return new C2nRths(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new C2nRths", parentKey);
|
||||
return new C2nRths(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class C2nRthsControllerFactory : EssentialsDeviceFactory<C2nRthsController>
|
||||
{
|
||||
public C2nRthsControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "c2nrths" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new C2N-RTHS Device");
|
||||
|
||||
return new C2nRthsController(dc.Key, GetC2nRthsDevice, dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using Crestron.SimplSharpProInternal;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3CardControllerBase:CrestronGenericBaseDevice
|
||||
{
|
||||
private readonly C3Card _card;
|
||||
|
||||
public C3CardControllerBase(string key, string name, C3Card hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Overrides of Object
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1}", Key, _card.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3Com3Controller:C3CardControllerBase, IComPorts
|
||||
{
|
||||
private readonly C3com3 _card;
|
||||
|
||||
public C3Com3Controller(string key, string name, C3com3 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Implementation of IComPorts
|
||||
|
||||
public CrestronCollection<ComPort> ComPorts
|
||||
{
|
||||
get { return _card.ComPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfComPorts
|
||||
{
|
||||
get { return _card.NumberOfComPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3Io16Controller:C3CardControllerBase,IIOPorts
|
||||
{
|
||||
private readonly C3io16 _card;
|
||||
|
||||
public C3Io16Controller(string key, string name, C3io16 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Implementation of IIOPorts
|
||||
|
||||
public CrestronCollection<Versiport> VersiPorts
|
||||
{
|
||||
get { return _card.VersiPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfVersiPorts
|
||||
{
|
||||
get { return _card.NumberOfVersiPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3Ir8Controller:C3CardControllerBase, IIROutputPorts
|
||||
{
|
||||
private readonly C3ir8 _card;
|
||||
|
||||
public C3Ir8Controller(string key, string name, C3ir8 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Implementation of IIROutputPorts
|
||||
|
||||
public CrestronCollection<IROutputPort> IROutputPorts
|
||||
{
|
||||
get { return _card.IROutputPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfIROutputPorts
|
||||
{
|
||||
get { return _card.NumberOfIROutputPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3Ry16Controller:C3CardControllerBase, IRelayPorts
|
||||
{
|
||||
private readonly C3ry16 _card;
|
||||
|
||||
public C3Ry16Controller(string key, string name, C3ry16 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Implementation of IRelayPorts
|
||||
|
||||
public CrestronCollection<Relay> RelayPorts
|
||||
{
|
||||
get { return _card.RelayPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfRelayPorts
|
||||
{
|
||||
get { return _card.NumberOfRelayPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
public class C3Ry8Controller:C3CardControllerBase, IRelayPorts
|
||||
{
|
||||
private readonly C3ry8 _card;
|
||||
|
||||
public C3Ry8Controller(string key, string name, C3ry8 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_card = hardware;
|
||||
}
|
||||
|
||||
#region Implementation of IRelayPorts
|
||||
|
||||
public CrestronCollection<Relay> RelayPorts
|
||||
{
|
||||
get { return _card.RelayPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfRelayPorts
|
||||
{
|
||||
get { return _card.NumberOfRelayPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
[ConfigSnippet("\"properties\":{\"card\":\"c3com3\"}")]
|
||||
public class CenCi31Controller : CrestronGenericBaseDevice
|
||||
{
|
||||
private const string CardKeyTemplate = "{0}-card";
|
||||
private const string CardNameTemplate = "{0}:{1}:{2}";
|
||||
private const uint CardSlot = 1;
|
||||
private readonly CenCi31 _cardCage;
|
||||
private readonly CenCi31Configuration _config;
|
||||
|
||||
private readonly Dictionary<string, Func<CenCi31, uint, C3CardControllerBase>> _cardDict;
|
||||
|
||||
public CenCi31Controller(string key, string name, CenCi31Configuration config, CenCi31 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_cardCage = hardware;
|
||||
|
||||
_config = config;
|
||||
|
||||
_cardDict = new Dictionary<string, Func<CenCi31, uint, C3CardControllerBase>>
|
||||
{
|
||||
{
|
||||
"c3com3",
|
||||
(c, s) =>
|
||||
new C3Com3Controller(String.Format(CardKeyTemplate, key),
|
||||
String.Format(CardNameTemplate, key, s, "C3Com3"), new C3com3(_cardCage))
|
||||
},
|
||||
{
|
||||
"c3io16",
|
||||
(c, s) =>
|
||||
new C3Io16Controller(String.Format(CardKeyTemplate, key),
|
||||
String.Format(CardNameTemplate, key, s,"C3Io16"), new C3io16(_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ir8",
|
||||
(c, s) =>
|
||||
new C3Ir8Controller(String.Format(CardKeyTemplate, key),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ir8"), new C3ir8(_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ry16",
|
||||
(c, s) =>
|
||||
new C3Ry16Controller(String.Format(CardKeyTemplate, key),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry16"), new C3ry16(_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ry8",
|
||||
(c, s) =>
|
||||
new C3Ry8Controller(String.Format(CardKeyTemplate, key),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry8"), new C3ry8(_cardCage))
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
GetCards();
|
||||
}
|
||||
|
||||
private void GetCards()
|
||||
{
|
||||
Func<CenCi31, uint, C3CardControllerBase> cardBuilder;
|
||||
|
||||
if (String.IsNullOrEmpty(_config.Card))
|
||||
{
|
||||
Debug.Console(0, this, "No card specified");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_cardDict.TryGetValue(_config.Card.ToLower(), out cardBuilder))
|
||||
{
|
||||
Debug.Console(0, "Unable to find factory for 3-Series card type {0}.", _config.Card);
|
||||
return;
|
||||
}
|
||||
|
||||
var device = cardBuilder(_cardCage, CardSlot);
|
||||
|
||||
DeviceManager.AddDevice(device);
|
||||
}
|
||||
}
|
||||
|
||||
public class CenCi31Configuration
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string Card { get; set; }
|
||||
}
|
||||
|
||||
public class CenCi31ControllerFactory : EssentialsDeviceFactory<CenCi31Controller>
|
||||
{
|
||||
public CenCi31ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> {"cenci31"};
|
||||
}
|
||||
#region Overrides of EssentialsDeviceFactory<CenCi31Controller>
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory attempting to build new CEN-CI-1");
|
||||
|
||||
var controlProperties = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var ipId = controlProperties.IpIdInt;
|
||||
|
||||
var cardCage = new CenCi31(ipId, Global.ControlSystem);
|
||||
var config = dc.Properties.ToObject<CenCi31Configuration>();
|
||||
|
||||
return new CenCi31Controller(dc.Key, dc.Name, config, cardCage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
[ConfigSnippet("\"properties\":{\"cards\":{\"1\":\"c3com3\",\"2\":\"c3ry16\",\"3\":\"c3ry8\"}}")]
|
||||
public class CenCi33Controller : CrestronGenericBaseDevice
|
||||
{
|
||||
private const string CardKeyTemplate = "{0}-card{1}";
|
||||
private const string CardNameTemplate = "{0}:{1}:{2}";
|
||||
private const uint CardSlots = 3;
|
||||
private readonly CenCi33 _cardCage;
|
||||
private readonly CenCi33Configuration _config;
|
||||
|
||||
private readonly Dictionary<string, Func<CenCi33, uint, C3CardControllerBase>> _cardDict;
|
||||
|
||||
public CenCi33Controller(string key, string name, CenCi33Configuration config, CenCi33 hardware) : base(key, name, hardware)
|
||||
{
|
||||
_cardCage = hardware;
|
||||
|
||||
_config = config;
|
||||
|
||||
_cardDict = new Dictionary<string, Func<CenCi33, uint, C3CardControllerBase>>
|
||||
{
|
||||
{
|
||||
"c3com3",
|
||||
(c, s) =>
|
||||
new C3Com3Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Com3"), new C3com3(s,_cardCage))
|
||||
},
|
||||
{
|
||||
"c3io16",
|
||||
(c, s) =>
|
||||
new C3Io16Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Io16"), new C3io16(s,_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ir8",
|
||||
(c, s) =>
|
||||
new C3Ir8Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ir8"), new C3ir8(s,_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ry16",
|
||||
(c, s) =>
|
||||
new C3Ry16Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry16"), new C3ry16(s,_cardCage))
|
||||
},
|
||||
{
|
||||
"c3ry8",
|
||||
(c, s) =>
|
||||
new C3Ry8Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry8"), new C3ry8(s,_cardCage))
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
GetCards();
|
||||
}
|
||||
|
||||
private void GetCards()
|
||||
{
|
||||
if (_config.Cards == null)
|
||||
{
|
||||
Debug.Console(0, this, "No card configuration for this device found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint i = 1; i <= CardSlots; i++)
|
||||
{
|
||||
string cardType;
|
||||
if (!_config.Cards.TryGetValue(i, out cardType))
|
||||
{
|
||||
Debug.Console(1, this, "No card found for slot {0}", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(cardType))
|
||||
{
|
||||
Debug.Console(0, this, "No card specified for slot {0}", i);
|
||||
return;
|
||||
}
|
||||
|
||||
Func<CenCi33, uint, C3CardControllerBase> cardBuilder;
|
||||
if (!_cardDict.TryGetValue(cardType.ToLower(), out cardBuilder))
|
||||
{
|
||||
Debug.Console(0, "Unable to find factory for 3-Series card type {0}.", cardType);
|
||||
return;
|
||||
}
|
||||
|
||||
var device = cardBuilder(_cardCage, i);
|
||||
|
||||
DeviceManager.AddDevice(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CenCi33Configuration
|
||||
{
|
||||
[JsonProperty("cards")]
|
||||
public Dictionary<uint, string> Cards { get; set; }
|
||||
}
|
||||
|
||||
public class CenCi33ControllerFactory : EssentialsDeviceFactory<CenCi33Controller>
|
||||
{
|
||||
public CenCi33ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> {"cenci33"};
|
||||
}
|
||||
#region Overrides of EssentialsDeviceFactory<CenCi33Controller>
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory attempting to build new CEN-CI-3");
|
||||
|
||||
var controlProperties = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var ipId = controlProperties.IpIdInt;
|
||||
|
||||
var cardCage = new CenCi33(ipId, Global.ControlSystem);
|
||||
var config = dc.Properties.ToObject<CenCi33Configuration>();
|
||||
|
||||
return new CenCi33Controller(dc.Key, dc.Name, config, cardCage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro.ThreeSeriesCards;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO.Cards
|
||||
{
|
||||
[ConfigSnippet("\"properties\":{\"cards\":{\"1\":\"c3com3\",\"2\":\"c3ry16\",\"3\":\"c3ry8\"}}")]
|
||||
public class InternalCardCageController : EssentialsDevice
|
||||
{
|
||||
private const string CardKeyTemplate = "{0}-card{1}";
|
||||
private const string CardNameTemplate = "{0}:{1}:{2}";
|
||||
private const uint CardSlots = 3;
|
||||
|
||||
private readonly InternalCardCageConfiguration _config;
|
||||
|
||||
private readonly Dictionary<string, Func<uint, C3CardControllerBase>> _cardDict;
|
||||
|
||||
public InternalCardCageController(string key, string name, InternalCardCageConfiguration config) : base(key, name)
|
||||
{
|
||||
_config = config;
|
||||
|
||||
_cardDict = new Dictionary<string, Func<uint, C3CardControllerBase>>
|
||||
{
|
||||
{
|
||||
"c3com3",
|
||||
(s) =>
|
||||
new C3Com3Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Com3"), new C3com3(s,Global.ControlSystem))
|
||||
},
|
||||
{
|
||||
"c3io16",
|
||||
(s) =>
|
||||
new C3Io16Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Io16"), new C3io16(s,Global.ControlSystem))
|
||||
},
|
||||
{
|
||||
"c3ir8",
|
||||
(s) =>
|
||||
new C3Ir8Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ir8"), new C3ir8(s,Global.ControlSystem))
|
||||
},
|
||||
{
|
||||
"c3ry16",
|
||||
(s) =>
|
||||
new C3Ry16Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry16"), new C3ry16(s,Global.ControlSystem))
|
||||
},
|
||||
{
|
||||
"c3ry8",
|
||||
(s) =>
|
||||
new C3Ry8Controller(String.Format(CardKeyTemplate, key, s),
|
||||
String.Format(CardNameTemplate, key, s, "C3Ry8"), new C3ry8(s,Global.ControlSystem))
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
GetCards();
|
||||
}
|
||||
|
||||
private void GetCards()
|
||||
{
|
||||
if (_config.Cards == null)
|
||||
{
|
||||
Debug.Console(0, this, "No card configuration for this device found");
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint i = 1; i <= CardSlots; i++)
|
||||
{
|
||||
string cardType;
|
||||
if (!_config.Cards.TryGetValue(i, out cardType))
|
||||
{
|
||||
Debug.Console(0, this, "No card found for slot {0}", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(cardType))
|
||||
{
|
||||
Debug.Console(0, this, "No card specified for slot {0}", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
Func<uint, C3CardControllerBase> cardBuilder;
|
||||
if (!_cardDict.TryGetValue(cardType.ToLower(), out cardBuilder))
|
||||
{
|
||||
Debug.Console(0, "Unable to find factory for 3-Series card type {0}.", cardType);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var device = cardBuilder(i);
|
||||
|
||||
|
||||
DeviceManager.AddDevice(device);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error,
|
||||
"Unable to add card {0} to internal card cage.\r\nError Message: {1}\r\nStack Trace: {2}",
|
||||
cardType, ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InternalCardCageConfiguration
|
||||
{
|
||||
[JsonProperty("cards")]
|
||||
public Dictionary<uint, string> Cards { get; set; }
|
||||
}
|
||||
|
||||
public class InternalCardCageControllerFactory : EssentialsDeviceFactory<InternalCardCageController>
|
||||
{
|
||||
public InternalCardCageControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> {"internalcardcage"};
|
||||
}
|
||||
#region Overrides of EssentialsDeviceFactory<InternalCardCageController>
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory attempting to build new Internal Card Cage Controller");
|
||||
|
||||
if (!Global.ControlSystem.SupportsThreeSeriesPlugInCards)
|
||||
{
|
||||
Debug.Console(0, Debug.ErrorLogLevel.Warning, "Current control system does NOT support 3-Series cards. Everything is NOT awesome.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var config = dc.Properties.ToObject<InternalCardCageConfiguration>();
|
||||
|
||||
return new InternalCardCageController(dc.Key, dc.Name, config);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class DinCenCn2Controller : CrestronGenericBaseDevice, IHasCresnetBranches
|
||||
{
|
||||
private readonly DinCenCn2 _device;
|
||||
|
||||
public CrestronCollection<CresnetBranch> CresnetBranches
|
||||
{
|
||||
get {
|
||||
return _device != null ? _device.Branches : null;
|
||||
}
|
||||
}
|
||||
|
||||
public DinCenCn2Controller(string key, string name, DinCenCn2 device, DeviceConfig config)
|
||||
: base(key, name, device)
|
||||
{
|
||||
_device = device;
|
||||
}
|
||||
|
||||
public class DinCenCn2ControllerFactory : EssentialsDeviceFactory<DinCenCn2Controller>
|
||||
{
|
||||
public DinCenCn2ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "dincencn2", "dincencn2poe", "din-cencn2", "din-cencn2-poe" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new DIN-CEN-CN2 Device");
|
||||
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var ipid = control.IpIdInt;
|
||||
|
||||
if (dc.Type.ToLower().Contains("poe"))
|
||||
{
|
||||
return new DinCenCn2Controller(dc.Key, dc.Name, new DinCenCn2Poe(ipid, Global.ControlSystem), dc);
|
||||
}
|
||||
|
||||
return new DinCenCn2Controller(dc.Key, dc.Name, new DinCenCn2(ipid, Global.ControlSystem), dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO
|
||||
{
|
||||
public class DinIo8Controller:CrestronGenericBaseDevice, IIOPorts
|
||||
{
|
||||
private DinIo8 _device;
|
||||
|
||||
public DinIo8Controller(string key, Func<DeviceConfig, DinIo8> preActivationFunc, DeviceConfig config):base(key, config.Name)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_device = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_device);
|
||||
});
|
||||
}
|
||||
|
||||
#region Implementation of IIOPorts
|
||||
|
||||
public CrestronCollection<Versiport> VersiPorts
|
||||
{
|
||||
get { return _device.VersiPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfVersiPorts
|
||||
{
|
||||
get { return _device.NumberOfVersiPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class DinIo8ControllerFactory : EssentialsDeviceFactory<DinIo8Controller>
|
||||
{
|
||||
public DinIo8ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "DinIo8" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new DinIo8 Device");
|
||||
|
||||
return new DinIo8Controller(dc.Key, GetDinIo8Device, dc);
|
||||
}
|
||||
|
||||
static DinIo8 GetDinIo8Device(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 DinIo8", parentKey);
|
||||
return new DinIo8(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new DinIo8", parentKey);
|
||||
return new DinIo8(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for CEN-IO-DIGIN-104 digital input module
|
||||
/// </summary>
|
||||
[Description("Wrapper class for the CEN-IO-DIGIN-104 diginal input module")]
|
||||
public class CenIoDigIn104Controller : CrestronGenericBaseDevice, IDigitalInputPorts
|
||||
{
|
||||
public CenIoDi104 Di104 { get; private set; }
|
||||
|
||||
public CenIoDigIn104Controller(string key, string name, CenIoDi104 di104)
|
||||
: base(key, name)
|
||||
{
|
||||
Di104 = di104;
|
||||
}
|
||||
|
||||
#region IDigitalInputPorts Members
|
||||
|
||||
public CrestronCollection<DigitalInput> DigitalInputPorts
|
||||
{
|
||||
get { return Di104.DigitalInputPorts; }
|
||||
}
|
||||
|
||||
public int NumberOfDigitalInputPorts
|
||||
{
|
||||
get { return Di104.NumberOfDigitalInputPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class CenIoDigIn104ControllerFactory : EssentialsDeviceFactory<CenIoDigIn104Controller>
|
||||
{
|
||||
public CenIoDigIn104ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "ceniodigin104" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new CEN-DIGIN-104 Device");
|
||||
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
if (control == null)
|
||||
{
|
||||
Debug.Console(1, "Factory failed to create a new CEN-DIGIN-104 Device, control properties not found");
|
||||
return null;
|
||||
}
|
||||
var ipid = control.IpIdInt;
|
||||
if (ipid != 0) return new CenIoDigIn104Controller(dc.Key, dc.Name, new CenIoDi104(ipid, Global.ControlSystem));
|
||||
|
||||
Debug.Console(1, "Factory failed to create a new CEN-IO-IR-104 Device using IP-ID-{0}", ipid);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for CEN-IO-IR-104 module
|
||||
/// </summary>
|
||||
[Description("Wrapper class for the CEN-IO-IR-104 module")]
|
||||
public class CenIoIr104Controller : CrestronGenericBaseDevice, IIROutputPorts
|
||||
{
|
||||
private readonly CenIoIr104 _ir104;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="ir104"></param>
|
||||
public CenIoIr104Controller(string key, string name, CenIoIr104 ir104)
|
||||
: base(key, name, ir104)
|
||||
{
|
||||
_ir104 = ir104;
|
||||
}
|
||||
|
||||
#region IDigitalInputPorts Members
|
||||
|
||||
/// <summary>
|
||||
/// IR port collection
|
||||
/// </summary>
|
||||
public CrestronCollection<IROutputPort> IROutputPorts
|
||||
{
|
||||
get { return _ir104.IROutputPorts; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of relay ports property
|
||||
/// </summary>
|
||||
public int NumberOfIROutputPorts
|
||||
{
|
||||
get { return _ir104.NumberOfIROutputPorts; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CEN-IO-IR-104 controller fatory
|
||||
/// </summary>
|
||||
public class CenIoIr104ControllerFactory : EssentialsDeviceFactory<CenIoIr104Controller>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public CenIoIr104ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "cenioir104" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build device CEN-IO-IR-104
|
||||
/// </summary>
|
||||
/// <param name="dc"></param>
|
||||
/// <returns></returns>
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new CEN-IO-IR-104 Device");
|
||||
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
if (control == null)
|
||||
{
|
||||
Debug.Console(1, "Factory failed to create a new CEN-IO-IR-104 Device, control properties not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
var ipid = control.IpIdInt;
|
||||
if(ipid != 0) return new CenIoIr104Controller(dc.Key, dc.Name, new CenIoIr104(ipid, Global.ControlSystem));
|
||||
|
||||
Debug.Console(1, "Factory failed to create a new CEN-IO-IR-104 Device using IP-ID-{0}", ipid);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for CEN-IO-RY-104 relay module
|
||||
/// </summary>
|
||||
[Description("Wrapper class for the CEN-IO-RY-104 relay module")]
|
||||
public class CenIoRy104Controller : CrestronGenericBaseDevice, IRelayPorts
|
||||
{
|
||||
private readonly CenIoRy104 _ry104;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="ry104"></param>
|
||||
public CenIoRy104Controller(string key, string name, CenIoRy104 ry104)
|
||||
: base(key, name, ry104)
|
||||
{
|
||||
_ry104 = ry104;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Relay port collection
|
||||
/// </summary>
|
||||
public CrestronCollection<Relay> RelayPorts
|
||||
{
|
||||
get { return _ry104.RelayPorts; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of relay ports property
|
||||
/// </summary>
|
||||
public int NumberOfRelayPorts
|
||||
{
|
||||
get { return _ry104.NumberOfRelayPorts; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CEN-IO-RY Controller factory
|
||||
/// </summary>
|
||||
public class CenIoRy104ControllerFactory : EssentialsDeviceFactory<CenIoRy104Controller>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public CenIoRy104ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "ceniory104" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create a new CEN-IO-RY-104 Device");
|
||||
|
||||
var controlPropertiesConfig = CommFactory.GetControlPropertiesConfig(dc);
|
||||
if (controlPropertiesConfig == null)
|
||||
{
|
||||
Debug.Console(1, "Factory failed to create a new CEN-IO-RY-104 Device, control properties not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
var ipid = controlPropertiesConfig.IpIdInt;
|
||||
if (ipid != 0) return new CenIoRy104Controller(dc.Key, dc.Name, new CenIoRy104(ipid, Global.ControlSystem));
|
||||
|
||||
Debug.Console(1, "Factory failed to create a new CEN-IO-RY-104 Device using IP-ID-{0}", ipid);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.CrestronIO
|
||||
{
|
||||
[Description("Wrapper class for the Crestron StatusSign device")]
|
||||
public class StatusSignController : CrestronGenericBridgeableBaseDevice
|
||||
{
|
||||
private StatusSign _device;
|
||||
|
||||
public BoolFeedback RedLedEnabledFeedback { get; private set; }
|
||||
public BoolFeedback GreenLedEnabledFeedback { get; private set; }
|
||||
public BoolFeedback BlueLedEnabledFeedback { get; private set; }
|
||||
|
||||
public IntFeedback RedLedBrightnessFeedback { get; private set; }
|
||||
public IntFeedback GreenLedBrightnessFeedback { get; private set; }
|
||||
public IntFeedback BlueLedBrightnessFeedback { get; private set; }
|
||||
|
||||
public StatusSignController(string key, Func<DeviceConfig, StatusSign> preActivationFunc, DeviceConfig config) : base(key, config.Name)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_device = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_device);
|
||||
|
||||
RedLedEnabledFeedback =
|
||||
new BoolFeedback(
|
||||
() =>
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Red]
|
||||
.ControlFeedback.BoolValue);
|
||||
GreenLedEnabledFeedback =
|
||||
new BoolFeedback(
|
||||
() =>
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Green]
|
||||
.ControlFeedback.BoolValue);
|
||||
BlueLedEnabledFeedback =
|
||||
new BoolFeedback(
|
||||
() =>
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue]
|
||||
.ControlFeedback.BoolValue);
|
||||
|
||||
RedLedBrightnessFeedback =
|
||||
new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Red].BrightnessFeedback);
|
||||
GreenLedBrightnessFeedback =
|
||||
new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Green].BrightnessFeedback);
|
||||
BlueLedBrightnessFeedback =
|
||||
new IntFeedback(() => (int)_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].BrightnessFeedback);
|
||||
|
||||
if (_device != null) _device.BaseEvent += _device_BaseEvent;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
void _device_BaseEvent(GenericBase device, BaseEventArgs args)
|
||||
{
|
||||
switch (args.EventId)
|
||||
{
|
||||
case StatusSign.LedBrightnessFeedbackEventId:
|
||||
RedLedBrightnessFeedback.FireUpdate();
|
||||
GreenLedBrightnessFeedback.FireUpdate();
|
||||
BlueLedBrightnessFeedback.FireUpdate();
|
||||
break;
|
||||
case StatusSign.LedControlFeedbackEventId:
|
||||
RedLedEnabledFeedback.FireUpdate();
|
||||
GreenLedEnabledFeedback.FireUpdate();
|
||||
BlueLedEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableLedControl(bool red, bool green, bool blue)
|
||||
{
|
||||
_device.Leds[(uint) StatusSign.Led.eLedColor.Red].Control.BoolValue = red;
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Control.BoolValue = green;
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Control.BoolValue = blue;
|
||||
}
|
||||
|
||||
public void SetColor(uint red, uint green, uint blue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Red].Brightness =
|
||||
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(red);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
Debug.Console(1, this, "Error converting value to Red LED brightness. value: {0}", red);
|
||||
}
|
||||
try
|
||||
{
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Brightness =
|
||||
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(green);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
Debug.Console(1, this, "Error converting value to Green LED brightness. value: {0}", green);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Brightness =
|
||||
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(blue);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
Debug.Console(1, this, "Error converting value to Blue LED brightness. value: {0}", blue);
|
||||
}
|
||||
}
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new StatusSignControllerJoinMap(joinStart);
|
||||
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<StatusSignControllerJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
|
||||
trilist.SetBoolSigAction(joinMap.RedControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
|
||||
trilist.SetBoolSigAction(joinMap.GreenControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
|
||||
trilist.SetBoolSigAction(joinMap.BlueControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
|
||||
|
||||
trilist.SetUShortSigAction(joinMap.RedLed.JoinNumber, u => SetColor(trilist, joinMap, this));
|
||||
trilist.SetUShortSigAction(joinMap.GreenLed.JoinNumber, u => SetColor(trilist, joinMap, this));
|
||||
trilist.SetUShortSigAction(joinMap.BlueLed.JoinNumber, u => SetColor(trilist, joinMap, this));
|
||||
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = Name;
|
||||
|
||||
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
RedLedEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RedControl.JoinNumber]);
|
||||
BlueLedEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.BlueControl.JoinNumber]);
|
||||
GreenLedEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.GreenControl.JoinNumber]);
|
||||
|
||||
RedLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.RedLed.JoinNumber]);
|
||||
BlueLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.BlueLed.JoinNumber]);
|
||||
GreenLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.GreenLed.JoinNumber]);
|
||||
}
|
||||
|
||||
private static void EnableControl(BasicTriList triList, StatusSignControllerJoinMap joinMap,
|
||||
StatusSignController device)
|
||||
{
|
||||
var redEnable = triList.BooleanOutput[joinMap.RedControl.JoinNumber].BoolValue;
|
||||
var greenEnable = triList.BooleanOutput[joinMap.GreenControl.JoinNumber].BoolValue;
|
||||
var blueEnable = triList.BooleanOutput[joinMap.BlueControl.JoinNumber].BoolValue;
|
||||
device.EnableLedControl(redEnable, greenEnable, blueEnable);
|
||||
}
|
||||
|
||||
private static void SetColor(BasicTriList triList, StatusSignControllerJoinMap joinMap,
|
||||
StatusSignController device)
|
||||
{
|
||||
var redBrightness = triList.UShortOutput[joinMap.RedLed.JoinNumber].UShortValue;
|
||||
var greenBrightness = triList.UShortOutput[joinMap.GreenLed.JoinNumber].UShortValue;
|
||||
var blueBrightness = triList.UShortOutput[joinMap.BlueLed.JoinNumber].UShortValue;
|
||||
|
||||
device.SetColor(redBrightness, greenBrightness, blueBrightness);
|
||||
}
|
||||
|
||||
#region PreActivation
|
||||
|
||||
private static StatusSign GetStatusSignDevice(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 StatusSign", parentKey);
|
||||
return new StatusSign(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new StatusSign", parentKey);
|
||||
return new StatusSign(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class StatusSignControllerFactory : EssentialsDeviceFactory<StatusSignController>
|
||||
{
|
||||
public StatusSignControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "statussign" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new StatusSign Device");
|
||||
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var cresnetId = control.CresnetIdInt;
|
||||
|
||||
return new StatusSignController(dc.Key, GetStatusSignDevice, dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,14 +7,4 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
bool BrandingEnabled { get; }
|
||||
void InitializeBranding(string roomKey);
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.DeviceTypeInterfaces
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.DeviceTypeInterfaces")]
|
||||
public interface IHasBranding
|
||||
{
|
||||
bool BrandingEnabled { get; }
|
||||
void InitializeBranding(string roomKey);
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,4 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
void EndPhoneCall();
|
||||
void SendDtmfToPhone(string digit);
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.DeviceTypeInterfaces
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.DeviceTypeInterfaces")]
|
||||
public interface IHasPhoneDialing
|
||||
{
|
||||
BoolFeedback PhoneOffHookFeedback { get; }
|
||||
StringFeedback CallerIdNameFeedback { get; }
|
||||
StringFeedback CallerIdNumberFeedback { get; }
|
||||
void DialPhoneCall(string number);
|
||||
void EndPhoneCall();
|
||||
void SendDtmfToPhone(string digit);
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,3 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
List<LanguageLabel> RoomNames { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.DeviceTypeInterfaces
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.DeviceTypeInterfaces")]
|
||||
public interface ILanguageDefinition
|
||||
{
|
||||
string LocaleName { get; set; }
|
||||
string FriendlyName { get; set; }
|
||||
bool Enable { get; set; }
|
||||
List<LanguageLabel> UiLabels { get; set; }
|
||||
List<LanguageLabel> Sources { get; set; }
|
||||
List<LanguageLabel> Destinations { get; set; }
|
||||
List<LanguageLabel> SourceGroupNames { get; set; }
|
||||
List<LanguageLabel> DestinationGroupNames { get; set; }
|
||||
List<LanguageLabel> RoomNames { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,3 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.DeviceTypeInterfaces
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.DeviceTypeInterfaces")]
|
||||
public interface ILanguageProvider
|
||||
{
|
||||
ILanguageDefinition CurrentLanguage { get; set; }
|
||||
|
||||
event EventHandler CurrentLanguageChanged;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,17 +13,6 @@ using PepperDash.Essentials.Core.SmartObjects;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ability to power a device on and off
|
||||
/// </summary>
|
||||
[Obsolete("Will be replaced by IHasPowerControlWithFeedback")]
|
||||
public interface IPower
|
||||
{
|
||||
void PowerOn();
|
||||
void PowerOff();
|
||||
void PowerToggle();
|
||||
BoolFeedback PowerIsOnFeedback { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds feedback for current power state
|
||||
|
||||
@@ -10,16 +10,4 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
public string DisplayText { get; set; }
|
||||
public uint JoinNumber { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.DeviceTypeInterfaces
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.DeviceTypeInterfaces")]
|
||||
public class LanguageLabel
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DisplayText { get; set; }
|
||||
public uint JoinNumber { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -35,35 +35,6 @@ namespace PepperDash.Essentials.Core.Devices
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generic monitor for TCP reachability. Default with 30s poll, 120s warning and 300s error times
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, string hostname, int port, string pollString)
|
||||
: this(key, name, hostname, port, pollString, 30000, 120000, 300000)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monitor for TCP reachability
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, string hostname, int port, string pollString,
|
||||
long pollTime, long warningTime, long errorTime)
|
||||
: base(key, name)
|
||||
{
|
||||
Client = new GenericTcpIpClient(key + "-tcp", hostname, port, 512);
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Client, pollTime, warningTime, errorTime, pollString);
|
||||
|
||||
// ------------------------------------------------------DELETE THIS
|
||||
CommunicationMonitor.StatusChange += (o, a) =>
|
||||
{
|
||||
Debug.Console(2, this, "Communication monitor status change: {0}", a.Status);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
CommunicationMonitor.Start();
|
||||
|
||||
@@ -9,18 +9,6 @@ using Crestron.SimplSharpPro.UI;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
//[Obsolete]
|
||||
//public class PresentationDeviceType
|
||||
//{
|
||||
// public const ushort Default = 1;
|
||||
// public const ushort CableSetTopBox = 2;
|
||||
// public const ushort SatelliteSetTopBox = 3;
|
||||
// public const ushort Dvd = 4;
|
||||
// public const ushort Bluray = 5;
|
||||
// public const ushort PC = 9;
|
||||
// public const ushort Laptop = 10;
|
||||
//}
|
||||
|
||||
public enum PresentationSourceType
|
||||
{
|
||||
None, Dvd, Laptop, PC, SetTopBox, VCR
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace PepperDash.Essentials.Core
|
||||
public IrOutputPortController IrPort { get; private set; }
|
||||
public ushort IrPulseTime { get; set; }
|
||||
|
||||
[Obsolete("This property will be removed in version 2.0.0")]
|
||||
public override BoolFeedback PowerIsOnFeedback { get; protected set; }
|
||||
|
||||
protected Func<bool> PowerIsOnFeedbackFunc
|
||||
{
|
||||
get { return () => _PowerIsOn; }
|
||||
@@ -46,14 +43,6 @@ namespace PepperDash.Essentials.Core
|
||||
IrPort = new IrOutputPortController(key + "-ir", port, irDriverFilepath);
|
||||
DeviceManager.AddDevice(IrPort);
|
||||
|
||||
PowerIsOnFeedback = new BoolFeedback(PowerIsOnFeedbackFunc);
|
||||
|
||||
PowerIsOnFeedback.OutputChange += (o, a) =>
|
||||
{
|
||||
Debug.Console(2, this, "Power on={0}", _PowerIsOn);
|
||||
if (_PowerIsOn) StartWarmingTimer();
|
||||
else StartCoolingTimer();
|
||||
};
|
||||
IsWarmingUpFeedback.OutputChange += (o, a) => Debug.Console(2, this, "Warming up={0}", _IsWarmingUp);
|
||||
IsCoolingDownFeedback.OutputChange += (o, a) => Debug.Console(2, this, "Cooling down={0}", _IsCoolingDown);
|
||||
|
||||
@@ -117,20 +106,17 @@ namespace PepperDash.Essentials.Core
|
||||
{
|
||||
IrPort.Pulse(IROutputStandardCommands.IROut_POWER_ON, IrPulseTime);
|
||||
_PowerIsOn = true;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
public override void PowerOff()
|
||||
{
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IrPort.Pulse(IROutputStandardCommands.IROut_POWER_OFF, IrPulseTime);
|
||||
}
|
||||
|
||||
public override void PowerToggle()
|
||||
{
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IrPort.Pulse(IROutputStandardCommands.IROut_POWER, IrPulseTime);
|
||||
}
|
||||
|
||||
@@ -193,7 +179,7 @@ namespace PepperDash.Essentials.Core
|
||||
action();
|
||||
};
|
||||
|
||||
if (!PowerIsOnFeedback.BoolValue)
|
||||
if (!_PowerIsOn)
|
||||
{
|
||||
PowerOn();
|
||||
EventHandler<FeedbackEventArgs> oneTimer = null;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace PepperDash.Essentials.Core
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public abstract class DisplayBase : EssentialsDevice, IHasFeedback, IRoutingSinkWithSwitching, IHasPowerControl, IWarmingCooling, IUsageTracking, IPower
|
||||
public abstract class DisplayBase : EssentialsDevice, IHasFeedback, IRoutingSinkWithSwitching, IHasPowerControl, IWarmingCooling, IUsageTracking
|
||||
{
|
||||
public event SourceInfoChangeHandler CurrentSourceChange;
|
||||
|
||||
@@ -51,9 +51,6 @@ namespace PepperDash.Essentials.Core
|
||||
public BoolFeedback IsCoolingDownFeedback { get; protected set; }
|
||||
public BoolFeedback IsWarmingUpFeedback { get; private set; }
|
||||
|
||||
[Obsolete("This property will be removed in version 2.0.0")]
|
||||
public abstract BoolFeedback PowerIsOnFeedback { get; protected set; }
|
||||
|
||||
public UsageTracking UsageTracker { get; set; }
|
||||
|
||||
public uint WarmupTime { get; set; }
|
||||
@@ -269,7 +266,7 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
abstract protected Func<string> CurrentInputFeedbackFunc { get; }
|
||||
|
||||
public override BoolFeedback PowerIsOnFeedback { get; protected set; }
|
||||
public BoolFeedback PowerIsOnFeedback { get; protected set; }
|
||||
|
||||
abstract protected Func<bool> PowerIsOnFeedbackFunc { get; }
|
||||
|
||||
|
||||
@@ -23,24 +23,3 @@ namespace PepperDash.Essentials.Core
|
||||
bool IsReady { get; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core")]
|
||||
public class IsReadyEventArgs : EventArgs
|
||||
{
|
||||
public bool IsReady { get; set; }
|
||||
|
||||
public IsReadyEventArgs(bool data)
|
||||
{
|
||||
IsReady = data;
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use PepperDash.Essentials.Core")]
|
||||
public interface IHasReady
|
||||
{
|
||||
event EventHandler<IsReadyEventArgs> IsReadyEvent;
|
||||
bool IsReady { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.Gateways;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for Crestron Infinet-EX Gateways")]
|
||||
public class CenRfgwController : CrestronGenericBaseDevice, IHasReady
|
||||
{
|
||||
public event EventHandler<IsReadyEventArgs> IsReadyEvent;
|
||||
|
||||
public bool IsReady { get; private set; }
|
||||
|
||||
private GatewayBase _gateway;
|
||||
|
||||
public GatewayBase GateWay
|
||||
{
|
||||
get { return _gateway; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the on-board gateway
|
||||
/// </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 = true;
|
||||
FireIsReadyEvent(IsReady);
|
||||
}
|
||||
|
||||
public CenRfgwController(string key, Func<DeviceConfig, GatewayBase> preActivationFunc, DeviceConfig config) :
|
||||
base(key, config.Name)
|
||||
{
|
||||
IsReady = false;
|
||||
FireIsReadyEvent(IsReady);
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_gateway = preActivationFunc(config);
|
||||
|
||||
IsReady = true;
|
||||
RegisterCrestronGenericBase(_gateway);
|
||||
FireIsReadyEvent(IsReady);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static GatewayBase GetNewIpRfGateway(DeviceConfig dc)
|
||||
{
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var type = dc.Type;
|
||||
var ipId = control.IpIdInt;
|
||||
|
||||
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenRfgwEx(ipId, Global.ControlSystem);
|
||||
}
|
||||
if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenErfgwPoe(ipId, Global.ControlSystem);
|
||||
}
|
||||
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);
|
||||
var ipId = control.IpIdInt;
|
||||
|
||||
if (dc.Type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenRfgwExEthernetSharable(ipId, Global.ControlSystem);
|
||||
}
|
||||
if (dc.Type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenErfgwPoeEthernetSharable(ipId, Global.ControlSystem);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GatewayBase GetCenRfgwCresnetController(DeviceConfig dc)
|
||||
{
|
||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||
var type = dc.Type;
|
||||
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 CenRfgw", parentKey);
|
||||
if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenErfgwPoeCresnet(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenRfgwExCresnet(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 CenRfgw", parentKey);
|
||||
|
||||
if (type.Equals("cenerfgwpoe", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenErfgwPoeCresnet(cresnetId, cresnetBridge.Branches[branchId]);
|
||||
}
|
||||
if (type.Equals("cenrfgwex", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return new CenRfgwExCresnet(cresnetId, cresnetBridge.Branches[branchId]);
|
||||
}
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum EExGatewayType
|
||||
{
|
||||
Ethernet,
|
||||
EthernetShared,
|
||||
Cresnet
|
||||
}
|
||||
|
||||
|
||||
#region Factory
|
||||
|
||||
public class CenRfgwControllerFactory : EssentialsDeviceFactory<CenRfgwController>
|
||||
{
|
||||
public CenRfgwControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> {"cenrfgwex", "cenerfgwpoe"};
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
|
||||
Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device");
|
||||
|
||||
var props = JsonConvert.DeserializeObject<EssentialsRfGatewayConfig>(dc.Properties.ToString());
|
||||
|
||||
EExGatewayType gatewayType =
|
||||
(EExGatewayType) Enum.Parse(typeof (EExGatewayType), props.GatewayType, true);
|
||||
|
||||
switch (gatewayType)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Full.Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class EssentialsRfGatewayConfig
|
||||
{
|
||||
[JsonProperty("control")]
|
||||
public EssentialsControlPropertiesConfig Control { get; set; }
|
||||
|
||||
[JsonProperty("gatewayType")]
|
||||
public string GatewayType { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -83,97 +83,6 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for join maps
|
||||
/// </summary>
|
||||
[Obsolete("This is being deprecated in favor of JoinMapBaseAdvanced")]
|
||||
public abstract class JoinMapBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Modifies all the join numbers by adding the offset. This should never be called twice
|
||||
/// </summary>
|
||||
/// <param name="joinStart"></param>
|
||||
public abstract void OffsetJoinNumbers(uint joinStart);
|
||||
|
||||
/// <summary>
|
||||
/// The collection of joins and associated metadata
|
||||
/// </summary>
|
||||
public Dictionary<string, JoinMetadata> Joins = new Dictionary<string, JoinMetadata>();
|
||||
|
||||
/// <summary>
|
||||
/// Prints the join information to console
|
||||
/// </summary>
|
||||
public void PrintJoinMapInfo()
|
||||
{
|
||||
Debug.Console(0, "{0}:\n", GetType().Name);
|
||||
|
||||
// Get the joins of each type and print them
|
||||
Debug.Console(0, "Digitals:");
|
||||
var digitals = Joins.Where(j => (j.Value.JoinType & eJoinType.Digital) == eJoinType.Digital).ToDictionary(j => j.Key, j => j.Value);
|
||||
Debug.Console(2, "Found {0} Digital Joins", digitals.Count);
|
||||
PrintJoinList(GetSortedJoins(digitals));
|
||||
|
||||
Debug.Console(0, "Analogs:");
|
||||
var analogs = Joins.Where(j => (j.Value.JoinType & eJoinType.Analog) == eJoinType.Analog).ToDictionary(j => j.Key, j => j.Value);
|
||||
Debug.Console(2, "Found {0} Analog Joins", analogs.Count);
|
||||
PrintJoinList(GetSortedJoins(analogs));
|
||||
|
||||
Debug.Console(0, "Serials:");
|
||||
var serials = Joins.Where(j => (j.Value.JoinType & eJoinType.Serial) == eJoinType.Serial).ToDictionary(j => j.Key, j => j.Value);
|
||||
Debug.Console(2, "Found {0} Serial Joins", serials.Count);
|
||||
PrintJoinList(GetSortedJoins(serials));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a sorted list by JoinNumber
|
||||
/// </summary>
|
||||
/// <param name="joins"></param>
|
||||
/// <returns></returns>
|
||||
List<KeyValuePair<string, JoinMetadata>> GetSortedJoins(Dictionary<string, JoinMetadata> joins)
|
||||
{
|
||||
var sortedJoins = joins.ToList();
|
||||
|
||||
sortedJoins.Sort((pair1, pair2) => pair1.Value.JoinNumber.CompareTo(pair2.Value.JoinNumber));
|
||||
|
||||
return sortedJoins;
|
||||
}
|
||||
|
||||
void PrintJoinList(List<KeyValuePair<string, JoinMetadata>> joins)
|
||||
{
|
||||
foreach (var join in joins)
|
||||
{
|
||||
Debug.Console(0,
|
||||
@"Join Number: {0} | Label: '{1}' | JoinSpan: '{2}' | Type: '{3}' | Capabilities: '{4}'",
|
||||
join.Value.JoinNumber,
|
||||
join.Value.Label,
|
||||
join.Value.JoinSpan,
|
||||
join.Value.JoinType.ToString(),
|
||||
join.Value.JoinCapabilities.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the join number for the join with the specified key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public uint GetJoinForKey(string key)
|
||||
{
|
||||
return Joins.ContainsKey(key) ? Joins[key].JoinNumber : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the join span for the join with the specified key
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public uint GetJoinSpanForKey(string key)
|
||||
{
|
||||
return Joins.ContainsKey(key) ? Joins[key].JoinSpan : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for join maps
|
||||
/// </summary>
|
||||
@@ -333,7 +242,7 @@ namespace PepperDash.Essentials.Core
|
||||
join.Value.JoinNumber,
|
||||
join.Value.JoinSpan,
|
||||
join.Key,
|
||||
String.IsNullOrEmpty(join.Value.AttributeName) ? join.Value.Metadata.Label : join.Value.AttributeName,
|
||||
join.Value.AttributeName,
|
||||
join.Value.Metadata.JoinType.ToString(),
|
||||
join.Value.Metadata.JoinCapabilities.ToString());
|
||||
}
|
||||
@@ -452,27 +361,6 @@ namespace PepperDash.Essentials.Core
|
||||
public class JoinMetadata
|
||||
{
|
||||
private string _description;
|
||||
|
||||
/// <summary>
|
||||
/// Join number (based on join offset value)
|
||||
/// </summary>
|
||||
[JsonProperty("joinNumber")]
|
||||
[Obsolete]
|
||||
public uint JoinNumber { get; set; }
|
||||
/// <summary>
|
||||
/// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
[JsonProperty("joinSpan")]
|
||||
public uint JoinSpan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A label for the join to better describe its usage
|
||||
/// </summary>
|
||||
[Obsolete("Use Description instead")]
|
||||
[JsonProperty("label")]
|
||||
public string Label { get { return _description; } set { _description = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// A description for the join to better describe its usage
|
||||
/// </summary>
|
||||
|
||||
@@ -1,777 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for CEN-ODT-C-POE")]
|
||||
[ConfigSnippet("\"properties\": {\"control\": {\"method\": \"cresnet\",\"cresnetId\": \"97\"},\"enablePir\": true,\"enableLedFlash\": true,\"enableRawStates\":true,\"remoteTimeout\": 30,\"internalPhotoSensorMinChange\": 0,\"externalPhotoSensorMinChange\": 0,\"enableUsA\": true,\"enableUsB\": true,\"orWhenVacatedState\": true}")]
|
||||
public class CenOdtOccupancySensorBaseController : CrestronGenericBridgeableBaseDevice, IOccupancyStatusProvider
|
||||
{
|
||||
public CenOdtCPoe OccSensor { get; private set; }
|
||||
|
||||
public GlsOccupancySensorPropertiesConfig PropertiesConfig { get; private set; }
|
||||
|
||||
public BoolFeedback RoomIsOccupiedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback GraceOccupancyDetectedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback PirSensorEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback LedFlashEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback ShortTimeoutEnabledFeedback { get; private set; }
|
||||
|
||||
public IntFeedback PirSensitivityInVacantStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback PirSensitivityInOccupiedStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback CurrentTimeoutFeedback { get; private set; }
|
||||
|
||||
public IntFeedback RemoteTimeoutFeedback { get; private set; }
|
||||
|
||||
public IntFeedback InternalPhotoSensorValue { get; set; }
|
||||
|
||||
public IntFeedback ExternalPhotoSensorValue { get; set; }
|
||||
|
||||
public BoolFeedback OrWhenVacatedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback AndWhenVacatedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback UltrasonicAEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback UltrasonicBEnabledFeedback { get; private set; }
|
||||
|
||||
public IntFeedback UltrasonicSensitivityInVacantStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback UltrasonicSensitivityInOccupiedStateFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyPirFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyUsFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback IdentityModeFeedback { get; private set; }
|
||||
|
||||
// Debug properties
|
||||
public bool InTestMode { get; private set; }
|
||||
|
||||
public bool TestRoomIsOccupiedFeedback { get; private set; }
|
||||
|
||||
public Func<bool> RoomIsOccupiedFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return () => InTestMode ? TestRoomIsOccupiedFeedback : OccSensor.OccupancyDetectedFeedback.BoolValue;
|
||||
}
|
||||
}
|
||||
|
||||
public CenOdtOccupancySensorBaseController(string key, string name, CenOdtCPoe sensor, GlsOccupancySensorPropertiesConfig config)
|
||||
: base(key, name, sensor)
|
||||
{
|
||||
PropertiesConfig = config;
|
||||
|
||||
OccSensor = sensor;
|
||||
|
||||
RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc);
|
||||
|
||||
PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PassiveInfraredSensorEnabledFeedback.BoolValue);
|
||||
|
||||
LedFlashEnabledFeedback = new BoolFeedback(() => OccSensor.LedFlashEnabledFeedback.BoolValue);
|
||||
|
||||
ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue);
|
||||
|
||||
PirSensitivityInVacantStateFeedback = new IntFeedback(() => (int)OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback);
|
||||
|
||||
PirSensitivityInOccupiedStateFeedback = new IntFeedback(() => (int)OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback);
|
||||
|
||||
CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue);
|
||||
|
||||
RemoteTimeoutFeedback = new IntFeedback(() => OccSensor.RemoteTimeout.UShortValue);
|
||||
|
||||
GraceOccupancyDetectedFeedback = new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue);
|
||||
|
||||
RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyDetectedFeedback.BoolValue);
|
||||
|
||||
InternalPhotoSensorValue = new IntFeedback(() => OccSensor.InternalPhotoSensorValueFeedback.UShortValue);
|
||||
|
||||
//ExternalPhotoSensorValue = new IntFeedback(() => OccSensor.ex.UShortValue);
|
||||
|
||||
AndWhenVacatedFeedback = new BoolFeedback(() => OccSensor.AndWhenVacatedFeedback.BoolValue);
|
||||
|
||||
OrWhenVacatedFeedback = new BoolFeedback(() => OccSensor.OrWhenVacatedFeedback.BoolValue);
|
||||
|
||||
UltrasonicAEnabledFeedback = new BoolFeedback(() => OccSensor.UltrasonicSensorSideAEnabledFeedback.BoolValue);
|
||||
|
||||
UltrasonicBEnabledFeedback = new BoolFeedback(() => OccSensor.UltrasonicSensorSideBEnabledFeedback.BoolValue);
|
||||
|
||||
RawOccupancyPirFeedback = new BoolFeedback(() => OccSensor.RawOccupancyDetectedByPassiveInfraredSensorFeedback.BoolValue);
|
||||
|
||||
RawOccupancyUsFeedback = new BoolFeedback(() => OccSensor.RawOccupancyDetectedByUltrasonicSensorFeedback.BoolValue);
|
||||
|
||||
IdentityModeFeedback = new BoolFeedback(()=>OccSensor.IdentityModeOnFeedback.BoolValue);
|
||||
|
||||
UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => (int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback);
|
||||
|
||||
UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => (int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback);
|
||||
|
||||
OccSensor.BaseEvent += new Crestron.SimplSharpPro.BaseEventHandler(OccSensor_BaseEvent);
|
||||
|
||||
OccSensor.CenOccupancySensorChange += new GenericEventHandler(OccSensor_CenOccupancySensorChange);
|
||||
|
||||
AddPostActivationAction(() =>
|
||||
{
|
||||
OccSensor.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (a.DeviceOnLine)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
}
|
||||
};
|
||||
|
||||
if (OccSensor.IsOnline)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies any sensor settings defined in config
|
||||
/// </summary>
|
||||
protected virtual void ApplySettingsToSensorFromConfig()
|
||||
{
|
||||
Debug.Console(1, this, "Checking config for settings to apply");
|
||||
|
||||
if (PropertiesConfig.EnablePir != null)
|
||||
{
|
||||
SetPirEnable((bool)PropertiesConfig.EnablePir);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableLedFlash != null)
|
||||
{
|
||||
SetLedFlashEnable((bool)PropertiesConfig.EnableLedFlash);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.RemoteTimeout != null)
|
||||
{
|
||||
SetRemoteTimeout((ushort)PropertiesConfig.RemoteTimeout);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.ShortTimeoutState != null)
|
||||
{
|
||||
SetShortTimeoutState((bool)PropertiesConfig.ShortTimeoutState);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableRawStates != null)
|
||||
{
|
||||
EnableRawStates((bool)PropertiesConfig.EnableRawStates);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.InternalPhotoSensorMinChange != null)
|
||||
{
|
||||
SetInternalPhotoSensorMinChange((ushort)PropertiesConfig.InternalPhotoSensorMinChange);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableUsA != null)
|
||||
{
|
||||
SetUsAEnable((bool)PropertiesConfig.EnableUsA);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableUsB != null)
|
||||
{
|
||||
SetUsBEnable((bool)PropertiesConfig.EnableUsB);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.OrWhenVacatedState != null)
|
||||
{
|
||||
SetOrWhenVacatedState((bool)PropertiesConfig.OrWhenVacatedState);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.AndWhenVacatedState != null)
|
||||
{
|
||||
SetAndWhenVacatedState((bool)PropertiesConfig.AndWhenVacatedState);
|
||||
}
|
||||
|
||||
// TODO [ ] feature/cenoodtcpoe-sensor-sensitivity-configuration
|
||||
if (PropertiesConfig.UsSensitivityOccupied != null)
|
||||
{
|
||||
SetUsSensitivityOccupied((ushort)PropertiesConfig.UsSensitivityOccupied);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.UsSensitivityVacant != null)
|
||||
{
|
||||
SetUsSensitivityVacant((ushort)PropertiesConfig.UsSensitivityVacant);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.PirSensitivityOccupied != null)
|
||||
{
|
||||
SetPirSensitivityOccupied((ushort)PropertiesConfig.PirSensitivityOccupied);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.PirSensitivityVacant != null)
|
||||
{
|
||||
SetPirSensitivityVacant((ushort)PropertiesConfig.PirSensitivityVacant);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catches events for feedbacks on the base class. Any extending wrapper class should call this delegate after it checks for it's own event IDs.
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="args"></param>
|
||||
protected virtual void OccSensor_CenOccupancySensorChange(object device, GenericEventArgs args)
|
||||
{
|
||||
if (args.EventId == GlsOccupancySensorBase.PirEnabledFeedbackEventId)
|
||||
PirSensorEnabledFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId)
|
||||
LedFlashEnabledFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId)
|
||||
ShortTimeoutEnabledFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId)
|
||||
PirSensitivityInOccupiedStateFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId)
|
||||
PirSensitivityInVacantStateFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.RawOccupancyPirFeedbackEventId)
|
||||
RawOccupancyPirFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.RawOccupancyUsFeedbackEventId)
|
||||
RawOccupancyUsFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args)
|
||||
{
|
||||
Debug.Console(2, this, "PoEOccupancySensorChange EventId: {0}", args.EventId);
|
||||
|
||||
if (args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomOccupiedFeedbackEventId
|
||||
|| args.EventId == Crestron.SimplSharpPro.GeneralIO.GlsOccupancySensorBase.RoomVacantFeedbackEventId)
|
||||
{
|
||||
Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue);
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
}
|
||||
else if (args.EventId == GlsOccupancySensorBase.TimeoutFeedbackEventId)
|
||||
CurrentTimeoutFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.TimeoutLocalFeedbackEventId)
|
||||
RemoteTimeoutFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId)
|
||||
GraceOccupancyDetectedFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.RawOccupancyFeedbackEventId)
|
||||
RawOccupancyFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId)
|
||||
InternalPhotoSensorValue.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId)
|
||||
ExternalPhotoSensorValue.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.AndWhenVacatedFeedbackEventId)
|
||||
AndWhenVacatedFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.OrWhenVacatedFeedbackEventId)
|
||||
OrWhenVacatedFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.UsAEnabledFeedbackEventId)
|
||||
UltrasonicAEnabledFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.UsBEnabledFeedbackEventId)
|
||||
UltrasonicBEnabledFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.UsSensitivityInOccupiedStateFeedbackEventId)
|
||||
UltrasonicSensitivityInOccupiedStateFeedback.FireUpdate();
|
||||
else if (args.EventId == GlsOccupancySensorBase.UsSensitivityInVacantStateFeedbackEventId)
|
||||
UltrasonicSensitivityInVacantStateFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
public void SetTestMode(bool mode)
|
||||
{
|
||||
InTestMode = mode;
|
||||
|
||||
Debug.Console(1, this, "In Mock Mode: '{0}'", InTestMode);
|
||||
}
|
||||
|
||||
public void SetTestOccupiedState(bool state)
|
||||
{
|
||||
if (!InTestMode)
|
||||
Debug.Console(1, "Mock mode not enabled");
|
||||
else
|
||||
{
|
||||
TestRoomIsOccupiedFeedback = state;
|
||||
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the identity mode on or off
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetIdentityMode(bool state)
|
||||
{
|
||||
if (state)
|
||||
OccSensor.IdentityModeOn();
|
||||
else
|
||||
OccSensor.IdentityModeOff();
|
||||
|
||||
Debug.Console(1, this, "Identity Mode: {0}", OccSensor.IdentityModeOnFeedback.BoolValue ? "On" : "Off");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the PIR sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetPirEnable(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnablePassiveInfraredSensor();
|
||||
}
|
||||
else
|
||||
{
|
||||
OccSensor.DisablePassiveInfraredSensor();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the LED Flash
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetLedFlashEnable(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnableLedFlash();
|
||||
}
|
||||
else
|
||||
{
|
||||
OccSensor.DisableLedFlash();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables short timeout based on state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetShortTimeoutState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnableShortTimeout();
|
||||
}
|
||||
else
|
||||
{
|
||||
OccSensor.DisableShortTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
public void IncrementPirSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback != 3)
|
||||
{
|
||||
OccSensor.PassiveInfraredSensorSensitivityInOccupiedState = OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void DecrementPirSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback != 0)
|
||||
{
|
||||
OccSensor.PassiveInfraredSensorSensitivityInOccupiedState = OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void IncrementPirSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback != 3)
|
||||
{
|
||||
OccSensor.PassiveInfraredSensorSensitivityInVacantState = OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void DecrementPirSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback != 0)
|
||||
{
|
||||
OccSensor.PassiveInfraredSensorSensitivityInVacantState = OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void IncrementUsSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback < 3)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback + 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback > 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback - 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback == 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void DecrementUsSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback > 0
|
||||
&& (int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback < 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback - 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback > 3
|
||||
&& (int)OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback < 7)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void IncrementUsSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback < 3)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback + 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback > 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback - 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback == 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void DecrementUsSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
if ((int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback > 0
|
||||
&& (int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback < 4)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback - 1;
|
||||
}
|
||||
else if ((int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback > 3
|
||||
&& (int)OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback < 7)
|
||||
{
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceOccupied()
|
||||
{
|
||||
OccSensor.ForceOccupied();
|
||||
}
|
||||
|
||||
public void ForceVacant()
|
||||
{
|
||||
OccSensor.ForceVacant();
|
||||
}
|
||||
|
||||
public void EnableRawStates(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnableRawStates();
|
||||
}
|
||||
else
|
||||
OccSensor.DisableRawStates();
|
||||
}
|
||||
|
||||
public void SetRemoteTimeout(ushort time)
|
||||
{
|
||||
OccSensor.RemoteTimeout.UShortValue = time;
|
||||
}
|
||||
|
||||
public void SetInternalPhotoSensorMinChange(ushort value)
|
||||
{
|
||||
OccSensor.InternalPhotoSensorMinimumChange.UShortValue = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the OrWhenVacated state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetOrWhenVacatedState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.OrWhenVacated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the AndWhenVacated state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetAndWhenVacatedState(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.AndWhenVacated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the Ultrasonic A sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetUsAEnable(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnableUltrasonicSensorSideA();
|
||||
}
|
||||
else
|
||||
{
|
||||
OccSensor.DisableUltrasonicSensorSideA();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the Ultrasonic B sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetUsBEnable(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OccSensor.EnableUltrasonicSensorSideB();
|
||||
}
|
||||
else
|
||||
{
|
||||
OccSensor.DisableUltrasonicSensorSideB();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the US sensor sensitivity for occupied state
|
||||
/// </summary>
|
||||
/// <param name="sensitivity"></param>
|
||||
public void SetUsSensitivityOccupied(ushort sensitivity)
|
||||
{
|
||||
var level = (eSensitivityLevel) sensitivity;
|
||||
if (level == 0) return;
|
||||
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedState = level;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the US sensor sensitivity for vacant state
|
||||
/// </summary>
|
||||
/// <param name="sensitivity"></param>
|
||||
public void SetUsSensitivityVacant(ushort sensitivity)
|
||||
{
|
||||
var level = (eSensitivityLevel)sensitivity;
|
||||
if (level == 0) return;
|
||||
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantState = level;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the PIR sensor sensitivity for occupied state
|
||||
/// </summary>
|
||||
/// <param name="sensitivity"></param>
|
||||
public void SetPirSensitivityOccupied(ushort sensitivity)
|
||||
{
|
||||
var level = (eSensitivityLevel)sensitivity;
|
||||
if (level == 0) return;
|
||||
|
||||
OccSensor.PassiveInfraredSensorSensitivityInOccupiedState = level;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the PIR sensor sensitivity for vacant state
|
||||
/// </summary>
|
||||
/// <param name="sensitivity"></param>
|
||||
public void SetPirSensitivityVacant(ushort sensitivity)
|
||||
{
|
||||
var level = (eSensitivityLevel)sensitivity;
|
||||
if (level == 0) return;
|
||||
|
||||
OccSensor.PassiveInfraredSensorSensitivityInVacantState = level;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to print current settings to console
|
||||
/// </summary>
|
||||
public void GetSettings()
|
||||
{
|
||||
var dash = new string('*', 50);
|
||||
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||
|
||||
Debug.Console(0, this, "Vacancy Detected: {0}",
|
||||
OccSensor.VacancyDetectedFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, Key, "Timeout Current: {0} | Remote: {1}",
|
||||
OccSensor.CurrentTimeoutFeedback.UShortValue,
|
||||
OccSensor.RemoteTimeout.UShortValue);
|
||||
|
||||
Debug.Console(0, Key, "Short Timeout Enabled: {0}",
|
||||
OccSensor.ShortTimeoutEnabledFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, Key, "PIR Sensor Enabled: {0} | Sensitivity Occupied: {1} | Sensitivity Vacant: {2}",
|
||||
OccSensor.PassiveInfraredSensorEnabledFeedback.BoolValue,
|
||||
OccSensor.PassiveInfraredSensorSensitivityInOccupiedStateFeedback,
|
||||
OccSensor.PassiveInfraredSensorSensitivityInVacantStateFeedback);
|
||||
|
||||
Debug.Console(0, Key, "Ultrasonic Enabled A: {0} | B: {1}",
|
||||
OccSensor.UltrasonicSensorSideAEnabledFeedback.BoolValue,
|
||||
OccSensor.UltrasonicSensorSideBEnabledFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, Key, "Ultrasonic Sensitivity Occupied: {0} | Vacant: {1}",
|
||||
OccSensor.UltrasonicSensorSensitivityInOccupiedStateFeedback,
|
||||
OccSensor.UltrasonicSensorSensitivityInVacantStateFeedback);
|
||||
|
||||
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||
}
|
||||
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
protected void LinkOccSensorToApi(CenOdtOccupancySensorBaseController occController,
|
||||
BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
CenOdtOccupancySensorBaseJoinMap joinMap = new CenOdtOccupancySensorBaseJoinMap(joinStart);
|
||||
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<CenOdtOccupancySensorBaseJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
|
||||
}
|
||||
|
||||
Debug.Console(1, occController, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
|
||||
occController.IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.Online.JoinNumber]);
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = occController.Name;
|
||||
|
||||
trilist.OnlineStatusChange += new Crestron.SimplSharpPro.OnlineStatusChangeEventHandler((d, args) =>
|
||||
{
|
||||
if (args.DeviceOnLine)
|
||||
{
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = occController.Name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Occupied status
|
||||
trilist.SetSigTrueAction(joinMap.ForceOccupied.JoinNumber, new Action(() => occController.ForceOccupied()));
|
||||
trilist.SetSigTrueAction(joinMap.ForceVacant.JoinNumber, new Action(() => occController.ForceVacant()));
|
||||
occController.RoomIsOccupiedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RoomOccupiedFeedback.JoinNumber]);
|
||||
occController.RoomIsOccupiedFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.RoomVacantFeedback.JoinNumber]);
|
||||
occController.RawOccupancyFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RawOccupancyFeedback.JoinNumber]);
|
||||
trilist.SetBoolSigAction(joinMap.EnableRawStates.JoinNumber, new Action<bool>((b) => occController.EnableRawStates(b)));
|
||||
|
||||
// Timouts
|
||||
trilist.SetUShortSigAction(joinMap.Timeout.JoinNumber, new Action<ushort>((u) => occController.SetRemoteTimeout(u)));
|
||||
occController.CurrentTimeoutFeedback.LinkInputSig(trilist.UShortInput[joinMap.Timeout.JoinNumber]);
|
||||
occController.RemoteTimeoutFeedback.LinkInputSig(trilist.UShortInput[joinMap.TimeoutLocalFeedback.JoinNumber]);
|
||||
|
||||
// LED Flash
|
||||
trilist.SetSigTrueAction(joinMap.EnableLedFlash.JoinNumber, new Action(() => occController.SetLedFlashEnable(true)));
|
||||
trilist.SetSigTrueAction(joinMap.DisableLedFlash.JoinNumber, new Action(() => occController.SetLedFlashEnable(false)));
|
||||
occController.LedFlashEnabledFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.EnableLedFlash.JoinNumber]);
|
||||
|
||||
// Short Timeout
|
||||
trilist.SetSigTrueAction(joinMap.EnableShortTimeout.JoinNumber, new Action(() => occController.SetShortTimeoutState(true)));
|
||||
trilist.SetSigTrueAction(joinMap.DisableShortTimeout.JoinNumber, new Action(() => occController.SetShortTimeoutState(false)));
|
||||
occController.ShortTimeoutEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableShortTimeout.JoinNumber]);
|
||||
|
||||
// PIR Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnablePir.JoinNumber, new Action(() => occController.SetPirEnable(true)));
|
||||
trilist.SetSigTrueAction(joinMap.DisablePir.JoinNumber, new Action(() => occController.SetPirEnable(false)));
|
||||
occController.PirSensorEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnablePir.JoinNumber]);
|
||||
|
||||
// PIR Sensitivity in Occupied State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementPirInOccupiedState.JoinNumber, new Action<bool>((b) => occController.IncrementPirSensitivityInOccupiedState(b)));
|
||||
trilist.SetBoolSigAction(joinMap.DecrementPirInOccupiedState.JoinNumber, new Action<bool>((b) => occController.DecrementPirSensitivityInOccupiedState(b)));
|
||||
occController.PirSensitivityInOccupiedStateFeedback.LinkInputSig(trilist.UShortInput[joinMap.PirSensitivityInOccupiedState.JoinNumber]);
|
||||
|
||||
// PIR Sensitivity in Vacant State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementPirInVacantState.JoinNumber, new Action<bool>((b) => occController.IncrementPirSensitivityInVacantState(b)));
|
||||
trilist.SetBoolSigAction(joinMap.DecrementPirInVacantState.JoinNumber, new Action<bool>((b) => occController.DecrementPirSensitivityInVacantState(b)));
|
||||
occController.PirSensitivityInVacantStateFeedback.LinkInputSig(trilist.UShortInput[joinMap.PirSensitivityInVacantState.JoinNumber]);
|
||||
|
||||
// OR When Vacated
|
||||
trilist.SetBoolSigAction(joinMap.OrWhenVacated.JoinNumber, new Action<bool>((b) => occController.SetOrWhenVacatedState(b)));
|
||||
occController.OrWhenVacatedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.OrWhenVacated.JoinNumber]);
|
||||
|
||||
// AND When Vacated
|
||||
trilist.SetBoolSigAction(joinMap.AndWhenVacated.JoinNumber, new Action<bool>((b) => occController.SetAndWhenVacatedState(b)));
|
||||
occController.AndWhenVacatedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.AndWhenVacated.JoinNumber]);
|
||||
|
||||
// Ultrasonic A Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnableUsA.JoinNumber, new Action(() => occController.SetUsAEnable(true)));
|
||||
trilist.SetSigTrueAction(joinMap.DisableUsA.JoinNumber, new Action(() => occController.SetUsAEnable(false)));
|
||||
occController.UltrasonicAEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableUsA.JoinNumber]);
|
||||
|
||||
// Ultrasonic B Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnableUsB.JoinNumber, new Action(() => occController.SetUsBEnable(true)));
|
||||
trilist.SetSigTrueAction(joinMap.DisableUsB.JoinNumber, new Action(() => occController.SetUsBEnable(false)));
|
||||
occController.UltrasonicAEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableUsB.JoinNumber]);
|
||||
|
||||
// US Sensitivity in Occupied State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementUsInOccupiedState.JoinNumber, new Action<bool>((b) => occController.IncrementUsSensitivityInOccupiedState(b)));
|
||||
trilist.SetBoolSigAction(joinMap.DecrementUsInOccupiedState.JoinNumber, new Action<bool>((b) => occController.DecrementUsSensitivityInOccupiedState(b)));
|
||||
occController.UltrasonicSensitivityInOccupiedStateFeedback.LinkInputSig(trilist.UShortInput[joinMap.UsSensitivityInOccupiedState.JoinNumber]);
|
||||
|
||||
// US Sensitivity in Vacant State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementUsInVacantState.JoinNumber, new Action<bool>((b) => occController.IncrementUsSensitivityInVacantState(b)));
|
||||
trilist.SetBoolSigAction(joinMap.DecrementUsInVacantState.JoinNumber, new Action<bool>((b) => occController.DecrementUsSensitivityInVacantState(b)));
|
||||
occController.UltrasonicSensitivityInVacantStateFeedback.LinkInputSig(trilist.UShortInput[joinMap.UsSensitivityInVacantState.JoinNumber]);
|
||||
|
||||
//Sensor Raw States
|
||||
occController.RawOccupancyPirFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RawOccupancyPirFeedback.JoinNumber]);
|
||||
occController.RawOccupancyUsFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RawOccupancyUsFeedback.JoinNumber]);
|
||||
|
||||
// Identity mode
|
||||
trilist.SetBoolSigAction(joinMap.IdentityMode.JoinNumber, occController.SetIdentityMode);
|
||||
occController.IdentityModeFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IdentityModeFeedback.JoinNumber]);
|
||||
}
|
||||
|
||||
public class CenOdtOccupancySensorBaseControllerFactory : EssentialsDeviceFactory<CenOdtOccupancySensorBaseController>
|
||||
{
|
||||
public CenOdtOccupancySensorBaseControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "cenodtcpoe", "cenodtocc" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device");
|
||||
|
||||
var typeName = dc.Type.ToLower();
|
||||
var key = dc.Key;
|
||||
var name = dc.Name;
|
||||
var comm = CommFactory.GetControlPropertiesConfig(dc);
|
||||
|
||||
var props = dc.Properties.ToObject<GlsOccupancySensorPropertiesConfig>();
|
||||
|
||||
var occSensor = new CenOdtCPoe(comm.IpIdInt, Global.ControlSystem);
|
||||
|
||||
if (occSensor == null)
|
||||
{
|
||||
Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CenOdtOccupancySensorBaseController(key, name, occSensor, props);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Occupancy
|
||||
{
|
||||
public class EssentialsGlsOccupancySensorBaseController : CrestronGenericBaseDevice, IOccupancyStatusProvider
|
||||
{
|
||||
public GlsOccupancySensorBase OccSensor { get; private set; }
|
||||
|
||||
public BoolFeedback RoomIsOccupiedFeedback { get; private set; }
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// <summary>
|
||||
/// Set by debugging functions
|
||||
/// </summary>
|
||||
public bool InMockMode { get; private set; }
|
||||
|
||||
public bool MockRoomIsOccupiedFeedback { get; private set; }
|
||||
=======
|
||||
// Debug properties
|
||||
public bool InTestMode { get; private set; }
|
||||
|
||||
public bool TestRoomIsOccupiedFeedback { get; private set; }
|
||||
>>>>>>> origin/feature/ecs-342-neil
|
||||
|
||||
public Func<bool> RoomIsOccupiedFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
return () => InMockMode ? MockRoomIsOccupiedFeedback : OccSensor.OccupancyDetectedFeedback.BoolValue;
|
||||
=======
|
||||
return () => InTestMode ? TestRoomIsOccupiedFeedback : OccSensor.OccupancyDetectedFeedback.BoolValue;
|
||||
>>>>>>> origin/feature/ecs-342-neil
|
||||
}
|
||||
}
|
||||
|
||||
public EssentialsGlsOccupancySensorBaseController(string key, string name, GlsOccupancySensorBase sensor, GlsOccupancySensorConfigurationProperties props)
|
||||
: base(key, name, sensor)
|
||||
{
|
||||
OccSensor = sensor;
|
||||
RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc);
|
||||
|
||||
OccSensor.GlsOccupancySensorChange += new GlsOccupancySensorChangeEventHandler(sensor_GlsOccupancySensorChange);
|
||||
}
|
||||
|
||||
void sensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args)
|
||||
{
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
public void SetTestMode(bool mode)
|
||||
{
|
||||
InTestMode = mode;
|
||||
|
||||
Debug.Console(1, this, "In Mock Mode: '{0}'", InTestMode);
|
||||
}
|
||||
|
||||
public void SetTestOccupiedState(bool state)
|
||||
{
|
||||
if (!InTestMode)
|
||||
Debug.Console(1, "Mock mode not enabled");
|
||||
else
|
||||
{
|
||||
TestRoomIsOccupiedFeedback = state;
|
||||
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GlsOccupancySensorConfigurationProperties
|
||||
{
|
||||
public string CresnetId { get; set; }
|
||||
public string Model { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,541 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for Single Technology GLS Occupancy Sensors")]
|
||||
[ConfigSnippet("\"properties\": {\"control\": {\"method\": \"cresnet\",\"cresnetId\": \"97\"},\"enablePir\": true,\"enableLedFlash\": true,\"enableRawStates\":true,\"remoteTimeout\": 30,\"internalPhotoSensorMinChange\": 0,\"externalPhotoSensorMinChange\": 0}")]
|
||||
public abstract class GlsOccupancySensorBaseController : CrestronGenericBridgeableBaseDevice, IOccupancyStatusProvider
|
||||
{
|
||||
public GlsOccupancySensorPropertiesConfig PropertiesConfig { get; private set; }
|
||||
|
||||
protected GlsOccupancySensorBase OccSensor;
|
||||
|
||||
public BoolFeedback RoomIsOccupiedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback GraceOccupancyDetectedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback PirSensorEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback LedFlashEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback ShortTimeoutEnabledFeedback { get; private set; }
|
||||
|
||||
public IntFeedback PirSensitivityInVacantStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback PirSensitivityInOccupiedStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback CurrentTimeoutFeedback { get; private set; }
|
||||
|
||||
public IntFeedback LocalTimoutFeedback { get; private set; }
|
||||
|
||||
public IntFeedback InternalPhotoSensorValue { get; set; }
|
||||
|
||||
public IntFeedback ExternalPhotoSensorValue { get; set; }
|
||||
|
||||
// Debug properties
|
||||
public bool InTestMode { get; private set; }
|
||||
|
||||
public bool TestRoomIsOccupiedFeedback { get; private set; }
|
||||
|
||||
public Func<bool> RoomIsOccupiedFeedbackFunc
|
||||
{
|
||||
get
|
||||
{
|
||||
return () => InTestMode ? TestRoomIsOccupiedFeedback : OccSensor.OccupancyDetectedFeedback.BoolValue;
|
||||
}
|
||||
}
|
||||
|
||||
protected GlsOccupancySensorBaseController(string key, DeviceConfig config)
|
||||
: this(key, config.Name, config)
|
||||
{
|
||||
}
|
||||
|
||||
protected GlsOccupancySensorBaseController(string key, string name, DeviceConfig config)
|
||||
: base(key, name)
|
||||
{
|
||||
|
||||
var props = config.Properties.ToObject<GlsOccupancySensorPropertiesConfig>();
|
||||
|
||||
if (props != null)
|
||||
{
|
||||
PropertiesConfig = props;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, this, "props are null. Unable to deserialize into GlsOccupancySensorPropertiesConfig");
|
||||
}
|
||||
|
||||
AddPostActivationAction(() =>
|
||||
{
|
||||
OccSensor.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (a.DeviceOnLine)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
}
|
||||
};
|
||||
|
||||
if (OccSensor.IsOnline)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Applies any sensor settings defined in config
|
||||
/// </summary>
|
||||
protected virtual void ApplySettingsToSensorFromConfig()
|
||||
{
|
||||
Debug.Console(1, this, "Attempting to apply settings to sensor from config");
|
||||
|
||||
if (PropertiesConfig.EnablePir != null)
|
||||
{
|
||||
Debug.Console(1, this, "EnablePir found, attempting to set value from config");
|
||||
SetPirEnable((bool)PropertiesConfig.EnablePir);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, this, "EnablePir null, no value specified in config");
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableLedFlash != null)
|
||||
{
|
||||
Debug.Console(1, this, "EnableLedFlash found, attempting to set value from config");
|
||||
SetLedFlashEnable((bool)PropertiesConfig.EnableLedFlash);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.RemoteTimeout != null)
|
||||
{
|
||||
Debug.Console(1, this, "RemoteTimeout found, attempting to set value from config");
|
||||
SetRemoteTimeout((ushort)PropertiesConfig.RemoteTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, this, "RemoteTimeout null, no value specified in config");
|
||||
}
|
||||
|
||||
if (PropertiesConfig.ShortTimeoutState != null)
|
||||
{
|
||||
SetShortTimeoutState((bool)PropertiesConfig.ShortTimeoutState);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.EnableRawStates != null)
|
||||
{
|
||||
EnableRawStates((bool)PropertiesConfig.EnableRawStates);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.InternalPhotoSensorMinChange != null)
|
||||
{
|
||||
SetInternalPhotoSensorMinChange((ushort)PropertiesConfig.InternalPhotoSensorMinChange);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.ExternalPhotoSensorMinChange != null)
|
||||
{
|
||||
SetExternalPhotoSensorMinChange((ushort)PropertiesConfig.ExternalPhotoSensorMinChange);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RegisterGlsOccupancySensorBaseController(GlsOccupancySensorBase occSensor)
|
||||
{
|
||||
OccSensor = occSensor;
|
||||
|
||||
RoomIsOccupiedFeedback = new BoolFeedback(RoomIsOccupiedFeedbackFunc);
|
||||
|
||||
PirSensorEnabledFeedback = new BoolFeedback(() => OccSensor.PirEnabledFeedback.BoolValue);
|
||||
|
||||
LedFlashEnabledFeedback = new BoolFeedback(() => OccSensor.LedFlashEnabledFeedback.BoolValue);
|
||||
|
||||
ShortTimeoutEnabledFeedback = new BoolFeedback(() => OccSensor.ShortTimeoutEnabledFeedback.BoolValue);
|
||||
|
||||
PirSensitivityInVacantStateFeedback =
|
||||
new IntFeedback(() => OccSensor.PirSensitivityInVacantStateFeedback.UShortValue);
|
||||
|
||||
PirSensitivityInOccupiedStateFeedback =
|
||||
new IntFeedback(() => OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue);
|
||||
|
||||
CurrentTimeoutFeedback = new IntFeedback(() => OccSensor.CurrentTimeoutFeedback.UShortValue);
|
||||
|
||||
LocalTimoutFeedback = new IntFeedback(() => OccSensor.LocalTimeoutFeedback.UShortValue);
|
||||
|
||||
GraceOccupancyDetectedFeedback =
|
||||
new BoolFeedback(() => OccSensor.GraceOccupancyDetectedFeedback.BoolValue);
|
||||
|
||||
RawOccupancyFeedback = new BoolFeedback(() => OccSensor.RawOccupancyFeedback.BoolValue);
|
||||
|
||||
InternalPhotoSensorValue = new IntFeedback(() => OccSensor.InternalPhotoSensorValueFeedback.UShortValue);
|
||||
|
||||
ExternalPhotoSensorValue = new IntFeedback(() => OccSensor.ExternalPhotoSensorValueFeedback.UShortValue);
|
||||
|
||||
OccSensor.BaseEvent += OccSensor_BaseEvent;
|
||||
|
||||
OccSensor.GlsOccupancySensorChange += OccSensor_GlsOccupancySensorChange;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Catches events for feedbacks on the base class. Any extending wrapper class should call this delegate after it checks for it's own event IDs.
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="args"></param>
|
||||
protected virtual void OccSensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args)
|
||||
{
|
||||
switch (args.EventId)
|
||||
{
|
||||
case GlsOccupancySensorBase.PirEnabledFeedbackEventId:
|
||||
PirSensorEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.LedFlashEnabledFeedbackEventId:
|
||||
LedFlashEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.ShortTimeoutEnabledFeedbackEventId:
|
||||
ShortTimeoutEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.PirSensitivityInOccupiedStateFeedbackEventId:
|
||||
PirSensitivityInOccupiedStateFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.PirSensitivityInVacantStateFeedbackEventId:
|
||||
PirSensitivityInVacantStateFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args)
|
||||
{
|
||||
Debug.Console(2, this, "GlsOccupancySensorChange EventId: {0}", args.EventId);
|
||||
|
||||
switch (args.EventId)
|
||||
{
|
||||
case GlsOccupancySensorBase.RoomVacantFeedbackEventId:
|
||||
case GlsOccupancySensorBase.RoomOccupiedFeedbackEventId:
|
||||
Debug.Console(1, this, "Occupancy State: {0}", OccSensor.OccupancyDetectedFeedback.BoolValue);
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.TimeoutFeedbackEventId:
|
||||
CurrentTimeoutFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.TimeoutLocalFeedbackEventId:
|
||||
LocalTimoutFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.GraceOccupancyDetectedFeedbackEventId:
|
||||
GraceOccupancyDetectedFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.RawOccupancyFeedbackEventId:
|
||||
RawOccupancyFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.InternalPhotoSensorValueFeedbackEventId:
|
||||
InternalPhotoSensorValue.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.ExternalPhotoSensorValueFeedbackEventId:
|
||||
ExternalPhotoSensorValue.FireUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTestMode(bool mode)
|
||||
{
|
||||
InTestMode = mode;
|
||||
|
||||
Debug.Console(1, this, "In Mock Mode: '{0}'", InTestMode);
|
||||
}
|
||||
|
||||
public void SetTestOccupiedState(bool state)
|
||||
{
|
||||
if (!InTestMode)
|
||||
Debug.Console(1, "Mock mode not enabled");
|
||||
else
|
||||
{
|
||||
TestRoomIsOccupiedFeedback = state;
|
||||
|
||||
RoomIsOccupiedFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the PIR sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetPirEnable(bool state)
|
||||
{
|
||||
Debug.Console(1, this, "Setting EnablePir to: {0}", state);
|
||||
|
||||
OccSensor.EnablePir.BoolValue = state;
|
||||
OccSensor.DisablePir.BoolValue = !state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the LED Flash
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetLedFlashEnable(bool state)
|
||||
{
|
||||
OccSensor.EnableLedFlash.BoolValue = state;
|
||||
OccSensor.DisableLedFlash.BoolValue = !state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables short timeout based on state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetShortTimeoutState(bool state)
|
||||
{
|
||||
OccSensor.EnableShortTimeout.BoolValue = state;
|
||||
OccSensor.DisableShortTimeout.BoolValue = !state;
|
||||
}
|
||||
|
||||
public void IncrementPirSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
OccSensor.IncrementPirSensitivityInOccupiedState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void DecrementPirSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
OccSensor.DecrementPirSensitivityInOccupiedState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void IncrementPirSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
OccSensor.IncrementPirSensitivityInVacantState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void DecrementPirSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
OccSensor.DecrementPirSensitivityInVacantState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulse ForceOccupied on the sensor for .5 seconds
|
||||
/// </summary>
|
||||
public void ForceOccupied()
|
||||
{
|
||||
CrestronInvoke.BeginInvoke((o) =>
|
||||
{
|
||||
ForceOccupied(true);
|
||||
CrestronEnvironment.Sleep(500);
|
||||
ForceOccupied(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void ForceOccupied(bool value)
|
||||
{
|
||||
OccSensor.ForceOccupied.BoolValue = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulse ForceVacant on the sensor for .5 seconds
|
||||
/// </summary>
|
||||
public void ForceVacant()
|
||||
{
|
||||
CrestronInvoke.BeginInvoke((o) =>
|
||||
{
|
||||
ForceVacant(true);
|
||||
CrestronEnvironment.Sleep(500);
|
||||
ForceVacant(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void ForceVacant(bool value)
|
||||
{
|
||||
OccSensor.ForceVacant.BoolValue = value;
|
||||
}
|
||||
|
||||
public void EnableRawStates(bool state)
|
||||
{
|
||||
OccSensor.EnableRawStates.BoolValue = state;
|
||||
}
|
||||
|
||||
public void SetRemoteTimeout(ushort time)
|
||||
{
|
||||
Debug.Console(1, this, "Setting RemoteTimout to: {0}", time);
|
||||
|
||||
OccSensor.RemoteTimeout.UShortValue = time;
|
||||
}
|
||||
|
||||
public void SetInternalPhotoSensorMinChange(ushort value)
|
||||
{
|
||||
OccSensor.InternalPhotoSensorMinimumChange.UShortValue = value;
|
||||
}
|
||||
|
||||
public void SetExternalPhotoSensorMinChange(ushort value)
|
||||
{
|
||||
OccSensor.ExternalPhotoSensorMinimumChange.UShortValue = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to print current occ settings to console.
|
||||
/// </summary>
|
||||
public virtual void GetSettings()
|
||||
{
|
||||
var dash = new string('*', 50);
|
||||
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||
|
||||
Debug.Console(0, this, "Vacancy Detected: {0}",
|
||||
OccSensor.VacancyDetectedFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, this, "Timeout Current: {0} | Local: {1}",
|
||||
OccSensor.CurrentTimeoutFeedback.UShortValue,
|
||||
OccSensor.LocalTimeoutFeedback.UShortValue);
|
||||
|
||||
Debug.Console(0, this, "Short Timeout Enabled: {0}",
|
||||
OccSensor.ShortTimeoutEnabledFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, this, "PIR Sensor Enabled: {0} | Sensitivity Occupied: {1} | Sensitivity Vacant: {2}",
|
||||
OccSensor.PirEnabledFeedback.BoolValue,
|
||||
OccSensor.PirSensitivityInOccupiedStateFeedback.UShortValue,
|
||||
OccSensor.PirSensitivityInVacantStateFeedback.UShortValue);
|
||||
|
||||
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||
}
|
||||
|
||||
protected void LinkOccSensorToApi(GlsOccupancySensorBaseController occController, BasicTriList trilist,
|
||||
uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new GlsOccupancySensorBaseJoinMap(joinStart);
|
||||
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<GlsOccupancySensorBaseJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
|
||||
}
|
||||
|
||||
Debug.Console(1, occController, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
|
||||
occController.IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = occController.Name;
|
||||
|
||||
trilist.OnlineStatusChange += (d, args) =>
|
||||
{
|
||||
if (args.DeviceOnLine)
|
||||
{
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = occController.Name;
|
||||
}
|
||||
};
|
||||
|
||||
LinkSingleTechSensorToApi(occController, trilist, joinMap);
|
||||
|
||||
LinkDualTechSensorToApi(occController, trilist, joinMap);
|
||||
}
|
||||
|
||||
private static void LinkDualTechSensorToApi(GlsOccupancySensorBaseController occController, BasicTriList trilist,
|
||||
GlsOccupancySensorBaseJoinMap joinMap)
|
||||
{
|
||||
var odtOccController = occController as GlsOdtOccupancySensorController;
|
||||
|
||||
if (odtOccController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// OR When Vacated
|
||||
trilist.SetBoolSigAction(joinMap.OrWhenVacated.JoinNumber, odtOccController.SetOrWhenVacatedState);
|
||||
odtOccController.OrWhenVacatedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.OrWhenVacated.JoinNumber]);
|
||||
|
||||
// AND When Vacated
|
||||
trilist.SetBoolSigAction(joinMap.AndWhenVacated.JoinNumber, odtOccController.SetAndWhenVacatedState);
|
||||
odtOccController.AndWhenVacatedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.AndWhenVacated.JoinNumber]);
|
||||
|
||||
// Ultrasonic A Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnableUsA.JoinNumber, () => odtOccController.SetUsAEnable(true));
|
||||
trilist.SetSigTrueAction(joinMap.DisableUsA.JoinNumber, () => odtOccController.SetUsAEnable(false));
|
||||
odtOccController.UltrasonicAEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableUsA.JoinNumber]);
|
||||
|
||||
// Ultrasonic B Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnableUsB.JoinNumber, () => odtOccController.SetUsBEnable(true));
|
||||
trilist.SetSigTrueAction(joinMap.DisableUsB.JoinNumber, () => odtOccController.SetUsBEnable(false));
|
||||
odtOccController.UltrasonicBEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableUsB.JoinNumber]);
|
||||
|
||||
// US Sensitivity in Occupied State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementUsInOccupiedState.JoinNumber,
|
||||
odtOccController.IncrementUsSensitivityInOccupiedState);
|
||||
trilist.SetBoolSigAction(joinMap.DecrementUsInOccupiedState.JoinNumber,
|
||||
odtOccController.DecrementUsSensitivityInOccupiedState);
|
||||
odtOccController.UltrasonicSensitivityInOccupiedStateFeedback.LinkInputSig(
|
||||
trilist.UShortInput[joinMap.UsSensitivityInOccupiedState.JoinNumber]);
|
||||
|
||||
// US Sensitivity in Vacant State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementUsInVacantState.JoinNumber,
|
||||
odtOccController.IncrementUsSensitivityInVacantState);
|
||||
trilist.SetBoolSigAction(joinMap.DecrementUsInVacantState.JoinNumber,
|
||||
odtOccController.DecrementUsSensitivityInVacantState);
|
||||
odtOccController.UltrasonicSensitivityInVacantStateFeedback.LinkInputSig(
|
||||
trilist.UShortInput[joinMap.UsSensitivityInVacantState.JoinNumber]);
|
||||
|
||||
//Sensor Raw States
|
||||
odtOccController.RawOccupancyPirFeedback.LinkInputSig(
|
||||
trilist.BooleanInput[joinMap.RawOccupancyPirFeedback.JoinNumber]);
|
||||
odtOccController.RawOccupancyUsFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RawOccupancyUsFeedback.JoinNumber]);
|
||||
}
|
||||
|
||||
private static void LinkSingleTechSensorToApi(GlsOccupancySensorBaseController occController, BasicTriList trilist,
|
||||
GlsOccupancySensorBaseJoinMap joinMap)
|
||||
{
|
||||
// Occupied status
|
||||
trilist.SetBoolSigAction(joinMap.ForceOccupied.JoinNumber, occController.ForceOccupied);
|
||||
trilist.SetBoolSigAction(joinMap.ForceVacant.JoinNumber, occController.ForceVacant);
|
||||
occController.RoomIsOccupiedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RoomOccupiedFeedback.JoinNumber]);
|
||||
occController.RoomIsOccupiedFeedback.LinkComplementInputSig(
|
||||
trilist.BooleanInput[joinMap.RoomVacantFeedback.JoinNumber]);
|
||||
occController.RawOccupancyFeedback.LinkInputSig(trilist.BooleanInput[joinMap.RawOccupancyFeedback.JoinNumber]);
|
||||
trilist.SetBoolSigAction(joinMap.EnableRawStates.JoinNumber, occController.EnableRawStates);
|
||||
|
||||
// Timouts
|
||||
trilist.SetUShortSigAction(joinMap.Timeout.JoinNumber, occController.SetRemoteTimeout);
|
||||
occController.CurrentTimeoutFeedback.LinkInputSig(trilist.UShortInput[joinMap.Timeout.JoinNumber]);
|
||||
occController.LocalTimoutFeedback.LinkInputSig(trilist.UShortInput[joinMap.TimeoutLocalFeedback.JoinNumber]);
|
||||
|
||||
// LED Flash
|
||||
trilist.SetSigTrueAction(joinMap.EnableLedFlash.JoinNumber, () => occController.SetLedFlashEnable(true));
|
||||
trilist.SetSigTrueAction(joinMap.DisableLedFlash.JoinNumber, () => occController.SetLedFlashEnable(false));
|
||||
occController.LedFlashEnabledFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.EnableLedFlash.JoinNumber]);
|
||||
|
||||
// Short Timeout
|
||||
trilist.SetSigTrueAction(joinMap.EnableShortTimeout.JoinNumber, () => occController.SetShortTimeoutState(true));
|
||||
trilist.SetSigTrueAction(joinMap.DisableShortTimeout.JoinNumber, () => occController.SetShortTimeoutState(false));
|
||||
occController.ShortTimeoutEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableShortTimeout.JoinNumber]);
|
||||
|
||||
// PIR Sensor
|
||||
trilist.SetSigTrueAction(joinMap.EnablePir.JoinNumber, () => occController.SetPirEnable(true));
|
||||
trilist.SetSigTrueAction(joinMap.DisablePir.JoinNumber, () => occController.SetPirEnable(false));
|
||||
occController.PirSensorEnabledFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnablePir.JoinNumber]);
|
||||
|
||||
// PIR Sensitivity in Occupied State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementPirInOccupiedState.JoinNumber,
|
||||
occController.IncrementPirSensitivityInOccupiedState);
|
||||
trilist.SetBoolSigAction(joinMap.DecrementPirInOccupiedState.JoinNumber,
|
||||
occController.DecrementPirSensitivityInOccupiedState);
|
||||
occController.PirSensitivityInOccupiedStateFeedback.LinkInputSig(
|
||||
trilist.UShortInput[joinMap.PirSensitivityInOccupiedState.JoinNumber]);
|
||||
|
||||
// PIR Sensitivity in Vacant State
|
||||
trilist.SetBoolSigAction(joinMap.IncrementPirInVacantState.JoinNumber,
|
||||
occController.IncrementPirSensitivityInVacantState);
|
||||
trilist.SetBoolSigAction(joinMap.DecrementPirInVacantState.JoinNumber,
|
||||
occController.DecrementPirSensitivityInVacantState);
|
||||
occController.PirSensitivityInVacantStateFeedback.LinkInputSig(
|
||||
trilist.UShortInput[joinMap.PirSensitivityInVacantState.JoinNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines configuration properties for Crestron GLS series occupancy sensors
|
||||
/// </summary>
|
||||
public class GlsOccupancySensorPropertiesConfig
|
||||
{
|
||||
// Single Technology Sensors (PIR): GlsOccupancySensorBase
|
||||
[JsonProperty("enablePir")]
|
||||
public bool? EnablePir { get; set; }
|
||||
|
||||
[JsonProperty("enableLedFlash")]
|
||||
public bool? EnableLedFlash { get; set; }
|
||||
|
||||
[JsonProperty("shortTimeoutState")]
|
||||
public bool? ShortTimeoutState { get; set; }
|
||||
|
||||
[JsonProperty("enableRawStates")]
|
||||
public bool? EnableRawStates { get; set; }
|
||||
|
||||
[JsonProperty("remoteTimeout")]
|
||||
public ushort? RemoteTimeout { get; set; }
|
||||
|
||||
[JsonProperty("internalPhotoSensorMinChange")]
|
||||
public ushort? InternalPhotoSensorMinChange { get; set; }
|
||||
|
||||
[JsonProperty("externalPhotoSensorMinChange")]
|
||||
public ushort? ExternalPhotoSensorMinChange { get; set; }
|
||||
|
||||
// Dual Technology Sensors: GlsOdtCCn
|
||||
[JsonProperty("enableUsA")]
|
||||
public bool? EnableUsA { get; set; }
|
||||
|
||||
[JsonProperty("enableUsB")]
|
||||
public bool? EnableUsB { get; set; }
|
||||
|
||||
[JsonProperty("orWhenVacatedState")]
|
||||
public bool? OrWhenVacatedState { get; set; }
|
||||
|
||||
[JsonProperty("andWhenVacatedState")]
|
||||
public bool? AndWhenVacatedState { get; set; }
|
||||
|
||||
// PoE Sensors: CenOdtCPoe
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sensitivity level for US while sensor is in occupied state
|
||||
/// 1 = low; 2 = medium; 3 = high; 4 = xlow; 5 = 2xlow; 6 = 3xlow
|
||||
/// </summary>
|
||||
[JsonProperty("usSensitivityOccupied")]
|
||||
public ushort? UsSensitivityOccupied { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sensitivity level for US while sensor is in vacant state
|
||||
/// 1 = low; 2 = medium; 3 = high; 4 = xlow; 5 = 2xlow; 6 = 3xlow
|
||||
/// </summary>
|
||||
[JsonProperty("usSensitivityVacant")]
|
||||
public ushort? UsSensitivityVacant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sensitivity level for PIR while sensor is in occupied state
|
||||
/// 1 = low; 2 = medium; 3 = high
|
||||
/// </summary>
|
||||
[JsonProperty("pirSensitivityOccupied")]
|
||||
public ushort? PirSensitivityOccupied { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sensitivity level for PIR while sensor is in vacant state
|
||||
/// 1 = low; 2 = medium; 3 = high
|
||||
/// </summary>
|
||||
[JsonProperty("pirSensitivityVacant")]
|
||||
public ushort? PirSensitivityVacant { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for Dual Technology GLS Occupancy Sensors")]
|
||||
[ConfigSnippet("\"properties\": {\"control\": {\"method\": \"cresnet\",\"cresnetId\": \"97\"},\"enablePir\": true,\"enableLedFlash\": true,\"enableRawStates\":true,\"remoteTimeout\": 30,\"internalPhotoSensorMinChange\": 0,\"externalPhotoSensorMinChange\": 0,\"enableUsA\": true,\"enableUsB\": true,\"orWhenVacatedState\": true}")]
|
||||
public class GlsOdtOccupancySensorController : GlsOccupancySensorBaseController
|
||||
{
|
||||
private GlsOdtCCn _occSensor;
|
||||
|
||||
public BoolFeedback OrWhenVacatedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback AndWhenVacatedFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback UltrasonicAEnabledFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback UltrasonicBEnabledFeedback { get; private set; }
|
||||
|
||||
public IntFeedback UltrasonicSensitivityInVacantStateFeedback { get; private set; }
|
||||
|
||||
public IntFeedback UltrasonicSensitivityInOccupiedStateFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyPirFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback RawOccupancyUsFeedback { get; private set; }
|
||||
|
||||
|
||||
public GlsOdtOccupancySensorController(string key, Func<DeviceConfig, GlsOdtCCn> preActivationFunc,
|
||||
DeviceConfig config)
|
||||
: base(key, config.Name, config)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_occSensor = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_occSensor);
|
||||
|
||||
RegisterGlsOccupancySensorBaseController(_occSensor);
|
||||
|
||||
AndWhenVacatedFeedback = new BoolFeedback(() => _occSensor.AndWhenVacatedFeedback.BoolValue);
|
||||
|
||||
OrWhenVacatedFeedback = new BoolFeedback(() => _occSensor.OrWhenVacatedFeedback.BoolValue);
|
||||
|
||||
UltrasonicAEnabledFeedback = new BoolFeedback(() => _occSensor.UsAEnabledFeedback.BoolValue);
|
||||
|
||||
UltrasonicBEnabledFeedback = new BoolFeedback(() => _occSensor.UsBEnabledFeedback.BoolValue);
|
||||
|
||||
RawOccupancyPirFeedback = new BoolFeedback(() => _occSensor.RawOccupancyPirFeedback.BoolValue);
|
||||
|
||||
RawOccupancyUsFeedback = new BoolFeedback(() => _occSensor.RawOccupancyUsFeedback.BoolValue);
|
||||
|
||||
UltrasonicSensitivityInVacantStateFeedback = new IntFeedback(() => _occSensor.UsSensitivityInVacantStateFeedback.UShortValue);
|
||||
|
||||
UltrasonicSensitivityInOccupiedStateFeedback = new IntFeedback(() => _occSensor.UsSensitivityInOccupiedStateFeedback.UShortValue);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected override void ApplySettingsToSensorFromConfig()
|
||||
{
|
||||
base.ApplySettingsToSensorFromConfig();
|
||||
|
||||
if (PropertiesConfig.EnableUsA != null)
|
||||
{
|
||||
Debug.Console(1, this, "EnableUsA found, attempting to set value from config");
|
||||
SetUsAEnable((bool)PropertiesConfig.EnableUsA);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, this, "EnableUsA null, no value specified in config");
|
||||
}
|
||||
|
||||
|
||||
if (PropertiesConfig.EnableUsB != null)
|
||||
{
|
||||
Debug.Console(1, this, "EnableUsB found, attempting to set value from config");
|
||||
SetUsBEnable((bool)PropertiesConfig.EnableUsB);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, this, "EnablePir null, no value specified in config");
|
||||
}
|
||||
|
||||
|
||||
if (PropertiesConfig.OrWhenVacatedState != null)
|
||||
{
|
||||
SetOrWhenVacatedState((bool)PropertiesConfig.OrWhenVacatedState);
|
||||
}
|
||||
|
||||
if (PropertiesConfig.AndWhenVacatedState != null)
|
||||
{
|
||||
SetAndWhenVacatedState((bool)PropertiesConfig.AndWhenVacatedState);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the base class event delegate to fire feedbacks for event IDs that pertain to this extended class.
|
||||
/// Then calls the base delegate method to ensure any common event IDs are captured.
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="args"></param>
|
||||
protected override void OccSensor_GlsOccupancySensorChange(GlsOccupancySensorBase device, GlsOccupancySensorChangeEventArgs args)
|
||||
{
|
||||
switch (args.EventId)
|
||||
{
|
||||
case GlsOccupancySensorBase.AndWhenVacatedFeedbackEventId:
|
||||
AndWhenVacatedFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.OrWhenVacatedFeedbackEventId:
|
||||
OrWhenVacatedFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.UsAEnabledFeedbackEventId:
|
||||
UltrasonicAEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.UsBEnabledFeedbackEventId:
|
||||
UltrasonicBEnabledFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.UsSensitivityInOccupiedStateFeedbackEventId:
|
||||
UltrasonicSensitivityInOccupiedStateFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.UsSensitivityInVacantStateFeedbackEventId:
|
||||
UltrasonicSensitivityInVacantStateFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
|
||||
base.OccSensor_GlsOccupancySensorChange(device, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the base class event delegate to fire feedbacks for event IDs that pertain to this extended class.
|
||||
/// Then calls the base delegate method to ensure any common event IDs are captured.
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="args"></param>
|
||||
protected override void OccSensor_BaseEvent(Crestron.SimplSharpPro.GenericBase device, Crestron.SimplSharpPro.BaseEventArgs args)
|
||||
{
|
||||
switch (args.EventId)
|
||||
{
|
||||
case GlsOccupancySensorBase.RawOccupancyPirFeedbackEventId:
|
||||
RawOccupancyPirFeedback.FireUpdate();
|
||||
break;
|
||||
case GlsOccupancySensorBase.RawOccupancyUsFeedbackEventId:
|
||||
RawOccupancyUsFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
|
||||
base.OccSensor_BaseEvent(device, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the OrWhenVacated state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetOrWhenVacatedState(bool state)
|
||||
{
|
||||
_occSensor.OrWhenVacated.BoolValue = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the AndWhenVacated state
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetAndWhenVacatedState(bool state)
|
||||
{
|
||||
_occSensor.AndWhenVacated.BoolValue = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the Ultrasonic A sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetUsAEnable(bool state)
|
||||
{
|
||||
_occSensor.EnableUsA.BoolValue = state;
|
||||
_occSensor.DisableUsA.BoolValue = !state;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables the Ultrasonic B sensor
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void SetUsBEnable(bool state)
|
||||
{
|
||||
_occSensor.EnableUsB.BoolValue = state;
|
||||
_occSensor.DisableUsB.BoolValue = !state;
|
||||
}
|
||||
|
||||
public void IncrementUsSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
_occSensor.IncrementUsSensitivityInOccupiedState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void DecrementUsSensitivityInOccupiedState(bool pressRelease)
|
||||
{
|
||||
_occSensor.DecrementUsSensitivityInOccupiedState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void IncrementUsSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
_occSensor.IncrementUsSensitivityInVacantState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public void DecrementUsSensitivityInVacantState(bool pressRelease)
|
||||
{
|
||||
_occSensor.DecrementUsSensitivityInVacantState.BoolValue = pressRelease;
|
||||
}
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to print occ sensor settings to console.
|
||||
/// </summary>
|
||||
public override void GetSettings()
|
||||
{
|
||||
base.GetSettings();
|
||||
|
||||
Debug.Console(0, this, "Ultrasonic Enabled A: {0} | B: {1}",
|
||||
_occSensor.UsAEnabledFeedback.BoolValue,
|
||||
_occSensor.UsBEnabledFeedback.BoolValue);
|
||||
|
||||
Debug.Console(0, this, "Ultrasonic Sensitivity Occupied: {0} | Vacant: {1}",
|
||||
_occSensor.UsSensitivityInOccupiedStateFeedback.UShortValue,
|
||||
_occSensor.UsSensitivityInVacantStateFeedback.UShortValue);
|
||||
|
||||
var dash = new string('*', 50);
|
||||
CrestronConsole.PrintLine(string.Format("{0}\n", dash));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory<GlsOdtOccupancySensorController>
|
||||
{
|
||||
public GlsOdtOccupancySensorControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "glsodtccn" };
|
||||
}
|
||||
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device");
|
||||
|
||||
return new GlsOdtOccupancySensorController(dc.Key, GetGlsOdtCCn, dc);
|
||||
}
|
||||
|
||||
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", parentKey);
|
||||
return new GlsOdtCCn(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOdtCCn", parentKey);
|
||||
return new GlsOdtCCn(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class GlsOirOccupancySensorController:GlsOccupancySensorBaseController
|
||||
{
|
||||
private GlsOirCCn _occSensor;
|
||||
|
||||
public GlsOirOccupancySensorController(string key, Func<DeviceConfig, GlsOirCCn> preActivationFunc,DeviceConfig config) : this(key,config.Name, preActivationFunc, config)
|
||||
{
|
||||
}
|
||||
|
||||
public GlsOirOccupancySensorController(string key, string name, Func<DeviceConfig, GlsOirCCn> preActivationFunc, DeviceConfig config) : base(key, name, config)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_occSensor = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_occSensor);
|
||||
|
||||
RegisterGlsOccupancySensorBaseController(_occSensor);
|
||||
});
|
||||
}
|
||||
|
||||
#region Overrides of CrestronGenericBridgeableBaseDevice
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory<GlsOccupancySensorBaseController>
|
||||
{
|
||||
public GlsOccupancySensorBaseControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "glsoirccn" };
|
||||
}
|
||||
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new GlsOirOccupancySensorController Device");
|
||||
|
||||
return new GlsOirOccupancySensorController(dc.Key, GetGlsOirCCn, dc);
|
||||
}
|
||||
|
||||
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", parentKey);
|
||||
return new GlsOirCCn(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsOirCCn", parentKey);
|
||||
return new GlsOirCCn(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Aggregates the RoomIsOccupied feedbacks of one or more IOccupancyStatusProvider objects
|
||||
/// </summary>
|
||||
public class IOccupancyStatusProviderAggregator : EssentialsDevice, IOccupancyStatusProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Aggregated feedback of all linked IOccupancyStatusProvider devices
|
||||
/// </summary>
|
||||
public BoolFeedback RoomIsOccupiedFeedback
|
||||
{
|
||||
get
|
||||
{
|
||||
return _aggregatedOccupancyStatus.Output;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly BoolFeedbackOr _aggregatedOccupancyStatus;
|
||||
|
||||
public IOccupancyStatusProviderAggregator(string key, string name)
|
||||
: base(key, name)
|
||||
{
|
||||
_aggregatedOccupancyStatus = new BoolFeedbackOr();
|
||||
}
|
||||
|
||||
public IOccupancyStatusProviderAggregator(string key, string name, OccupancyAggregatorConfig config)
|
||||
: this(key, name)
|
||||
{
|
||||
AddPostActivationAction(() =>
|
||||
{
|
||||
if (config.DeviceKeys.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var deviceKey in config.DeviceKeys)
|
||||
{
|
||||
var device = DeviceManager.GetDeviceForKey(deviceKey);
|
||||
|
||||
if (device == null)
|
||||
{
|
||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice,
|
||||
"Unable to retrieve Occupancy provider with key {0}", deviceKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
var provider = device as IOccupancyStatusProvider;
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice,
|
||||
"Device with key {0} does NOT implement IOccupancyStatusProvider. Please check configuration.");
|
||||
continue;
|
||||
}
|
||||
|
||||
AddOccupancyStatusProvider(provider);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an IOccupancyStatusProvider device
|
||||
/// </summary>
|
||||
/// <param name="statusProvider"></param>
|
||||
public void AddOccupancyStatusProvider(IOccupancyStatusProvider statusProvider)
|
||||
{
|
||||
_aggregatedOccupancyStatus.AddOutputIn(statusProvider.RoomIsOccupiedFeedback);
|
||||
}
|
||||
|
||||
public void RemoveOccupancyStatusProvider(IOccupancyStatusProvider statusProvider)
|
||||
{
|
||||
_aggregatedOccupancyStatus.RemoveOutputIn(statusProvider.RoomIsOccupiedFeedback);
|
||||
}
|
||||
|
||||
public void ClearOccupancyStatusProviders()
|
||||
{
|
||||
_aggregatedOccupancyStatus.ClearOutputs();
|
||||
}
|
||||
}
|
||||
|
||||
public class OccupancyAggregatorFactory : EssentialsDeviceFactory<IOccupancyStatusProviderAggregator>
|
||||
{
|
||||
public OccupancyAggregatorFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "occupancyAggregator", "occAggregate" };
|
||||
}
|
||||
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device");
|
||||
|
||||
var config = dc.Properties.ToObject<OccupancyAggregatorConfig>();
|
||||
|
||||
return new IOccupancyStatusProviderAggregator(dc.Key, dc.Name, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class OccupancyAggregatorConfig
|
||||
{
|
||||
[JsonProperty("deviceKeys")] public List<string> DeviceKeys { get; set; }
|
||||
|
||||
public OccupancyAggregatorConfig()
|
||||
{
|
||||
DeviceKeys = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.GeneralIO;
|
||||
using Full.Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Bridges.JoinMaps;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash_Essentials_Core.PartitionSensor;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for GLS Cresnet Partition Sensor")]
|
||||
public class GlsPartitionSensorController : CrestronGenericBridgeableBaseDevice, IPartitionStateProvider
|
||||
{
|
||||
|
||||
public GlsPartitionSensorPropertiesConfig PropertiesConfig { get; private set; }
|
||||
|
||||
private GlsPartCn _partitionSensor;
|
||||
|
||||
public BoolFeedback EnableFeedback { get; private set; }
|
||||
public BoolFeedback PartitionPresentFeedback { get; private set; }
|
||||
public BoolFeedback PartitionNotSensedFeedback { get; private set; }
|
||||
public IntFeedback SensitivityFeedback { get; private set; }
|
||||
|
||||
public bool InTestMode { get; private set; }
|
||||
public bool TestEnableFeedback { get; private set; }
|
||||
public bool TestPartitionSensedFeedback { get; private set; }
|
||||
public int TestSensitivityFeedback { get; private set; }
|
||||
|
||||
|
||||
public GlsPartitionSensorController(string key, Func<DeviceConfig, GlsPartCn> preActivationFunc, DeviceConfig config)
|
||||
: 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(() =>
|
||||
{
|
||||
_partitionSensor = preActivationFunc(config);
|
||||
|
||||
RegisterCrestronGenericBase(_partitionSensor);
|
||||
|
||||
EnableFeedback = new BoolFeedback(() => InTestMode ? TestEnableFeedback : _partitionSensor.EnableFeedback.BoolValue);
|
||||
PartitionPresentFeedback = new BoolFeedback(() => InTestMode ? TestPartitionSensedFeedback : _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||
PartitionNotSensedFeedback = new BoolFeedback(() => InTestMode ? !TestPartitionSensedFeedback : _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||
SensitivityFeedback = new IntFeedback(() => InTestMode ? TestSensitivityFeedback : _partitionSensor.SensitivityFeedback.UShortValue);
|
||||
|
||||
if (_partitionSensor != null)
|
||||
{
|
||||
_partitionSensor.BaseEvent += PartitionSensor_BaseEvent;
|
||||
}
|
||||
});
|
||||
|
||||
AddPostActivationAction(() =>
|
||||
{
|
||||
_partitionSensor.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (a.DeviceOnLine)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
}
|
||||
};
|
||||
|
||||
if (_partitionSensor.IsOnline)
|
||||
{
|
||||
ApplySettingsToSensorFromConfig();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
switch (args.EventId)
|
||||
{
|
||||
case (GlsPartCn.EnableFeedbackEventId):
|
||||
{
|
||||
EnableFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
case (GlsPartCn.PartitionSensedFeedbackEventId):
|
||||
{
|
||||
Debug.Console(1, this, "Partition Sensed State: {0}", _partitionSensor.PartitionSensedFeedback.BoolValue);
|
||||
PartitionPresentFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
case (GlsPartCn.PartitionNotSensedFeedbackEventId):
|
||||
{
|
||||
Debug.Console(1, this, "Partition Not Sensed State: {0}", _partitionSensor.PartitionNotSensedFeedback.BoolValue);
|
||||
PartitionNotSensedFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
case (GlsPartCn.SensitivityFeedbackEventId):
|
||||
{
|
||||
SensitivityFeedback.FireUpdate();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug.Console(2, this, "Unhandled args.EventId: {0}", args.EventId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTestMode(bool mode)
|
||||
{
|
||||
InTestMode = mode;
|
||||
Debug.Console(1, this, "InTestMode: {0}", InTestMode.ToString());
|
||||
}
|
||||
|
||||
public void SetTestEnableState(bool state)
|
||||
{
|
||||
if (InTestMode)
|
||||
{
|
||||
TestEnableFeedback = state;
|
||||
|
||||
EnableFeedback.FireUpdate();
|
||||
|
||||
Debug.Console(1, this, "TestEnableFeedback: {0}", TestEnableFeedback.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "InTestMode: {0}, unable to set enable state: {1}", InTestMode.ToString(), state.ToString());
|
||||
}
|
||||
|
||||
public void SetTestPartitionSensedState(bool state)
|
||||
{
|
||||
if (InTestMode)
|
||||
{
|
||||
TestPartitionSensedFeedback = state;
|
||||
|
||||
PartitionPresentFeedback.FireUpdate();
|
||||
PartitionNotSensedFeedback.FireUpdate();
|
||||
|
||||
Debug.Console(1, this, "TestPartitionSensedFeedback: {0}", TestPartitionSensedFeedback.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "InTestMode: {0}, unable to set partition state: {1}", InTestMode.ToString(), state.ToString());
|
||||
}
|
||||
|
||||
public void SetTestSensitivityValue(int value)
|
||||
{
|
||||
if (InTestMode)
|
||||
{
|
||||
TestSensitivityFeedback = value;
|
||||
|
||||
SensitivityFeedback.FireUpdate();
|
||||
Debug.Console(1, this, "TestSensitivityFeedback: {0}", TestSensitivityFeedback);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "InTestMode: {0}, unable to set sensitivity value: {1}", InTestMode.ToString(), value);
|
||||
}
|
||||
|
||||
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);
|
||||
if (_partitionSensor == null)
|
||||
return;
|
||||
|
||||
_partitionSensor.Enable.BoolValue = state;
|
||||
}
|
||||
|
||||
public void IncreaseSensitivity()
|
||||
{
|
||||
Debug.Console(2, this, "Sensor is {0}, IncreaseSensitivity", _partitionSensor == null ? "null" : "not null");
|
||||
if (_partitionSensor == null)
|
||||
return;
|
||||
|
||||
_partitionSensor.IncreaseSensitivity();
|
||||
}
|
||||
|
||||
public void DecreaseSensitivity()
|
||||
{
|
||||
Debug.Console(2, this, "Sensor is {0}, DecreaseSensitivity", _partitionSensor == null ? "null" : "not null");
|
||||
if (_partitionSensor == null)
|
||||
return;
|
||||
|
||||
_partitionSensor.DecreaseSensitivity();
|
||||
}
|
||||
|
||||
public void SetSensitivity(ushort value)
|
||||
{
|
||||
Debug.Console(2, this, "Sensor is {0}, SetSensitivity: {1}", _partitionSensor == null ? "null" : "not null", value);
|
||||
if (_partitionSensor == null)
|
||||
return;
|
||||
|
||||
_partitionSensor.Sensitivity.UShortValue = value;
|
||||
}
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new GlsPartitionSensorJoinMap(joinStart);
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<GlsPartitionSensorJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'type': 'EiscApiAdvanced' to get all join map features for this device");
|
||||
}
|
||||
|
||||
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
||||
Debug.Console(0, this, "Linking to Bridge Type {0}", GetType().Name);
|
||||
|
||||
IsOnline.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = _partitionSensor.Name;
|
||||
|
||||
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.DecreaseSensitivity.JoinNumber, DecreaseSensitivity);
|
||||
|
||||
SensitivityFeedback.LinkInputSig(trilist.UShortInput[joinMap.Sensitivity.JoinNumber]);
|
||||
trilist.SetUShortSigAction(joinMap.Sensitivity.JoinNumber, SetSensitivity);
|
||||
|
||||
FeedbacksFireUpdates();
|
||||
|
||||
// update when device is online
|
||||
_partitionSensor.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (a.DeviceOnLine)
|
||||
{
|
||||
FeedbacksFireUpdates();
|
||||
}
|
||||
};
|
||||
|
||||
// update when trilist is online
|
||||
trilist.OnlineStatusChange += (o, a) =>
|
||||
{
|
||||
if (a.DeviceOnLine)
|
||||
{
|
||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = _partitionSensor.Name;
|
||||
FeedbacksFireUpdates();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void FeedbacksFireUpdates()
|
||||
{
|
||||
IsOnline.FireUpdate();
|
||||
EnableFeedback.FireUpdate();
|
||||
PartitionPresentFeedback.FireUpdate();
|
||||
PartitionNotSensedFeedback.FireUpdate();
|
||||
SensitivityFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
#region PreActivation
|
||||
|
||||
private static GlsPartCn GetGlsPartCnDevice(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 GlsPartCn", parentKey);
|
||||
return new GlsPartCn(cresnetId, Global.ControlSystem);
|
||||
}
|
||||
var cresnetBridge = DeviceManager.GetDeviceForKey(parentKey) as IHasCresnetBranches;
|
||||
|
||||
if (cresnetBridge != null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} is a valid cresnet master - creating new GlsPartCn", parentKey);
|
||||
return new GlsPartCn(cresnetId, cresnetBridge.CresnetBranches[branchId]);
|
||||
}
|
||||
Debug.Console(0, "Device {0} is not a valid cresnet master", parentKey);
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public class GlsPartitionSensorControllerFactory : EssentialsDeviceFactory<GlsPartitionSensorController>
|
||||
{
|
||||
public GlsPartitionSensorControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "glspartcn" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new GlsPartitionSensorController Device");
|
||||
|
||||
return new GlsPartitionSensorController(dc.Key, GetGlsPartCnDevice, dc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Full.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; }
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,5 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />
|
||||
<None Include="Occupancy\EssentialsGlsOccupancySensorBaseController.cs.orig" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -62,78 +62,6 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows either the byte[] or string to be sent
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return _bytes != null ? _bytes.ToString() : _string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
/// <summary>
|
||||
/// IBasicCommunication Message for IQueue
|
||||
/// </summary>
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public class ComsMessage : IQueueMessage
|
||||
{
|
||||
private readonly byte[] _bytes;
|
||||
private readonly IBasicCommunication _coms;
|
||||
private readonly string _string;
|
||||
private readonly bool _isByteMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for a string message
|
||||
/// </summary>
|
||||
/// <param name="coms">IBasicCommunication to send the message</param>
|
||||
/// <param name="message">Message to send</param>
|
||||
public ComsMessage(IBasicCommunication coms, string message)
|
||||
{
|
||||
Validate(coms, message);
|
||||
_coms = coms;
|
||||
_string = message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for a byte message
|
||||
/// </summary>
|
||||
/// <param name="coms">IBasicCommunication to send the message</param>
|
||||
/// <param name="message">Message to send</param>
|
||||
public ComsMessage(IBasicCommunication coms, byte[] message)
|
||||
{
|
||||
Validate(coms, message);
|
||||
_coms = coms;
|
||||
_bytes = message;
|
||||
_isByteMessage = true;
|
||||
}
|
||||
|
||||
private void Validate(IBasicCommunication coms, object message)
|
||||
{
|
||||
if (coms == null)
|
||||
throw new ArgumentNullException("coms");
|
||||
|
||||
if (message == null)
|
||||
throw new ArgumentNullException("message");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatchs the string/byte[] to the IBasicCommunication specified
|
||||
/// </summary>
|
||||
public void Dispatch()
|
||||
{
|
||||
if (_isByteMessage)
|
||||
{
|
||||
_coms.SendBytes(_bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
_coms.SendText(_string);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows either the byte[] or string to be sent
|
||||
/// </summary>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
using Crestron.SimplSharpPro.CrestronThread;
|
||||
using PepperDash.Core;
|
||||
using Thread = Crestron.SimplSharpPro.CrestronThread.Thread;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Queues
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
public class GenericQueue : IQueue<IQueueMessage>
|
||||
{
|
||||
private readonly string _key;
|
||||
protected readonly CrestronQueue<IQueueMessage> _queue;
|
||||
protected readonly ConcurrentQueue<IQueueMessage> _queue;
|
||||
protected readonly Thread _worker;
|
||||
protected readonly CEvent _waitHandle = new CEvent();
|
||||
|
||||
@@ -33,7 +34,7 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
{
|
||||
get
|
||||
{
|
||||
return _queue.Size;
|
||||
return int.MaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +138,8 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
{
|
||||
cap = capacity; // overrides default
|
||||
}
|
||||
_queue = new CrestronQueue<IQueueMessage>(cap);
|
||||
|
||||
_queue = new ConcurrentQueue<IQueueMessage>();
|
||||
_worker = new Thread(ProcessQueue, null, Thread.eThreadStartOptions.Running)
|
||||
{
|
||||
Priority = priority,
|
||||
@@ -170,14 +172,9 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
IQueueMessage item = null;
|
||||
if (_queue.TryDequeue(out var item) && item == null)
|
||||
break;
|
||||
|
||||
if (_queue.Count > 0)
|
||||
{
|
||||
item = _queue.Dequeue();
|
||||
if (item == null)
|
||||
break;
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
try
|
||||
@@ -188,7 +185,7 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
if (_delayEnabled)
|
||||
Thread.Sleep(_delayTime);
|
||||
}
|
||||
catch (System.Threading.ThreadAbortException)
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
//swallowing this exception, as it should only happen on shut down
|
||||
}
|
||||
@@ -244,14 +241,13 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
Debug.Console(2, this, "Disposing...");
|
||||
if (_queue != null && !_queue.Disposed)
|
||||
using (_waitHandle)
|
||||
{
|
||||
_queue.Clear();
|
||||
Enqueue(null);
|
||||
Debug.Console(2, this, "Disposing...");
|
||||
_queue.Enqueue(null);
|
||||
_waitHandle.Set();
|
||||
_worker.Join();
|
||||
}
|
||||
_worker.Abort();
|
||||
_waitHandle.Close();
|
||||
}
|
||||
|
||||
Disposed = true;
|
||||
@@ -271,261 +267,3 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
/// <summary>
|
||||
/// Threadsafe processing of queued items with pacing if required
|
||||
/// </summary>
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public class GenericQueue : IQueue<IQueueMessage>
|
||||
{
|
||||
private readonly string _key;
|
||||
protected readonly CrestronQueue<IQueueMessage> _queue;
|
||||
protected readonly Thread _worker;
|
||||
protected readonly CEvent _waitHandle = new CEvent();
|
||||
|
||||
private bool _delayEnabled;
|
||||
private int _delayTime;
|
||||
|
||||
private const Thread.eThreadPriority _defaultPriority = Thread.eThreadPriority.MediumPriority;
|
||||
|
||||
/// <summary>
|
||||
/// If the instance has been disposed.
|
||||
/// </summary>
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the capacity of the CrestronQueue (fixed Size property)
|
||||
/// </summary>
|
||||
public int QueueCapacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _queue.Size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of elements currently in the CrestronQueue
|
||||
/// </summary>
|
||||
public int QueueCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _queue.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with no thread priority
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public GenericQueue(string key)
|
||||
: this(key, _defaultPriority, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with queue size
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="capacity">Fixed size for the queue to hold</param>
|
||||
public GenericQueue(string key, int capacity)
|
||||
: this(key, _defaultPriority, capacity, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for generic queue with no pacing
|
||||
/// </summary>
|
||||
/// <param name="key">Key</param>
|
||||
/// <param name="pacing">Pacing in ms between actions</param>
|
||||
public GenericQueue(int pacing, string key)
|
||||
: this(key, _defaultPriority, 0, pacing)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with pacing and capacity
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="pacing"></param>
|
||||
/// <param name="capacity"></param>
|
||||
public GenericQueue(string key, int pacing, int capacity)
|
||||
: this(key, _defaultPriority, capacity, pacing)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with pacing and priority
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="pacing"></param>
|
||||
/// <param name="priority"></param>
|
||||
public GenericQueue(string key, int pacing, Thread.eThreadPriority priority)
|
||||
: this(key, priority, 0, pacing)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with pacing, priority and capacity
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="capacity"></param>
|
||||
public GenericQueue(string key, Thread.eThreadPriority priority, int capacity)
|
||||
: this(key, priority, capacity, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with pacing, priority and capacity
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="pacing"></param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="capacity"></param>
|
||||
public GenericQueue(string key, int pacing, Thread.eThreadPriority priority, int capacity)
|
||||
: this(key, priority, capacity, pacing)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for generic queue with no pacing
|
||||
/// </summary>
|
||||
/// <param name="key">Key</param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="capacity"></param>
|
||||
/// <param name="pacing"></param>
|
||||
protected GenericQueue(string key, Thread.eThreadPriority priority, int capacity, int pacing)
|
||||
{
|
||||
_key = key;
|
||||
int cap = 25; // sets default
|
||||
if (capacity > 0)
|
||||
{
|
||||
cap = capacity; // overrides default
|
||||
}
|
||||
_queue = new CrestronQueue<IQueueMessage>(cap);
|
||||
_worker = new Thread(ProcessQueue, null, Thread.eThreadStartOptions.Running)
|
||||
{
|
||||
Priority = priority
|
||||
};
|
||||
|
||||
SetDelayValues(pacing);
|
||||
}
|
||||
|
||||
private void SetDelayValues(int pacing)
|
||||
{
|
||||
_delayEnabled = pacing > 0;
|
||||
_delayTime = pacing;
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += programEvent =>
|
||||
{
|
||||
if (programEvent != eProgramStatusEventType.Stopping)
|
||||
return;
|
||||
|
||||
Dispose(true);
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread callback
|
||||
/// </summary>
|
||||
/// <param name="obj">The action used to process dequeued items</param>
|
||||
/// <returns>Null when the thread is exited</returns>
|
||||
private object ProcessQueue(object obj)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
IQueueMessage item = null;
|
||||
|
||||
if (_queue.Count > 0)
|
||||
{
|
||||
item = _queue.Dequeue();
|
||||
if (item == null)
|
||||
break;
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.Console(2, this, "Processing queue item: '{0}'", item.ToString());
|
||||
item.Dispatch();
|
||||
|
||||
if (_delayEnabled)
|
||||
Thread.Sleep(_delayTime);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}", ex.Message);
|
||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.StackTrace);
|
||||
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}", ex.InnerException.Message);
|
||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Stack Trace: {0}", ex.InnerException.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
else _waitHandle.Wait();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Enqueue(IQueueMessage item)
|
||||
{
|
||||
_queue.Enqueue(item);
|
||||
_waitHandle.Set();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the thread and cleans up resources. Thread cannot be restarted once
|
||||
/// disposed.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
CrestronEnvironment.GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actually does the disposing. If you override this method, be sure to either call the base implementation
|
||||
/// or clean up all the resources yourself.
|
||||
/// </summary>
|
||||
/// <param name="disposing">set to true unless called from finalizer</param>
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (Disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
Debug.Console(2, this, "Disposing...");
|
||||
if (_queue != null && !_queue.Disposed)
|
||||
{
|
||||
_queue.Clear();
|
||||
Enqueue(null);
|
||||
}
|
||||
_worker.Abort();
|
||||
_waitHandle.Close();
|
||||
}
|
||||
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
~GenericQueue()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Key
|
||||
/// </summary>
|
||||
public string Key
|
||||
{
|
||||
get { return _key; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Queues
|
||||
@@ -13,13 +9,3 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
bool Disposed { get; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public interface IQueue<T> : IKeyed, IDisposable where T : class
|
||||
{
|
||||
void Enqueue(T item);
|
||||
bool Disposed { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,4 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
{
|
||||
void Dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public interface IQueueMessage
|
||||
{
|
||||
void Dispatch();
|
||||
}
|
||||
}
|
||||
@@ -42,47 +42,3 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
/// <summary>
|
||||
/// Message class for processing strings via an IQueue
|
||||
/// </summary>
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public class ProcessStringMessage : IQueueMessage
|
||||
{
|
||||
private readonly Action<string> _action;
|
||||
private readonly string _message;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="message">Message to be processed</param>
|
||||
/// <param name="action">Action to invoke on the message</param>
|
||||
public ProcessStringMessage(string message, Action<string> action)
|
||||
{
|
||||
_message = message;
|
||||
_action = action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the string with the given action
|
||||
/// </summary>
|
||||
public void Dispatch()
|
||||
{
|
||||
if (_action == null || String.IsNullOrEmpty(_message))
|
||||
return;
|
||||
|
||||
_action(_message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To string
|
||||
/// </summary>
|
||||
/// <returns>The current message</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return _message ?? String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,107 +104,3 @@ namespace PepperDash.Essentials.Core.Queues
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace PepperDash_Essentials_Core.Queues
|
||||
{
|
||||
[Obsolete("Use PepperDash.Essentials.Core.Queues")]
|
||||
public sealed class StringResponseProcessor : IKeyed, IDisposable
|
||||
{
|
||||
private readonly Action<string> _processStringAction;
|
||||
private readonly IQueue<IQueueMessage> _queue;
|
||||
private readonly IBasicCommunication _coms;
|
||||
private readonly CommunicationGather _gather;
|
||||
|
||||
private StringResponseProcessor(string key, Action<string> processStringAction)
|
||||
{
|
||||
_processStringAction = processStringAction;
|
||||
_queue = new GenericQueue(key);
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += programEvent =>
|
||||
{
|
||||
if (programEvent != eProgramStatusEventType.Stopping)
|
||||
return;
|
||||
|
||||
Dispose();
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that builds an instance and subscribes to coms TextReceived for processing
|
||||
/// </summary>
|
||||
/// <param name="coms">Com port to process strings from</param>
|
||||
/// <param name="processStringAction">Action to process the incoming strings</param>
|
||||
public StringResponseProcessor(IBasicCommunication coms, Action<string> processStringAction)
|
||||
: this(coms.Key, processStringAction)
|
||||
{
|
||||
_coms = coms;
|
||||
coms.TextReceived += OnResponseReceived;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that builds an instance and subscribes to gather Line Received for processing
|
||||
/// </summary>
|
||||
/// <param name="gather">Gather to process strings from</param>
|
||||
/// <param name="processStringAction">Action to process the incoming strings</param>
|
||||
public StringResponseProcessor(CommunicationGather gather, Action<string> processStringAction)
|
||||
: this(gather.Port.Key, processStringAction)
|
||||
{
|
||||
_gather = gather;
|
||||
gather.LineReceived += OnResponseReceived;
|
||||
}
|
||||
|
||||
private void OnResponseReceived(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
_queue.Enqueue(new ProcessStringMessage(args.Text, _processStringAction));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Key
|
||||
/// </summary>
|
||||
public string Key
|
||||
{
|
||||
get { return _queue.Key; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the instance and cleans up resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
CrestronEnvironment.GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (Disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (_coms != null)
|
||||
_coms.TextReceived -= OnResponseReceived;
|
||||
|
||||
if (_gather != null)
|
||||
{
|
||||
_gather.LineReceived -= OnResponseReceived;
|
||||
_gather.Stop();
|
||||
}
|
||||
|
||||
_queue.Dispose();
|
||||
}
|
||||
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the instance has been disposed or not. If it has, you can not use it anymore
|
||||
/// </summary>
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
~StringResponseProcessor()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public static class ButtonExtensions
|
||||
{
|
||||
public static Button SetButtonAction(this Button button, Action<bool> a)
|
||||
{
|
||||
button.UserObject = a;
|
||||
return button;
|
||||
}
|
||||
|
||||
public static Button SetButtonAction(this CrestronCollection<Button> bc, uint sigNum, Action<bool> a)
|
||||
{
|
||||
return bc[sigNum].SetButtonAction(a);
|
||||
}
|
||||
|
||||
public static bool GetBool(this CrestronCollection<Button> bc, uint sigNum)
|
||||
{
|
||||
return bc[sigNum].State == eButtonState.Pressed ? true : false;
|
||||
}
|
||||
|
||||
public static Button SetButtonPressedAction(this CrestronCollection<Button> bc, uint sigNum, Action a)
|
||||
{
|
||||
return bc[sigNum].SetButtonAction(b => { if (b) a(); });
|
||||
}
|
||||
|
||||
public static Button SetButtonReleasedAction(this CrestronCollection<Button> bc, uint sigNum, Action a)
|
||||
{
|
||||
return bc[sigNum].SetButtonAction(b => { if (!b) a(); });
|
||||
}
|
||||
|
||||
public static Button SetButtonFalseAction(this Button button, Action a)
|
||||
{
|
||||
return button.SetButtonAction(b => { if (!b) a(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Full.Newtonsoft.Json.Converters;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class CrestronRemotePropertiesConfig
|
||||
{
|
||||
[JsonProperty("control")]
|
||||
public EssentialsControlPropertiesConfig Control { get; set; }
|
||||
|
||||
[JsonProperty("gatewayDeviceKey")]
|
||||
public string GatewayDeviceKey { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,827 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.Gateways;
|
||||
using Crestron.SimplSharpPro.Remotes;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
[Description("Wrapper class for all HR-Series remotes")]
|
||||
public class Hrxx0WirelessRemoteController : EssentialsBridgeableDevice, IHasFeedback, IHR52Button
|
||||
{
|
||||
private CenRfgwController _gateway;
|
||||
|
||||
private GatewayBase _gatewayBase;
|
||||
|
||||
private Hr1x0WirelessRemoteBase _remote;
|
||||
|
||||
public FeedbackCollection<Feedback> Feedbacks { get; set; }
|
||||
|
||||
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)
|
||||
{
|
||||
Feedbacks = new FeedbackCollection<Feedback>();
|
||||
|
||||
var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString());
|
||||
|
||||
_config = config;
|
||||
|
||||
if (props.GatewayDeviceKey == "processor")
|
||||
{
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_remote = preActivationFunc(config);
|
||||
RegisterEvents();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController;
|
||||
if (gatewayDev == null)
|
||||
{
|
||||
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey);
|
||||
}
|
||||
if (gatewayDev != null)
|
||||
{
|
||||
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey);
|
||||
_gateway = gatewayDev;
|
||||
}
|
||||
|
||||
|
||||
if (_gateway == null) return;
|
||||
|
||||
_gateway.IsReadyEvent += _gateway_IsReadyEvent;
|
||||
if (_gateway.IsReady)
|
||||
{
|
||||
AddPreActivationAction(() =>
|
||||
{
|
||||
_remote = preActivationFunc(config);
|
||||
|
||||
RegisterEvents();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _gateway_IsReadyEvent(object sender, IsReadyEventArgs e)
|
||||
{
|
||||
if (e.IsReady != true) return;
|
||||
_remote = GetHr1x0WirelessRemote(_config);
|
||||
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
void _remote_BaseEvent(GenericBase device, BaseEventArgs args)
|
||||
{
|
||||
if(args.EventId == Hr1x0EventIds.BatteryCriticalFeedbackEventId)
|
||||
Feedbacks["BatteryCritical"].FireUpdate();
|
||||
if(args.EventId == Hr1x0EventIds.BatteryLowFeedbackEventId)
|
||||
Feedbacks["BatteryLow"].FireUpdate();
|
||||
if(args.EventId == Hr1x0EventIds.BatteryVoltageFeedbackEventId)
|
||||
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
|
||||
{
|
||||
var handler = args.Button.UserObject;
|
||||
|
||||
if (handler == null) return;
|
||||
|
||||
Debug.Console(1, this, "Executing Action: {0}", handler.ToString());
|
||||
|
||||
if (handler is Action<bool>)
|
||||
{
|
||||
(handler as Action<bool>)(args.Button.State == eButtonState.Pressed ? true : false);
|
||||
}
|
||||
|
||||
var newHandler = ButtonStateChange;
|
||||
if (ButtonStateChange != null)
|
||||
{
|
||||
newHandler(device, args);
|
||||
}
|
||||
|
||||
var newerHandler = EssentialsButtonStateChange;
|
||||
if (EssentialsButtonStateChange != null)
|
||||
{
|
||||
newerHandler(this, args);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(2, this, "Error in ButtonStateChange handler: {0}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Preactivation
|
||||
|
||||
private static Hr1x0WirelessRemoteBase GetHr1x0WirelessRemote(DeviceConfig config)
|
||||
{
|
||||
var props = JsonConvert.DeserializeObject<CrestronRemotePropertiesConfig>(config.Properties.ToString());
|
||||
|
||||
var type = config.Type;
|
||||
var rfId = (uint)props.Control.InfinetIdInt;
|
||||
|
||||
GatewayBase gateway;
|
||||
|
||||
if (props.GatewayDeviceKey == "processor")
|
||||
{
|
||||
gateway = Global.ControlSystem.ControllerRFGatewayDevice;
|
||||
}
|
||||
else
|
||||
{
|
||||
var gatewayDev = DeviceManager.GetDeviceForKey(props.GatewayDeviceKey) as CenRfgwController;
|
||||
if (gatewayDev == null)
|
||||
{
|
||||
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid device", props.GatewayDeviceKey);
|
||||
return null;
|
||||
}
|
||||
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is a valid device", props.GatewayDeviceKey);
|
||||
gateway = gatewayDev.GateWay;
|
||||
}
|
||||
|
||||
if (gateway == null)
|
||||
{
|
||||
Debug.Console(0, "GetHr1x0WirelessRemote: Device '{0}' is not a valid gateway", props.GatewayDeviceKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
Hr1x0WirelessRemoteBase remoteBase;
|
||||
switch (type)
|
||||
{
|
||||
case ("hr100"):
|
||||
remoteBase = new Hr100(rfId, gateway);
|
||||
break;
|
||||
case ("hr150"):
|
||||
remoteBase = new Hr150(rfId, gateway);
|
||||
break;
|
||||
case ("hr310"):
|
||||
remoteBase = new Hr310(rfId, gateway);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
// register the device when using an internal RF gateway
|
||||
if (props.GatewayDeviceKey == "processor")
|
||||
{
|
||||
remoteBase.RegisterWithLogging(config.Key);
|
||||
}
|
||||
|
||||
return remoteBase;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Factory
|
||||
public class Hrxx0WirelessRemoteControllerFactory : EssentialsDeviceFactory<Hrxx0WirelessRemoteController>
|
||||
{
|
||||
public Hrxx0WirelessRemoteControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "hr100", "hr150", "hr310" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new HR-x00 Remote Device");
|
||||
|
||||
return new Hrxx0WirelessRemoteController(dc.Key, GetHr1x0WirelessRemote, dc);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = new Hrxxx0WirelessRemoteControllerJoinMap(joinStart);
|
||||
|
||||
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
|
||||
|
||||
if (!string.IsNullOrEmpty(joinMapSerialized))
|
||||
joinMap = JsonConvert.DeserializeObject<Hrxxx0WirelessRemoteControllerJoinMap>(joinMapSerialized);
|
||||
|
||||
if (bridge != null)
|
||||
{
|
||||
bridge.AddJoinMap(Key, joinMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device.");
|
||||
}
|
||||
|
||||
//List<string> ExcludedKeys = new List<string>();
|
||||
foreach (var feedback in Feedbacks)
|
||||
{
|
||||
var myFeedback = feedback;
|
||||
|
||||
var joinData =
|
||||
joinMap.Joins.FirstOrDefault(
|
||||
x =>
|
||||
x.Key.Equals(myFeedback.Key, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (string.IsNullOrEmpty((joinData.Key))) continue;
|
||||
|
||||
var name = joinData.Key;
|
||||
var join = joinData.Value;
|
||||
|
||||
if (join.Metadata.JoinType == eJoinType.Digital)
|
||||
{
|
||||
Debug.Console(0, this, "Linking Bool Feedback '{0}' to join {1}", name, join.JoinNumber);
|
||||
var someFeedback = myFeedback as BoolFeedback;
|
||||
if(someFeedback == null) continue;
|
||||
someFeedback.LinkInputSig(trilist.BooleanInput[join.JoinNumber]);
|
||||
}
|
||||
if (join.Metadata.JoinType == eJoinType.Analog)
|
||||
{
|
||||
Debug.Console(0, this, "Linking Analog Feedback '{0}' to join {1}", name, join.JoinNumber);
|
||||
var someFeedback = myFeedback as IntFeedback;
|
||||
if (someFeedback == null) continue;
|
||||
someFeedback.LinkInputSig(trilist.UShortInput[join.JoinNumber]);
|
||||
}
|
||||
if (join.Metadata.JoinType == eJoinType.Serial)
|
||||
{
|
||||
Debug.Console(0, this, "Linking Serial Feedback '{0}' to join {1}", name, join.JoinNumber);
|
||||
var someFeedback = myFeedback as StringFeedback;
|
||||
if (someFeedback == null) continue;
|
||||
someFeedback.LinkInputSig(trilist.StringInput[join.JoinNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
//var newJoinKeys = joinMap.Joins.Keys.Except(ExcludedKeys).ToList();
|
||||
|
||||
//var newJoinMap = newJoinKeys.Where(k => joinMap.Joins.ContainsKey(k)).Select(k => joinMap.Joins[k]);
|
||||
|
||||
|
||||
Debug.Console(2, this, "There are {0} remote buttons", _remote.Button.Count);
|
||||
for (uint i = 1; i <= _remote.Button.Count; i++)
|
||||
{
|
||||
Debug.Console(2, this, "Attempting to link join index {0}", i);
|
||||
var index = i;
|
||||
var joinData =
|
||||
joinMap.Joins.FirstOrDefault(
|
||||
o =>
|
||||
o.Key.Equals(_remote.Button[index].Name.ToString(),
|
||||
StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (string.IsNullOrEmpty((joinData.Key))) continue;
|
||||
|
||||
var join = joinData.Value;
|
||||
var name = joinData.Key;
|
||||
|
||||
Debug.Console(2, this, "Setting User Object for '{0}'", name);
|
||||
if (join.Metadata.JoinType == eJoinType.Digital)
|
||||
{
|
||||
_remote.Button[i].SetButtonAction((b) => trilist.BooleanInput[join.JoinNumber].BoolValue = b);
|
||||
}
|
||||
}
|
||||
|
||||
trilist.OnlineStatusChange += (d, args) =>
|
||||
{
|
||||
if (!args.DeviceOnLine) return;
|
||||
|
||||
foreach (var feedback in Feedbacks)
|
||||
{
|
||||
feedback.FireUpdate();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
public void SetTrilistBool(BasicTriList trilist, uint join, bool b)
|
||||
{
|
||||
trilist.BooleanInput[join].BoolValue = b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region IHR52Button Members
|
||||
|
||||
public Button Custom9
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR52Button) _remote;
|
||||
return localRemote == null ? null : localRemote.Custom9;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Favorite
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR52Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Favorite;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Button Home
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR52Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Home;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHR49Button Members
|
||||
|
||||
public Button Clear
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Clear;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom5
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom5;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom6
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom6;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom7
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom7;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom8
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom8;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Enter
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Enter;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad0
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad0;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad1
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad1;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad2Abc
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad2Abc;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad3Def
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad3Def;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad4Ghi
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad4Ghi;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad5Jkl
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad5Jkl;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad6Mno
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad6Mno;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad7Pqrs
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad7Pqrs;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad8Tuv
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad8Tuv;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Keypad9Wxyz
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR49Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Keypad9Wxyz;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHR33Button Members
|
||||
|
||||
public Button Blue
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
public Button ChannelDown
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.ChannelDown;
|
||||
}
|
||||
}
|
||||
|
||||
public Button ChannelUp
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.ChannelUp;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom1
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom1;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom2
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom2;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom3
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom3;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Custom4
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Custom4;
|
||||
}
|
||||
}
|
||||
|
||||
public Button DialPadDown
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.DialPadDown;
|
||||
}
|
||||
}
|
||||
|
||||
public Button DialPadEnter
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.DialPadEnter;
|
||||
}
|
||||
}
|
||||
|
||||
public Button DialPadLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.DialPadLeft;
|
||||
}
|
||||
}
|
||||
|
||||
public Button DialPadRight
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.DialPadRight;
|
||||
}
|
||||
}
|
||||
|
||||
public Button DialPadUp
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.DialPadUp;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Dvr
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Dvr;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Exit
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Exit;
|
||||
}
|
||||
}
|
||||
|
||||
public Button FastForward
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.FastForward;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Green
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Green;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Guide
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Information
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Information;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Last
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Last;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Menu
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Menu;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Mute
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Mute;
|
||||
}
|
||||
}
|
||||
|
||||
public Button NextTrack
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.NextTrack;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Pause
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Pause;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Play
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Play;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Power
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Power;
|
||||
}
|
||||
}
|
||||
|
||||
public Button PreviousTrack
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.PreviousTrack;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Record
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Record;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Red
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Red;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Rewind
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Rewind;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Stop
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Stop;
|
||||
}
|
||||
}
|
||||
|
||||
public Button VolumeDown
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.VolumeDown;
|
||||
}
|
||||
}
|
||||
|
||||
public Button VolumeUp
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.VolumeUp;
|
||||
}
|
||||
}
|
||||
|
||||
public Button Yellow
|
||||
{
|
||||
get
|
||||
{
|
||||
var localRemote = (IHR33Button)_remote;
|
||||
return localRemote == null ? null : localRemote.Yellow;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IButton Members
|
||||
|
||||
public CrestronCollection<Button> Button
|
||||
{
|
||||
get { return Buttons; }
|
||||
}
|
||||
|
||||
public event ButtonEventHandler ButtonStateChange;
|
||||
|
||||
public delegate void EssentialsButtonEventHandler(EssentialsDevice device, ButtonEventArgs args);
|
||||
|
||||
public event EssentialsButtonEventHandler EssentialsButtonStateChange;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -55,15 +55,6 @@ namespace PepperDash.Essentials.Core
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For fixed-source endpoint devices
|
||||
/// </summary>
|
||||
[Obsolete("Please switch to IRoutingSink")]
|
||||
public interface IRoutingSinkNoSwitching : IRoutingSink
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Endpoint device like a display, that selects inputs
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Shades
|
||||
{
|
||||
@@ -16,16 +11,6 @@ namespace PepperDash.Essentials.Core.Shades
|
||||
List<ShadeBase> Shades { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requirements for a device that implements basic Open/Close shade control
|
||||
/// </summary>
|
||||
[Obsolete("Please use IShadesOpenCloseStop instead")]
|
||||
public interface IShadesOpenClose
|
||||
{
|
||||
void Open();
|
||||
void Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requirements for a device that implements basic Open/Close/Stop shade control (Uses 3 relays)
|
||||
/// </summary>
|
||||
@@ -45,15 +30,6 @@ namespace PepperDash.Essentials.Core.Shades
|
||||
event EventHandler PresetSaved;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requirements for a shade that implements press/hold raise/lower functions
|
||||
/// </summary>
|
||||
[Obsolete("Please use IShadesOpenCloseStop instead")]
|
||||
public interface IShadesRaiseLower
|
||||
{
|
||||
void Raise(bool state);
|
||||
void Lower(bool state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requirements for a shade device that provides raising/lowering feedback
|
||||
@@ -73,15 +49,6 @@ namespace PepperDash.Essentials.Core.Shades
|
||||
BoolFeedback ShadeIsClosedFeedback { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Obsolete("Please use IShadesOpenCloseStop instead")]
|
||||
public interface IShadesStop
|
||||
{
|
||||
void Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to implement raise/stop/lower/stop from single button
|
||||
/// </summary>
|
||||
@@ -125,7 +92,7 @@ namespace PepperDash.Essentials.Core.Shades
|
||||
BoolFeedback AllAreAtSceneFeedback { get; }
|
||||
}
|
||||
|
||||
public interface ICrestronBasicShade : IShadesOpenClosedFeedback, IShadesStop,
|
||||
public interface ICrestronBasicShade : IShadesOpenClosedFeedback,
|
||||
IShadesStopOrMove, IShadesFeedback, IShadesRaiseLowerFeedback
|
||||
{
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
@@ -14,8 +10,6 @@ using PepperDash.Essentials.Core.Devices;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Presets;
|
||||
using PepperDash.Essentials.Devices.Common.Codec;
|
||||
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Cameras
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Cameras
|
||||
|
||||
@@ -3,17 +3,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Devices.Common.Codec;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Cameras
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Cameras
|
||||
{
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Codec
|
||||
namespace PepperDash.Essentials.Devices.Common.Codec
|
||||
{
|
||||
public interface IHasCallHold
|
||||
{
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Devices.Common.Codec;
|
||||
using PepperDash.Essentials.Devices.Common.VideoCodec;
|
||||
|
||||
using Full.Newtonsoft.Json;
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Codec
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Codec
|
||||
{
|
||||
|
||||
@@ -3,14 +3,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using Full.Newtonsoft.Json;
|
||||
using Full.Newtonsoft.Json.Converters;
|
||||
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Devices.Common.VideoCodec;
|
||||
|
||||
@@ -38,12 +32,6 @@ namespace PepperDash.Essentials.Devices.Common.Codec
|
||||
void GetDirectoryParentFolderContents();
|
||||
|
||||
BoolFeedback CurrentDirectoryResultIsNotDirectoryRoot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the directory browse history when browsing beyond the root directory
|
||||
/// </summary>
|
||||
[Obsolete("Please use the Stack-based history instead")]
|
||||
List<CodecDirectory> DirectoryBrowseHistory { get; }
|
||||
}
|
||||
|
||||
public interface IHasDirectoryHistoryStack : IHasDirectory
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
@@ -1,396 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
|
||||
// QUESTIONS:
|
||||
//
|
||||
// When subscribing, just use the Instance ID for Custom Name?
|
||||
|
||||
// Verbose on subscriptions?
|
||||
|
||||
// Example subscription feedback responses
|
||||
// ! "publishToken":"name" "value":-77.0
|
||||
// ! "myLevelName" -77
|
||||
|
||||
public class BiampTesiraForteDsp : DspBase
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
public CommunicationGather PortGather { get; private set; }
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
public new Dictionary<string, TesiraForteLevelControl> LevelControlPoints { get; private set; }
|
||||
|
||||
public bool isSubscribed;
|
||||
|
||||
private CTimer SubscriptionTimer;
|
||||
|
||||
private CrestronQueue CommandQueue;
|
||||
|
||||
private bool CommandQueueInProgress = false;
|
||||
|
||||
//new public Dictionary<string, DspControlPoint> DialerControlPoints { get; private set; }
|
||||
|
||||
//new public Dictionary<string, DspControlPoint> SwitcherControlPoints { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shows received lines as hex
|
||||
/// </summary>
|
||||
public bool ShowHexResponse { get; set; }
|
||||
|
||||
public BiampTesiraForteDsp(string key, string name, IBasicCommunication comm,
|
||||
BiampTesiraFortePropertiesConfig props) :
|
||||
base(key, name)
|
||||
{
|
||||
CommandQueue = new CrestronQueue(100);
|
||||
|
||||
Communication = comm;
|
||||
var socket = comm as ISocketStatus;
|
||||
if (socket != null)
|
||||
{
|
||||
// This instance uses IP control
|
||||
|
||||
socket.ConnectionChange += new EventHandler<GenericSocketStatusChageEventArgs>(socket_ConnectionChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This instance uses RS-232 control
|
||||
}
|
||||
PortGather = new CommunicationGather(Communication, "\x0d\x0a");
|
||||
PortGather.LineReceived += this.Port_LineReceived;
|
||||
if (props.CommunicationMonitorProperties != null)
|
||||
{
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication,
|
||||
props.CommunicationMonitorProperties);
|
||||
}
|
||||
else
|
||||
{
|
||||
//#warning Need to deal with this poll string
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000,
|
||||
"SESSION get aliases\x0d\x0a");
|
||||
}
|
||||
|
||||
LevelControlPoints = new Dictionary<string, TesiraForteLevelControl>();
|
||||
|
||||
foreach (KeyValuePair<string, BiampTesiraForteLevelControlBlockConfig> block in props.LevelControlBlocks)
|
||||
{
|
||||
this.LevelControlPoints.Add(block.Key, new TesiraForteLevelControl(block.Key, block.Value, this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
CommunicationMonitor.StatusChange +=
|
||||
(o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
|
||||
CommunicationMonitor.Start();
|
||||
|
||||
CrestronConsole.AddNewConsoleCommand(SendLine, "send" + Key, "", ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(s => Communication.Connect(), "con" + Key, "",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
|
||||
{
|
||||
Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString());
|
||||
|
||||
if (e.Client.IsConnected)
|
||||
{
|
||||
// Tasks on connect
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cleanup items from this session
|
||||
|
||||
if (SubscriptionTimer != null)
|
||||
{
|
||||
SubscriptionTimer.Stop();
|
||||
SubscriptionTimer = null;
|
||||
}
|
||||
|
||||
isSubscribed = false;
|
||||
CommandQueue.Clear();
|
||||
CommandQueueInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initiates the subscription process to the DSP
|
||||
/// </summary>
|
||||
private void SubscribeToAttributes()
|
||||
{
|
||||
SendLine("SESSION set verbose true");
|
||||
|
||||
foreach (KeyValuePair<string, TesiraForteLevelControl> level in LevelControlPoints)
|
||||
{
|
||||
level.Value.Subscribe();
|
||||
}
|
||||
|
||||
if (!CommandQueueInProgress)
|
||||
SendNextQueuedCommand();
|
||||
|
||||
ResetSubscriptionTimer();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets or Sets the subscription timer
|
||||
/// </summary>
|
||||
private void ResetSubscriptionTimer()
|
||||
{
|
||||
isSubscribed = true;
|
||||
|
||||
if (SubscriptionTimer != null)
|
||||
{
|
||||
SubscriptionTimer = new CTimer(o => SubscribeToAttributes(), 30000);
|
||||
SubscriptionTimer.Reset();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a response message from the DSP
|
||||
/// </summary>
|
||||
/// <param name="dev"></param>
|
||||
/// <param name="args"></param>
|
||||
private void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (args.Text.IndexOf("Welcome to the Tesira Text Protocol Server...") > -1)
|
||||
{
|
||||
// Indicates a new TTP session
|
||||
|
||||
SubscribeToAttributes();
|
||||
}
|
||||
else if (args.Text.IndexOf("publishToken") > -1)
|
||||
{
|
||||
// response is from a subscribed attribute
|
||||
|
||||
string pattern = "! \"publishToken\":[\"](.*)[\"] \"value\":(.*)";
|
||||
|
||||
Match match = Regex.Match(args.Text, pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
|
||||
string key;
|
||||
|
||||
string customName;
|
||||
|
||||
string value;
|
||||
|
||||
customName = match.Groups[1].Value;
|
||||
|
||||
// Finds the key (everything before the '~' character
|
||||
key = customName.Substring(0, customName.IndexOf("~", 0) - 1);
|
||||
|
||||
value = match.Groups[2].Value;
|
||||
|
||||
foreach (KeyValuePair<string, TesiraForteLevelControl> controlPoint in LevelControlPoints)
|
||||
{
|
||||
if (customName == controlPoint.Value.LevelCustomName ||
|
||||
customName == controlPoint.Value.MuteCustomName)
|
||||
{
|
||||
controlPoint.Value.ParseSubscriptionMessage(customName, value);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// same for dialers
|
||||
/// same for switchers
|
||||
|
||||
}
|
||||
else if (args.Text.IndexOf("+OK") > -1)
|
||||
{
|
||||
if (args.Text == "+OK" || args.Text.IndexOf("list\":") > -1)
|
||||
// Check for a simple "+OK" only 'ack' repsonse or a list response and ignore
|
||||
return;
|
||||
|
||||
// response is not from a subscribed attribute. From a get/set/toggle/increment/decrement command
|
||||
|
||||
if (!CommandQueue.IsEmpty)
|
||||
{
|
||||
if (CommandQueue.Peek() is QueuedCommand)
|
||||
{
|
||||
// Expected response belongs to a child class
|
||||
QueuedCommand tempCommand = (QueuedCommand) CommandQueue.TryToDequeue();
|
||||
//Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
|
||||
|
||||
tempCommand.ControlPoint.ParseGetMessage(tempCommand.AttributeCode, args.Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Expected response belongs to this class
|
||||
string temp = (string) CommandQueue.TryToDequeue();
|
||||
//Debug.Console(1, this, "Command Dequeued. CommandQueue Size: {0}", CommandQueue.Count);
|
||||
|
||||
}
|
||||
|
||||
if (CommandQueue.IsEmpty)
|
||||
CommandQueueInProgress = false;
|
||||
else
|
||||
SendNextQueuedCommand();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (args.Text.IndexOf("-ERR") > -1)
|
||||
{
|
||||
// Error response
|
||||
|
||||
switch (args.Text)
|
||||
{
|
||||
case "-ERR ALREADY_SUBSCRIBED":
|
||||
{
|
||||
ResetSubscriptionTimer();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug.Console(0, this, "Error From DSP: '{0}'", args.Text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a command to the DSP (with delimiter appended)
|
||||
/// </summary>
|
||||
/// <param name="s">Command to send</param>
|
||||
public void SendLine(string s)
|
||||
{
|
||||
Communication.SendText(s + "\x0a");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a command from a child module to the queue
|
||||
/// </summary>
|
||||
/// <param name="command">Command object from child module</param>
|
||||
public void EnqueueCommand(QueuedCommand commandToEnqueue)
|
||||
{
|
||||
CommandQueue.Enqueue(commandToEnqueue);
|
||||
//Debug.Console(1, this, "Command (QueuedCommand) Enqueued '{0}'. CommandQueue has '{1}' Elements.", commandToEnqueue.Command, CommandQueue.Count);
|
||||
|
||||
if (!CommandQueueInProgress)
|
||||
SendNextQueuedCommand();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a raw string command to the queue
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
public void EnqueueCommand(string command)
|
||||
{
|
||||
CommandQueue.Enqueue(command);
|
||||
//Debug.Console(1, this, "Command (string) Enqueued '{0}'. CommandQueue has '{1}' Elements.", command, CommandQueue.Count);
|
||||
|
||||
if (!CommandQueueInProgress)
|
||||
SendNextQueuedCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the next queued command to the DSP
|
||||
/// </summary>
|
||||
private void SendNextQueuedCommand()
|
||||
{
|
||||
//Debug.Console(2, this, "Attempting to send next queued command. CommandQueueInProgress: {0} Communication isConnected: {1}", CommandQueueInProgress, Communication.IsConnected);
|
||||
|
||||
//if (CommandQueue.IsEmpty)
|
||||
// CommandQueueInProgress = false;
|
||||
|
||||
//Debug.Console(1, this, "CommandQueue has {0} Elements:\n", CommandQueue.Count);
|
||||
|
||||
//foreach (object o in CommandQueue)
|
||||
//{
|
||||
// if (o is string)
|
||||
// Debug.Console(1, this, "{0}", o);
|
||||
// else if(o is QueuedCommand)
|
||||
// {
|
||||
// var item = (QueuedCommand)o;
|
||||
// Debug.Console(1, this, "{0}", item.Command);
|
||||
// }
|
||||
//}
|
||||
|
||||
//Debug.Console(1, this, "End of CommandQueue");
|
||||
|
||||
if (Communication.IsConnected && !CommandQueue.IsEmpty)
|
||||
{
|
||||
CommandQueueInProgress = true;
|
||||
|
||||
if (CommandQueue.Peek() is QueuedCommand)
|
||||
{
|
||||
QueuedCommand nextCommand = new QueuedCommand();
|
||||
|
||||
nextCommand = (QueuedCommand) CommandQueue.Peek();
|
||||
|
||||
SendLine(nextCommand.Command);
|
||||
}
|
||||
else
|
||||
{
|
||||
string nextCommand = (string) CommandQueue.Peek();
|
||||
|
||||
SendLine(nextCommand);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a command to execute a preset
|
||||
/// </summary>
|
||||
/// <param name="name">Preset Name</param>
|
||||
public void RunPreset(string name)
|
||||
{
|
||||
SendLine(string.Format("DEVICE recallPreset {0}", name));
|
||||
}
|
||||
|
||||
public class QueuedCommand
|
||||
{
|
||||
public string Command { get; set; }
|
||||
public string AttributeCode { get; set; }
|
||||
public TesiraForteControlPoint ControlPoint { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class BiampTesiraForteDspFactory : EssentialsDeviceFactory<BiampTesiraForteDsp>
|
||||
{
|
||||
public BiampTesiraForteDspFactory()
|
||||
{
|
||||
TypeNames = new List<string>() {"biamptesira"};
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new BiampTesira Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<BiampTesiraFortePropertiesConfig>(
|
||||
dc.Properties.ToString());
|
||||
return new BiampTesiraForteDsp(dc.Key, dc.Name, comm, props);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,379 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
public interface IBiampTesiraDspLevelControl : IBasicVolumeWithFeedback
|
||||
{
|
||||
/// <summary>
|
||||
/// In BiAmp: Instance Tag, QSC: Named Control, Polycom:
|
||||
/// </summary>
|
||||
string ControlPointTag { get; }
|
||||
int Index1 { get; }
|
||||
int Index2 { get; }
|
||||
bool HasMute { get; }
|
||||
bool HasLevel { get; }
|
||||
bool AutomaticUnmuteOnVolumeUp { get; }
|
||||
}
|
||||
|
||||
public class TesiraForteLevelControl : TesiraForteControlPoint, IBiampTesiraDspLevelControl, IKeyed
|
||||
{
|
||||
bool _IsMuted;
|
||||
ushort _VolumeLevel;
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
|
||||
public IntFeedback VolumeLevelFeedback { get; private set; }
|
||||
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string ControlPointTag { get { return base.InstanceTag; } }
|
||||
|
||||
/// <summary>
|
||||
/// Used for to identify level subscription values
|
||||
/// </summary>
|
||||
public string LevelCustomName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used for to identify mute subscription values
|
||||
/// </summary>
|
||||
public string MuteCustomName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Minimum fader level
|
||||
/// </summary>
|
||||
double MinLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum fader level
|
||||
/// </summary>
|
||||
double MaxLevel;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a valid subscription string has been recieved for all subscriptions
|
||||
/// </summary>
|
||||
public bool IsSubsribed
|
||||
{
|
||||
get
|
||||
{
|
||||
bool isSubscribed = false;
|
||||
|
||||
if (HasMute && MuteIsSubscribed)
|
||||
isSubscribed = true;
|
||||
|
||||
if (HasLevel && LevelIsSubscribed)
|
||||
isSubscribed = true;
|
||||
|
||||
return isSubscribed;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AutomaticUnmuteOnVolumeUp { get; private set; }
|
||||
|
||||
public bool HasMute { get; private set; }
|
||||
|
||||
public bool HasLevel { get; private set; }
|
||||
|
||||
bool MuteIsSubscribed;
|
||||
|
||||
bool LevelIsSubscribed;
|
||||
|
||||
//public TesiraForteLevelControl(string label, string id, int index1, int index2, bool hasMute, bool hasLevel, BiampTesiraForteDsp parent)
|
||||
// : base(id, index1, index2, parent)
|
||||
//{
|
||||
// Initialize(label, hasMute, hasLevel);
|
||||
//}
|
||||
|
||||
public TesiraForteLevelControl(string key, BiampTesiraForteLevelControlBlockConfig config, BiampTesiraForteDsp parent)
|
||||
: base(config.InstanceTag, config.Index1, config.Index2, parent)
|
||||
{
|
||||
Initialize(key, config.Label, config.HasMute, config.HasLevel);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this attribute based on config values and generates subscriptions commands and adds commands to the parent's queue.
|
||||
/// </summary>
|
||||
public void Initialize(string key, string label, bool hasMute, bool hasLevel)
|
||||
{
|
||||
Key = string.Format("{0}--{1}", Parent.Key, key);
|
||||
|
||||
DeviceManager.AddDevice(this);
|
||||
|
||||
Debug.Console(2, this, "Adding LevelControl '{0}'", Key);
|
||||
|
||||
this.IsSubscribed = false;
|
||||
|
||||
MuteFeedback = new BoolFeedback(() => _IsMuted);
|
||||
|
||||
VolumeLevelFeedback = new IntFeedback(() => _VolumeLevel);
|
||||
|
||||
HasMute = hasMute;
|
||||
HasLevel = hasLevel;
|
||||
}
|
||||
|
||||
public void Subscribe()
|
||||
{
|
||||
// Do subscriptions and blah blah
|
||||
|
||||
// Subscribe to mute
|
||||
if (this.HasMute)
|
||||
{
|
||||
MuteCustomName = string.Format("{0}~mute{1}", this.InstanceTag, this.Index1);
|
||||
|
||||
SendSubscriptionCommand(MuteCustomName, "mute", 500);
|
||||
}
|
||||
|
||||
// Subscribe to level
|
||||
if (this.HasLevel)
|
||||
{
|
||||
LevelCustomName = string.Format("{0}~level{1}", this.InstanceTag, this.Index1);
|
||||
|
||||
SendSubscriptionCommand(LevelCustomName, "level", 250);
|
||||
|
||||
SendFullCommand("get", "minLevel", null);
|
||||
|
||||
SendFullCommand("get", "maxLevel", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Parses the response from the DspBase
|
||||
/// </summary>
|
||||
/// <param name="customName"></param>
|
||||
/// <param name="value"></param>
|
||||
public void ParseSubscriptionMessage(string customName, string value)
|
||||
{
|
||||
|
||||
// Check for valid subscription response
|
||||
|
||||
if (this.HasMute && customName == MuteCustomName)
|
||||
{
|
||||
//if (value.IndexOf("+OK") > -1)
|
||||
//{
|
||||
// int pointer = value.IndexOf(" +OK");
|
||||
|
||||
// MuteIsSubscribed = true;
|
||||
|
||||
// // Removes the +OK
|
||||
// value = value.Substring(0, value.Length - (value.Length - (pointer - 1)));
|
||||
//}
|
||||
|
||||
if (value.IndexOf("true") > -1)
|
||||
{
|
||||
_IsMuted = true;
|
||||
MuteIsSubscribed = true;
|
||||
|
||||
}
|
||||
else if (value.IndexOf("false") > -1)
|
||||
{
|
||||
_IsMuted = false;
|
||||
MuteIsSubscribed = true;
|
||||
}
|
||||
|
||||
MuteFeedback.FireUpdate();
|
||||
}
|
||||
else if (this.HasLevel && customName == LevelCustomName)
|
||||
{
|
||||
//if (value.IndexOf("+OK") > -1)
|
||||
//{
|
||||
// int pointer = value.IndexOf(" +OK");
|
||||
|
||||
// LevelIsSubscribed = true;
|
||||
|
||||
//}
|
||||
|
||||
var _value = Double.Parse(value);
|
||||
|
||||
_VolumeLevel = (ushort)Scale(_value, MinLevel, MaxLevel, 0, 65535);
|
||||
|
||||
LevelIsSubscribed = true;
|
||||
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a non subscription response
|
||||
/// </summary>
|
||||
/// <param name="attributeCode">The attribute code of the command</param>
|
||||
/// <param name="message">The message to parse</param>
|
||||
public override void ParseGetMessage(string attributeCode, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse an "+OK" message
|
||||
string pattern = @"\+OK ""value"":(.*)";
|
||||
|
||||
Match match = Regex.Match(message, pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
|
||||
string value = match.Groups[1].Value;
|
||||
|
||||
Debug.Console(1, this, "Response: '{0}' Value: '{1}'", attributeCode, value);
|
||||
|
||||
if (message.IndexOf("\"value\":") > -1)
|
||||
{
|
||||
switch (attributeCode)
|
||||
{
|
||||
case "minLevel":
|
||||
{
|
||||
MinLevel = Double.Parse(value);
|
||||
|
||||
Debug.Console(1, this, "MinLevel is '{0}'", MinLevel);
|
||||
|
||||
break;
|
||||
}
|
||||
case "maxLevel":
|
||||
{
|
||||
MaxLevel = Double.Parse(value);
|
||||
|
||||
Debug.Console(1, this, "MaxLevel is '{0}'", MaxLevel);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug.Console(2, "Response does not match expected attribute codes: '{0}'", message);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(2, "Unable to parse message: '{0}'\n{1}", message, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the mute off
|
||||
/// </summary>
|
||||
public void MuteOff()
|
||||
{
|
||||
SendFullCommand("set", "mute", "false");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the mute on
|
||||
/// </summary>
|
||||
public void MuteOn()
|
||||
{
|
||||
SendFullCommand("set", "mute", "true");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the volume to a specified level
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
Debug.Console(1, this, "volume: {0}", level);
|
||||
// Unmute volume if new level is higher than existing
|
||||
if (level > _VolumeLevel && AutomaticUnmuteOnVolumeUp)
|
||||
if(_IsMuted)
|
||||
MuteOff();
|
||||
|
||||
double volumeLevel = Scale(level, 0, 65535, MinLevel, MaxLevel);
|
||||
|
||||
SendFullCommand("set", "level", string.Format("{0:0.000000}", volumeLevel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles mute status
|
||||
/// </summary>
|
||||
public void MuteToggle()
|
||||
{
|
||||
SendFullCommand("toggle", "mute", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrements volume level
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeDown(bool pressRelease)
|
||||
{
|
||||
SendFullCommand("decrement", "level", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increments volume level
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeUp(bool pressRelease)
|
||||
{
|
||||
SendFullCommand("increment", "level", "");
|
||||
|
||||
if (AutomaticUnmuteOnVolumeUp)
|
||||
if (!_IsMuted)
|
||||
MuteOff();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Scales the input from the input range to the output range
|
||||
///// </summary>
|
||||
///// <param name="input"></param>
|
||||
///// <param name="inMin"></param>
|
||||
///// <param name="inMax"></param>
|
||||
///// <param name="outMin"></param>
|
||||
///// <param name="outMax"></param>
|
||||
///// <returns></returns>
|
||||
//int Scale(int input, int inMin, int inMax, int outMin, int outMax)
|
||||
//{
|
||||
// Debug.Console(1, this, "Scaling (int) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'", input, inMin, inMax, outMin, outMax);
|
||||
|
||||
// int inputRange = inMax - inMin;
|
||||
|
||||
// int outputRange = outMax - outMin;
|
||||
|
||||
// var output = (((input-inMin) * outputRange) / inputRange ) - outMin;
|
||||
|
||||
// Debug.Console(1, this, "Scaled output '{0}'", output);
|
||||
|
||||
// return output;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Scales the input from the input range to the output range
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="inMin"></param>
|
||||
/// <param name="inMax"></param>
|
||||
/// <param name="outMin"></param>
|
||||
/// <param name="outMax"></param>
|
||||
/// <returns></returns>
|
||||
double Scale(double input, double inMin, double inMax, double outMin, double outMax)
|
||||
{
|
||||
Debug.Console(1, this, "Scaling (double) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'",input ,inMin ,inMax ,outMin, outMax);
|
||||
|
||||
double inputRange = inMax - inMin;
|
||||
|
||||
if (inputRange <= 0)
|
||||
{
|
||||
throw new ArithmeticException(string.Format("Invalid Input Range '{0}' for Scaling. Min '{1}' Max '{2}'.", inputRange, inMin, inMax));
|
||||
}
|
||||
|
||||
double outputRange = outMax - outMin;
|
||||
|
||||
var output = (((input - inMin) * outputRange) / inputRange) + outMin;
|
||||
|
||||
Debug.Console(1, this, "Scaled output '{0}'", output);
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BiampTesiraFortePropertiesConfig
|
||||
{
|
||||
public CommunicationMonitorConfig CommunicationMonitorProperties { get; set; }
|
||||
|
||||
public ControlPropertiesConfig Control { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// These are key-value pairs, string id, string type.
|
||||
/// Valid types are level and mute.
|
||||
/// Need to include the index values somehow
|
||||
/// </summary>
|
||||
public Dictionary<string, BiampTesiraForteLevelControlBlockConfig> LevelControlBlocks { get; set; }
|
||||
// public Dictionary<string, BiampTesiraForteDialerControlBlockConfig> DialerControlBlocks {get; set;}
|
||||
}
|
||||
|
||||
public class BiampTesiraForteLevelControlBlockConfig
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public string Label { get; set; }
|
||||
public string InstanceTag { get; set; }
|
||||
public int Index1 { get; set; }
|
||||
public int Index2 { get; set; }
|
||||
public bool HasMute { get; set; }
|
||||
public bool HasLevel { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
public abstract class TesiraForteControlPoint : DspControlPoint
|
||||
{
|
||||
public string Key { get; protected set; }
|
||||
|
||||
public string InstanceTag { get; set; }
|
||||
public int Index1 { get; private set; }
|
||||
public int Index2 { get; private set; }
|
||||
public BiampTesiraForteDsp Parent { get; private set; }
|
||||
|
||||
public bool IsSubscribed { get; protected set; }
|
||||
|
||||
protected TesiraForteControlPoint(string id, int index1, int index2, BiampTesiraForteDsp parent)
|
||||
{
|
||||
InstanceTag = id;
|
||||
Index1 = index1;
|
||||
Index2 = index2;
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
virtual public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a command to the DSP
|
||||
/// </summary>
|
||||
/// <param name="command">command</param>
|
||||
/// <param name="attribute">attribute code</param>
|
||||
/// <param name="value">value (use "" if not applicable)</param>
|
||||
public virtual void SendFullCommand(string command, string attributeCode, string value)
|
||||
{
|
||||
// Command Format: InstanceTag get/set/toggle/increment/decrement/subscribe/unsubscribe attributeCode [index] [value]
|
||||
// Ex: "RoomLevel set level 1.00"
|
||||
|
||||
string cmd;
|
||||
|
||||
if (attributeCode == "level" || attributeCode == "mute" || attributeCode == "minLevel" || attributeCode == "maxLevel" || attributeCode == "label" || attributeCode == "rampInterval" || attributeCode == "rampStep")
|
||||
{
|
||||
//Command requires Index
|
||||
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{
|
||||
// format command without value
|
||||
cmd = string.Format("{0} {1} {2} {3}", InstanceTag, command, attributeCode, Index1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// format commadn with value
|
||||
cmd = string.Format("{0} {1} {2} {3} {4}", InstanceTag, command, attributeCode, Index1, value);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Command does not require Index
|
||||
|
||||
if (String.IsNullOrEmpty(value))
|
||||
{
|
||||
cmd = string.Format("{0} {1} {2} {3}", InstanceTag, command, attributeCode, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = string.Format("{0} {1} {2}", InstanceTag, command, attributeCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (command == "get")
|
||||
{
|
||||
// This command will generate a return value response so it needs to be queued
|
||||
Parent.EnqueueCommand(new BiampTesiraForteDsp.QueuedCommand{ Command = cmd, AttributeCode = attributeCode, ControlPoint = this });
|
||||
}
|
||||
else
|
||||
{
|
||||
// This command will generate a simple "+OK" response and doesn't need to be queued
|
||||
Parent.SendLine(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual public void ParseGetMessage(string attributeCode, string message)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual void SendSubscriptionCommand(string customName, string attributeCode, int responseRate)
|
||||
{
|
||||
// Subscription string format: InstanceTag subscribe attributeCode Index1 customName responseRate
|
||||
// Ex: "RoomLevel subscribe level 1 MyRoomLevel 500"
|
||||
|
||||
string cmd;
|
||||
|
||||
if (responseRate > 0)
|
||||
{
|
||||
cmd = string.Format("{0} subscribe {1} {2} {3} {4}", InstanceTag, attributeCode, Index1, customName, responseRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = string.Format("{0} subscribe {1} {2} {3}", InstanceTag, attributeCode, Index1, customName);
|
||||
}
|
||||
|
||||
Parent.SendLine(cmd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
|
||||
//QUESTIONS:
|
||||
|
||||
//When subscribing, just use the Instance ID for Custom Name?
|
||||
|
||||
//Verbose on subscriptions?
|
||||
|
||||
//! "publishToken":"name" "value":-77.0
|
||||
//! "myLevelName" -77
|
||||
|
||||
//public class TesiraForteMuteControl : IDspLevelControl
|
||||
//{
|
||||
// BiampTesiraForteDsp Parent;
|
||||
// bool _IsMuted;
|
||||
// ushort _VolumeLevel;
|
||||
|
||||
// public TesiraForteMuteControl(string id, BiampTesiraForteDsp parent)
|
||||
// : base(id)
|
||||
// {
|
||||
// Parent = parent;
|
||||
// }
|
||||
|
||||
// public void Initialize()
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// protected override Func<bool> MuteFeedbackFunc
|
||||
// {
|
||||
// get { return () => _IsMuted; }
|
||||
// }
|
||||
|
||||
// protected override Func<int> VolumeLevelFeedbackFunc
|
||||
// {
|
||||
// get { return () => _VolumeLevel; }
|
||||
// }
|
||||
|
||||
// public override void MuteOff()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void MuteOn()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void SetVolume(ushort level)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void MuteToggle()
|
||||
// {
|
||||
// }
|
||||
|
||||
// public override void VolumeDown(bool pressRelease)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void VolumeUp(bool pressRelease)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.DSP
|
||||
{
|
||||
public class SoundStructureBasics
|
||||
{
|
||||
// public Dictionary<string, IBiampTesiraDspLevelControl> Levels { get; private set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,749 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.CrestronThread;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Routing;
|
||||
using Feedback = PepperDash.Essentials.Core.Feedback;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class AvocorDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor, IInputDisplayPort1,
|
||||
IInputHdmi1, IInputHdmi2, IInputHdmi3, IInputHdmi4, IInputVga1, IBridgeAdvanced
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
public CommunicationGather PortGather { get; private set; }
|
||||
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
public byte ID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0x08
|
||||
/// </summary>
|
||||
const byte InputVga1Value = 0x00;
|
||||
/// <summary>
|
||||
/// 0x09
|
||||
/// </summary>
|
||||
const byte InputHdmi1Value = 0x09;
|
||||
/// <summary>
|
||||
/// 0x0a
|
||||
/// </summary>
|
||||
const byte InputHdmi2Value = 0x0a;
|
||||
/// <summary>
|
||||
/// 0x0b
|
||||
/// </summary>
|
||||
const byte InputHdmi3Value = 0x0b;
|
||||
/// <summary>
|
||||
/// 0x0c
|
||||
/// </summary>
|
||||
const byte InputHdmi4Value = 0x0c;
|
||||
/// <summary>
|
||||
/// 0c0d
|
||||
/// </summary>
|
||||
const byte InputDisplayPort1Value = 0x0d;
|
||||
/// <summary>
|
||||
/// 0x0e
|
||||
/// </summary>
|
||||
const byte InputIpcOpsValue = 0x0e;
|
||||
/// <summary>
|
||||
/// 0x11
|
||||
/// </summary>
|
||||
const byte InputHdmi5Value = 0x11;
|
||||
/// <summary>
|
||||
/// 0x12
|
||||
/// </summary>
|
||||
const byte InputMediaPlayerValue = 0x12;
|
||||
|
||||
|
||||
bool _PowerIsOn;
|
||||
bool _IsWarmingUp;
|
||||
bool _IsCoolingDown;
|
||||
ushort _VolumeLevelForSig;
|
||||
int _LastVolumeSent;
|
||||
ushort _PreMuteVolumeLevel;
|
||||
bool _IsMuted;
|
||||
RoutingInputPort _CurrentInputPort;
|
||||
ActionIncrementer VolumeIncrementer;
|
||||
bool VolumeIsRamping;
|
||||
public bool IsInStandby { get; private set; }
|
||||
|
||||
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
|
||||
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
|
||||
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
|
||||
protected override Func<string> CurrentInputFeedbackFunc { get { return () => _CurrentInputPort.Key; } }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IBasicCommunication
|
||||
/// </summary>
|
||||
public AvocorDisplay(string key, string name, IBasicCommunication comm, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = comm;
|
||||
//Communication.BytesReceived += new EventHandler<GenericCommMethodReceiveBytesArgs>(Communication_BytesReceived);
|
||||
|
||||
PortGather = new CommunicationGather(Communication, '\x08');
|
||||
PortGather.IncludeDelimiter = true;
|
||||
PortGather.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);
|
||||
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for TCP
|
||||
/// </summary>
|
||||
public AvocorDisplay(string key, string name, string hostname, int port, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
|
||||
|
||||
PortGather = new CommunicationGather(Communication, '\x0d');
|
||||
PortGather.IncludeDelimiter = true;
|
||||
PortGather.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);
|
||||
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for COM
|
||||
/// </summary>
|
||||
public AvocorDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new ComPortController(key + "-com", port, spec);
|
||||
|
||||
PortGather = new CommunicationGather(Communication, '\x0d');
|
||||
PortGather.IncludeDelimiter = true;
|
||||
PortGather.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);
|
||||
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
void AddRoutingInputPort(RoutingInputPort port, byte fbMatch)
|
||||
{
|
||||
port.FeedbackMatchObject = fbMatch;
|
||||
InputPorts.Add(port);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
WarmupTime = 10000;
|
||||
CooldownTime = 8000;
|
||||
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, StatusGet);
|
||||
DeviceManager.AddDevice(CommunicationMonitor);
|
||||
|
||||
VolumeIncrementer = new ActionIncrementer(655, 0, 65535, 800, 80,
|
||||
v => SetVolume((ushort)v),
|
||||
() => _LastVolumeSent);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), InputHdmi1Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this), InputHdmi2Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this), InputHdmi3Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn4, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi4), this), InputHdmi4Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn5, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi5), this), InputHdmi5Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this), InputDisplayPort1Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Dvi, new Action(InputVga1), this), InputVga1Value);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.IpcOps, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Composite, new Action(InputIpcOps), this), InputIpcOpsValue);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.MediaPlayer, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Vga, new Action(InputMediaPlayer), this), InputMediaPlayerValue);
|
||||
|
||||
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevelForSig; });
|
||||
MuteFeedback = new BoolFeedback(() => _IsMuted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
|
||||
var socket = Communication as ISocketStatus;
|
||||
if (socket != null)
|
||||
{
|
||||
socket.ConnectionChange += new EventHandler<GenericSocketStatusChageEventArgs>(socket_ConnectionChange);
|
||||
}
|
||||
|
||||
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
|
||||
CommunicationMonitor.Start();
|
||||
|
||||
StatusGet();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
|
||||
{
|
||||
if (e.Client.IsConnected)
|
||||
StatusGet();
|
||||
}
|
||||
|
||||
public override FeedbackCollection<Feedback> Feedbacks
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = base.Feedbacks;
|
||||
list.AddRange(new List<Feedback>
|
||||
{
|
||||
VolumeLevelFeedback,
|
||||
MuteFeedback,
|
||||
CurrentInputFeedback
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// /
|
||||
///// </summary>
|
||||
///// <param name="sender"></param>
|
||||
//void Communication_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs e)
|
||||
//{
|
||||
// // This is probably not thread-safe buffering
|
||||
// // Append the incoming bytes with whatever is in the buffer
|
||||
// var newBytes = new byte[IncomingBuffer.Length + e.Bytes.Length];
|
||||
// IncomingBuffer.CopyTo(newBytes, 0);
|
||||
// e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
|
||||
|
||||
// if (Debug.Level == 2) // This check is here to prevent following string format from building unnecessarily on level 0 or 1
|
||||
// Debug.Console(2, this, "Received:{0}", ComTextHelper.GetEscapedText(newBytes));
|
||||
|
||||
// // Need to find AA FF and have
|
||||
// for (int i = 0; i < newBytes.Length; i++)
|
||||
// {
|
||||
// if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
|
||||
// {
|
||||
// newBytes = newBytes.Skip(i).ToArray(); // Trim off junk if there's "dirt" in the buffer
|
||||
|
||||
// // parse it
|
||||
// // If it's at least got the header, then process it,
|
||||
// while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
|
||||
// {
|
||||
// var msgLen = newBytes[3];
|
||||
// // if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
|
||||
// // give and save it for next time
|
||||
// if (newBytes.Length < msgLen + 4)
|
||||
// break;
|
||||
|
||||
// // Good length, grab the message
|
||||
// var message = newBytes.Skip(4).Take(msgLen).ToArray();
|
||||
|
||||
// // At this point, the ack/nak is the first byte
|
||||
// if (message[0] == 0x41)
|
||||
// {
|
||||
// switch (message[1]) // type byte
|
||||
// {
|
||||
// case 0x00: // General status
|
||||
// UpdatePowerFB(message[2], message[5]); // "power" can be misrepresented when the display sleeps
|
||||
// UpdateInputFb(message[5]);
|
||||
// UpdateVolumeFB(message[3]);
|
||||
// UpdateMuteFb(message[4]);
|
||||
// UpdateInputFb(message[5]);
|
||||
// break;
|
||||
|
||||
// case 0x11:
|
||||
// UpdatePowerFB(message[2]);
|
||||
// break;
|
||||
|
||||
// case 0x12:
|
||||
// UpdateVolumeFB(message[2]);
|
||||
// break;
|
||||
|
||||
// case 0x13:
|
||||
// UpdateMuteFb(message[2]);
|
||||
// break;
|
||||
|
||||
// case 0x14:
|
||||
// UpdateInputFb(message[2]);
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// // Skip over what we've used and save the rest for next time
|
||||
// newBytes = newBytes.Skip(5 + msgLen).ToArray();
|
||||
// }
|
||||
|
||||
// break; // parsing will mean we can stop looking for header in loop
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Save whatever partial message is here
|
||||
// IncomingBuffer = newBytes;
|
||||
//}
|
||||
|
||||
void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||
{
|
||||
Debug.Console(1, this, "Receivied: '{0}'", ComTextHelper.GetEscapedText(e.Text));
|
||||
|
||||
if (e.Text.IndexOf("\x50\x4F\x57") > -1)
|
||||
{
|
||||
// Power Status Response
|
||||
|
||||
var value = e.Text.ToCharArray();
|
||||
|
||||
switch (value[6])
|
||||
{
|
||||
case '\x00':
|
||||
{
|
||||
_PowerIsOn = false;
|
||||
break;
|
||||
}
|
||||
case '\x01':
|
||||
{
|
||||
_PowerIsOn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
Debug.Console(1, this, "PowerIsOn State: {0}", PowerIsOnFeedback.BoolValue);
|
||||
|
||||
}
|
||||
else if (e.Text.IndexOf("\x4D\x49\x4E") > -1)
|
||||
{
|
||||
var value = e.Text.ToCharArray();
|
||||
|
||||
var b = value[6];
|
||||
|
||||
var newInput = InputPorts.FirstOrDefault(i => i.FeedbackMatchObject.Equals(b));
|
||||
if (newInput != null && newInput != _CurrentInputPort)
|
||||
{
|
||||
_CurrentInputPort = newInput;
|
||||
CurrentInputFeedback.FireUpdate();
|
||||
Debug.Console(1, this, "Current Input: {0}", CurrentInputFeedback.StringValue);
|
||||
}
|
||||
|
||||
}
|
||||
else if (e.Text.IndexOf("\x56\x4F\x4C") > -1)
|
||||
{
|
||||
// Volume Status Response
|
||||
|
||||
var value = e.Text.ToCharArray();
|
||||
|
||||
var b = value[6];
|
||||
|
||||
var newVol = (ushort)NumericalHelpers.Scale((double)b, 0, 100, 0, 65535);
|
||||
if (!VolumeIsRamping)
|
||||
_LastVolumeSent = newVol;
|
||||
if (newVol != _VolumeLevelForSig)
|
||||
{
|
||||
_VolumeLevelForSig = newVol;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
|
||||
if (_VolumeLevelForSig > 0)
|
||||
_IsMuted = false;
|
||||
else
|
||||
_IsMuted = true;
|
||||
|
||||
MuteFeedback.FireUpdate();
|
||||
|
||||
Debug.Console(1, this, "Volume Level: {0}", VolumeLevelFeedback.IntValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdatePowerFB(byte powerByte)
|
||||
{
|
||||
var newVal = powerByte == 1;
|
||||
if (newVal != _PowerIsOn)
|
||||
{
|
||||
_PowerIsOn = newVal;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates power status from general updates where source is included.
|
||||
/// Compensates for errant standby / power off hiccups by ignoring
|
||||
/// power off states with input < 0x10
|
||||
/// </summary>
|
||||
void UpdatePowerFB(byte powerByte, byte inputByte)
|
||||
{
|
||||
// This should reject errant power feedbacks when switching away from input on standby.
|
||||
if (powerByte == 0x01 && inputByte < 0x10)
|
||||
IsInStandby = true;
|
||||
if (powerByte == 0x00 && IsInStandby) // Ignore power off if coming from standby - glitch
|
||||
{
|
||||
IsInStandby = false;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePowerFB(powerByte);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateVolumeFB(byte b)
|
||||
{
|
||||
var newVol = (ushort)NumericalHelpers.Scale((double)b, 0, 100, 0, 65535);
|
||||
if (!VolumeIsRamping)
|
||||
_LastVolumeSent = newVol;
|
||||
if (newVol != _VolumeLevelForSig)
|
||||
{
|
||||
_VolumeLevelForSig = newVol;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateMuteFb(byte b)
|
||||
{
|
||||
var newMute = b == 1;
|
||||
if (newMute != _IsMuted)
|
||||
{
|
||||
_IsMuted = newMute;
|
||||
MuteFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateInputFb(byte b)
|
||||
{
|
||||
var newInput = InputPorts.FirstOrDefault(i => i.FeedbackMatchObject.Equals(b));
|
||||
if (newInput != null && newInput != _CurrentInputPort)
|
||||
{
|
||||
_CurrentInputPort = newInput;
|
||||
CurrentInputFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats an outgoing message. Replaces third byte with ID and replaces last byte with checksum
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
void SendBytes(byte[] b)
|
||||
{
|
||||
b[1] = ID;
|
||||
|
||||
var command = b.ToString();
|
||||
|
||||
Debug.Console(1, this, "Sending: '{0}'",ComTextHelper.GetEscapedText(b));
|
||||
|
||||
Communication.SendBytes(b);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StatusGet()
|
||||
{
|
||||
PowerGet();
|
||||
|
||||
CrestronEnvironment.Sleep(100);
|
||||
|
||||
InputGet();
|
||||
|
||||
CrestronEnvironment.Sleep(100);
|
||||
|
||||
VolumeGet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override void PowerOn()
|
||||
{
|
||||
//Send(PowerOnCmd);
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x50, 0x4F, 0x57, 0x01, 0x08, 0x0d });
|
||||
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
_IsWarmingUp = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
// Fake power-up cycle
|
||||
WarmupTimer = new CTimer(o =>
|
||||
{
|
||||
_IsWarmingUp = false;
|
||||
_PowerIsOn = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}, WarmupTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override void PowerOff()
|
||||
{
|
||||
// If a display has unreliable-power off feedback, just override this and
|
||||
// remove this check.
|
||||
if (!_IsWarmingUp && !_IsCoolingDown) // PowerIsOnFeedback.BoolValue &&
|
||||
{
|
||||
//Send(PowerOffCmd);
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x50, 0x4F, 0x57, 0x00, 0x08, 0x0d });
|
||||
_IsCoolingDown = true;
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
// Fake cool-down cycle
|
||||
CooldownTimer = new CTimer(o =>
|
||||
{
|
||||
_IsCoolingDown = false;
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
}, CooldownTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerToggle()
|
||||
{
|
||||
if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue)
|
||||
PowerOff();
|
||||
else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue)
|
||||
PowerOn();
|
||||
}
|
||||
|
||||
public void PowerGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x01, 0x50, 0x4F, 0x57, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputHdmi1()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputHdmi1Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputHdmi2()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputHdmi2Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputHdmi3()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputHdmi3Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputHdmi4()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputHdmi4Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputHdmi5()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputHdmi5Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputDisplayPort1()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputDisplayPort1Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputVga1()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputVga1Value, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputIpcOps()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputIpcOpsValue, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputMediaPlayer()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x4D, 0x49, 0x4E, InputMediaPlayerValue, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void InputGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x01, 0x4D, 0x49, 0x4E, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
public void VolumeGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0x07, ID, 0x01, 0x56, 0x4F, 0x4C, 0x08, 0x0d });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Executes a switch, turning on display if necessary.
|
||||
/// </summary>
|
||||
/// <param name="selector"></param>
|
||||
public override void ExecuteSwitch(object selector)
|
||||
{
|
||||
//if (!(selector is Action))
|
||||
// Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType());
|
||||
|
||||
if (_PowerIsOn)
|
||||
(selector as Action)();
|
||||
else // if power is off, wait until we get on FB to send it.
|
||||
{
|
||||
// One-time event handler to wait for power on before executing switch
|
||||
EventHandler<FeedbackEventArgs> handler = null; // necessary to allow reference inside lambda to handler
|
||||
handler = (o, a) =>
|
||||
{
|
||||
if (!_IsWarmingUp) // Done warming
|
||||
{
|
||||
IsWarmingUpFeedback.OutputChange -= handler;
|
||||
(selector as Action)();
|
||||
}
|
||||
};
|
||||
IsWarmingUpFeedback.OutputChange += handler; // attach and wait for on FB
|
||||
PowerOn();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales the level to the range of the display and sends the command
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
_LastVolumeSent = level;
|
||||
var scaled = (int)NumericalHelpers.Scale(level, 0, 65535, 0, 100);
|
||||
// The inputs to Scale ensure that byte won't overflow
|
||||
SendBytes(new byte[] { 0x07, ID, 0x02, 0x56, 0x4F, 0x4C, Convert.ToByte(scaled), 0x08, 0x0d });
|
||||
}
|
||||
|
||||
#region IBasicVolumeWithFeedback Members
|
||||
|
||||
public IntFeedback VolumeLevelFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteOff()
|
||||
{
|
||||
SetVolume(_PreMuteVolumeLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteOn()
|
||||
{
|
||||
_PreMuteVolumeLevel = _VolumeLevelForSig;
|
||||
|
||||
SetVolume(0);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
/////
|
||||
///// </summary>
|
||||
//public void MuteGet()
|
||||
//{
|
||||
// SendBytes(new byte[] { 0x07, ID, 0x01, });
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IBasicVolumeControls Members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteToggle()
|
||||
{
|
||||
if (_IsMuted)
|
||||
MuteOff();
|
||||
else
|
||||
MuteOn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeDown(bool pressRelease)
|
||||
{
|
||||
if (pressRelease)
|
||||
{
|
||||
VolumeIncrementer.StartDown();
|
||||
VolumeIsRamping = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
VolumeIsRamping = false;
|
||||
VolumeIncrementer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeUp(bool pressRelease)
|
||||
{
|
||||
if (pressRelease)
|
||||
{
|
||||
VolumeIncrementer.StartUp();
|
||||
VolumeIsRamping = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
VolumeIsRamping = false;
|
||||
VolumeIncrementer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class AvocorDisplayFactory : EssentialsDeviceFactory<AvocorDisplay>
|
||||
{
|
||||
public AvocorDisplayFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "avocorvtf" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
if (comm != null)
|
||||
return new AvocorDisplay(dc.Key, dc.Name, comm, null);
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
[Obsolete("Please use TwoWayDisplayBase instead")]
|
||||
public abstract class ComTcpDisplayBase : TwoWayDisplayBase
|
||||
{
|
||||
|
||||
///// <summary>
|
||||
///// Sets the communication method for this - swaps out event handlers and output handlers
|
||||
///// </summary>
|
||||
//public IBasicCommunication CommunicationMethod
|
||||
//{
|
||||
// get { return _CommunicationMethod; }
|
||||
// set
|
||||
// {
|
||||
// if (_CommunicationMethod != null)
|
||||
// _CommunicationMethod.BytesReceived -= this.CommunicationMethod_BytesReceived;
|
||||
// // Outputs???
|
||||
// _CommunicationMethod = value;
|
||||
// if (_CommunicationMethod != null)
|
||||
// _CommunicationMethod.BytesReceived += this.CommunicationMethod_BytesReceived;
|
||||
// // Outputs?
|
||||
// }
|
||||
//}
|
||||
//IBasicCommunication _CommunicationMethod;
|
||||
|
||||
public ComTcpDisplayBase(string key, string name)
|
||||
: base(key, name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//protected abstract void CommunicationMethod_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputDisplayPort1 { void InputDisplayPort1(); }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputDisplayPort2 { void InputDisplayPort2(); }
|
||||
}
|
||||
@@ -4,9 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash_Essentials_Core.Gateways
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public class CenCn2Controller
|
||||
{
|
||||
}
|
||||
public interface IInputHdmi1 { void InputHdmi1(); }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputHdmi2 { void InputHdmi2(); }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputHdmi3 { void InputHdmi3(); }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputHdmi4 { void InputHdmi4(); }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputVga1 { void InputVga1(); }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
public interface IInputHdmi1 { void InputHdmi1(); }
|
||||
public interface IInputHdmi2 { void InputHdmi2(); }
|
||||
public interface IInputHdmi3 { void InputHdmi3(); }
|
||||
public interface IInputHdmi4 { void InputHdmi4(); }
|
||||
public interface IInputDisplayPort1 { void InputDisplayPort1(); }
|
||||
public interface IInputDisplayPort2 { void InputDisplayPort2(); }
|
||||
public interface IInputVga1 { void InputVga1(); }
|
||||
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Routing;
|
||||
using Feedback = PepperDash.Essentials.Core.Feedback;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class NecPSXMDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor, IBridgeAdvanced
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
public CommunicationGather PortGather { get; private set; }
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
#region Command constants
|
||||
public const string InputGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x30\x03\x03\x0D";
|
||||
public const string Hdmi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x31\x03\x72\x0d";
|
||||
public const string Hdmi2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x32\x03\x71\x0D";
|
||||
public const string Hdmi3Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x32\x03\x78\x0D";
|
||||
public const string Hdmi4Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x33\x03\x79\x0D";
|
||||
public const string Dp1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x46\x03\x04\x0D";
|
||||
public const string Dp2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x30\x03\x73\x0D";
|
||||
public const string Dvi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x33\x03\x71\x0d";
|
||||
public const string Video1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x35\x03\x77\x0D";
|
||||
public const string VgaCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x31\x03\x73\x0D";
|
||||
public const string RgbCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x32\x03\x70\x0D";
|
||||
|
||||
public const string PowerOnCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x31\x03\x73\x0D";
|
||||
public const string PowerOffCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x34\x03\x76\x0D";
|
||||
public const string PowerToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x30\x33\x30\x33\x03\x02\x0D";
|
||||
|
||||
public const string MuteOffCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x30\x03\x08\x0D";
|
||||
public const string MuteOnCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x31\x03\x09\x0D";
|
||||
public const string MuteToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x42\x30\x33\x03\x72\x0D";
|
||||
public const string MuteGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x38\x44\x03\x79\x0D";
|
||||
|
||||
public const string VolumeGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x32\x03\x01\x0D";
|
||||
public const string VolumeLevelPartialCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x32"; //\x46\x46\x46\x46\x03\xNN\x0D
|
||||
public const string VolumeUpCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x31\x03\x71\x0D";
|
||||
public const string VolumeDownCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x32\x03\x72\x0D";
|
||||
|
||||
public const string MenuIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x30\x30\x33\x03\x03\x0D";
|
||||
public const string UpIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x35\x30\x33\x03\x05\x0D";
|
||||
public const string DownIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x34\x30\x33\x03\x04\x0D";
|
||||
public const string LeftIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x31\x30\x33\x03\x02\x0D";
|
||||
public const string RightIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x32\x30\x33\x03\x01\x0D";
|
||||
public const string SelectIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x33\x30\x33\x03\x00\x0D";
|
||||
public const string ExitIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x46\x30\x33\x03\x76\x0D";
|
||||
#endregion
|
||||
|
||||
bool _PowerIsOn;
|
||||
bool _IsWarmingUp;
|
||||
bool _IsCoolingDown;
|
||||
ushort _VolumeLevel;
|
||||
bool _IsMuted;
|
||||
|
||||
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
|
||||
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
|
||||
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
|
||||
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IBasicCommunication
|
||||
/// </summary>
|
||||
public NecPSXMDisplay(string key, string name, IBasicCommunication comm)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = comm;
|
||||
Init();
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor for TCP
|
||||
/// </summary>
|
||||
public NecPSXMDisplay(string key, string name, string hostname, int port)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for COM
|
||||
/// </summary>
|
||||
public NecPSXMDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new ComPortController(key + "-com", port, spec);
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
PortGather = new CommunicationGather(Communication, '\x0d');
|
||||
PortGather.LineReceived += this.Port_LineReceived;
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, "xx\x0d");
|
||||
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn4, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi4), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort2), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Vga, new Action(InputVga), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.RgbIn, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb)), this));
|
||||
|
||||
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; });
|
||||
MuteFeedback = new BoolFeedback(() => _IsMuted);
|
||||
|
||||
// new BoolCueActionPair(CommonBoolCue.Menu, b => { if(b) Send(MenuIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Up, b => { if(b) Send(UpIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Down, b => { if(b) Send(DownIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Left, b => { if(b) Send(LeftIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Right, b => { if(b) Send(RightIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Select, b => { if(b) Send(SelectIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Exit, b => { if(b) Send(ExitIrCmd); }),
|
||||
//};
|
||||
}
|
||||
|
||||
~NecPSXMDisplay()
|
||||
{
|
||||
PortGather = null;
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
|
||||
CommunicationMonitor.Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
public override FeedbackCollection<Feedback> Feedbacks
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = base.Feedbacks;
|
||||
list.AddRange(new List<Feedback>
|
||||
{
|
||||
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
|
||||
|
||||
if (args.Text=="DO SOMETHING HERE EVENTUALLY")
|
||||
{
|
||||
_IsMuted = true;
|
||||
MuteFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void AppendChecksumAndSend(string s)
|
||||
{
|
||||
int x = 0;
|
||||
for (int i = 1; i < s.Length; i++)
|
||||
x = x ^ s[i];
|
||||
|
||||
string send = s + (char)x + '\x0d';
|
||||
Send(send);
|
||||
}
|
||||
|
||||
void Send(string s)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(s));
|
||||
Communication.SendText(s);
|
||||
}
|
||||
|
||||
|
||||
public override void PowerOn()
|
||||
{
|
||||
Send(PowerOnCmd);
|
||||
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
_IsWarmingUp = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
// Fake power-up cycle
|
||||
WarmupTimer = new CTimer(o =>
|
||||
{
|
||||
_IsWarmingUp = false;
|
||||
_PowerIsOn = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}, WarmupTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerOff()
|
||||
{
|
||||
// If a display has unreliable-power off feedback, just override this and
|
||||
// remove this check.
|
||||
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
Send(PowerOffCmd);
|
||||
_IsCoolingDown = true;
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
// Fake cool-down cycle
|
||||
CooldownTimer = new CTimer(o =>
|
||||
{
|
||||
Debug.Console(2, this, "Cooldown timer ending");
|
||||
_IsCoolingDown = false;
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
}, CooldownTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerToggle()
|
||||
{
|
||||
if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue)
|
||||
PowerOff();
|
||||
else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue)
|
||||
PowerOn();
|
||||
}
|
||||
|
||||
public void InputHdmi1()
|
||||
{
|
||||
Send(Hdmi1Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi2()
|
||||
{
|
||||
Send(Hdmi2Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi3()
|
||||
{
|
||||
Send(Hdmi3Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi4()
|
||||
{
|
||||
Send(Hdmi4Cmd);
|
||||
}
|
||||
|
||||
public void InputDisplayPort1()
|
||||
{
|
||||
Send(Dp1Cmd);
|
||||
}
|
||||
|
||||
public void InputDisplayPort2()
|
||||
{
|
||||
Send(Dp2Cmd);
|
||||
}
|
||||
|
||||
public void InputDvi1()
|
||||
{
|
||||
Send(Dvi1Cmd);
|
||||
}
|
||||
|
||||
public void InputVideo1()
|
||||
{
|
||||
Send(Video1Cmd);
|
||||
}
|
||||
|
||||
public void InputVga()
|
||||
{
|
||||
Send(VgaCmd);
|
||||
}
|
||||
|
||||
public void InputRgb()
|
||||
{
|
||||
Send(RgbCmd);
|
||||
}
|
||||
|
||||
public override void ExecuteSwitch(object selector)
|
||||
{
|
||||
if (selector is Action)
|
||||
(selector as Action).Invoke();
|
||||
else
|
||||
Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType());
|
||||
//Send((string)selector);
|
||||
}
|
||||
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
var levelString = string.Format("{0}{1:X4}\x03", VolumeLevelPartialCmd, level);
|
||||
AppendChecksumAndSend(levelString);
|
||||
//Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString));
|
||||
_VolumeLevel = level;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
#region IBasicVolumeWithFeedback Members
|
||||
|
||||
public IntFeedback VolumeLevelFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
|
||||
public void MuteOff()
|
||||
{
|
||||
Send(MuteOffCmd);
|
||||
}
|
||||
|
||||
public void MuteOn()
|
||||
{
|
||||
Send(MuteOnCmd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void IBasicVolumeWithFeedback.SetVolume(ushort level)
|
||||
{
|
||||
SetVolume(level);
|
||||
}
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region IBasicVolumeControls Members
|
||||
|
||||
public void MuteToggle()
|
||||
{
|
||||
Send(MuteToggleIrCmd);
|
||||
}
|
||||
|
||||
public void VolumeDown(bool pressRelease)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
//#warning need incrementer for these
|
||||
SetVolume(_VolumeLevel++);
|
||||
}
|
||||
|
||||
public void VolumeUp(bool pressRelease)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
SetVolume(_VolumeLevel--);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class NecPSXMDisplayFactory : EssentialsDeviceFactory<NecPSXMDisplay>
|
||||
{
|
||||
public NecPSXMDisplayFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "necmpsx" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
if (comm != null)
|
||||
return new NecPSXMDisplay(dc.Key, dc.Name, comm);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
//public class NecPaSeriesProjector : TwoWayDisplayBase, IBridgeAdvanced
|
||||
//{
|
||||
// public readonly IntFeedback Lamp1RemainingPercent;
|
||||
// int _Lamp1RemainingPercent;
|
||||
// public readonly IntFeedback Lamp2RemainingPercent;
|
||||
// int _Lamp2RemainingPercent;
|
||||
|
||||
// RoutingInputPort _CurrentInputPort;
|
||||
|
||||
// protected override Func<string> CurrentInputFeedbackFunc { get { return () => _CurrentInputPort.Key; } }
|
||||
|
||||
// protected override Func<bool> PowerIsOnFeedbackFunc
|
||||
// {
|
||||
// get { return () => _PowerIsOn; }
|
||||
// }
|
||||
// bool _PowerIsOn;
|
||||
|
||||
// protected override Func<bool> IsCoolingDownFeedbackFunc
|
||||
// {
|
||||
// get { return () => false; }
|
||||
// }
|
||||
|
||||
// protected override Func<bool> IsWarmingUpFeedbackFunc
|
||||
// {
|
||||
// get { return () => false; }
|
||||
// }
|
||||
|
||||
// public override void PowerToggle()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void ExecuteSwitch(object selector)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// Dictionary<string, string> InputMap;
|
||||
|
||||
// /// <summary>
|
||||
// /// Constructor
|
||||
// /// </summary>
|
||||
// public NecPaSeriesProjector(string key, string name)
|
||||
// : base(key, name)
|
||||
// {
|
||||
// Lamp1RemainingPercent = new IntFeedback("Lamp1RemainingPercent", () => _Lamp1RemainingPercent);
|
||||
// Lamp2RemainingPercent = new IntFeedback("Lamp2RemainingPercent", () => _Lamp2RemainingPercent);
|
||||
|
||||
// InputMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
// {
|
||||
// { "computer1", "\x02\x03\x00\x00\x02\x01\x01\x09" },
|
||||
// { "computer2", "\x02\x03\x00\x00\x02\x01\x02\x0a" },
|
||||
// { "computer3", "\x02\x03\x00\x00\x02\x01\x03\x0b" },
|
||||
// { "hdmi", "\x02\x03\x00\x00\x02\x01\x1a\x22" },
|
||||
// { "dp", "\x02\x03\x00\x00\x02\x01\x1b\x23" },
|
||||
// { "video", "\x02\x03\x00\x00\x02\x01\x06\x0e" },
|
||||
// { "viewer", "\x02\x03\x00\x00\x02\x01\x1f\x27" },
|
||||
// { "network", "\x02\x03\x00\x00\x02\x01\x20\x28" },
|
||||
// };
|
||||
// }
|
||||
|
||||
// void IsConnected_OutputChange(object sender, EventArgs e)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
// public void SetEnable(bool state)
|
||||
// {
|
||||
// var tcp = CommunicationMethod as GenericTcpIpClient;
|
||||
// if (tcp != null)
|
||||
// {
|
||||
// tcp.Connect();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public override void PowerOn()
|
||||
// {
|
||||
// SendText("\x02\x00\x00\x00\x00\x02");
|
||||
// }
|
||||
|
||||
// public override void PowerOff()
|
||||
// {
|
||||
// SendText("\x02\x01\x00\x00\x00\x03");
|
||||
// }
|
||||
|
||||
// public void PictureMuteOn()
|
||||
// {
|
||||
// SendText("\x02\x10\x00\x00\x00\x12");
|
||||
// }
|
||||
|
||||
// public void PictureMuteOff()
|
||||
// {
|
||||
// SendText("\x02\x11\x00\x00\x00\x13");
|
||||
// }
|
||||
|
||||
// public void GetRunningStatus()
|
||||
// {
|
||||
// SendText("\x00\x85\x00\x00\x01\x01\x87");
|
||||
// }
|
||||
|
||||
// public void GetLampRemaining(int lampNum)
|
||||
// {
|
||||
// if (!_PowerIsOn) return;
|
||||
|
||||
// var bytes = new byte[]{0x03,0x96,0x00,0x00,0x02,0x00,0x04};
|
||||
// if (lampNum == 2)
|
||||
// bytes[5] = 0x01;
|
||||
// SendBytes(AppendChecksum(bytes));
|
||||
// }
|
||||
|
||||
// public void SelectInput(string inputKey)
|
||||
// {
|
||||
// if (InputMap.ContainsKey(inputKey))
|
||||
// SendText(InputMap[inputKey]);
|
||||
// }
|
||||
|
||||
// void SendText(string text)
|
||||
// {
|
||||
// if (CommunicationMethod != null)
|
||||
// CommunicationMethod.SendText(text);
|
||||
// }
|
||||
|
||||
// void SendBytes(byte[] bytes)
|
||||
// {
|
||||
// if (CommunicationMethod != null)
|
||||
// CommunicationMethod.SendBytes(bytes);
|
||||
// }
|
||||
|
||||
// byte[] AppendChecksum(byte[] bytes)
|
||||
// {
|
||||
// byte sum = unchecked((byte)bytes.Sum(x => (int)x));
|
||||
// var retVal = new byte[bytes.Length + 1];
|
||||
// bytes.CopyTo(retVal, 0);
|
||||
// retVal[retVal.Length - 1] = sum;
|
||||
// return retVal;
|
||||
// }
|
||||
|
||||
// protected override void CommunicationMethod_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs args)
|
||||
// {
|
||||
// var bytes = args.Bytes;
|
||||
// ParseBytes(args.Bytes);
|
||||
// }
|
||||
|
||||
// void ParseBytes(byte[] bytes)
|
||||
// {
|
||||
// if (bytes[0] == 0x22)
|
||||
// {
|
||||
// // Power on
|
||||
// if (bytes[1] == 0x00)
|
||||
// {
|
||||
// _PowerIsOn = true;
|
||||
// PowerIsOnFeedback.FireUpdate();
|
||||
// }
|
||||
// // Power off
|
||||
// else if (bytes[1] == 0x01)
|
||||
// {
|
||||
// _PowerIsOn = false;
|
||||
// PowerIsOnFeedback.FireUpdate();
|
||||
// }
|
||||
// }
|
||||
// // Running Status
|
||||
// else if (bytes[0] == 0x20 && bytes[1] == 0x85 && bytes[4] == 0x10)
|
||||
// {
|
||||
// var operationStates = new Dictionary<int, string>
|
||||
// {
|
||||
// { 0x00, "Standby" },
|
||||
// { 0x04, "Power On" },
|
||||
// { 0x05, "Cooling" },
|
||||
// { 0x06, "Standby (error)" },
|
||||
// { 0x0f, "Standby (power saving" },
|
||||
// { 0x10, "Network Standby" },
|
||||
// { 0xff, "Not supported" }
|
||||
// };
|
||||
|
||||
// var newPowerIsOn = bytes[7] == 0x01;
|
||||
// if (newPowerIsOn != _PowerIsOn)
|
||||
// {
|
||||
// _PowerIsOn = newPowerIsOn;
|
||||
// PowerIsOnFeedback.FireUpdate();
|
||||
// }
|
||||
|
||||
// Debug.Console(2, this, "PowerIsOn={0}\rCooling={1}\rPowering on/off={2}\rStatus={3}",
|
||||
// _PowerIsOn,
|
||||
// bytes[8] == 0x01,
|
||||
// bytes[9] == 0x01,
|
||||
// operationStates[bytes[10]]);
|
||||
|
||||
// }
|
||||
// // Lamp remaining
|
||||
// else if (bytes[0] == 0x23 && bytes[1] == 0x96 && bytes[4] == 0x06 && bytes[6] == 0x04)
|
||||
// {
|
||||
// var newValue = bytes[7];
|
||||
// if (bytes[5] == 0x00)
|
||||
// {
|
||||
// if (newValue != _Lamp1RemainingPercent)
|
||||
// {
|
||||
// _Lamp1RemainingPercent = newValue;
|
||||
// Lamp1RemainingPercent.FireUpdate();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (newValue != _Lamp2RemainingPercent)
|
||||
// {
|
||||
// _Lamp2RemainingPercent = newValue;
|
||||
// Lamp2RemainingPercent.FireUpdate();
|
||||
// }
|
||||
// }
|
||||
// Debug.Console(0, this, "Lamp {0}, {1}% remaining", (bytes[5] + 1), bytes[7]);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
// {
|
||||
// LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -1,367 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Routing;
|
||||
using Feedback = PepperDash.Essentials.Core.Feedback;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PanasonicThDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor, IBridgeAdvanced
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
public CommunicationGather PortGather { get; private set; }
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
#region Command constants
|
||||
public const string InputGetCmd = "\x02QMI\x03";
|
||||
public const string Hdmi1Cmd = "\x02IMS:HM1\x03";
|
||||
public const string Hdmi2Cmd = "\x02IMS:HM2\x03";
|
||||
public const string Hdmi3Cmd = "";
|
||||
public const string Hdmi4Cmd = "";
|
||||
public const string Dp1Cmd = "";
|
||||
public const string Dp2Cmd = "";
|
||||
public const string Dvi1Cmd = "\x02IMS:DV1";
|
||||
public const string Video1Cmd = "";
|
||||
public const string VgaCmd = "";
|
||||
public const string RgbCmd = "";
|
||||
|
||||
public const string PowerOnCmd = "\x02PON\x03";
|
||||
public const string PowerOffCmd = "\x02POF\x03";
|
||||
public const string PowerToggleIrCmd = "";
|
||||
|
||||
public const string MuteOffCmd = "\x02AMT:0\x03";
|
||||
public const string MuteOnCmd = "\x02AMT:1\x03";
|
||||
public const string MuteToggleIrCmd = "\x02AMT\x03";
|
||||
public const string MuteGetCmd = "\x02QAM\x03";
|
||||
|
||||
public const string VolumeGetCmd = "\x02QAV\x03";
|
||||
public const string VolumeLevelPartialCmd = "\x02AVL:"; //
|
||||
public const string VolumeUpCmd = "\x02AUU\x03";
|
||||
public const string VolumeDownCmd = "\x02AUD\x03";
|
||||
|
||||
public const string MenuIrCmd = "";
|
||||
public const string UpIrCmd = "";
|
||||
public const string DownIrCmd = "";
|
||||
public const string LeftIrCmd = "";
|
||||
public const string RightIrCmd = "";
|
||||
public const string SelectIrCmd = "";
|
||||
public const string ExitIrCmd = "";
|
||||
#endregion
|
||||
|
||||
bool _PowerIsOn;
|
||||
bool _IsWarmingUp;
|
||||
bool _IsCoolingDown;
|
||||
ushort _VolumeLevel;
|
||||
bool _IsMuted;
|
||||
|
||||
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
|
||||
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
|
||||
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
|
||||
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IBasicCommunication
|
||||
/// </summary>
|
||||
public PanasonicThDisplay(string key, string name, IBasicCommunication comm)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = comm;
|
||||
Init();
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor for TCP
|
||||
/// </summary>
|
||||
public PanasonicThDisplay(string key, string name, string hostname, int port)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for COM
|
||||
/// </summary>
|
||||
public PanasonicThDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new ComPortController(key + "-com", port, spec);
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
PortGather = new CommunicationGather(Communication, '\x0d');
|
||||
PortGather.LineReceived += this.Port_LineReceived;
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, "\x02QPW\x03"); // Query Power
|
||||
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this));
|
||||
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this));
|
||||
InputPorts.Add(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Vga, new Action(InputVga), this));
|
||||
|
||||
|
||||
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; });
|
||||
MuteFeedback = new BoolFeedback(() => _IsMuted);
|
||||
|
||||
// new BoolCueActionPair(CommonBoolCue.Menu, b => { if(b) Send(MenuIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Up, b => { if(b) Send(UpIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Down, b => { if(b) Send(DownIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Left, b => { if(b) Send(LeftIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Right, b => { if(b) Send(RightIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Select, b => { if(b) Send(SelectIrCmd); }),
|
||||
// new BoolCueActionPair(CommonBoolCue.Exit, b => { if(b) Send(ExitIrCmd); }),
|
||||
//};
|
||||
}
|
||||
|
||||
~PanasonicThDisplay()
|
||||
{
|
||||
PortGather = null;
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
|
||||
CommunicationMonitor.Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
public override FeedbackCollection<Feedback> Feedbacks
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = base.Feedbacks;
|
||||
list.AddRange(new List<Feedback>
|
||||
{
|
||||
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
|
||||
|
||||
if (args.Text=="DO SOMETHING HERE EVENTUALLY")
|
||||
{
|
||||
_IsMuted = true;
|
||||
MuteFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void Send(string s)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(s));
|
||||
Communication.SendText(s);
|
||||
}
|
||||
|
||||
|
||||
public override void PowerOn()
|
||||
{
|
||||
Send(PowerOnCmd);
|
||||
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
_IsWarmingUp = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
// Fake power-up cycle
|
||||
WarmupTimer = new CTimer(o =>
|
||||
{
|
||||
_IsWarmingUp = false;
|
||||
_PowerIsOn = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}, WarmupTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerOff()
|
||||
{
|
||||
// If a display has unreliable-power off feedback, just override this and
|
||||
// remove this check.
|
||||
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
Send(PowerOffCmd);
|
||||
_IsCoolingDown = true;
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
// Fake cool-down cycle
|
||||
CooldownTimer = new CTimer(o =>
|
||||
{
|
||||
Debug.Console(2, this, "Cooldown timer ending");
|
||||
_IsCoolingDown = false;
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
}, CooldownTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerToggle()
|
||||
{
|
||||
if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue)
|
||||
PowerOff();
|
||||
else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue)
|
||||
PowerOn();
|
||||
}
|
||||
|
||||
public void InputHdmi1()
|
||||
{
|
||||
Send(Hdmi1Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi2()
|
||||
{
|
||||
Send(Hdmi2Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi3()
|
||||
{
|
||||
Send(Hdmi3Cmd);
|
||||
}
|
||||
|
||||
public void InputHdmi4()
|
||||
{
|
||||
Send(Hdmi4Cmd);
|
||||
}
|
||||
|
||||
public void InputDisplayPort1()
|
||||
{
|
||||
Send(Dp1Cmd);
|
||||
}
|
||||
|
||||
public void InputDisplayPort2()
|
||||
{
|
||||
Send(Dp2Cmd);
|
||||
}
|
||||
|
||||
public void InputDvi1()
|
||||
{
|
||||
Send(Dvi1Cmd);
|
||||
}
|
||||
|
||||
public void InputVideo1()
|
||||
{
|
||||
Send(Video1Cmd);
|
||||
}
|
||||
|
||||
public void InputVga()
|
||||
{
|
||||
Send(VgaCmd);
|
||||
}
|
||||
|
||||
public void InputRgb()
|
||||
{
|
||||
Send(RgbCmd);
|
||||
}
|
||||
|
||||
public override void ExecuteSwitch(object selector)
|
||||
{
|
||||
if (selector is Action)
|
||||
(selector as Action).Invoke();
|
||||
else
|
||||
Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType());
|
||||
//Send((string)selector);
|
||||
}
|
||||
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
var levelString = string.Format("{0}{1:X3}\x03", VolumeLevelPartialCmd, level);
|
||||
|
||||
//Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString));
|
||||
_VolumeLevel = level;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
}
|
||||
|
||||
#region IBasicVolumeWithFeedback Members
|
||||
|
||||
public IntFeedback VolumeLevelFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
|
||||
public void MuteOff()
|
||||
{
|
||||
Send(MuteOffCmd);
|
||||
}
|
||||
|
||||
public void MuteOn()
|
||||
{
|
||||
Send(MuteOnCmd);
|
||||
}
|
||||
|
||||
/*
|
||||
void IBasicVolumeWithFeedback.SetVolume(ushort level)
|
||||
{
|
||||
SetVolume(level);
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region IBasicVolumeControls Members
|
||||
|
||||
public void MuteToggle()
|
||||
{
|
||||
Send(MuteToggleIrCmd);
|
||||
}
|
||||
|
||||
public void VolumeDown(bool pressRelease)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
//#warning need incrementer for these
|
||||
SetVolume(_VolumeLevel++);
|
||||
}
|
||||
|
||||
public void VolumeUp(bool pressRelease)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
SetVolume(_VolumeLevel--);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class PanasonicThDisplayFactory : EssentialsDeviceFactory<PanasonicThDisplay>
|
||||
{
|
||||
public PanasonicThDisplayFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "panasonicthef" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
if (comm != null)
|
||||
return new PanasonicThDisplay(dc.Key, dc.Name, comm);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,665 +0,0 @@
|
||||
extern alias Full;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.CrestronThread;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Routing;
|
||||
using Feedback = PepperDash.Essentials.Core.Feedback;
|
||||
|
||||
using Full.Newtonsoft.Json.Linq;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Displays
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class SamsungMDC : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor, IInputDisplayPort1, IInputDisplayPort2,
|
||||
IInputHdmi1, IInputHdmi2, IInputHdmi3, IInputHdmi4, IBridgeAdvanced
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
|
||||
|
||||
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
public byte ID { get; private set; }
|
||||
|
||||
bool LastCommandSentWasVolume;
|
||||
|
||||
bool _PowerIsOn;
|
||||
bool _IsWarmingUp;
|
||||
bool _IsCoolingDown;
|
||||
ushort _VolumeLevelForSig;
|
||||
int _LastVolumeSent;
|
||||
bool _IsMuted;
|
||||
RoutingInputPort _CurrentInputPort;
|
||||
byte[] IncomingBuffer = new byte[]{};
|
||||
ActionIncrementer VolumeIncrementer;
|
||||
bool VolumeIsRamping;
|
||||
public bool IsInStandby { get; private set; }
|
||||
bool IsPoweringOnIgnorePowerFb;
|
||||
|
||||
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
|
||||
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
|
||||
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
|
||||
protected override Func<string> CurrentInputFeedbackFunc { get { return () => _CurrentInputPort.Key; } }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IBasicCommunication
|
||||
/// </summary>
|
||||
public SamsungMDC(string key, string name, IBasicCommunication comm, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = comm;
|
||||
Communication.BytesReceived += new EventHandler<GenericCommMethodReceiveBytesArgs>(Communication_BytesReceived);
|
||||
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for TCP
|
||||
/// </summary>
|
||||
public SamsungMDC(string key, string name, string hostname, int port, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for COM
|
||||
/// </summary>
|
||||
public SamsungMDC(string key, string name, ComPort port, ComPort.ComPortSpec spec, string id)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = new ComPortController(key + "-com", port, spec);
|
||||
//Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
|
||||
|
||||
ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
|
||||
Init();
|
||||
}
|
||||
|
||||
void AddRoutingInputPort(RoutingInputPort port, byte fbMatch)
|
||||
{
|
||||
port.FeedbackMatchObject = fbMatch;
|
||||
InputPorts.Add(port);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
WarmupTime = 10000;
|
||||
CooldownTime = 8000;
|
||||
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 2000, 120000, 300000, StatusGet, true);
|
||||
DeviceManager.AddDevice(CommunicationMonitor);
|
||||
|
||||
VolumeIncrementer = new ActionIncrementer(655, 0, 65535, 800, 80,
|
||||
v => SetVolume((ushort)v),
|
||||
() => _LastVolumeSent);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), 0x21);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1PC, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1PC), this), 0x22);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this), 0x23);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2PC, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2PC), this), 0x24);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this), 0x32);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this), 0x25);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this), 0x18);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.Audio | eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this), 0x08);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn1, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Vga, new Action(InputRgb1), this), 0x14);
|
||||
|
||||
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn2, eRoutingSignalType.Video,
|
||||
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this), 0x1E);
|
||||
|
||||
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevelForSig; });
|
||||
MuteFeedback = new BoolFeedback(() => _IsMuted);
|
||||
|
||||
StatusGet();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
CommunicationMonitor.StatusChange += (o, a) => Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status);
|
||||
CommunicationMonitor.Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
}
|
||||
|
||||
public override FeedbackCollection<Feedback> Feedbacks
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = base.Feedbacks;
|
||||
list.AddRange(new List<Feedback>
|
||||
{
|
||||
VolumeLevelFeedback,
|
||||
MuteFeedback,
|
||||
CurrentInputFeedback
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
void Communication_BytesReceived(object sender, GenericCommMethodReceiveBytesArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// This is probably not thread-safe buffering
|
||||
// Append the incoming bytes with whatever is in the buffer
|
||||
var newBytes = new byte[IncomingBuffer.Length + e.Bytes.Length];
|
||||
IncomingBuffer.CopyTo(newBytes, 0);
|
||||
e.Bytes.CopyTo(newBytes, IncomingBuffer.Length);
|
||||
|
||||
// Need to find AA FF and have
|
||||
for (int i = 0; i < newBytes.Length; i++)
|
||||
{
|
||||
if (newBytes[i] == 0xAA && newBytes[i + 1] == 0xFF)
|
||||
{
|
||||
newBytes = newBytes.Skip(i).ToArray(); // Trim off junk if there's "dirt" in the buffer
|
||||
|
||||
// parse it
|
||||
// If it's at least got the header, then process it,
|
||||
while (newBytes.Length > 4 && newBytes[0] == 0xAA && newBytes[1] == 0xFF)
|
||||
{
|
||||
var msgLen = newBytes[3];
|
||||
// if the buffer is shorter than the header (3) + message (msgLen) + checksum (1),
|
||||
// give and save it for next time
|
||||
if (newBytes.Length < msgLen + 4)
|
||||
break;
|
||||
|
||||
// Good length, grab the message
|
||||
var message = newBytes.Skip(4).Take(msgLen).ToArray();
|
||||
|
||||
// At this point, the ack/nak is the first byte
|
||||
if (message[0] == 0x41)
|
||||
{
|
||||
switch (message[1]) // type byte
|
||||
{
|
||||
case 0x00: // General status
|
||||
//UpdatePowerFB(message[2], message[5]); // "power" can be misrepresented when the display sleeps
|
||||
|
||||
// Handle the first power on fb when waiting for it.
|
||||
if (IsPoweringOnIgnorePowerFb && message[2] == 0x01)
|
||||
IsPoweringOnIgnorePowerFb = false;
|
||||
// Ignore general-status power off messages when powering up
|
||||
if (!(IsPoweringOnIgnorePowerFb && message[2] == 0x00))
|
||||
UpdatePowerFB(message[2]);
|
||||
UpdateVolumeFB(message[3]);
|
||||
UpdateMuteFb(message[4]);
|
||||
UpdateInputFb(message[5]);
|
||||
break;
|
||||
|
||||
case 0x11:
|
||||
UpdatePowerFB(message[2]);
|
||||
break;
|
||||
|
||||
case 0x12:
|
||||
UpdateVolumeFB(message[2]);
|
||||
break;
|
||||
|
||||
case 0x13:
|
||||
UpdateMuteFb(message[2]);
|
||||
break;
|
||||
|
||||
case 0x14:
|
||||
UpdateInputFb(message[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Skip over what we've used and save the rest for next time
|
||||
newBytes = newBytes.Skip(5 + msgLen).ToArray();
|
||||
}
|
||||
|
||||
break; // parsing will mean we can stop looking for header in loop
|
||||
}
|
||||
}
|
||||
|
||||
// Save whatever partial message is here
|
||||
IncomingBuffer = newBytes;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Debug.Console(2, this, "Error parsing feedback: {0}", err);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdatePowerFB(byte powerByte)
|
||||
{
|
||||
var newVal = powerByte == 1;
|
||||
if (newVal != _PowerIsOn)
|
||||
{
|
||||
_PowerIsOn = newVal;
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Feedback Power State: {0}", _PowerIsOn);
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates power status from general updates where source is included.
|
||||
/// Compensates for errant standby / power off hiccups by ignoring
|
||||
/// power off states with input < 0x10
|
||||
/// </summary>
|
||||
void UpdatePowerFB(byte powerByte, byte inputByte)
|
||||
{
|
||||
// This should reject errant power feedbacks when switching away from input on standby.
|
||||
if (powerByte == 0x01 && inputByte < 0x10)
|
||||
IsInStandby = true;
|
||||
if (powerByte == 0x00 && IsInStandby) // Ignore power off if coming from standby - glitch
|
||||
{
|
||||
IsInStandby = false;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePowerFB(powerByte);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateVolumeFB(byte b)
|
||||
{
|
||||
var newVol = (ushort)NumericalHelpers.Scale((double)b, 0, 100, 0, 65535);
|
||||
if (!VolumeIsRamping)
|
||||
_LastVolumeSent = newVol;
|
||||
if (newVol != _VolumeLevelForSig)
|
||||
{
|
||||
_VolumeLevelForSig = newVol;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateMuteFb(byte b)
|
||||
{
|
||||
var newMute = b == 1;
|
||||
if (newMute != _IsMuted)
|
||||
{
|
||||
_IsMuted = newMute;
|
||||
MuteFeedback.FireUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void UpdateInputFb(byte b)
|
||||
{
|
||||
var newInput = InputPorts.FirstOrDefault(i => i.FeedbackMatchObject.Equals(b));
|
||||
if (newInput != null && newInput != _CurrentInputPort)
|
||||
{
|
||||
_CurrentInputPort = newInput;
|
||||
CurrentInputFeedback.FireUpdate();
|
||||
OnSwitchChange(new RoutingNumericEventArgs(null, _CurrentInputPort, eRoutingSignalType.AudioVideo));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats an outgoing message. Replaces third byte with ID and replaces last byte with checksum
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
void SendBytes(byte[] b)
|
||||
{
|
||||
if (LastCommandSentWasVolume) // If the last command sent was volume
|
||||
if (b[1] != 0x12) // Check if this command is volume, and if not, delay this command
|
||||
CrestronEnvironment.Sleep(100);
|
||||
|
||||
b[2] = ID;
|
||||
// append checksum by adding all bytes, except last which should be 00
|
||||
int checksum = 0;
|
||||
for (var i = 1; i < b.Length - 1; i++) // add 2nd through 2nd-to-last bytes
|
||||
{
|
||||
checksum += b[i];
|
||||
}
|
||||
checksum = checksum & 0x000000FF; // mask off MSBs
|
||||
b[b.Length - 1] = (byte)checksum;
|
||||
|
||||
if (b[1] == 0x12)
|
||||
LastCommandSentWasVolume = true;
|
||||
else
|
||||
LastCommandSentWasVolume = false;
|
||||
|
||||
Communication.SendBytes(b);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StatusGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x00, 0x00, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override void PowerOn()
|
||||
{
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Powering On Display");
|
||||
|
||||
IsPoweringOnIgnorePowerFb = true;
|
||||
//Send(PowerOnCmd);
|
||||
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x01, 0x01, 0x00 });
|
||||
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||
{
|
||||
_IsWarmingUp = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
// Fake power-up cycle
|
||||
WarmupTimer = new CTimer(o =>
|
||||
{
|
||||
_IsWarmingUp = false;
|
||||
_PowerIsOn = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
}, WarmupTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override void PowerOff()
|
||||
{
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Powering Off Display");
|
||||
|
||||
IsPoweringOnIgnorePowerFb = false;
|
||||
// If a display has unreliable-power off feedback, just override this and
|
||||
// remove this check.
|
||||
if (!_IsWarmingUp && !_IsCoolingDown) // PowerIsOnFeedback.BoolValue &&
|
||||
{
|
||||
//Send(PowerOffCmd);
|
||||
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x01, 0x00, 0x00 });
|
||||
_IsCoolingDown = true;
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
// Fake cool-down cycle
|
||||
CooldownTimer = new CTimer(o =>
|
||||
{
|
||||
_IsCoolingDown = false;
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
}, CooldownTime);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PowerToggle()
|
||||
{
|
||||
if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue)
|
||||
PowerOff();
|
||||
else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue)
|
||||
PowerOn();
|
||||
}
|
||||
|
||||
public void PowerGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi1()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x21, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi1PC()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x22, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi2()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x23, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi2PC()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x24, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi3()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x32, 0x00 });
|
||||
}
|
||||
|
||||
public void InputHdmi4()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x34, 0x00 });
|
||||
}
|
||||
|
||||
public void InputDisplayPort1()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x25, 0x00 });
|
||||
}
|
||||
|
||||
public void InputDisplayPort2()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x26, 0x00 });
|
||||
}
|
||||
|
||||
public void InputDvi1()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x18, 0x00 });
|
||||
}
|
||||
|
||||
public void InputVideo1()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x08, 0x00 });
|
||||
}
|
||||
|
||||
public void InputRgb1()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x14, 0x00 });
|
||||
}
|
||||
|
||||
public void InputRgb2()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x1E, 0x00 });
|
||||
}
|
||||
|
||||
public void InputGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Executes a switch, turning on display if necessary.
|
||||
/// </summary>
|
||||
/// <param name="selector"></param>
|
||||
public override void ExecuteSwitch(object selector)
|
||||
{
|
||||
//if (!(selector is Action))
|
||||
// Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType());
|
||||
|
||||
if (_PowerIsOn)
|
||||
(selector as Action)();
|
||||
else // if power is off, wait until we get on FB to send it.
|
||||
{
|
||||
// One-time event handler to wait for power on before executing switch
|
||||
EventHandler<FeedbackEventArgs> handler = null; // necessary to allow reference inside lambda to handler
|
||||
handler = (o, a) =>
|
||||
{
|
||||
if (!_IsWarmingUp) // Done warming
|
||||
{
|
||||
IsWarmingUpFeedback.OutputChange -= handler;
|
||||
(selector as Action)();
|
||||
}
|
||||
};
|
||||
IsWarmingUpFeedback.OutputChange += handler; // attach and wait for on FB
|
||||
PowerOn();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales the level to the range of the display and sends the command
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
_LastVolumeSent = level;
|
||||
var scaled = (int)NumericalHelpers.Scale(level, 0, 65535, 0, 100);
|
||||
// The inputs to Scale ensure that byte won't overflow
|
||||
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x01, Convert.ToByte(scaled), 0x00 });
|
||||
}
|
||||
|
||||
#region IBasicVolumeWithFeedback Members
|
||||
|
||||
public IntFeedback VolumeLevelFeedback { get; private set; }
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteOff()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x01, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteOn()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x01, 0x01, 0x00 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IBasicVolumeControls Members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void MuteToggle()
|
||||
{
|
||||
if (_IsMuted)
|
||||
MuteOff();
|
||||
else
|
||||
MuteOn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeDown(bool pressRelease)
|
||||
{
|
||||
if (pressRelease)
|
||||
{
|
||||
VolumeIncrementer.StartDown();
|
||||
VolumeIsRamping = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
VolumeIsRamping = false;
|
||||
VolumeIncrementer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pressRelease"></param>
|
||||
public void VolumeUp(bool pressRelease)
|
||||
{
|
||||
if (pressRelease)
|
||||
{
|
||||
VolumeIncrementer.StartUp();
|
||||
VolumeIsRamping = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
VolumeIsRamping = false;
|
||||
VolumeIncrementer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void VolumeGet()
|
||||
{
|
||||
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x00, 0x00 });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class SamsungMDCFactory : EssentialsDeviceFactory<SamsungMDC>
|
||||
{
|
||||
public SamsungMDCFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "samsungmdc" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
if (comm != null)
|
||||
return new SamsungMDC(dc.Key, dc.Name, comm, dc.Properties["id"].Value<string>());
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.Lighting;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.CrestronIO;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Environment.Lighting
|
||||
{
|
||||
public class Din8sw8Controller : EssentialsDevice, ISwitchedOutputCollection
|
||||
{
|
||||
// Need to figure out some sort of interface to make these switched outputs behave like processor relays so they can be used interchangably
|
||||
|
||||
public Din8Sw8 SwitchModule { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of generic switched outputs
|
||||
/// </summary>
|
||||
public Dictionary<uint, ISwitchedOutput> SwitchedOutputs { get; private set; }
|
||||
|
||||
public Din8sw8Controller(string key, uint cresnetId)
|
||||
: base(key)
|
||||
{
|
||||
SwitchedOutputs = new Dictionary<uint, ISwitchedOutput>();
|
||||
|
||||
SwitchModule = new Din8Sw8(cresnetId, Global.ControlSystem);
|
||||
|
||||
if (SwitchModule.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
|
||||
{
|
||||
Debug.Console(2, this, "Error registering Din8sw8. Reason: {0}", SwitchModule.RegistrationFailureReason);
|
||||
}
|
||||
|
||||
PopulateDictionary();
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
|
||||
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the generic collection with the loads from the Crestron collection
|
||||
/// </summary>
|
||||
void PopulateDictionary()
|
||||
{
|
||||
foreach (var item in SwitchModule.SwitchedLoads)
|
||||
{
|
||||
SwitchedOutputs.Add(item.Number, new Din8sw8Output(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper class to
|
||||
/// </summary>
|
||||
public class Din8sw8Output : ISwitchedOutput
|
||||
{
|
||||
SwitchedLoadWithOverrideParameter SwitchedOutput;
|
||||
|
||||
public BoolFeedback OutputIsOnFeedback { get; protected set; }
|
||||
|
||||
public Din8sw8Output(SwitchedLoadWithOverrideParameter switchedOutput)
|
||||
{
|
||||
SwitchedOutput = switchedOutput;
|
||||
|
||||
OutputIsOnFeedback = new BoolFeedback(new Func<bool>(() => SwitchedOutput.IsOn));
|
||||
}
|
||||
|
||||
public void On()
|
||||
{
|
||||
SwitchedOutput.FullOn();
|
||||
}
|
||||
|
||||
public void Off()
|
||||
{
|
||||
SwitchedOutput.FullOff();
|
||||
}
|
||||
}
|
||||
|
||||
public class Din8sw8ControllerFactory : EssentialsDeviceFactory<Din8sw8Controller>
|
||||
{
|
||||
public Din8sw8ControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "din8sw8" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Din8sw8Controller Device");
|
||||
var comm = CommFactory.GetControlPropertiesConfig(dc);
|
||||
|
||||
return new Din8sw8Controller(dc.Key, comm.CresnetIdInt);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Lighting;
|
||||
using LightingBase = PepperDash.Essentials.Core.Lighting.LightingBase;
|
||||
|
||||
namespace PepperDash.Essentials.Devices.Common.Environment.Lutron
|
||||
{
|
||||
public class LutronQuantumArea : LightingBase, ILightingMasterRaiseLower, ICommunicationMonitor
|
||||
{
|
||||
public IBasicCommunication Communication { get; private set; }
|
||||
public CommunicationGather PortGather { get; private set; }
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
CTimer SubscribeAfterLogin;
|
||||
|
||||
public string IntegrationId;
|
||||
string Username;
|
||||
string Password;
|
||||
|
||||
const string Delimiter = "\x0d\x0a";
|
||||
const string Set = "#";
|
||||
const string Get = "?";
|
||||
|
||||
public LutronQuantumArea(string key, string name, IBasicCommunication comm, LutronQuantumPropertiesConfig props)
|
||||
: base(key, name)
|
||||
{
|
||||
Communication = comm;
|
||||
|
||||
IntegrationId = props.IntegrationId;
|
||||
|
||||
if (props.Control.Method != eControlMethod.Com)
|
||||
{
|
||||
|
||||
Username = props.Control.TcpSshProperties.Username;
|
||||
Password = props.Control.TcpSshProperties.Password;
|
||||
}
|
||||
|
||||
|
||||
LightingScenes = props.Scenes;
|
||||
|
||||
var socket = comm as ISocketStatus;
|
||||
if (socket != null)
|
||||
{
|
||||
// IP Control
|
||||
socket.ConnectionChange += new EventHandler<GenericSocketStatusChageEventArgs>(socket_ConnectionChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
// RS-232 Control
|
||||
}
|
||||
|
||||
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
|
||||
|
||||
PortGather = new CommunicationGather(Communication, Delimiter);
|
||||
PortGather.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);
|
||||
|
||||
if (props.CommunicationMonitorProperties != null)
|
||||
{
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, props.CommunicationMonitorProperties);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "?ETHERNET,0\x0d\x0a");
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
Communication.Connect();
|
||||
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
|
||||
CommunicationMonitor.Start();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
|
||||
{
|
||||
var joinMap = LinkLightingToApi(this, trilist, joinStart, joinMapKey, bridge);
|
||||
|
||||
CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||
trilist.SetStringSigAction(joinMap.IntegrationIdSet.JoinNumber , s => IntegrationId = s);
|
||||
}
|
||||
|
||||
void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
|
||||
{
|
||||
Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString());
|
||||
|
||||
if (e.Client.IsConnected)
|
||||
{
|
||||
// Tasks on connect
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for responses that do not contain the delimiter
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
Debug.Console(2, this, "Text Received: '{0}'", args.Text);
|
||||
|
||||
if (args.Text.Contains("login:"))
|
||||
{
|
||||
// Login
|
||||
SendLine(Username);
|
||||
}
|
||||
else if (args.Text.Contains("password:"))
|
||||
{
|
||||
// Login
|
||||
SendLine(Password);
|
||||
SubscribeAfterLogin = new CTimer(x => SubscribeToFeedback(), null, 5000);
|
||||
|
||||
}
|
||||
else if (args.Text.Contains("Access Granted"))
|
||||
{
|
||||
if (SubscribeAfterLogin != null)
|
||||
{
|
||||
SubscribeAfterLogin.Stop();
|
||||
}
|
||||
SubscribeToFeedback();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles all responses that contain the delimiter
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs args)
|
||||
{
|
||||
Debug.Console(2, this, "Line Received: '{0}'", args.Text);
|
||||
|
||||
try
|
||||
{
|
||||
if (args.Text.Contains("~AREA"))
|
||||
{
|
||||
var response = args.Text.Split(',');
|
||||
|
||||
var integrationId = response[1];
|
||||
|
||||
if (integrationId != IntegrationId)
|
||||
{
|
||||
Debug.Console(2, this, "Response is not for correct Integration ID");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var action = Int32.Parse(response[2]);
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case (int)eAction.Scene:
|
||||
{
|
||||
var scene = response[3];
|
||||
CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene));
|
||||
|
||||
OnLightingSceneChange();
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(2, this, "Error parsing response:\n{0}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to feedback
|
||||
/// </summary>
|
||||
public void SubscribeToFeedback()
|
||||
{
|
||||
Debug.Console(1, "Sending Monitoring Subscriptions");
|
||||
SendLine("#MONITORING,6,1");
|
||||
SendLine("#MONITORING,8,1");
|
||||
SendLine("#MONITORING,5,2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalls the specified scene
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
///
|
||||
|
||||
public override void SelectScene(LightingScene scene)
|
||||
{
|
||||
Debug.Console(1, this, "Selecting Scene: '{0}'", scene.Name);
|
||||
SendLine(string.Format("{0}AREA,{1},{2},{3}", Set, IntegrationId, (int)eAction.Scene, scene.ID));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins raising the lights in the area
|
||||
/// </summary>
|
||||
public void MasterRaise()
|
||||
{
|
||||
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Raise));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins lowering the lights in the area
|
||||
/// </summary>
|
||||
public void MasterLower()
|
||||
{
|
||||
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Lower));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the current raise/lower action
|
||||
/// </summary>
|
||||
public void MasterRaiseLowerStop()
|
||||
{
|
||||
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Stop));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the delimiter and sends the string
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public void SendLine(string s)
|
||||
{
|
||||
Communication.SendText(s + Delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
public enum eAction : int
|
||||
{
|
||||
SetLevel = 1,
|
||||
Raise = 2,
|
||||
Lower = 3,
|
||||
Stop = 4,
|
||||
Scene = 6,
|
||||
DaylightMode = 7,
|
||||
OccupancyState = 8,
|
||||
OccupancyMode = 9,
|
||||
OccupiedLevelOrScene = 12,
|
||||
UnoccupiedLevelOrScene = 13,
|
||||
HyperionShaddowSensorOverrideState = 26,
|
||||
HyperionBrightnessSensorOverrideStatue = 27
|
||||
}
|
||||
|
||||
public class LutronQuantumPropertiesConfig
|
||||
{
|
||||
public CommunicationMonitorConfig CommunicationMonitorProperties { get; set; }
|
||||
public ControlPropertiesConfig Control { get; set; }
|
||||
|
||||
public string IntegrationId { get; set; }
|
||||
public List<LightingScene> Scenes { get; set; }
|
||||
|
||||
// Moved to use existing properties in Control object
|
||||
// public string Username { get; set; }
|
||||
// public string Password { get; set; }
|
||||
}
|
||||
|
||||
public class LutronQuantumAreaFactory : EssentialsDeviceFactory<LutronQuantumArea>
|
||||
{
|
||||
public LutronQuantumAreaFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "lutronqs" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new LutronQuantumArea Device");
|
||||
var comm = CommFactory.CreateCommForDevice(dc);
|
||||
|
||||
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<Environment.Lutron.LutronQuantumPropertiesConfig>(dc.Properties.ToString());
|
||||
|
||||
return new LutronQuantumArea(dc.Key, dc.Name, comm, props);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user