Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add video mute #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GetPackages.BAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Echo ON
nuget install .\packages.config -OutputDirectory .\packages -excludeVersion
171 changes: 149 additions & 22 deletions epi-display-lg/LgDisplayDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Routing;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


using PepperDash.Essentials.Core.Queues;

namespace Epi.Display.Lg
{
public class LgDisplayController : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor,
IBridgeAdvanced

{

GenericQueue ReceiveQueue;
Expand All @@ -32,6 +34,7 @@ public class LgDisplayController : TwoWayDisplayBase, IBasicVolumeWithFeedback,
private int _inputNumber;
private bool _isCoolingDown;
private bool _isMuted;
private bool _VideoIsMuted;
private bool _isSerialComm;
private bool _isWarmingUp;
private bool _lastCommandSentWasVolume;
Expand Down Expand Up @@ -108,8 +111,8 @@ public bool PowerIsOn
IsCoolingDown = false;
}, CooldownTime);
}
PowerIsOnFeedback.FireUpdate();

PowerIsOnFeedback.FireUpdate();
}
}

Expand Down Expand Up @@ -143,6 +146,19 @@ public bool IsMuted
}
}

public bool VideoIsMuted
{
get
{
return _VideoIsMuted;
}
set
{
_VideoIsMuted = value;
VideoIsMutedFeedback.FireUpdate();
}
}

private readonly int _lowerLimit;
private readonly int _upperLimit;
private readonly uint _coolingTimeMs;
Expand All @@ -163,7 +179,7 @@ private set
}

private bool ScaleVolume { get; set; }

protected override Func<bool> PowerIsOnFeedbackFunc
{
get { return () => PowerIsOn; }
Expand Down Expand Up @@ -196,6 +212,12 @@ protected override Func<string> CurrentInputFeedbackFunc
/// </summary>
public BoolFeedback MuteFeedback { get; private set; }

/// <summary>
/// Video Mute Feedback Property
/// </summary>
public BoolFeedback VideoIsMutedFeedback { get; private set; }


/// <summary>
/// Scales the level to the range of the display and sends the command
/// Set: "kf [SetID] [Range 0x00 - 0x64]"
Expand All @@ -207,11 +229,11 @@ public void SetVolume(ushort level)
_lastVolumeSent = level;
if (!ScaleVolume)
{
scaled = (int) NumericalHelpers.Scale(level, 0, 65535, 0, 100);
scaled = (int)NumericalHelpers.Scale(level, 0, 65535, 0, 100);
}
else
{
scaled = (int) NumericalHelpers.Scale(level, 0, 65535, _lowerLimit, _upperLimit);
scaled = (int)NumericalHelpers.Scale(level, 0, 65535, _lowerLimit, _upperLimit);
}

SendData(string.Format("kf {0} {1}", Id, scaled));
Expand Down Expand Up @@ -248,6 +270,37 @@ public void MuteToggle()
}
}

/// <summary>
/// Set VideoMute On
/// </summary>
public void VideoMuteOn()
{
SendData(string.Format("kd {0} {1}", Id, "01"));
}

/// <summary>
/// Set VideoMute Off
/// </summary>
public void VideoMuteOff()
{
SendData(string.Format("kd {0} {1}", Id, "00"));
}

/// <summary>
/// Toggle Current VideoMute State
/// </summary>
public void VideoMuteToggle()
{
if (VideoIsMuted)
{
VideoMuteOff();
}
else
{
VideoMuteOn();
}
}

/// <summary>
/// Decrement Volume on Press
/// </summary>
Expand Down Expand Up @@ -288,9 +341,42 @@ public void VolumeUp(bool pressRelease)

#region IBridgeAdvanced Members

/// <summary>
/// Calls the extension method to bridge the device to an EiscApi class (SIMPL Bridge)
/// </summary>
/// <param name="trilist"></param>
/// <param name="joinStart"></param>
/// <param name="joinMapKey"></param>

public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);

LgDisplayJoinMap joinMap = new LgDisplayJoinMap(joinStart);

var JoinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey);

if (!string.IsNullOrEmpty(JoinMapSerialized))
joinMap = JsonConvert.DeserializeObject<LgDisplayJoinMap>(JoinMapSerialized);

if (bridge != null)
{
bridge.AddJoinMap(Key, joinMap);
}

Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
Debug.Console(0, "Linking to Display: {0}", Name);

trilist.SetSigTrueAction(joinMap.VideoMuteOn.JoinNumber, this.VideoMuteOn);
trilist.SetSigTrueAction(joinMap.VideoMuteOff.JoinNumber, this.VideoMuteOff);
trilist.SetSigTrueAction(joinMap.VideoMuteToggle.JoinNumber, this.VideoMuteToggle);

VideoIsMutedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VideoMuteOn.JoinNumber]);
VideoIsMutedFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.VideoMuteOff.JoinNumber]);
VideoIsMutedFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VideoMuteToggle.JoinNumber]);


base.LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge);
}

