Fixes USB Routing for routing via Inputs and input to input

Also adds feedbacks for Audio Breakaway and USB Breakaway status
This commit is contained in:
Andrew Welker
2020-05-18 11:32:44 -06:00
parent 19c4428dc8
commit 46ecb676c0
2 changed files with 192 additions and 159 deletions

View File

@@ -1,127 +1,127 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.GeneralIO; using Crestron.SimplSharpPro.GeneralIO;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.CrestronIO namespace PepperDash.Essentials.Core.CrestronIO
{ {
[Description("Wrapper class for the Crestron StatusSign device")] [Description("Wrapper class for the Crestron StatusSign device")]
public class StatusSignController : CrestronGenericBridgeableBaseDevice public class StatusSignController : CrestronGenericBridgeableBaseDevice
{ {
private readonly StatusSign _device; private readonly StatusSign _device;
public BoolFeedback RedLedEnabledFeedback { get; private set; } public BoolFeedback RedLedEnabledFeedback { get; private set; }
public BoolFeedback GreenLedEnabledFeedback { get; private set; } public BoolFeedback GreenLedEnabledFeedback { get; private set; }
public BoolFeedback BlueLedEnabledFeedback { get; private set; } public BoolFeedback BlueLedEnabledFeedback { get; private set; }
public IntFeedback RedLedBrightnessFeedback { get; private set; } public IntFeedback RedLedBrightnessFeedback { get; private set; }
public IntFeedback GreenLedBrightnessFeedback { get; private set; } public IntFeedback GreenLedBrightnessFeedback { get; private set; }
public IntFeedback BlueLedBrightnessFeedback { get; private set; } public IntFeedback BlueLedBrightnessFeedback { get; private set; }
public StatusSignController(string key, string name, GenericBase hardware) : base(key, name, hardware) public StatusSignController(string key, string name, GenericBase hardware) : base(key, name, hardware)
{
_device = hardware as StatusSign;
RedLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Red]
.ControlFeedback.BoolValue);
GreenLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Green]
.ControlFeedback.BoolValue);
BlueLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Blue]
.ControlFeedback.BoolValue);
RedLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Red].BrightnessFeedback);
GreenLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Green].BrightnessFeedback);
BlueLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Blue].BrightnessFeedback);
if (_device != null) _device.BaseEvent += _device_BaseEvent;
}
void _device_BaseEvent(GenericBase device, BaseEventArgs args)
{
switch (args.EventId)
{
case StatusSign.LedBrightnessFeedbackEventId:
RedLedBrightnessFeedback.FireUpdate();
GreenLedBrightnessFeedback.FireUpdate();
BlueLedBrightnessFeedback.FireUpdate();
break;
case StatusSign.LedControlFeedbackEventId:
RedLedEnabledFeedback.FireUpdate();
GreenLedEnabledFeedback.FireUpdate();
BlueLedEnabledFeedback.FireUpdate();
break;
}
}
public void EnableLedControl(bool red, bool green, bool blue)
{
_device.Leds[(uint) StatusSign.Led.eLedColor.Red].Control.BoolValue = red;
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Control.BoolValue = green;
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Control.BoolValue = blue;
}
public void SetColor(uint red, uint green, uint blue)
{
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Red].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(red);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Red LED brightness. value: {0}", red);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(green);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Green LED brightness. value: {0}", green);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(blue);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Blue LED brightness. value: {0}", blue);
}
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{ {
var joinMap = new StatusSignControllerJoinMap(joinStart); _device = hardware as StatusSign;
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); RedLedEnabledFeedback =
new BoolFeedback(
if (!string.IsNullOrEmpty(joinMapSerialized)) () =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Red]
.ControlFeedback.BoolValue);
GreenLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Green]
.ControlFeedback.BoolValue);
BlueLedEnabledFeedback =
new BoolFeedback(
() =>
_device.Leds[(uint) StatusSign.Led.eLedColor.Blue]
.ControlFeedback.BoolValue);
RedLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Red].BrightnessFeedback);
GreenLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Green].BrightnessFeedback);
BlueLedBrightnessFeedback =
new IntFeedback(() => (int) _device.Leds[(uint) StatusSign.Led.eLedColor.Blue].BrightnessFeedback);
if (_device != null) _device.BaseEvent += _device_BaseEvent;
}
void _device_BaseEvent(GenericBase device, BaseEventArgs args)
{
switch (args.EventId)
{
case StatusSign.LedBrightnessFeedbackEventId:
RedLedBrightnessFeedback.FireUpdate();
GreenLedBrightnessFeedback.FireUpdate();
BlueLedBrightnessFeedback.FireUpdate();
break;
case StatusSign.LedControlFeedbackEventId:
RedLedEnabledFeedback.FireUpdate();
GreenLedEnabledFeedback.FireUpdate();
BlueLedEnabledFeedback.FireUpdate();
break;
}
}
public void EnableLedControl(bool red, bool green, bool blue)
{
_device.Leds[(uint) StatusSign.Led.eLedColor.Red].Control.BoolValue = red;
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Control.BoolValue = green;
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Control.BoolValue = blue;
}
public void SetColor(uint red, uint green, uint blue)
{
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Red].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(red);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Red LED brightness. value: {0}", red);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Green].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(green);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Green LED brightness. value: {0}", green);
}
try
{
_device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Brightness =
(StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(blue);
}
catch (InvalidOperationException)
{
Debug.Console(1, this, "Error converting value to Blue LED brightness. value: {0}", blue);
}
}
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
var joinMap = new StatusSignControllerJoinMap(joinStart);
var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);
if (!string.IsNullOrEmpty(joinMapSerialized))
joinMap = JsonConvert.DeserializeObject<StatusSignControllerJoinMap>(joinMapSerialized); joinMap = JsonConvert.DeserializeObject<StatusSignControllerJoinMap>(joinMapSerialized);
bridge.AddJoinMap(Key, joinMap); bridge.AddJoinMap(Key, joinMap);
Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); Debug.Console(1, this, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
trilist.SetBoolSigAction(joinMap.RedControl.JoinNumber, b => EnableControl(trilist, joinMap, this)); trilist.SetBoolSigAction(joinMap.RedControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
trilist.SetBoolSigAction(joinMap.GreenControl.JoinNumber, b => EnableControl(trilist, joinMap, this)); trilist.SetBoolSigAction(joinMap.GreenControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
trilist.SetBoolSigAction(joinMap.BlueControl.JoinNumber, b => EnableControl(trilist, joinMap, this)); trilist.SetBoolSigAction(joinMap.BlueControl.JoinNumber, b => EnableControl(trilist, joinMap, this));
@@ -139,44 +139,44 @@ namespace PepperDash.Essentials.Core.CrestronIO
RedLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.RedLed.JoinNumber]); RedLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.RedLed.JoinNumber]);
BlueLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.BlueLed.JoinNumber]); BlueLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.BlueLed.JoinNumber]);
GreenLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.GreenLed.JoinNumber]); GreenLedBrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.GreenLed.JoinNumber]);
} }
private static void EnableControl(BasicTriList triList, StatusSignControllerJoinMap joinMap, private static void EnableControl(BasicTriList triList, StatusSignControllerJoinMap joinMap,
StatusSignController device) StatusSignController device)
{ {
var redEnable = triList.BooleanOutput[joinMap.RedControl.JoinNumber].BoolValue; var redEnable = triList.BooleanOutput[joinMap.RedControl.JoinNumber].BoolValue;
var greenEnable = triList.BooleanOutput[joinMap.GreenControl.JoinNumber].BoolValue; var greenEnable = triList.BooleanOutput[joinMap.GreenControl.JoinNumber].BoolValue;
var blueEnable = triList.BooleanOutput[joinMap.BlueControl.JoinNumber].BoolValue; var blueEnable = triList.BooleanOutput[joinMap.BlueControl.JoinNumber].BoolValue;
device.EnableLedControl(redEnable, greenEnable, blueEnable); device.EnableLedControl(redEnable, greenEnable, blueEnable);
} }
private static void SetColor(BasicTriList triList, StatusSignControllerJoinMap joinMap, private static void SetColor(BasicTriList triList, StatusSignControllerJoinMap joinMap,
StatusSignController device) StatusSignController device)
{ {
var redBrightness = triList.UShortOutput[joinMap.RedLed.JoinNumber].UShortValue; var redBrightness = triList.UShortOutput[joinMap.RedLed.JoinNumber].UShortValue;
var greenBrightness = triList.UShortOutput[joinMap.GreenLed.JoinNumber].UShortValue; var greenBrightness = triList.UShortOutput[joinMap.GreenLed.JoinNumber].UShortValue;
var blueBrightness = triList.UShortOutput[joinMap.BlueLed.JoinNumber].UShortValue; var blueBrightness = triList.UShortOutput[joinMap.BlueLed.JoinNumber].UShortValue;
device.SetColor(redBrightness, greenBrightness, blueBrightness); device.SetColor(redBrightness, greenBrightness, blueBrightness);
} }
} }
public class StatusSignControllerFactory : EssentialsDeviceFactory<StatusSignController> public class StatusSignControllerFactory : EssentialsDeviceFactory<StatusSignController>
{ {
public StatusSignControllerFactory() public StatusSignControllerFactory()
{ {
TypeNames = new List<string>() { "statussign" }; TypeNames = new List<string>() { "statussign" };
} }
public override EssentialsDevice BuildDevice(DeviceConfig dc) public override EssentialsDevice BuildDevice(DeviceConfig dc)
{ {
Debug.Console(1, "Factory Attempting to create new StatusSign Device"); Debug.Console(1, "Factory Attempting to create new StatusSign Device");
var control = CommFactory.GetControlPropertiesConfig(dc); var control = CommFactory.GetControlPropertiesConfig(dc);
var cresnetId = control.CresnetIdInt; var cresnetId = control.CresnetIdInt;
return new StatusSignController(dc.Key, dc.Name, new StatusSign(cresnetId, Global.ControlSystem)); return new StatusSignController(dc.Key, dc.Name, new StatusSign(cresnetId, Global.ControlSystem));
} }
} }
} }

