Skip to content

Commit

Permalink
feature: implements IHasInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
AECohn committed May 3, 2024
1 parent f1387c0 commit 0887e99
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 47 deletions.
101 changes: 101 additions & 0 deletions src/SamsungInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Independentsoft.Exchange;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Queues;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PepperDashPluginSamsungMdcDisplay;

namespace PepperDashPluginSamsungMdcDisplay
{
#if SERIES4
public class SamsungInputs : ISelectableItems<byte>
{
private Dictionary<byte, ISelectableItem> _items = new Dictionary<byte, ISelectableItem>();

public Dictionary<byte, ISelectableItem> Items
{
get
{
return _items;
}
set
{
if (_items == value)
return;

_items = value;

ItemsUpdated?.Invoke(this, null);
}
}

private byte _currentItem;

public byte 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 SamsungInput : ISelectableItem
{
private bool _isSelected;

private readonly SamsungMdcDisplayController _parent;

private Action _inputMethod;

public SamsungInput(string key, string name, SamsungMdcDisplayController parent, Action inputMethod)
{
Key = key;
Name = name;
_parent = parent;
_inputMethod = inputMethod;
}

public string Key { get; private set; }
public string Name { get; private set; }

public event EventHandler ItemUpdated;

public bool IsSelected
{
get { return _isSelected; }
set
{
if (value == _isSelected)
return;

_isSelected = value;
var handler = ItemUpdated;
if (handler != null)
handler(this, EventArgs.Empty);
}
}

public void Select()
{
_inputMethod();
}
}
#endif
}
144 changes: 97 additions & 47 deletions src/SamsungMdc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.DeviceInfo;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Routing;
using PepperDash.Essentials.Devices.Displays;
using Feedback = PepperDash.Essentials.Core.Feedback;
Expand All @@ -21,6 +22,10 @@ namespace PepperDashPluginSamsungMdcDisplay
{
public class SamsungMdcDisplayController : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor,
IBridgeAdvanced, IDeviceInfoProvider, IInputDisplayPort1, IInputDisplayPort2, IInputHdmi1, IInputHdmi2, IInputHdmi3, IInputHdmi4
#if SERIES4
,IHasInputs<byte, int>
#endif

{
public StatusMonitorBase CommunicationMonitor { get; private set; }
public IBasicCommunication Communication { get; private set; }
Expand Down Expand Up @@ -87,31 +92,49 @@ private set
UpdateBooleanFeedback();
}
}
#if SERIES4
public ISelectableItems<byte> Inputs { get; private set; }

public int SetInput
{
set
{
if (value <= 0 || value >= InputPorts.Count) return;

Debug.Console(DebugLevelDebug, this, "SetInput: value-'{0}'", value);
//what I need to do, use existing logic that sets inputs and passes into an int value, and have that value select the
//input from the list of ISelectableItems Inputs

// -1 to get actual input after'0d' check
var port = GetInputPort(value - 1);
if (port == null)
{
Debug.Console(DebugLevelDebug, this, "SetInput: failed to get input port");
return;
}
/* To-Do: Find the actual thing that sends the command.
Build a class that satisfies Iselectable Items and an IselectableItems Class
Each Input needs an implementation of Select and IsSelected, look at LG for examples
ALL I NEED TO DO IS: when select is asserted on the input, it sends the command to the display
when the main class parses the current selected input, it should iterate through my ISelectableItems and set them accordingly
Debug.Console(DebugLevelDebug, this, "SetInput: port.Key-'{0}', port.Selector-'{1}', port.ConnectionType-'{2}', port.FeedbackMatchObject-'{3}'",
port.Key, port.Selector, port.ConnectionType, port.FeedbackMatchObject);
Create a separate file for the inputs class (see LG )
The select method should just have an Action, and I can pass in the input method to be called
*/
#endif

ExecuteSwitch(port.Selector);
UpdateInputFb((byte)port.FeedbackMatchObject);
}
public void SetInput(int value)
{
if (value <= 0 || value >= InputPorts.Count) return;

Debug.Console(DebugLevelDebug, this, "SetInput: value-'{0}'", value);

// -1 to get actual input after'0d' check
var port = GetInputPort(value - 1);
if (port == null)
{
Debug.Console(DebugLevelDebug, this, "SetInput: failed to get input port");
return;
}

Debug.Console(DebugLevelDebug, this, "SetInput: port.Key-'{0}', port.Selector-'{1}', port.ConnectionType-'{2}', port.FeedbackMatchObject-'{3}'",
port.Key, port.Selector, port.ConnectionType, port.FeedbackMatchObject);

ExecuteSwitch(port.Selector);
UpdateInputFb((byte)port.FeedbackMatchObject);


}



private RoutingInputPort GetInputPort(int input)
{
return InputPorts.ElementAt(input);
Expand Down Expand Up @@ -275,7 +298,7 @@ public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, E
trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + count), () =>
{
Debug.Console(DebugLevelVerbose, this, "InputSelect Digital-'{0}'", inputIndex);
SetInput = inputIndex;
SetInput(inputIndex);
});

var friendlyName = _config.FriendlyNames.FirstOrDefault(n => n.InputKey == i.Key);
Expand All @@ -298,7 +321,7 @@ public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, E
trilist.SetUShortSigAction(joinMap.InputSelect.JoinNumber, a =>
{
Debug.Console(DebugLevelVerbose, this, "InputSelect Analog-'{0}'", a);
SetInput = a;
SetInput(a);
});

// input analog feedback
Expand Down Expand Up @@ -644,6 +667,10 @@ private void Init()
InitTemperatureFeedback();

StatusGet();

#if SERIES4
SetupInputs();
#endif
}

