Skip to content

Commit

Permalink
Merge pull request #113 from PepperDash/development
Browse files Browse the repository at this point in the history
feat: implemented IBasicVolumeWithFeedback
  • Loading branch information
ngenovese11 authored Mar 13, 2024
2 parents 6decf35 + 9c1e631 commit 6c96bf9
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 3 deletions.
49 changes: 48 additions & 1 deletion src/NvxEpi/Devices/Nvx36X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NvxEpi.Abstractions.HdmiInput;
using NvxEpi.Abstractions.HdmiOutput;
using NvxEpi.Abstractions.Usb;
using NvxEpi.Features.Audio;
using NvxEpi.Features.AutomaticRouting;
using NvxEpi.Features.Config;
using NvxEpi.Features.Hdmi.Input;
Expand All @@ -19,6 +20,7 @@
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config;
using Feedback = PepperDash.Essentials.Core.Feedback;

namespace NvxEpi.Devices
{
Expand All @@ -30,8 +32,10 @@ public class Nvx36X :
IHdmiInput,
IVideowallMode,
IRouting,
ICec
ICec,
IBasicVolumeWithFeedback
{
private IBasicVolumeWithFeedback _audio;
private IHdmiInput _hdmiInput;
private IVideowallMode _hdmiOutput;
private IUsbStreamWithHardware _usbStream;
Expand All @@ -50,10 +54,13 @@ public override bool CustomActivate()
{
var result = base.CustomActivate();

_audio = new Nvx36XAudio((DmNvx36x) Hardware, this);
_usbStream = UsbStream.GetUsbStream(this, _config.Usb);
_hdmiInput = new HdmiInput1(this);
_hdmiOutput = new VideowallModeOutput(this);

Feedbacks.AddRange(new [] { (Feedback)_audio.MuteFeedback, _audio.VolumeLevelFeedback });

if (_config.EnableAutoRoute)
// ReSharper disable once ObjectCreationAsStatement
new AutomaticInputRouter(_hdmiInput);
Expand Down Expand Up @@ -212,5 +219,45 @@ public StringFeedback UsbLocalId
{
get { return _usbStream.UsbLocalId; }
}

public void VolumeUp(bool pressRelease)
{
_audio.VolumeUp(pressRelease);
}

public void VolumeDown(bool pressRelease)
{
_audio.VolumeDown(pressRelease);
}

public void MuteToggle()
{
_audio.MuteToggle();
}

public void SetVolume(ushort level)
{
_audio.SetVolume(level);
}

public void MuteOn()
{
_audio.MuteOn();
}

public void MuteOff()
{
_audio.MuteOff();
}

public IntFeedback VolumeLevelFeedback
{
get { return _audio.VolumeLevelFeedback; }
}

public BoolFeedback MuteFeedback
{
get { return _audio.MuteFeedback; }
}
}
}
2 changes: 1 addition & 1 deletion src/NvxEpi/Factories/NvxDirectorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override EssentialsDevice BuildDevice(DeviceConfig dc)
switch (dc.Type.ToLower())
{
case "xiodirector":
xio = new DmXioDirector80(config.Control.IpIdInt, Global.ControlSystem);
xio = new DmXioDirectorEnterprise(config.Control.IpIdInt, Global.ControlSystem);
break;
case "xiodirector80":
xio = new DmXioDirector80(config.Control.IpIdInt, Global.ControlSystem);
Expand Down
89 changes: 89 additions & 0 deletions src/NvxEpi/Features/Audio/Nvx36xAudio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM.Streaming;
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace NvxEpi.Features.Audio
{
public class Nvx36XAudio : IBasicVolumeWithFeedback
{
private readonly DmNvx36x _device;
private readonly IKeyed _parent;

public Nvx36XAudio(DmNvx36x device, IKeyed parent)
{
_device = device;
_parent = parent;

MuteFeedback = new BoolFeedback("Muted", () => _device.Control.AudioMutedFeedback.BoolValue);

VolumeLevelFeedback = new IntFeedback("Volume", () =>
{
var volume = _device.Control.AnalogAudioOutputVolumeFeedback.ShortValue;
var result = MapVolume(volume);
return result;
});

_device.OnlineStatusChange += (@base, args) => MuteFeedback.FireUpdate();
_device.OnlineStatusChange += (@base, args) => VolumeLevelFeedback.FireUpdate();

_device.BaseEvent += (@base, args) => MuteFeedback.FireUpdate();
_device.BaseEvent += (@base, args) => VolumeLevelFeedback.FireUpdate();
}

public static int MapVolume(short level)
{
const float inputMin = -800;
const float inputMax = 240;

const float outputMin = 0;
const float outputMax = ushort.MaxValue;

var normalized = (level - inputMin) / (inputMax - inputMin);
var mappedValue = (int)(normalized * (outputMax - outputMin) + outputMin);

return mappedValue;
}

public void VolumeUp(bool pressRelease)
{
Debug.Console(0, _parent, "Volume press not implemented");
}

public void VolumeDown(bool pressRelease)
{
Debug.Console(0, _parent, "Volume press not implemented");
}

public void MuteToggle()
{
if (_device.Control.AudioMutedFeedback.BoolValue)
{
_device.Control.AudioUnmute();
}
else
{
_device.Control.AudioMute();
}
}

public void SetVolume(ushort level)
{
var volume = CrestronEnvironment.ScaleWithLimits(level, ushort.MaxValue, ushort.MinValue, 240, -800);
_device.Control.AnalogAudioOutputVolume.ShortValue = (short) volume;
}

public void MuteOn()
{
_device.Control.AudioMute();
}

public void MuteOff()
{
_device.Control.AudioUnmute();
}

public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
}
}
1 change: 1 addition & 0 deletions src/NvxEpi/NvxEpi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="Application\Entities\NvxApplicationVideoReceiver.cs" />
<Compile Include="Application\Entities\NvxApplicationVideoTransmitter.cs" />
<Compile Include="Devices\NvxXioDirector.cs" />
<Compile Include="Features\Audio\Nvx36xAudio.cs" />
<Compile Include="Features\AutomaticRouting\AutomaticInputRouter.cs" />
<Compile Include="Features\Config\NvxDirectorConfig.cs" />
<Compile Include="Factories\NvxDirectorFactory.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/NvxEpi/Services/Feedback/UsbRouteFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ private static int ReturnRoute(DmNvxBaseClass device)

if (remoteEndpoint == null)
{
Debug.Console(0, "RemoteEndpoint is Null", deviceIp);
return 0;
}

Expand Down

0 comments on commit 6c96bf9

Please sign in to comment.