Merge branch 'feature-2.0.0/interface-updates' of https://github.com/PepperDash/Essentials into feature-2.0.0/interface-updates

This commit is contained in:
Andrew Welker
2024-03-19 11:08:42 -05:00
9 changed files with 255 additions and 45 deletions

View File

@@ -1,11 +1,24 @@
using System;
using PepperDash.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
public interface IHasInputs
/// <summary>
/// Describes a device that has selectable inputs
/// </summary>
/// <typeparam name="TKey">the type to use as the key for each input item. Most likely an enum or string</typeparam>\
/// <example>
/// See MockDisplay for example implemntation
/// </example>
public interface IHasInputs<TKey, TSelector>: IKeyName
{
event EventHandler InputsUpdated;
IDictionary<string, IInput> Inputs { get; }
ISelectableItems<TKey> Inputs { get; }
void SetInput(TSelector selector);
}
}
}

View File

@@ -0,0 +1,20 @@
using PepperDash.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Describes a device that has selectable surround sound modes
/// </summary>
/// <typeparam name="TKey">the type to use as the key for each input item. Most likely an enum or string</typeparam>
public interface IHasSurroundSoundModes<TKey, TSelector>: IKeyName
{
ISelectableItems<TKey> SurroundSoundModes { get; }
void SetSurroundSoundMode(TSelector selector);
}
}

View File

@@ -1,12 +0,0 @@
using System;
using PepperDash.Core;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
public interface IInput : IKeyName
{
event EventHandler InputUpdated;
bool IsSelected { get; }
void Select();
}
}

View File

@@ -0,0 +1,19 @@
using System;
using Newtonsoft.Json;
using PepperDash.Core;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Describes an item that can be selected
/// </summary>
public interface ISelectableItem : IKeyName
{
event EventHandler ItemUpdated;
[JsonProperty("isSelected")]
bool IsSelected { get; set; }
void Select();
}
}

View File

@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Describes a collection of items that can be selected
/// </summary>
/// <typeparam name="TKey">type for the keys in the collection. Probably a string or enum</typeparam>
public interface ISelectableItems<TKey>
{
event EventHandler ItemsUpdated;
event EventHandler CurrentItemChanged;
[JsonProperty("items")]
Dictionary<TKey, ISelectableItem> Items { get; set; }
[JsonProperty("currentItem")]
string CurrentItem { get; set; }
}
}

View File

