mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
Updated IRPortHelper
Updated IrOurputPortController #205 Please Check my work - I'm a little less confident in this one
This commit is contained in:
@@ -80,6 +80,81 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IROutputPort GetIrOutputPort(DeviceConfig dc)
|
||||||
|
{
|
||||||
|
var irControllerKey = dc.Key + "-ir";
|
||||||
|
if (dc.Properties == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "[{0}] WARNING: Device config does not include properties. IR will not function.", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var control = dc.Properties["control"];
|
||||||
|
if (control == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0,
|
||||||
|
"WARNING: Device config does not include control properties. IR will not function for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var portDevKey = control.Value<string>("controlPortDevKey");
|
||||||
|
var portNum = control.Value<uint>("controlPortNumber");
|
||||||
|
IIROutputPorts irDev = null;
|
||||||
|
|
||||||
|
if (portDevKey == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: control properties is missing ir device for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portNum == 0)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: control properties is missing ir port number for {0}", dc.Key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
|
||||||
|
irDev = Global.ControlSystem;
|
||||||
|
else
|
||||||
|
irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
|
||||||
|
|
||||||
|
if (irDev == null)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: device with IR ports '{0}' not found", portDevKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (portNum >= irDev.NumberOfIROutputPorts)
|
||||||
|
{
|
||||||
|
Debug.Console(0, "WARNING: device '{0}' IR port {1} out of range",
|
||||||
|
portDevKey, portNum);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var port = irDev.IROutputPorts[portNum];
|
||||||
|
|
||||||
|
port.LoadIRDriver(Global.FilePathPrefix + "IR" + Global.DirectorySeparator + control["irFile"].Value<string>());
|
||||||
|
|
||||||
|
return port;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IrOutputPortController GetIrOutputPortController(DeviceConfig config)
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Attempting to create new Ir Port Controller");
|
||||||
|
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var irDevice = new IrOutputPortController(config.Key, GetIrOutputPort, config);
|
||||||
|
|
||||||
|
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>
|
||||||
@@ -141,7 +216,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
portDevKey, portNum);
|
portDevKey, portNum);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ using System.Linq;
|
|||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharpPro.DeviceSupport;
|
using Crestron.SimplSharpPro.DeviceSupport;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
@@ -39,6 +42,18 @@ namespace PepperDash.Essentials.Core
|
|||||||
LoadDriver(irDriverFilepath);
|
LoadDriver(irDriverFilepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IrOutputPortController(string key, Func<DeviceConfig, IROutputPort> postActivationFunc,
|
||||||
|
DeviceConfig config)
|
||||||
|
: base(key)
|
||||||
|
{
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
IrPort = postActivationFunc(config);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the IR driver at path
|
/// Loads the IR driver at path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -119,6 +134,5 @@ namespace PepperDash.Essentials.Core
|
|||||||
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
||||||
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user