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;
namespace PepperDash.Essentials
{
///
/// Used for interlocking sigs, using a set-clears-last-set model.
///
public class SigInterlock
{
///
///
///
public BoolInputSig CurrentSig { get; private set; }
///
///
///
public SigInterlock()
{
}
///
/// Hides CurrentJoin and shows join. Does nothing when resending CurrentJoin
///
public void ShowInterlocked(BoolInputSig sig)
{
if (CurrentSig == sig)
return;
SetButDontShow(sig);
sig.BoolValue = true;
}
///
///
///
///
public void ShowInterlockedWithToggle(BoolInputSig sig)
{
if(CurrentSig == sig)
HideAndClear();
else
{
if(CurrentSig != null)
CurrentSig.BoolValue = false;
CurrentSig = sig;
CurrentSig.BoolValue = true;
}
}
///
/// Hides current Sig and clears CurrentSig
///
public void HideAndClear()
{
Hide();
CurrentSig = null;
}
///
/// Hides the current Sig but does not clear the selected Sig in case
/// it needs to be reshown
///
public void Hide()
{
if(CurrentSig != null)
CurrentSig.BoolValue = false;
}
///
/// If CurrentSig is set, it restores that Sig
///
public void Show()
{
if(CurrentSig != null)
CurrentSig.BoolValue = true;
}
///
/// Useful for pre-setting the interlock but not enabling it. Sets CurrentSig
///
///
public void SetButDontShow(BoolInputSig sig)
{
if (CurrentSig != null)
CurrentSig.BoolValue = false;
CurrentSig = sig;
}
}
}