View File

@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM;
using Crestron.SimplSharpPro.DM.Cards; using Crestron.SimplSharpPro.DM.Cards;
@@ -383,6 +384,11 @@ namespace PepperDash.Essentials.DM
} }
} }
private void ChassisOnBaseEvent(GenericBase device, BaseEventArgs args)
{
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -775,6 +781,20 @@ namespace PepperDash.Essentials.DM
SystemIdBusyFeedback.FireUpdate(); SystemIdBusyFeedback.FireUpdate();
break; break;
} }
case DMSystemEventIds.AudioBreakawayEventId:
{
Debug.Console(2, this, "AudioBreakaway Event: value: {0}",
(Chassis as DmMDMnxn).EnableAudioBreakawayFeedback.BoolValue);
EnableAudioBreakawayFeedback.FireUpdate();
break;
}
case DMSystemEventIds.USBBreakawayEventId:
{
Debug.Console(2, this, "USBBreakaway Event: value: {0}",
(Chassis as DmMDMnxn).EnableUSBBreakawayFeedback.BoolValue);
EnableUsbBreakawayFeedback.FireUpdate();
break;
}
} }
} }
@@ -1036,7 +1056,7 @@ namespace PepperDash.Essentials.DM
Debug.Console(2, this, "Executing USB Input switch.\r\n in:{0} output: {1}", input, output); Debug.Console(2, this, "Executing USB Input switch.\r\n in:{0} output: {1}", input, output);
if (input > chassisSize) if (output > chassisSize)
{ {
//wanting to route an input to an output. Subtract chassis size and get output, unless it's 8x8 //wanting to route an input to an output. Subtract chassis size and get output, unless it's 8x8
//need this to determine USB routing values //need this to determine USB routing values
@@ -1064,12 +1084,12 @@ namespace PepperDash.Essentials.DM
Chassis.USBEnter.BoolValue = true; Chassis.USBEnter.BoolValue = true;
if (Chassis.Inputs[input] == null) if (Chassis.Inputs[output] == null)
{ {
return; return;
} }
Debug.Console(2, this, "Routing USB for input {0} to {1}", Chassis.Inputs[input], dmCard); Debug.Console(2, this, "Routing USB for input {0} to {1}", Chassis.Inputs[output], dmCard);
Chassis.Inputs[input].USBRoutedTo = dmCard; Chassis.Inputs[output].USBRoutedTo = dmCard;
} }
} }
#endregion #endregion
@@ -1105,6 +1125,19 @@ namespace PepperDash.Essentials.DM
SystemIdFeebdack.LinkInputSig(trilist.UShortInput[joinMap.SystemId.JoinNumber]); SystemIdFeebdack.LinkInputSig(trilist.UShortInput[joinMap.SystemId.JoinNumber]);
SystemIdBusyFeedback.LinkInputSig(trilist.BooleanInput[joinMap.SystemId.JoinNumber]); SystemIdBusyFeedback.LinkInputSig(trilist.BooleanInput[joinMap.SystemId.JoinNumber]);
EnableAudioBreakawayFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableAudioBreakaway.JoinNumber]);
EnableUsbBreakawayFeedback.LinkInputSig(trilist.BooleanInput[joinMap.EnableUsbBreakaway.JoinNumber]);
trilist.OnlineStatusChange += (o, a) =>
{
if (!a.DeviceOnLine) return;
EnableAudioBreakawayFeedback.FireUpdate();
EnableUsbBreakawayFeedback.FireUpdate();
SystemIdBusyFeedback.FireUpdate();
SystemIdFeebdack.FireUpdate();
};
// Link up outputs // Link up outputs
for (uint i = 1; i <= Chassis.NumberOfOutputs; i++) for (uint i = 1; i <= Chassis.NumberOfOutputs; i++)
{ {