mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 19:08:29 +00:00
chore: move all files to file-scoped namespace
This commit is contained in:
parent
aaa5b0532b
commit
3ece4f0b7b
522 changed files with 39628 additions and 45678 deletions
|
|
@ -11,286 +11,247 @@ using PepperDash.Essentials.Core.CrestronIO;
|
|||
using Serilog.Events;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core.Privacy
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for applications where one or more microphones with momentary contact closure outputs are used to
|
||||
/// toggle the privacy state of the room. Privacy state feedback is represented
|
||||
/// </summary>
|
||||
public class MicrophonePrivacyController : EssentialsDevice
|
||||
{
|
||||
MicrophonePrivacyControllerConfig Config;
|
||||
namespace PepperDash.Essentials.Core.Privacy;
|
||||
|
||||
bool initialized;
|
||||
/// <summary>
|
||||
/// Used for applications where one or more microphones with momentary contact closure outputs are used to
|
||||
/// toggle the privacy state of the room. Privacy state feedback is represented
|
||||
/// </summary>
|
||||
public class MicrophonePrivacyController : EssentialsDevice
|
||||
{
|
||||
MicrophonePrivacyControllerConfig Config;
|
||||
|
||||
bool initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether LED control is enabled
|
||||
/// </summary>
|
||||
public bool EnableLeds
|
||||
public bool EnableLeds
|
||||
{
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enableLeds;
|
||||
}
|
||||
set
|
||||
{
|
||||
_enableLeds = value;
|
||||
return _enableLeds;
|
||||
}
|
||||
set
|
||||
{
|
||||
_enableLeds = value;
|
||||
|
||||
if (initialized)
|
||||
if (initialized)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
CheckPrivacyMode();
|
||||
SetLedStates();
|
||||
}
|
||||
else
|
||||
TurnOffAllLeds();
|
||||
CheckPrivacyMode();
|
||||
SetLedStates();
|
||||
}
|
||||
else
|
||||
TurnOffAllLeds();
|
||||
}
|
||||
}
|
||||
bool _enableLeds;
|
||||
}
|
||||
|
||||
bool _enableLeds;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Inputs
|
||||
/// </summary>
|
||||
public List<IDigitalInput> Inputs { get; private set; }
|
||||
public List<IDigitalInput> Inputs { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RedLedRelay
|
||||
/// </summary>
|
||||
public GenericRelayDevice RedLedRelay { get; private set; }
|
||||
bool _redLedRelayState;
|
||||
public GenericRelayDevice RedLedRelay { get; private set; }
|
||||
bool _redLedRelayState;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GreenLedRelay
|
||||
/// </summary>
|
||||
public GenericRelayDevice GreenLedRelay { get; private set; }
|
||||
bool _greenLedRelayState;
|
||||
public GenericRelayDevice GreenLedRelay { get; private set; }
|
||||
bool _greenLedRelayState;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PrivacyDevice
|
||||
/// </summary>
|
||||
public IPrivacy PrivacyDevice { get; private set; }
|
||||
public IPrivacy PrivacyDevice { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for MicrophonePrivacyController
|
||||
/// </summary>
|
||||
/// <param name="key">key of the controller device</param>
|
||||
/// <param name="config">configuration for the controller device</param>
|
||||
public MicrophonePrivacyController(string key, MicrophonePrivacyControllerConfig config) :
|
||||
base(key)
|
||||
public MicrophonePrivacyController(string key, MicrophonePrivacyControllerConfig config) :
|
||||
base(key)
|
||||
{
|
||||
Config = config;
|
||||
|
||||
Inputs = new List<IDigitalInput>();
|
||||
}
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
foreach (var i in Config.Inputs)
|
||||
{
|
||||
Config = config;
|
||||
var input = DeviceManager.GetDeviceForKey(i.DeviceKey) as IDigitalInput;
|
||||
|
||||
Inputs = new List<IDigitalInput>();
|
||||
if(input != null)
|
||||
AddInput(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CustomActivate method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
foreach (var i in Config.Inputs)
|
||||
{
|
||||
var input = DeviceManager.GetDeviceForKey(i.DeviceKey) as IDigitalInput;
|
||||
var greenLed = DeviceManager.GetDeviceForKey(Config.GreenLedRelay.DeviceKey) as GenericRelayDevice;
|
||||
|
||||
if(input != null)
|
||||
AddInput(input);
|
||||
}
|
||||
if (greenLed != null)
|
||||
GreenLedRelay = greenLed;
|
||||
else
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Unable to add Green LED device");
|
||||
|
||||
var greenLed = DeviceManager.GetDeviceForKey(Config.GreenLedRelay.DeviceKey) as GenericRelayDevice;
|
||||
var redLed = DeviceManager.GetDeviceForKey(Config.RedLedRelay.DeviceKey) as GenericRelayDevice;
|
||||
|
||||
if (greenLed != null)
|
||||
GreenLedRelay = greenLed;
|
||||
else
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Unable to add Green LED device");
|
||||
if (redLed != null)
|
||||
RedLedRelay = redLed;
|
||||
else
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Unable to add Red LED device");
|
||||
|
||||
var redLed = DeviceManager.GetDeviceForKey(Config.RedLedRelay.DeviceKey) as GenericRelayDevice;
|
||||
AddPostActivationAction(() => {
|
||||
PrivacyDevice.PrivacyModeIsOnFeedback.OutputChange -= PrivacyModeIsOnFeedback_OutputChange;
|
||||
PrivacyDevice.PrivacyModeIsOnFeedback.OutputChange += PrivacyModeIsOnFeedback_OutputChange;
|
||||
});
|
||||
|
||||
if (redLed != null)
|
||||
RedLedRelay = redLed;
|
||||
else
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Unable to add Red LED device");
|
||||
initialized = true;
|
||||
|
||||
AddPostActivationAction(() => {
|
||||
PrivacyDevice.PrivacyModeIsOnFeedback.OutputChange -= PrivacyModeIsOnFeedback_OutputChange;
|
||||
PrivacyDevice.PrivacyModeIsOnFeedback.OutputChange += PrivacyModeIsOnFeedback_OutputChange;
|
||||
});
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
#region Overrides of Device
|
||||
|
||||
return base.CustomActivate();
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
CheckPrivacyMode();
|
||||
}
|
||||
|
||||
#region Overrides of Device
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
CheckPrivacyMode();
|
||||
}
|
||||
public void SetPrivacyDevice(IPrivacy privacyDevice)
|
||||
{
|
||||
PrivacyDevice = privacyDevice;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// SetPrivacyDevice method
|
||||
/// </summary>
|
||||
public void SetPrivacyDevice(IPrivacy privacyDevice)
|
||||
{
|
||||
PrivacyDevice = privacyDevice;
|
||||
}
|
||||
|
||||
void PrivacyModeIsOnFeedback_OutputChange(object sender, EventArgs e)
|
||||
{
|
||||
void PrivacyModeIsOnFeedback_OutputChange(object sender, EventArgs e)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, this, "Privacy mode change: {0}", sender as BoolFeedback);
|
||||
CheckPrivacyMode();
|
||||
}
|
||||
CheckPrivacyMode();
|
||||
}
|
||||
|
||||
void CheckPrivacyMode()
|
||||
void CheckPrivacyMode()
|
||||
{
|
||||
if (PrivacyDevice != null)
|
||||
{
|
||||
if (PrivacyDevice != null)
|
||||
{
|
||||
var privacyState = PrivacyDevice.PrivacyModeIsOnFeedback.BoolValue;
|
||||
var privacyState = PrivacyDevice.PrivacyModeIsOnFeedback.BoolValue;
|
||||
|
||||
if (privacyState)
|
||||
TurnOnRedLeds();
|
||||
else
|
||||
TurnOnGreenLeds();
|
||||
}
|
||||
}
|
||||
|
||||
void AddInput(IDigitalInput input)
|
||||
{
|
||||
Inputs.Add(input);
|
||||
|
||||
input.InputStateFeedback.OutputChange += InputStateFeedback_OutputChange;
|
||||
}
|
||||
|
||||
void RemoveInput(IDigitalInput input)
|
||||
{
|
||||
var tempInput = Inputs.FirstOrDefault(i => i.Equals(input));
|
||||
|
||||
if (tempInput != null)
|
||||
tempInput.InputStateFeedback.OutputChange -= InputStateFeedback_OutputChange;
|
||||
|
||||
Inputs.Remove(input);
|
||||
}
|
||||
|
||||
void SetRedLedRelay(GenericRelayDevice relay)
|
||||
{
|
||||
RedLedRelay = relay;
|
||||
}
|
||||
|
||||
void SetGreenLedRelay(GenericRelayDevice relay)
|
||||
{
|
||||
GreenLedRelay = relay;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check the state of the input change and handle accordingly
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void InputStateFeedback_OutputChange(object sender, EventArgs e)
|
||||
{
|
||||
if ((sender as BoolFeedback).BoolValue == true)
|
||||
TogglePrivacyMute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the state of the privacy mute
|
||||
/// </summary>
|
||||
public void TogglePrivacyMute()
|
||||
{
|
||||
PrivacyDevice.PrivacyModeToggle();
|
||||
}
|
||||
|
||||
void TurnOnRedLeds()
|
||||
{
|
||||
_greenLedRelayState = false;
|
||||
_redLedRelayState = true;
|
||||
SetLedStates();
|
||||
}
|
||||
|
||||
void TurnOnGreenLeds()
|
||||
{
|
||||
_redLedRelayState = false;
|
||||
_greenLedRelayState = true;
|
||||
SetLedStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, sets the actual state of the relays
|
||||
/// </summary>
|
||||
void SetLedStates()
|
||||
{
|
||||
if (_enableLeds)
|
||||
{
|
||||
SetRelayStates();
|
||||
}
|
||||
if (privacyState)
|
||||
TurnOnRedLeds();
|
||||
else
|
||||
TurnOffAllLeds();
|
||||
TurnOnGreenLeds();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns off all LEDs
|
||||
/// </summary>
|
||||
void TurnOffAllLeds()
|
||||
{
|
||||
_redLedRelayState = false;
|
||||
_greenLedRelayState = false;
|
||||
void AddInput(IDigitalInput input)
|
||||
{
|
||||
Inputs.Add(input);
|
||||
|
||||
SetRelayStates();
|
||||
}
|
||||
input.InputStateFeedback.OutputChange += InputStateFeedback_OutputChange;
|
||||
}
|
||||
|
||||
void SetRelayStates()
|
||||
{
|
||||
if (RedLedRelay != null)
|
||||
{
|
||||
if (_redLedRelayState)
|
||||
RedLedRelay.CloseRelay();
|
||||
else
|
||||
RedLedRelay.OpenRelay();
|
||||
}
|
||||
void RemoveInput(IDigitalInput input)
|
||||
{
|
||||
var tempInput = Inputs.FirstOrDefault(i => i.Equals(input));
|
||||
|
||||
if(GreenLedRelay != null)
|
||||
{
|
||||
if (_greenLedRelayState)
|
||||
GreenLedRelay.CloseRelay();
|
||||
else
|
||||
GreenLedRelay.OpenRelay();
|
||||
}
|
||||
}
|
||||
if (tempInput != null)
|
||||
tempInput.InputStateFeedback.OutputChange -= InputStateFeedback_OutputChange;
|
||||
|
||||
Inputs.Remove(input);
|
||||
}
|
||||
|
||||
void SetRedLedRelay(GenericRelayDevice relay)
|
||||
{
|
||||
RedLedRelay = relay;
|
||||
}
|
||||
|
||||
void SetGreenLedRelay(GenericRelayDevice relay)
|
||||
{
|
||||
GreenLedRelay = relay;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a MicrophonePrivacyControllerFactory
|
||||
/// Check the state of the input change and handle accordingly
|
||||
/// </summary>
|
||||
public class MicrophonePrivacyControllerFactory : EssentialsDeviceFactory<MicrophonePrivacyController>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void InputStateFeedback_OutputChange(object sender, EventArgs e)
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for MicrophonePrivacyControllerFactory
|
||||
/// </summary>
|
||||
public MicrophonePrivacyControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "microphoneprivacycontroller" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BuildDevice method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new MIcrophonePrivacyController Device");
|
||||
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<Core.Privacy.MicrophonePrivacyControllerConfig>(dc.Properties.ToString());
|
||||
|
||||
return new Core.Privacy.MicrophonePrivacyController(dc.Key, props);
|
||||
}
|
||||
if ((sender as BoolFeedback).BoolValue == true)
|
||||
TogglePrivacyMute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the state of the privacy mute
|
||||
/// </summary>
|
||||
public void TogglePrivacyMute()
|
||||
{
|
||||
PrivacyDevice.PrivacyModeToggle();
|
||||
}
|
||||
|
||||
void TurnOnRedLeds()
|
||||
{
|
||||
_greenLedRelayState = false;
|
||||
_redLedRelayState = true;
|
||||
SetLedStates();
|
||||
}
|
||||
|
||||
void TurnOnGreenLeds()
|
||||
{
|
||||
_redLedRelayState = false;
|
||||
_greenLedRelayState = true;
|
||||
SetLedStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If enabled, sets the actual state of the relays
|
||||
/// </summary>
|
||||
void SetLedStates()
|
||||
{
|
||||
if (_enableLeds)
|
||||
{
|
||||
SetRelayStates();
|
||||
}
|
||||
else
|
||||
TurnOffAllLeds();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns off all LEDs
|
||||
/// </summary>
|
||||
void TurnOffAllLeds()
|
||||
{
|
||||
_redLedRelayState = false;
|
||||
_greenLedRelayState = false;
|
||||
|
||||
SetRelayStates();
|
||||
}
|
||||
|
||||
void SetRelayStates()
|
||||
{
|
||||
if (RedLedRelay != null)
|
||||
{
|
||||
if (_redLedRelayState)
|
||||
RedLedRelay.CloseRelay();
|
||||
else
|
||||
RedLedRelay.OpenRelay();
|
||||
}
|
||||
|
||||
if(GreenLedRelay != null)
|
||||
{
|
||||
if (_greenLedRelayState)
|
||||
GreenLedRelay.CloseRelay();
|
||||
else
|
||||
GreenLedRelay.OpenRelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MicrophonePrivacyControllerFactory : EssentialsDeviceFactory<MicrophonePrivacyController>
|
||||
{
|
||||
public MicrophonePrivacyControllerFactory()
|
||||
{
|
||||
TypeNames = new List<string>() { "microphoneprivacycontroller" };
|
||||
}
|
||||
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new MIcrophonePrivacyController Device");
|
||||
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<Core.Privacy.MicrophonePrivacyControllerConfig>(dc.Properties.ToString());
|
||||
|
||||
return new Core.Privacy.MicrophonePrivacyController(dc.Key, props);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Essentials.Core.CrestronIO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Privacy
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue