using System;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Devices.Common.Displays
{
///
/// Abstract base class for two-way display devices that provide feedback capabilities.
/// Extends DisplayBase with routing feedback and power control feedback functionality.
///
public abstract class TwoWayDisplayBase : DisplayBase, IRoutingFeedback, IHasPowerControlWithFeedback
{
///
/// Gets feedback for the current input selection on the display.
///
public StringFeedback CurrentInputFeedback { get; private set; }
///
/// Abstract function that must be implemented by derived classes to provide the current input feedback value.
/// Must be implemented by concrete sub-classes.
///
abstract protected Func CurrentInputFeedbackFunc { get; }
///
/// Gets feedback indicating whether the display is currently powered on.
///
public BoolFeedback PowerIsOnFeedback { get; protected set; }
///
/// Abstract function that must be implemented by derived classes to provide the power state feedback value.
/// Must be implemented by concrete sub-classes.
///
abstract protected Func PowerIsOnFeedbackFunc { get; }
///
/// Gets the default mock display instance for testing and development purposes.
///
public static MockDisplay DefaultDisplay
{
get
{
if (_DefaultDisplay == null)
_DefaultDisplay = new MockDisplay("default", "Default Display");
return _DefaultDisplay;
}
}
static MockDisplay _DefaultDisplay;
///
/// Initializes a new instance of the TwoWayDisplayBase class.
///
/// The unique key identifier for this display device.
/// The friendly name for this display device.
public TwoWayDisplayBase(string key, string name)
: base(key, name)
{
CurrentInputFeedback = new StringFeedback("currentInput", CurrentInputFeedbackFunc);
WarmupTime = 7000;
CooldownTime = 15000;
PowerIsOnFeedback = new BoolFeedback("PowerOnFeedback", PowerIsOnFeedbackFunc);
Feedbacks.Add(CurrentInputFeedback);
Feedbacks.Add(PowerIsOnFeedback);
PowerIsOnFeedback.OutputChange += PowerIsOnFeedback_OutputChange;
}
void PowerIsOnFeedback_OutputChange(object sender, EventArgs e)
{
if (UsageTracker != null)
{
if (PowerIsOnFeedback.BoolValue)
UsageTracker.StartDeviceUsage();
else
UsageTracker.EndDeviceUsage();
}
}
///
/// Event that is raised when a numeric switch change occurs on the display.
///
public event EventHandler NumericSwitchChange;
///
/// Raise an event when the status of a switch object changes.
///
/// Arguments defined as IKeyName sender, output, input, and eRoutingSignalType
protected void OnSwitchChange(RoutingNumericEventArgs e)
{
NumericSwitchChange?.Invoke(this, e);
}
}
}