#endregion
Expand Down Expand Up @@ -339,21 +425,22 @@ private void Init()
if (!ScaleVolume)
{
_volumeIncrementer = new ActionIncrementer(655, 0, 65535, 800, 80,
v => SetVolume((ushort) v),
v => SetVolume((ushort)v),
() => _lastVolumeSent);
}
else
{
var scaleUpper = NumericalHelpers.Scale(_upperLimit, 0, 100, 0, 65535);
var scaleLower = NumericalHelpers.Scale(_lowerLimit, 0, 100, 0, 65535);

_volumeIncrementer = new ActionIncrementer(655, (int) scaleLower, (int) scaleUpper, 800, 80,
v => SetVolume((ushort) v),
_volumeIncrementer = new ActionIncrementer(655, (int)scaleLower, (int)scaleUpper, 800, 80,
v => SetVolume((ushort)v),
() => _lastVolumeSent);
}

MuteFeedback = new BoolFeedback(() => IsMuted);
VolumeLevelFeedback = new IntFeedback(() => _volumeLevelForSig);
VideoIsMutedFeedback = new BoolFeedback(() => { return VideoIsMuted; });

AddRoutingInputPort(
new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.Audio | eRoutingSignalType.Video,
Expand Down Expand Up @@ -398,7 +485,7 @@ private void ProcessResponse(string s)
}


var data = s.Trim().Replace("OK", "").Split(' ');
var data = s.Trim().Replace("OK", "").Split(' '); //d 01 OK00x / d 01 01x

string command;
string id;
Expand All @@ -407,7 +494,7 @@ private void ProcessResponse(string s)
if (data.Length < 3)
{
Debug.Console(2, this, "Unable to parse message, not enough data in message: {0}", s);
return;
return;
}
else
{
Expand Down Expand Up @@ -437,6 +524,9 @@ private void ProcessResponse(string s)
case ("e"):
UpdateMuteFb(responseValue);
break;
case ("d"):
UpdateVideoMuteFb(responseValue);
break;
}
}

Expand Down Expand Up @@ -514,6 +604,15 @@ public void InputGet()
SendData(string.Format("kb {0} FF", Id));
}

/// <summary>
/// Poll VideoMute State
/// </summary>
public void VideoMuteGet()
{
SendData(string.Format("kd {0} FF", Id));
}


/// <summary>
/// Executes a switch, turning on display if necessary.
/// </summary>
Expand Down Expand Up @@ -563,7 +662,7 @@ public override void PowerOn()
{
if (_isSerialComm || _overrideWol)
{
SendData(string.Format("ka {0} {1}", Id, _smallDisplay ? "1": "01"));
SendData(string.Format("ka {0} {1}", Id, _smallDisplay ? "1" : "01"));
}
}

Expand Down Expand Up @@ -633,7 +732,7 @@ public void UpdateInputFb(string s)
public void UpdatePowerFb(string s)
{
PowerIsOn = s.Contains("1");

}

/// <summary>
Expand Down Expand Up @@ -697,6 +796,31 @@ public void UpdateMuteFb(string s)
}
}

/// <summary>
/// Process VideoMute Feedback from Response
/// </summary>
/// <param name="s">response from device</param>
public void UpdateVideoMuteFb(string s)
{
try
{
var state = Convert.ToInt32(s);

if (state == 0)
{
VideoIsMuted = false;
}
else if (state == 1)
{
VideoIsMuted = true;
}
}
catch (Exception e)
{
Debug.Console(2, this, "Unable to parse {0} to Int32 {1}", s, e);
}
}

/// <summary>
/// Updates Digital Route Feedback for Simpl EISC
/// </summary>
Expand Down Expand Up @@ -735,15 +859,18 @@ public void StatusGet()
{
//SendBytes(new byte[] { Header, StatusControlCmd, 0x00, 0x00, StatusControlGet, 0x00 });
CrestronInvoke.BeginInvoke((o) =>
{
PowerGet();
CrestronEnvironment.Sleep(1500);
InputGet();
CrestronEnvironment.Sleep(1500);
VolumeGet();
CrestronEnvironment.Sleep(1500);
MuteGet();
});
{
PowerGet();
CrestronEnvironment.Sleep(1500);
InputGet();
CrestronEnvironment.Sleep(1500);
VolumeGet();
CrestronEnvironment.Sleep(1500);
MuteGet();
CrestronEnvironment.Sleep(1500);
VideoMuteGet();

});
}


Expand Down
45 changes: 45 additions & 0 deletions epi-display-lg/LgDisplayJoinMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core;

namespace Epi.Display.Lg
{
public class LgDisplayJoinMap : DisplayControllerJoinMap
{
public LgDisplayJoinMap(uint joinStart)
: base(joinStart, typeof(LgDisplayJoinMap))
{
}
[JoinName("VideoMuteOff")]
public JoinDataComplete VideoMuteOff =
new JoinDataComplete(new JoinData { JoinNumber = 21, JoinSpan = 1 },
new JoinMetadata
{
Description = "VideoMuteOff",
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
JoinType = eJoinType.Digital
});
[JoinName("VideoMuteOn")]
public JoinDataComplete VideoMuteOn =
new JoinDataComplete(new JoinData { JoinNumber = 22, JoinSpan = 1 },
new JoinMetadata
{
Description = "VideoMuteOn",
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
JoinType = eJoinType.Digital
});
[JoinName("VideoMuteToggle")]
public JoinDataComplete VideoMuteToggle =
new JoinDataComplete(new JoinData { JoinNumber = 23, JoinSpan = 1 },
new JoinMetadata
{
Description = "VideoMuteOn",
JoinCapabilities = eJoinCapabilities.ToFromSIMPL,
JoinType = eJoinType.Digital
});
}
}
1 change: 1 addition & 0 deletions epi-display-lg/epi-display-lg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<ItemGroup>
<Compile Include="LgDisplayControllerFactory.cs" />
<Compile Include="LgDisplayDevice.cs" />
<Compile Include="LgDisplayJoinMap.cs" />
<Compile Include="LgDisplayPropertiesConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Properties\ControlSystem.cfg" />
Expand Down
Loading