@@ -371,9 +371,9 @@ namespace PepperDash.Essentials
{
try
{
Debug.Console(0, $"Checking if type {type.Name} is IPluginDeviceFactory");
//Debug.Console(0, $"Checking if type {type.Name} is IPluginDeviceFactory");
Debug.Console(0, $"{type.Name} is plugin factory: {typeof(IPluginDeviceFactory).IsAssignableFrom(type) && !type.IsAbstract}");
//Debug.Console(0, $"{type.Name} is plugin factory: {typeof(IPluginDeviceFactory).IsAssignableFrom(type) && !type.IsAbstract}");
if (typeof (IPluginDeviceFactory).IsAssignableFrom(type) && !type.IsAbstract)
{

View File

@@ -8,10 +8,16 @@ using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using Feedback = PepperDash.Essentials.Core.Feedback;
using Newtonsoft.Json;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
namespace PepperDash.Essentials.Devices.Common.Displays
{
public abstract class DisplayBase : EssentialsDevice, IHasFeedback, IRoutingSinkWithSwitching, IHasPowerControl, IWarmingCooling, IUsageTracking
public abstract class DisplayBase : EssentialsDevice
, IHasFeedback
, IRoutingSinkWithSwitching
, IHasPowerControl
, IWarmingCooling
, IUsageTracking
{
public event SourceInfoChangeHandler CurrentSourceChange;

View File

@@ -1,21 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Devices.Common.Displays
{
public class MockDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, IBridgeAdvanced
public class MockDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, IBridgeAdvanced, IHasInputs<string, string>
{
public RoutingInputPort HdmiIn1 { get; private set; }
public RoutingInputPort HdmiIn2 { get; private set; }
public RoutingInputPort HdmiIn3 { get; private set; }
public RoutingInputPort ComponentIn1 { get; private set; }
public RoutingInputPort VgaIn1 { get; private set; }
public ISelectableItems<string> Inputs { get; private set; }
bool _PowerIsOn;
bool _IsWarmingUp;
@@ -53,7 +51,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays
};
}
}
protected override Func<string> CurrentInputFeedbackFunc { get { return () => "Not Implemented"; } }
protected override Func<string> CurrentInputFeedbackFunc { get { return () => Inputs.CurrentItem; } }
int VolumeHeldRepeatInterval = 200;
ushort VolumeInterval = 655;
@@ -63,17 +61,31 @@ namespace PepperDash.Essentials.Devices.Common.Displays
public MockDisplay(string key, string name)
: base(key, name)
{
HdmiIn1 = new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
eRoutingPortConnectionType.Hdmi, null, this);
HdmiIn2 = new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.Audio | eRoutingSignalType.Video,
eRoutingPortConnectionType.Hdmi, null, this);
HdmiIn3 = new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.Audio | eRoutingSignalType.Video,
eRoutingPortConnectionType.Hdmi, null, this);
ComponentIn1 = new RoutingInputPort(RoutingPortNames.ComponentIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Component, null, this);
VgaIn1 = new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Composite, null, this);
InputPorts.AddRange(new[] { HdmiIn1, HdmiIn2, HdmiIn3, ComponentIn1, VgaIn1 });
Inputs = new MockDisplayInputs
{
Items = new Dictionary<string, ISelectableItem>
{
{ "HDMI1", new MockDisplayInput ( "HDMI1", "HDMI 1",this ) },
{ "HDMI2", new MockDisplayInput ("HDMI2", "HDMI 2",this ) },
{ "HDMI3", new MockDisplayInput ("HDMI3", "HDMI 3",this ) },
{ "HDMI4", new MockDisplayInput ("HDMI4", "HDMI 4",this )},
{ "DP", new MockDisplayInput ("DP", "DisplayPort", this ) }
}
};
Inputs.CurrentItemChanged += (o, a) => CurrentInputFeedback.FireUpdate();
var hdmiIn1 = new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, "HDMI1", this);
var hdmiIn2 = new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, "HDMI2", this);
var hdmiIn3 = new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, "HDMI3", this);
var hdmiIn4 = new RoutingInputPort(RoutingPortNames.ComponentIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, "HDMI4", this);
var dpIn = new RoutingInputPort(RoutingPortNames.DisplayPortIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, "DP", this);
InputPorts.AddRange(new[] { hdmiIn1, hdmiIn2, hdmiIn3, hdmiIn4, dpIn });
VolumeLevelFeedback = new IntFeedback(() => { return _FakeVolumeLevel; });
MuteFeedback = new BoolFeedback("MuteOn", () => _IsMuted);
@@ -135,13 +147,43 @@ namespace PepperDash.Essentials.Devices.Common.Displays
{
PowerOn();
}
if (!Inputs.Items.TryGetValue(selector.ToString(), out var input))
return;
input.Select();
}
public void SetInput(string selector)
{
ISelectableItem currentInput = null;
try
{
currentInput = Inputs.Items.SingleOrDefault(Inputs => Inputs.Value.IsSelected).Value;
}
catch { }
if (currentInput != null)
{
Debug.Console(2, this, "SetInput: {0}", selector);
currentInput.IsSelected = false;
}
if (!Inputs.Items.TryGetValue(selector, out var input))
return;
input.IsSelected = true;
Inputs.CurrentItem = selector;
}
#region IBasicVolumeWithFeedback Members
public IntFeedback VolumeLevelFeedback { get; private set; }
#region IBasicVolumeWithFeedback Members
public IntFeedback VolumeLevelFeedback { get; private set; }
public void SetVolume(ushort level)
{
@@ -163,11 +205,12 @@ namespace PepperDash.Essentials.Devices.Common.Displays
public BoolFeedback MuteFeedback { get; private set; }
#endregion
#region IBasicVolumeControls Members
#endregion
public void VolumeUp(bool pressRelease)
#region IBasicVolumeControls Members
public void VolumeUp(bool pressRelease)
{
//while (pressRelease)
//{
@@ -207,5 +250,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays
{
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
}
}
}
}

View File

@@ -0,0 +1,97 @@
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Essentials.Devices.Common.Displays
{
public class MockDisplayInputs : ISelectableItems<string>
{
private Dictionary<string, ISelectableItem> _items;
public Dictionary<string, ISelectableItem> Items
{
get
{
return _items;
}
set
{
if (_items == value)
return;
_items = value;
ItemsUpdated?.Invoke(this, null);
}
}
private string _currentItem;
public string CurrentItem
{
get
{
return _currentItem;
}
set
{
if (_currentItem == value)
return;
_currentItem = value;
CurrentItemChanged?.Invoke(this, null);
}
}
public event EventHandler ItemsUpdated;
public event EventHandler CurrentItemChanged;
}
public class MockDisplayInput : ISelectableItem
{
private IHasInputs<string, string> _parent;
private bool _isSelected;
public bool IsSelected
{
get
{
return _isSelected;
}
set
{
if (_isSelected == value)
return;
_isSelected = value;
ItemUpdated?.Invoke(this, null);
}
}
public string Name { get; set; }
public string Key { get; set; }
public event EventHandler ItemUpdated;
public MockDisplayInput(string key, string name, MockDisplay parent)
{
Key = key;
Name = name;
_parent = parent;
}
public void Select()
{
_parent.SetInput(Key);
}
}
}