Updates conditional check to allow for the highes numbered IR port to be used.

This commit is contained in:
Neil Dorin
2020-08-10 10:11:54 -06:00
parent 22ff61d7f3
commit e5d4ba48fb

View File

@@ -1,83 +1,83 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public static class IRPortHelper public static class IRPortHelper
{ {
public static string IrDriverPathPrefix public static string IrDriverPathPrefix
{ {
get get
{ {
return Global.FilePathPrefix + "IR" + Global.DirectorySeparator; return Global.FilePathPrefix + "IR" + Global.DirectorySeparator;
} }
} }
/// <summary> /// <summary>
/// Finds either the ControlSystem or a device controller that contains IR ports and /// Finds either the ControlSystem or a device controller that contains IR ports and
/// returns a port from the hardware device /// returns a port from the hardware device
/// </summary> /// </summary>
/// <param name="propsToken"></param> /// <param name="propsToken"></param>
/// <returns>IrPortConfig object. The port and or filename will be empty/null /// <returns>IrPortConfig object. The port and or filename will be empty/null
/// if valid values don't exist on config</returns> /// if valid values don't exist on config</returns>
public static IrOutPortConfig GetIrPort(JToken propsToken) public static IrOutPortConfig GetIrPort(JToken propsToken)
{ {
var control = propsToken["control"]; var control = propsToken["control"];
if (control == null) if (control == null)
return null; return null;
if (control["method"].Value<string>() != "ir") if (control["method"].Value<string>() != "ir")
{ {
Debug.Console(0, "IRPortHelper called with non-IR properties"); Debug.Console(0, "IRPortHelper called with non-IR properties");
return null; return null;
} }
var port = new IrOutPortConfig(); var port = new IrOutPortConfig();
var portDevKey = control.Value<string>("controlPortDevKey"); var portDevKey = control.Value<string>("controlPortDevKey");
var portNum = control.Value<uint>("controlPortNumber"); var portNum = control.Value<uint>("controlPortNumber");
if (portDevKey == null || portNum == 0) if (portDevKey == null || portNum == 0)
{ {
Debug.Console(1, "WARNING: Properties is missing port device or port number"); Debug.Console(1, "WARNING: Properties is missing port device or port number");
return port; return port;
} }
IIROutputPorts irDev = null; IIROutputPorts irDev = null;
if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase) if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase)
|| portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase)) || portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
irDev = Global.ControlSystem; irDev = Global.ControlSystem;
else else
irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts; irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
if (irDev == null) if (irDev == null)
{ {
Debug.Console(1, "[Config] Error, device with IR ports '{0}' not found", portDevKey); Debug.Console(1, "[Config] Error, device with IR ports '{0}' not found", portDevKey);
return port; return port;
} }
if (portNum <= irDev.NumberOfIROutputPorts) // success! if (portNum <= irDev.NumberOfIROutputPorts) // success!
{ {
var file = IrDriverPathPrefix + control["irFile"].Value<string>(); var file = IrDriverPathPrefix + control["irFile"].Value<string>();
port.Port = irDev.IROutputPorts[portNum]; port.Port = irDev.IROutputPorts[portNum];
port.FileName = file; port.FileName = file;
return port; // new IrOutPortConfig { Port = irDev.IROutputPorts[portNum], FileName = file }; return port; // new IrOutPortConfig { Port = irDev.IROutputPorts[portNum], FileName = file };
} }
else else
{ {
Debug.Console(1, "[Config] Error, device '{0}' IR port {1} out of range", Debug.Console(1, "[Config] Error, device '{0}' IR port {1} out of range",
portDevKey, portNum); portDevKey, portNum);
return port; return port;
} }
} }
public static IROutputPort GetIrOutputPort(DeviceConfig dc) public static IROutputPort GetIrOutputPort(DeviceConfig dc)
@@ -124,7 +124,7 @@ namespace PepperDash.Essentials.Core
Debug.Console(0, "WARNING: device with IR ports '{0}' not found", portDevKey); Debug.Console(0, "WARNING: device with IR ports '{0}' not found", portDevKey);
return null; return null;
} }
if (portNum >= irDev.NumberOfIROutputPorts) if (portNum > irDev.NumberOfIROutputPorts)
{ {
Debug.Console(0, "WARNING: device '{0}' IR port {1} out of range", Debug.Console(0, "WARNING: device '{0}' IR port {1} out of range",
portDevKey, portNum); portDevKey, portNum);
@@ -154,82 +154,82 @@ namespace PepperDash.Essentials.Core
return irDevice; return irDevice;
} }
/* /*
/// <summary> /// <summary>
/// Returns a ready-to-go IrOutputPortController from a DeviceConfig object. /// Returns a ready-to-go IrOutputPortController from a DeviceConfig object.
/// </summary> /// </summary>
public static IrOutputPortController GetIrOutputPortController(DeviceConfig devConf) public static IrOutputPortController GetIrOutputPortController(DeviceConfig devConf)
{ {
var irControllerKey = devConf.Key + "-ir"; var irControllerKey = devConf.Key + "-ir";
if (devConf.Properties == null) if (devConf.Properties == null)
{ {
Debug.Console(0, "[{0}] WARNING: Device config does not include properties. IR will not function.", devConf.Key); Debug.Console(0, "[{0}] WARNING: Device config does not include properties. IR will not function.", devConf.Key);
return new IrOutputPortController(irControllerKey, null, ""); return new IrOutputPortController(irControllerKey, null, "");
} }
var control = devConf.Properties["control"]; var control = devConf.Properties["control"];
if (control == null) if (control == null)
{ {
var c = new IrOutputPortController(irControllerKey, null, ""); var c = new IrOutputPortController(irControllerKey, null, "");
Debug.Console(0, c, "WARNING: Device config does not include control properties. IR will not function"); Debug.Console(0, c, "WARNING: Device config does not include control properties. IR will not function");
return c; return c;
} }
var portDevKey = control.Value<string>("controlPortDevKey"); var portDevKey = control.Value<string>("controlPortDevKey");
var portNum = control.Value<uint>("controlPortNumber"); var portNum = control.Value<uint>("controlPortNumber");
IIROutputPorts irDev = null; IIROutputPorts irDev = null;
if (portDevKey == null) if (portDevKey == null)
{ {
var c = new IrOutputPortController(irControllerKey, null, ""); var c = new IrOutputPortController(irControllerKey, null, "");
Debug.Console(0, c, "WARNING: control properties is missing ir device"); Debug.Console(0, c, "WARNING: control properties is missing ir device");
return c; return c;
} }
if (portNum == 0) if (portNum == 0)
{ {
var c = new IrOutputPortController(irControllerKey, null, ""); var c = new IrOutputPortController(irControllerKey, null, "");
Debug.Console(0, c, "WARNING: control properties is missing ir port number"); Debug.Console(0, c, "WARNING: control properties is missing ir port number");
return c; return c;
} }
if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase) if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase)
|| portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase)) || portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
irDev = Global.ControlSystem; irDev = Global.ControlSystem;
else else
irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts; irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
if (irDev == null) if (irDev == null)
{ {
var c = new IrOutputPortController(irControllerKey, null, ""); var c = new IrOutputPortController(irControllerKey, null, "");
Debug.Console(0, c, "WARNING: device with IR ports '{0}' not found", portDevKey); Debug.Console(0, c, "WARNING: device with IR ports '{0}' not found", portDevKey);
return c; return c;
} }
if (portNum <= irDev.NumberOfIROutputPorts) // success! if (portNum <= irDev.NumberOfIROutputPorts) // success!
return new IrOutputPortController(irControllerKey, irDev.IROutputPorts[portNum], return new IrOutputPortController(irControllerKey, irDev.IROutputPorts[portNum],
IrDriverPathPrefix + control["irFile"].Value<string>()); IrDriverPathPrefix + control["irFile"].Value<string>());
else else
{ {
var c = new IrOutputPortController(irControllerKey, null, ""); var c = new IrOutputPortController(irControllerKey, null, "");
Debug.Console(0, c, "WARNING: device '{0}' IR port {1} out of range", Debug.Console(0, c, "WARNING: device '{0}' IR port {1} out of range",
portDevKey, portNum); portDevKey, portNum);
return c; return c;
} }
}*/ }*/
} }
/// <summary> /// <summary>
/// Wrapper to help in IR port creation /// Wrapper to help in IR port creation
/// </summary> /// </summary>
public class IrOutPortConfig public class IrOutPortConfig
{ {
public IROutputPort Port { get; set; } public IROutputPort Port { get; set; }
public string FileName { get; set; } public string FileName { get; set; }
public IrOutPortConfig() public IrOutPortConfig()
{ {
FileName = ""; FileName = "";
} }
} }
} }