private void InitCommMonitor()
Expand Down Expand Up @@ -950,6 +977,44 @@ public override void ExecuteSwitch(object selector)
}
}

#if SERIES4
private void SetupInputs() //DELETE:a2472
{
Inputs = new SamsungInputs
{
Items = new Dictionary<byte, ISelectableItem>
{
{
SamsungMdcCommands.InputHdmi1, new SamsungInput("hdmi1", "HDMI 1", this, InputHdmi1)
},
{
SamsungMdcCommands.InputHdmi2, new SamsungInput("hdmi2", "HDMI 2", this, InputHdmi2)
},
{
SamsungMdcCommands.InputHdmi3, new SamsungInput("hdmi3", "HDMI 3", this, InputHdmi3)
},
{
SamsungMdcCommands.InputHdmi4, new SamsungInput("hdmi4", "HDMI 4", this, InputHdmi4)
},
{
SamsungMdcCommands.InputDisplayPort1, new SamsungInput("displayPort1", "Display Port 1", this, InputDisplayPort1)
},
{
SamsungMdcCommands.InputDisplayPort2, new SamsungInput("displayPort2", "Display Port 2", this, InputDisplayPort2)
},
{
SamsungMdcCommands.InputDvi1, new SamsungInput("dvi1", "DVI 1", this, InputDvi1)
},
{
SamsungMdcCommands.InputMagicInfo, new SamsungInput("magicInfo", "Magic Info", this, InputMagicInfo)
}

}
};
}
#endif


/// <summary>
/// Input HDMI 1 (Cmd: 0x14) pdf page 426
/// Set: [HEADER=0xAA][Cmd=0x14][ID][DATA_LEN=0x01][DATA-1=0x21][CS=0x00]
Expand Down Expand Up @@ -1061,37 +1126,22 @@ private void UpdateInputFb(byte b)
}
CurrentInputNumber = inputIndex;

/*
switch (key)
#if SERIES4
if (Inputs.Items.ContainsKey(b))
{
case "hdmiIn1":
CurrentInputNumber = 1;
break;
case "hdmiIn2":
CurrentInputNumber = 2;
break;
case "hdmiIn3":
CurrentInputNumber = 3;
break;
case "hdmiIn4":
CurrentInputNumber = 4;
break;
case "displayPortIn1":
CurrentInputNumber = 5;
break;
case "displayPortIn2":
CurrentInputNumber = 6;
break;
case "dviIn":
CurrentInputNumber = 7;
break;
case "streaming":
CurrentInputNumber = 8;
break;

foreach (var item in Inputs.Items)
{
item.Value.IsSelected = item.Key.Equals(b);
}
}
*/

Inputs.CurrentItem = b;
#endif

}


private void UpdateBooleanFeedback()
{
try
Expand Down

0 comments on commit 0887e99

Please sign in to comment.