mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-13 19:54:59 +00:00
Fixes #362 by addressing issues with Loading IR driver as post activation action
This commit is contained in:
@@ -134,7 +134,9 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var port = irDev.IROutputPorts[portNum];
|
var port = irDev.IROutputPorts[portNum];
|
||||||
|
|
||||||
port.LoadIRDriver(Global.FilePathPrefix + "IR" + Global.DirectorySeparator + control["irFile"].Value<string>());
|
var filePath = Global.FilePathPrefix + "ir" + Global.DirectorySeparator + control["irFile"].Value<string>();
|
||||||
|
Debug.Console(1, "*************Attemting to load IR file: {0}***************", filePath);
|
||||||
|
port.LoadIRDriver(filePath);
|
||||||
|
|
||||||
return port;
|
return port;
|
||||||
|
|
||||||
@@ -149,7 +151,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var irDevice = new IrOutputPortController(config.Key + "-irController", GetIrOutputPort, config);
|
var postActivationFunc = new Func<DeviceConfig,IROutputPort> (GetIrOutputPort);
|
||||||
|
var irDevice = new IrOutputPortController(config.Key + "-ir", postActivationFunc, config);
|
||||||
|
|
||||||
return irDevice;
|
return irDevice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
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 Newtonsoft.Json.Linq;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IR port wrapper. May act standalone
|
/// IR port wrapper. May act standalone
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IrOutputPortController : Device
|
public class IrOutputPortController : Device
|
||||||
{
|
{
|
||||||
uint IrPortUid;
|
uint IrPortUid;
|
||||||
IROutputPort IrPort;
|
IROutputPort IrPort;
|
||||||
|
|
||||||
public ushort StandardIrPulseTime { get; set; }
|
public ushort StandardIrPulseTime { get; set; }
|
||||||
public string DriverFilepath { get; private set; }
|
public string DriverFilepath { get; private set; }
|
||||||
public bool DriverIsLoaded { get; private set; }
|
public bool DriverIsLoaded { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for IrDevice base class. If a null port is provided, this class will
|
/// Constructor for IrDevice base class. If a null port is provided, this class will
|
||||||
/// still function without trying to talk to a port.
|
/// still function without trying to talk to a port.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IrOutputPortController(string key, IROutputPort port, string irDriverFilepath)
|
public IrOutputPortController(string key, IROutputPort port, string irDriverFilepath)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
//if (port == null) throw new ArgumentNullException("port");
|
//if (port == null) throw new ArgumentNullException("port");
|
||||||
IrPort = port;
|
IrPort = port;
|
||||||
if (port == null)
|
if (port == null)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "WARNING No valid IR Port assigned to controller. IR will not function");
|
Debug.Console(0, this, "WARNING No valid IR Port assigned to controller. IR will not function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LoadDriver(irDriverFilepath);
|
LoadDriver(irDriverFilepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrOutputPortController(string key, Func<DeviceConfig, IROutputPort> postActivationFunc,
|
public IrOutputPortController(string key, Func<DeviceConfig, IROutputPort> postActivationFunc,
|
||||||
@@ -49,90 +49,94 @@ namespace PepperDash.Essentials.Core
|
|||||||
AddPostActivationAction(() =>
|
AddPostActivationAction(() =>
|
||||||
{
|
{
|
||||||
IrPort = postActivationFunc(config);
|
IrPort = postActivationFunc(config);
|
||||||
|
if (IrPort != null)
|
||||||
|
{
|
||||||
|
DriverIsLoaded = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the IR driver at path
|
/// Loads the IR driver at path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
public void LoadDriver(string path)
|
public void LoadDriver(string path)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path)) path = DriverFilepath;
|
if (string.IsNullOrEmpty(path)) path = DriverFilepath;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IrPortUid = IrPort.LoadIRDriver(path);
|
IrPortUid = IrPort.LoadIRDriver(path);
|
||||||
DriverFilepath = path;
|
DriverFilepath = path;
|
||||||
StandardIrPulseTime = 200;
|
StandardIrPulseTime = 200;
|
||||||
DriverIsLoaded = true;
|
DriverIsLoaded = true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
DriverIsLoaded = false;
|
DriverIsLoaded = false;
|
||||||
var message = string.Format("WARNING IR Driver '{0}' failed to load", path);
|
var message = string.Format("WARNING IR Driver '{0}' failed to load", path);
|
||||||
Debug.Console(0, this, message);
|
Debug.Console(0, this, message);
|
||||||
ErrorLog.Error(message);
|
ErrorLog.Error(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Starts and stops IR command on driver. Safe for missing commands
|
|
||||||
/// </summary>
|
|
||||||
public virtual void PressRelease(string command, bool state)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "IR:'{0}'={1}", command, state);
|
|
||||||
if (IrPort == null)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "WARNING No IR Port assigned to controller");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!DriverIsLoaded)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "WARNING IR driver is not loaded");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
if (IrPort.IsIRCommandAvailable(IrPortUid, command))
|
|
||||||
IrPort.Press(IrPortUid, command);
|
|
||||||
else
|
|
||||||
NoIrCommandError(command);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
IrPort.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Pulses a command on driver. Safe for missing commands
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Pulse(string command, ushort time)
|
|
||||||
{
|
|
||||||
if (IrPort == null)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "WARNING No IR Port assigned to controller");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!DriverIsLoaded)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "WARNING IR driver is not loaded");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (IrPort.IsIRCommandAvailable(IrPortUid, command))
|
|
||||||
IrPort.PressAndRelease(IrPortUid, command, time);
|
|
||||||
else
|
|
||||||
NoIrCommandError(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Notifies the console when a bad command is used.
|
|
||||||
/// </summary>
|
|
||||||
protected void NoIrCommandError(string command)
|
|
||||||
{
|
|
||||||
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
|
||||||
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts and stops IR command on driver. Safe for missing commands
|
||||||
|
/// </summary>
|
||||||
|
public virtual void PressRelease(string command, bool state)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "IR:'{0}'={1}", command, state);
|
||||||
|
if (IrPort == null)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "WARNING No IR Port assigned to controller");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!DriverIsLoaded)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "WARNING IR driver is not loaded");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
if (IrPort.IsIRCommandAvailable(IrPortUid, command))
|
||||||
|
IrPort.Press(IrPortUid, command);
|
||||||
|
else
|
||||||
|
NoIrCommandError(command);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IrPort.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pulses a command on driver. Safe for missing commands
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Pulse(string command, ushort time)
|
||||||
|
{
|
||||||
|
if (IrPort == null)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "WARNING No IR Port assigned to controller");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!DriverIsLoaded)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "WARNING IR driver is not loaded");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IrPort.IsIRCommandAvailable(IrPortUid, command))
|
||||||
|
IrPort.PressAndRelease(IrPortUid, command, time);
|
||||||
|
else
|
||||||
|
NoIrCommandError(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Notifies the console when a bad command is used.
|
||||||
|
/// </summary>
|
||||||
|
protected void NoIrCommandError(string command)
|
||||||
|
{
|
||||||
|
Debug.Console(2, this, "Device {0}: IR Driver {1} does not contain command {2}",
|
||||||
|
Key, IrPort.IRDriverFileNameByIRDriverId(IrPortUid), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user