mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 00:05:05 +00:00
Combining repos
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class DeviceJsonApi
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
public static void DoDeviceActionWithJson(string json)
|
||||
{
|
||||
var action = JsonConvert.DeserializeObject<DeviceActionWrapper>(json);
|
||||
DoDeviceAction(action);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
public static void DoDeviceAction(DeviceActionWrapper action)
|
||||
{
|
||||
var key = action.DeviceKey;
|
||||
var obj = FindObjectOnPath(key);
|
||||
if (obj == null)
|
||||
return;
|
||||
|
||||
CType t = obj.GetType();
|
||||
var method = t.GetMethod(action.MethodName);
|
||||
if (method == null)
|
||||
{
|
||||
Debug.Console(0, "Method '{0}' not found", action.MethodName);
|
||||
return;
|
||||
}
|
||||
var mParams = method.GetParameters();
|
||||
// Add empty params if not provided
|
||||
if (action.Params == null) action.Params = new object[0];
|
||||
if (mParams.Length > action.Params.Length)
|
||||
{
|
||||
Debug.Console(0, "Method '{0}' requires {1} params", action.MethodName, mParams.Length);
|
||||
return;
|
||||
}
|
||||
object[] convertedParams = mParams
|
||||
.Select((p, i) => Convert.ChangeType(action.Params[i], p.ParameterType,
|
||||
System.Globalization.CultureInfo.InvariantCulture))
|
||||
.ToArray();
|
||||
object ret = method.Invoke(obj, convertedParams);
|
||||
//Debug.Console(0, JsonConvert.SerializeObject(ret));
|
||||
// return something?
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetProperties(string deviceObjectPath)
|
||||
{
|
||||
var obj = FindObjectOnPath(deviceObjectPath);
|
||||
if (obj == null)
|
||||
return "{ \"error\":\"No Device\"}";
|
||||
|
||||
CType t = obj.GetType();
|
||||
// get the properties and set them into a new collection of NameType wrappers
|
||||
var props = t.GetProperties().Select(p => new PropertyNameType(p));
|
||||
return JsonConvert.SerializeObject(props, Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMethods(string deviceObjectPath)
|
||||
{
|
||||
var obj = FindObjectOnPath(deviceObjectPath);
|
||||
if (obj == null)
|
||||
return "{ \"error\":\"No Device\"}";
|
||||
|
||||
// Package up method names using helper objects
|
||||
CType t = obj.GetType();
|
||||
var methods = t.GetMethods()
|
||||
.Where(m => !m.IsSpecialName)
|
||||
.Select(p => new MethodNameParams(p));
|
||||
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
||||
}
|
||||
|
||||
public static string GetApiMethods(string deviceObjectPath)
|
||||
{
|
||||
var obj = FindObjectOnPath(deviceObjectPath);
|
||||
if (obj == null)
|
||||
return "{ \"error\":\"No Device\"}";
|
||||
|
||||
// Package up method names using helper objects
|
||||
CType t = obj.GetType();
|
||||
var methods = t.GetMethods()
|
||||
.Where(m => !m.IsSpecialName)
|
||||
.Where(m => m.GetCustomAttributes(typeof(ApiAttribute), true).Any())
|
||||
.Select(p => new MethodNameParams(p));
|
||||
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Walks down a dotted object path, starting with a Device, and returns the object
|
||||
/// at the end of the path
|
||||
/// </summary>
|
||||
public static object FindObjectOnPath(string deviceObjectPath)
|
||||
{
|
||||
var path = deviceObjectPath.Split('.');
|
||||
|
||||
var dev = DeviceManager.GetDeviceForKey(path[0]);
|
||||
if (dev == null)
|
||||
{
|
||||
Debug.Console(0, "Device {0} not found", path[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
// loop through any dotted properties
|
||||
object obj = dev;
|
||||
if (path.Length > 1)
|
||||
{
|
||||
for (int i = 1; i < path.Length; i++)
|
||||
{
|
||||
var objName = path[i];
|
||||
string indexStr = null;
|
||||
var indexOpen = objName.IndexOf('[');
|
||||
if (indexOpen != -1)
|
||||
{
|
||||
var indexClose = objName.IndexOf(']');
|
||||
if (indexClose == -1)
|
||||
{
|
||||
Debug.Console(0, dev, "ERROR Unmatched index brackets");
|
||||
return null;
|
||||
}
|
||||
// Get the index and strip quotes if any
|
||||
indexStr = objName.Substring(indexOpen + 1, indexClose - indexOpen - 1).Replace("\"", "");
|
||||
objName = objName.Substring(0, indexOpen);
|
||||
Debug.Console(0, dev, " Checking for collection '{0}', index '{1}'", objName, indexStr);
|
||||
}
|
||||
|
||||
CType oType = obj.GetType();
|
||||
var prop = oType.GetProperty(objName);
|
||||
if (prop == null)
|
||||
{
|
||||
Debug.Console(0, dev, "Property {0} not found on {1}", objName, path[i - 1]);
|
||||
return null;
|
||||
}
|
||||
// if there's an index, try to get the property
|
||||
if (indexStr != null)
|
||||
{
|
||||
if (!typeof(ICollection).IsAssignableFrom(prop.PropertyType))
|
||||
{
|
||||
Debug.Console(0, dev, "Property {0} is not collection", objName);
|
||||
return null;
|
||||
}
|
||||
var collection = prop.GetValue(obj, null) as ICollection;
|
||||
// Get the indexed items "property"
|
||||
var indexedPropInfo = prop.PropertyType.GetProperty("Item");
|
||||
// These are the parameters for the indexing. Only care about one
|
||||
var indexParams = indexedPropInfo.GetIndexParameters();
|
||||
if (indexParams.Length > 0)
|
||||
{
|
||||
Debug.Console(0, " Indexed, param type: {0}", indexParams[0].ParameterType.Name);
|
||||
var properParam = Convert.ChangeType(indexStr, indexParams[0].ParameterType,
|
||||
System.Globalization.CultureInfo.InvariantCulture);
|
||||
try
|
||||
{
|
||||
obj = indexedPropInfo.GetValue(collection, new object[] { properParam });
|
||||
}
|
||||
// if the index is bad, catch it here.
|
||||
catch (Crestron.SimplSharp.Reflection.TargetInvocationException e)
|
||||
{
|
||||
if (e.InnerException is ArgumentOutOfRangeException)
|
||||
Debug.Console(0, " Index Out of range");
|
||||
else if (e.InnerException is KeyNotFoundException)
|
||||
Debug.Console(0, " Key not found");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
obj = prop.GetValue(obj, null);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public class DeviceActionWrapper
|
||||
{
|
||||
public string DeviceKey { get; set; }
|
||||
public string MethodName { get; set; }
|
||||
public object[] Params { get; set; }
|
||||
}
|
||||
|
||||
public class PropertyNameType
|
||||
{
|
||||
[JsonIgnore]
|
||||
public PropertyInfo PropInfo { get; private set; }
|
||||
public string Name { get { return PropInfo.Name; } }
|
||||
public string Type { get { return PropInfo.PropertyType.Name; } }
|
||||
|
||||
public PropertyNameType(PropertyInfo info)
|
||||
{
|
||||
PropInfo = info;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodNameParams
|
||||
{
|
||||
[JsonIgnore]
|
||||
public MethodInfo MethodInfo { get; private set; }
|
||||
|
||||
public string Name { get { return MethodInfo.Name; } }
|
||||
public IEnumerable<NameType> Params { get {
|
||||
return MethodInfo.GetParameters().Select(p =>
|
||||
new NameType { Name = p.Name, Type = p.ParameterType.Name });
|
||||
} }
|
||||
|
||||
public MethodNameParams(MethodInfo info)
|
||||
{
|
||||
MethodInfo = info;
|
||||
}
|
||||
}
|
||||
|
||||
public class NameType
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
public class ApiAttribute : CAttribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
using Crestron.SimplSharpPro.UI;
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public static class DeviceManager
|
||||
{
|
||||
//public static List<Device> Devices { get { return _Devices; } }
|
||||
//static List<Device> _Devices = new List<Device>();
|
||||
|
||||
static Dictionary<string, IKeyed> Devices = new Dictionary<string, IKeyed>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of all the devices in a list
|
||||
/// </summary>
|
||||
public static List<IKeyed> AllDevices { get { return new List<IKeyed>(Devices.Values); } }
|
||||
|
||||
public static void Initialize(CrestronControlSystem cs)
|
||||
{
|
||||
CrestronConsole.AddNewConsoleCommand(ListDeviceCommands, "devcmdlist", "Lists commands",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(DoDeviceCommand, "devcmd", "Runs a command on device - key Name value",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(ListDeviceCommStatuses, "devcommstatus", "Lists the communication status of all devices",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(ListDeviceFeedbacks, "devfb", "Lists current feedbacks",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(ListDevices, "devlist", "Lists current managed devices",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(DeviceJsonApi.DoDeviceActionWithJson, "devjson", "",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(s =>
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetProperties(s));
|
||||
}, "devprops", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(s =>
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetMethods(s));
|
||||
}, "devmethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(s =>
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetApiMethods(s));
|
||||
}, "apimethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls activate on all Device class items
|
||||
/// </summary>
|
||||
public static void ActivateAll()
|
||||
{
|
||||
foreach (var d in Devices.Values)
|
||||
{
|
||||
if (d is Device)
|
||||
(d as Device).Activate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls activate on all Device class items
|
||||
/// </summary>
|
||||
public static void DeactivateAll()
|
||||
{
|
||||
foreach (var d in Devices.Values)
|
||||
{
|
||||
if (d is Device)
|
||||
(d as Device).Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
//static void ListMethods(string devKey)
|
||||
//{
|
||||
// var dev = GetDeviceForKey(devKey);
|
||||
// if(dev != null)
|
||||
// {
|
||||
// var type = dev.GetType().GetCType();
|
||||
// var methods = type.GetMethods(BindingFlags.Public|BindingFlags.Instance);
|
||||
// var sb = new StringBuilder();
|
||||
// sb.AppendLine(string.Format("{2} methods on [{0}] ({1}):", dev.Key, type.Name, methods.Length));
|
||||
// foreach (var m in methods)
|
||||
// {
|
||||
// sb.Append(string.Format("{0}(", m.Name));
|
||||
// var pars = m.GetParameters();
|
||||
// foreach (var p in pars)
|
||||
// sb.Append(string.Format("({1}){0} ", p.Name, p.ParameterType.Name));
|
||||
// sb.AppendLine(")");
|
||||
// }
|
||||
// CrestronConsole.ConsoleCommandResponse(sb.ToString());
|
||||
// }
|
||||
//}
|
||||
|
||||
static void ListDevices(string s)
|
||||
{
|
||||
Debug.Console(0, "{0} Devices registered with Device Mangager:",Devices.Count);
|
||||
var sorted = Devices.Values.ToList();
|
||||
sorted.Sort((a, b) => a.Key.CompareTo(b.Key));
|
||||
//var devs = Devices.Values.Where(d => d is IKeyed).Select(d => d as IKeyed);
|
||||
|
||||
foreach (var d in sorted)
|
||||
{
|
||||
var name = d is IKeyName ? (d as IKeyName).Name : "---";
|
||||
Debug.Console(0, " [{0}] {1}", d.Key, name);
|
||||
}
|
||||
}
|
||||
|
||||
static void ListDeviceFeedbacks(string devKey)
|
||||
{
|
||||
var dev = GetDeviceForKey(devKey);
|
||||
if(dev == null)
|
||||
{
|
||||
Debug.Console(0, "Device '{0}' not found", devKey);
|
||||
return;
|
||||
}
|
||||
var statusDev = dev as IHasFeedback;
|
||||
if(statusDev == null)
|
||||
{
|
||||
Debug.Console(0, "Device '{0}' does not have visible feedbacks", devKey);
|
||||
return;
|
||||
}
|
||||
statusDev.DumpFeedbacksToConsole(true);
|
||||
}
|
||||
|
||||
static void ListDeviceCommands(string devKey)
|
||||
{
|
||||
var dev = GetDeviceForKey(devKey);
|
||||
if (dev == null)
|
||||
{
|
||||
Debug.Console(0, "Device '{0}' not found", devKey);
|
||||
return;
|
||||
}
|
||||
Debug.Console(0, "This needs to be reworked. Stay tuned.", devKey);
|
||||
}
|
||||
|
||||
static void ListDeviceCommStatuses(string input)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var dev in Devices.Values)
|
||||
{
|
||||
if (dev is ICommunicationMonitor)
|
||||
sb.Append(string.Format("{0}: {1}\r", dev.Key, (dev as ICommunicationMonitor).CommunicationMonitor.Status));
|
||||
}
|
||||
CrestronConsole.ConsoleCommandResponse(sb.ToString());
|
||||
}
|
||||
|
||||
|
||||
static void DoDeviceCommand(string command)
|
||||
{
|
||||
Debug.Console(0, "Not yet implemented. Stay tuned");
|
||||
}
|
||||
|
||||
public static void AddDevice(IKeyed newDev)
|
||||
{
|
||||
// Check for device with same key
|
||||
//var existingDevice = _Devices.FirstOrDefault(d => d.Key.Equals(newDev.Key, StringComparison.OrdinalIgnoreCase));
|
||||
////// If it exists, remove or warn??
|
||||
//if (existingDevice != null)
|
||||
if(Devices.ContainsKey(newDev.Key))
|
||||
{
|
||||
Debug.Console(0, newDev, "A device with this key already exists. Not added to manager");
|
||||
return;
|
||||
}
|
||||
Devices.Add(newDev.Key, newDev);
|
||||
//if (!(_Devices.Contains(newDev)))
|
||||
// _Devices.Add(newDev);
|
||||
}
|
||||
|
||||
public static void RemoveDevice(IKeyed newDev)
|
||||
{
|
||||
if(newDev == null)
|
||||
return;
|
||||
if (Devices.ContainsKey(newDev.Key))
|
||||
Devices.Remove(newDev.Key);
|
||||
//if (_Devices.Contains(newDev))
|
||||
// _Devices.Remove(newDev);
|
||||
else
|
||||
Debug.Console(0, "Device manager: Device '{0}' does not exist in manager. Cannot remove", newDev.Key);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetDeviceKeys()
|
||||
{
|
||||
//return _Devices.Select(d => d.Key).ToList();
|
||||
return Devices.Keys;
|
||||
}
|
||||
|
||||
public static IEnumerable<IKeyed> GetDevices()
|
||||
{
|
||||
//return _Devices.Select(d => d.Key).ToList();
|
||||
return Devices.Values;
|
||||
}
|
||||
|
||||
public static IKeyed GetDeviceForKey(string key)
|
||||
{
|
||||
//return _Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
||||
if (key != null && Devices.ContainsKey(key))
|
||||
return Devices[key];
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Integers that represent the "source type number" for given sources.
|
||||
/// Primarily used by the UI to calculate subpage join offsets
|
||||
/// Note, for UI, only values 1-49 are valid.
|
||||
/// </summary>
|
||||
public class DisplayUiConstants
|
||||
{
|
||||
public const uint TypeRadio = 1;
|
||||
public const uint TypeDirecTv = 9;
|
||||
public const uint TypeBluray = 13;
|
||||
public const uint TypeChromeTv = 15;
|
||||
public const uint TypeFireTv = 16;
|
||||
public const uint TypeAppleTv = 17;
|
||||
public const uint TypeRoku = 18;
|
||||
public const uint TypeLaptop = 31;
|
||||
public const uint TypePc = 32;
|
||||
|
||||
public const uint TypeNoControls = 49;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public interface IOnline
|
||||
{
|
||||
BoolFeedback IsOnline { get; }
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// ** WANT THIS AND ALL ITS FRIENDS TO GO AWAY **
|
||||
///// Defines a class that has a list of CueAction objects, typically
|
||||
///// for linking functions to user interfaces or API calls
|
||||
///// </summary>
|
||||
//public interface IHasCueActionList
|
||||
//{
|
||||
// List<CueActionPair> CueActionList { get; }
|
||||
//}
|
||||
|
||||
|
||||
//public interface IHasComPortsHardware
|
||||
//{
|
||||
// IComPorts ComPortsDevice { get; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a device that can have a video sync providing device attached to it
|
||||
/// </summary>
|
||||
public interface IAttachVideoStatus : IKeyed
|
||||
{
|
||||
// Extension methods will depend on this
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For display classes that can provide usage data
|
||||
/// </summary>
|
||||
public interface IDisplayUsage
|
||||
{
|
||||
IntFeedback LampHours { get; }
|
||||
}
|
||||
|
||||
public interface IMakeModel : IKeyed
|
||||
{
|
||||
string DeviceMake { get; }
|
||||
string DeviceModel { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core.Devices
|
||||
{
|
||||
public class GenericCommunicationMonitoredDevice : Device, ICommunicationMonitor
|
||||
{
|
||||
IBasicCommunication Client;
|
||||
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, IBasicCommunication comm, string pollString,
|
||||
long pollTime, long warningTime, long errorTime)
|
||||
: base(key, name)
|
||||
{
|
||||
Client = comm;
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Client, pollTime, warningTime, errorTime, pollString);
|
||||
|
||||
// ------------------------------------------------------DELETE THIS
|
||||
CommunicationMonitor.StatusChange += (o, a) =>
|
||||
{
|
||||
Debug.Console(2, this, "Communication monitor status change: {0}", a.Status);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, IBasicCommunication comm, string pollString)
|
||||
: this(key, name, comm, pollString, 30000, 120000, 300000)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generic monitor for TCP reachability. Default with 30s poll, 120s warning and 300s error times
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, string hostname, int port, string pollString)
|
||||
: this(key, name, hostname, port, pollString, 30000, 120000, 300000)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monitor for TCP reachability
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public GenericCommunicationMonitoredDevice(string key, string name, string hostname, int port, string pollString,
|
||||
long pollTime, long warningTime, long errorTime)
|
||||
: base(key, name)
|
||||
{
|
||||
Client = new GenericTcpIpClient(key + "-tcp", hostname, port, 512);
|
||||
CommunicationMonitor = new GenericCommunicationMonitor(this, Client, pollTime, warningTime, errorTime, pollString);
|
||||
|
||||
// ------------------------------------------------------DELETE THIS
|
||||
CommunicationMonitor.StatusChange += (o, a) =>
|
||||
{
|
||||
Debug.Console(2, this, "Communication monitor status change: {0}", a.Status);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
CommunicationMonitor.Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Deactivate()
|
||||
{
|
||||
CommunicationMonitor.Stop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public static class IAttachVideoStatusExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the VideoStatusOutputs for the device
|
||||
/// </summary>
|
||||
/// <param name="attachDev"></param>
|
||||
/// <returns>Attached VideoStatusOutputs or the default if none attached</returns>
|
||||
public static VideoStatusOutputs GetVideoStatuses(this IAttachVideoStatus attachedDev)
|
||||
{
|
||||
// See if this device is connected to a status-providing port
|
||||
var tl = TieLineCollection.Default.FirstOrDefault(t =>
|
||||
t.SourcePort.ParentDevice == attachedDev
|
||||
&& t.DestinationPort is RoutingInputPortWithVideoStatuses);
|
||||
if (tl != null)
|
||||
{
|
||||
// if so, and it's got status, return it -- or null
|
||||
var port = tl.DestinationPort as RoutingInputPortWithVideoStatuses;
|
||||
if (port != null)
|
||||
return port.VideoStatus;
|
||||
}
|
||||
return VideoStatusOutputs.NoStatus;
|
||||
}
|
||||
|
||||
public static bool HasVideoStatuses(this IAttachVideoStatus attachedDev)
|
||||
{
|
||||
return TieLineCollection.Default.FirstOrDefault(t =>
|
||||
t.SourcePort.ParentDevice == attachedDev
|
||||
&& t.DestinationPort is RoutingInputPortWithVideoStatuses) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public interface IHasFeedback : IKeyed
|
||||
{
|
||||
/// <summary>
|
||||
/// This method shall return a list of all Output objects on a device,
|
||||
/// including all "aggregate" devices.
|
||||
/// </summary>
|
||||
List<Feedback> Feedbacks { get; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class IHasFeedbackExtensions
|
||||
{
|
||||
public static void DumpFeedbacksToConsole(this IHasFeedback source, bool getCurrentStates)
|
||||
{
|
||||
var outputs = source.Feedbacks.OrderBy(x => x.Type);
|
||||
if (outputs != null)
|
||||
{
|
||||
Debug.Console(0, source, "\n\nAvailable outputs:");
|
||||
foreach (var o in outputs)
|
||||
{
|
||||
string val = "";
|
||||
if (getCurrentStates)
|
||||
{
|
||||
switch (o.Type)
|
||||
{
|
||||
case eCueType.Bool:
|
||||
val = " = " + o.BoolValue;
|
||||
break;
|
||||
case eCueType.Int:
|
||||
val = " = " + o.IntValue;
|
||||
break;
|
||||
case eCueType.String:
|
||||
val = " = " + o.StringValue;
|
||||
break;
|
||||
//case eOutputType.Other:
|
||||
// break;
|
||||
}
|
||||
}
|
||||
Debug.Console(0, "{0,-8} {1,5} {2}{3}", o.Type, o.Cue.Number,
|
||||
(string.IsNullOrEmpty(o.Cue.Name) ? "-none-" : o.Cue.Name), val);
|
||||
}
|
||||
}
|
||||
else
|
||||
Debug.Console(0, source, "No available outputs:");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines minimal volume control methods
|
||||
/// </summary>
|
||||
public interface IBasicVolumeControls
|
||||
{
|
||||
void VolumeUp(bool pressRelease);
|
||||
void VolumeDown(bool pressRelease);
|
||||
void MuteToggle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds feedback and direct volume level set to IBasicVolumeControls
|
||||
/// </summary>
|
||||
public interface IBasicVolumeWithFeedback : IBasicVolumeControls
|
||||
{
|
||||
void SetVolume(ushort level);
|
||||
void MuteOn();
|
||||
void MuteOff();
|
||||
IntFeedback VolumeLevelFeedback { get; }
|
||||
BoolFeedback MuteFeedback { get; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IFullAudioSettings : IBasicVolumeWithFeedback
|
||||
{
|
||||
void SetBalance(ushort level);
|
||||
void BalanceLeft(bool pressRelease);
|
||||
void BalanceRight(bool pressRelease);
|
||||
|
||||
void SetBass(ushort level);
|
||||
void BassUp(bool pressRelease);
|
||||
void BassDown(bool pressRelease);
|
||||
|
||||
void SetTreble(ushort level);
|
||||
void TrebleUp(bool pressRelease);
|
||||
void TrebleDown(bool pressRelease);
|
||||
|
||||
bool hasMaxVolume { get; }
|
||||
void SetMaxVolume(ushort level);
|
||||
void MaxVolumeUp(bool pressRelease);
|
||||
void MaxVolumeDown(bool pressRelease);
|
||||
|
||||
bool hasDefaultVolume { get; }
|
||||
void SetDefaultVolume(ushort level);
|
||||
void DefaultVolumeUp(bool pressRelease);
|
||||
void DefaultVolumeDown(bool pressRelease);
|
||||
|
||||
void LoudnessToggle();
|
||||
void MonoToggle();
|
||||
|
||||
BoolFeedback LoudnessFeedback { get; }
|
||||
BoolFeedback MonoFeedback { get; }
|
||||
IntFeedback BalanceFeedback { get; }
|
||||
IntFeedback BassFeedback { get; }
|
||||
IntFeedback TrebleFeedback { get; }
|
||||
IntFeedback MaxVolumeFeedback { get; }
|
||||
IntFeedback DefaultVolumeFeedback { get; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A class that implements this, contains a reference to an IBasicVolumeControls device.
|
||||
/// For example, speakers attached to an audio zone. The speakers can provide reference
|
||||
/// to their linked volume control.
|
||||
/// </summary>
|
||||
public interface IHasVolumeDevice
|
||||
{
|
||||
IBasicVolumeControls VolumeDevice { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Identifies a device that contains audio zones
|
||||
/// </summary>
|
||||
public interface IAudioZones : IRouting
|
||||
{
|
||||
Dictionary<uint, IAudioZone> Zone { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines minimum functionality for an audio zone
|
||||
/// </summary>
|
||||
public interface IAudioZone : IBasicVolumeWithFeedback
|
||||
{
|
||||
void SelectInput(ushort input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// IR port wrapper. May act standalone
|
||||
/// </summary>
|
||||
public class IrOutputPortController : Device
|
||||
{
|
||||
uint IrPortUid;
|
||||
IROutputPort IrPort;
|
||||
|
||||
public ushort StandardIrPulseTime { get; set; }
|
||||
public string DriverFilepath { get; private set; }
|
||||
public bool DriverIsLoaded { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for IrDevice base class. If a null port is provided, this class will
|
||||
/// still function without trying to talk to a port.
|
||||
/// </summary>
|
||||
public IrOutputPortController(string key, IROutputPort port, string irDriverFilepath)
|
||||
: base(key)
|
||||
{
|
||||
//if (port == null) throw new ArgumentNullException("port");
|
||||
IrPort = port;
|
||||
if (port == null)
|
||||
{
|
||||
Debug.Console(0, this, "WARNING No valid IR Port assigned to controller. IR will not function");
|
||||
return;
|
||||
}
|
||||
LoadDriver(irDriverFilepath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the IR driver at path
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void LoadDriver(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) path = DriverFilepath;
|
||||
try
|
||||
{
|
||||
IrPortUid = IrPort.LoadIRDriver(path);
|
||||
DriverFilepath = path;
|
||||
StandardIrPulseTime = 200;
|
||||
DriverIsLoaded = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
DriverIsLoaded = false;
|
||||
var message = string.Format("WARNING IR Driver '{0}' failed to load", path);
|
||||
Debug.Console(0, this, 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>
|
||||
///// When fed a dictionary of uint, string, will return UOs for each item,
|
||||
///// attached to this IrOutputPort
|
||||
///// </summary>
|
||||
///// <param name="numStringDict"></param>
|
||||
///// <returns></returns>
|
||||
//public List<CueActionPair> GetUOsForIrCommands(Dictionary<Cue, string> numStringDict)
|
||||
//{
|
||||
// var funcs = new List<CueActionPair>(numStringDict.Count);
|
||||
// foreach (var kvp in numStringDict)
|
||||
// {
|
||||
// // Have to assign these locally because of kvp's scope
|
||||
// var cue = kvp.Key;
|
||||
// var command = kvp.Value;
|
||||
// funcs.Add(new BoolCueActionPair(cue, b => this.PressRelease(command, b)));
|
||||
// }
|
||||
// return funcs;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
// //*********************************************************************************************************
|
||||
// /// <summary>
|
||||
// /// The core event and status-bearing class that most if not all device and connectors can derive from.
|
||||
// /// </summary>
|
||||
// public class Device : IKeyed
|
||||
// {
|
||||
// public string Key { get; protected set; }
|
||||
// public string Name { get; protected set; }
|
||||
// public bool Enabled { get; protected set; }
|
||||
// List<Action> _PreActivationActions;
|
||||
// List<Action> _PostActivationActions;
|
||||
|
||||
// public static Device DefaultDevice { get { return _DefaultDevice; } }
|
||||
// static Device _DefaultDevice = new Device("Default", "Default");
|
||||
|
||||
// /// <summary>
|
||||
// /// Base constructor for all Devices.
|
||||
// /// </summary>
|
||||
// /// <param name="key"></param>
|
||||
// public Device(string key)
|
||||
// {
|
||||
// Key = key;
|
||||
// if (key.Contains('.')) Debug.Console(0, this, "WARNING: Device name's should not include '.'");
|
||||
// Name = "";
|
||||
// }
|
||||
|
||||
// public Device(string key, string name) : this(key)
|
||||
// {
|
||||
// Name = name;
|
||||
// }
|
||||
|
||||
// public void AddPreActivationAction(Action act)
|
||||
// {
|
||||
// if (_PreActivationActions == null)
|
||||
// _PreActivationActions = new List<Action>();
|
||||
// _PreActivationActions.Add(act);
|
||||
// }
|
||||
|
||||
// public void AddPostActivationAction(Action act)
|
||||
// {
|
||||
// if (_PostActivationActions == null)
|
||||
// _PostActivationActions = new List<Action>();
|
||||
// _PostActivationActions.Add(act);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets this device ready to be used in the system. Runs any added pre-activation items, and
|
||||
// /// all post-activation at end. Classes needing additional logic to
|
||||
// /// run should override CustomActivate()
|
||||
// /// </summary>
|
||||
// public bool Activate()
|
||||
// {
|
||||
// if (_PreActivationActions != null)
|
||||
// _PreActivationActions.ForEach(a => a.Invoke());
|
||||
// var result = CustomActivate();
|
||||
// if(result && _PostActivationActions != null)
|
||||
// _PostActivationActions.ForEach(a => a.Invoke());
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Called in between Pre and PostActivationActions when Activate() is called.
|
||||
// /// Override to provide addtitional setup when calling activation. Overriding classes
|
||||
// /// do not need to call base.CustomActivate()
|
||||
// /// </summary>
|
||||
// /// <returns>true if device activated successfully.</returns>
|
||||
// public virtual bool CustomActivate() { return true; }
|
||||
|
||||
// /// <summary>
|
||||
// /// Call to deactivate device - unlink events, etc. Overriding classes do not
|
||||
// /// need to call base.Deactivate()
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public virtual bool Deactivate() { return true; }
|
||||
|
||||
// /// <summary>
|
||||
// /// Helper method to check object for bool value false and fire an Action method
|
||||
// /// </summary>
|
||||
// /// <param name="o">Should be of type bool, others will be ignored</param>
|
||||
// /// <param name="a">Action to be run when o is false</param>
|
||||
// public void OnFalse(object o, Action a)
|
||||
// {
|
||||
// if (o is bool && !(bool)o) a();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
//public interface IVolumeFunctions
|
||||
//{
|
||||
// BoolCueActionPair VolumeUpCueActionPair { get; }
|
||||
// BoolCueActionPair VolumeDownCueActionPair { get; }
|
||||
// BoolCueActionPair MuteToggleCueActionPair { get; }
|
||||
//}
|
||||
|
||||
//public interface IVolumeTwoWay : IVolumeFunctions
|
||||
//{
|
||||
// IntFeedback VolumeLevelFeedback { get; }
|
||||
// UShortCueActionPair VolumeLevelCueActionPair { get; }
|
||||
// BoolFeedback IsMutedFeedback { get; }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
/////
|
||||
///// </summary>
|
||||
//public static class IFunctionListExtensions
|
||||
//{
|
||||
// public static string GetFunctionsConsoleList(this IHasCueActionList device)
|
||||
// {
|
||||
// var sb = new StringBuilder();
|
||||
// var list = device.CueActionList;
|
||||
// foreach (var cap in list)
|
||||
// sb.AppendFormat("{0,-15} {1,4} {2}\r", cap.Cue.Name, cap.Cue.Number, cap.GetType().Name);
|
||||
// return sb.ToString();
|
||||
// }
|
||||
//}
|
||||
|
||||
public enum AudioChangeType
|
||||
{
|
||||
Mute, Volume
|
||||
}
|
||||
|
||||
public class AudioChangeEventArgs
|
||||
{
|
||||
public AudioChangeType ChangeType { get; private set; }
|
||||
public IBasicVolumeControls AudioDevice { get; private set; }
|
||||
|
||||
public AudioChangeEventArgs(IBasicVolumeControls device, AudioChangeType changeType)
|
||||
{
|
||||
ChangeType = changeType;
|
||||
AudioDevice = device;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
using Crestron.SimplSharpPro.UI;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
//[Obsolete]
|
||||
//public class PresentationDeviceType
|
||||
//{
|
||||
// public const ushort Default = 1;
|
||||
// public const ushort CableSetTopBox = 2;
|
||||
// public const ushort SatelliteSetTopBox = 3;
|
||||
// public const ushort Dvd = 4;
|
||||
// public const ushort Bluray = 5;
|
||||
// public const ushort PC = 9;
|
||||
// public const ushort Laptop = 10;
|
||||
//}
|
||||
|
||||
public enum PresentationSourceType
|
||||
{
|
||||
None, Dvd, Laptop, PC, SetTopBox, VCR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Crestron.SimplSharp;
|
||||
//using Crestron.SimplSharpPro;
|
||||
//using Crestron.SimplSharpPro.DeviceSupport;
|
||||
//using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
//using Crestron.SimplSharpPro.UI;
|
||||
|
||||
//using PepperDash.Core;
|
||||
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
|
||||
//[Obsolete]
|
||||
// public class PresentationDevice : Device, IPresentationSource
|
||||
// {
|
||||
// public PresentationSourceType Type { get; protected set; }
|
||||
// public string IconName { get { return "Blank"; } set { } }
|
||||
// public BoolFeedback HasPowerOnFeedback { get; protected set; }
|
||||
|
||||
// PresentationDevice()
|
||||
// : base("Default", "Default")
|
||||
// {
|
||||
// HasPowerOnFeedback = new BoolFeedback(CommonBoolCue.HasPowerFeedback, () => false);
|
||||
// Type = PresentationSourceType.None;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Returns a "default" presentation device, with no abilities.
|
||||
// /// </summary>
|
||||
// public static IPresentationSource Default
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (_Default == null)
|
||||
// _Default = new PresentationDevice();
|
||||
// return _Default;
|
||||
// }
|
||||
// }
|
||||
// static IPresentationSource _Default;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,52 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using Crestron.SimplSharp;
|
||||
//using Crestron.SimplSharpPro;
|
||||
|
||||
//using Newtonsoft.Json;
|
||||
//using Newtonsoft.Json.Linq;
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
|
||||
// public class DeviceConfig
|
||||
// {
|
||||
// public string Key { get; set; }
|
||||
// public string Name { get; set; }
|
||||
// public string Type { get; set; }
|
||||
// [JsonConverter(typeof(DevicePropertiesJsonConverter))]
|
||||
// public JToken Properties { get; set; }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// The gist of this converter: The comspec JSON comes in with normal values that need to be converted
|
||||
// /// into enum names. This converter takes the value and applies the appropriate enum's name prefix to the value
|
||||
// /// and then returns the enum value using Enum.Parse
|
||||
// /// </summary>
|
||||
// public class DevicePropertiesJsonConverter : JsonConverter
|
||||
// {
|
||||
// public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
// {
|
||||
// return JObject.Load(reader);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// This will be hit with every value in the ComPortConfig class. We only need to
|
||||
// /// do custom conversion on the comspec items.
|
||||
// /// </summary>
|
||||
// public override bool CanConvert(Type objectType)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public override bool CanRead { get { return true; } }
|
||||
// public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
//public interface IHasFeedback : IKeyed
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// This method shall return a list of all Output objects on a device,
|
||||
// /// including all "aggregate" devices.
|
||||
// /// </summary>
|
||||
// List<Feedback> Feedbacks { get; }
|
||||
|
||||
//}
|
||||
|
||||
|
||||
//public static class IHasFeedbackExtensions
|
||||
//{
|
||||
// public static void DumpFeedbacksToConsole(this IHasFeedback source, bool getCurrentStates)
|
||||
// {
|
||||
// var outputs = source.Feedbacks.OrderBy(x => x.Type);
|
||||
// if (outputs != null)
|
||||
// {
|
||||
// Debug.Console(0, source, "\n\nAvailable outputs:");
|
||||
// foreach (var o in outputs)
|
||||
// {
|
||||
// string val = "";
|
||||
// if (getCurrentStates)
|
||||
// {
|
||||
// switch (o.Type)
|
||||
// {
|
||||
// case eCueType.Bool:
|
||||
// val = " = " + o.BoolValue;
|
||||
// break;
|
||||
// case eCueType.Int:
|
||||
// val = " = " + o.IntValue;
|
||||
// break;
|
||||
// case eCueType.String:
|
||||
// val = " = " + o.StringValue;
|
||||
// break;
|
||||
// //case eOutputType.Other:
|
||||
// // break;
|
||||
// }
|
||||
// }
|
||||
// Debug.Console(0, "{0,-8} {1,5} {2}{3}", o.Type, o.Cue.Number,
|
||||
// (string.IsNullOrEmpty(o.Cue.Name) ? "-none-" : o.Cue.Name), val);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// Debug.Console(0, source, "No available outputs:");
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using Crestron.SimplSharp;
|
||||
//using Crestron.SimplSharpPro;
|
||||
//using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
//using PepperDash.Core;
|
||||
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
// public abstract class DvdDeviceBase : Device, IPresentationSource, IHasCueActionList
|
||||
// {
|
||||
// public DvdDeviceBase(string key, string name)
|
||||
// : base(key, name)
|
||||
// {
|
||||
// HasPowerOnFeedback = new BoolFeedback(() => false);
|
||||
|
||||
// }
|
||||
|
||||
// #region IPresentationSource Members
|
||||
|
||||
// PresentationSourceType IPresentationSource.Type
|
||||
// {
|
||||
// get { return PresentationSourceType.Dvd; }
|
||||
// }
|
||||
|
||||
// public string IconName
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return "DVD";
|
||||
// }
|
||||
// set { }
|
||||
// }
|
||||
|
||||
// public virtual BoolFeedback HasPowerOnFeedback { get; private set; }
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region IFunctionList Members
|
||||
|
||||
// public abstract List<CueActionPair> CueActionList { get; }
|
||||
|
||||
// #endregion
|
||||
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,130 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Crestron.SimplSharpPro;
|
||||
|
||||
//using PepperDash.Essentials.Core;
|
||||
|
||||
//using PepperDash.Core;
|
||||
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// This DVD class should cover most IR, one-way DVD and Bluray fuctions
|
||||
// /// </summary>
|
||||
// public class IrDvdBase : Device, IHasCueActionList,
|
||||
// IPresentationSource, IAttachVideoStatus, IHasFeedback, IRoutingOutputs
|
||||
// {
|
||||
// public PresentationSourceType Type { get; protected set; }
|
||||
// public string IconName { get; set; }
|
||||
|
||||
// public BoolFeedback HasPowerOnFeedback { get; private set; }
|
||||
// public IrOutputPortController IrPort { get; private set; }
|
||||
|
||||
// public RoutingOutputPort HdmiOut { get; private set; }
|
||||
|
||||
// #region IRoutingOutputs Members
|
||||
|
||||
// /// <summary>
|
||||
// /// Options: hdmi
|
||||
// /// </summary>
|
||||
// public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; }
|
||||
|
||||
// #endregion
|
||||
|
||||
// public IrDvdBase(string key, string name, IROutputPort port, IrDriverInfo driverInfo)
|
||||
// : base(key, name)
|
||||
// {
|
||||
// IrPort = new IrOutputPortController("ir-" + key, port, driverInfo.FileName);
|
||||
// Type = PresentationSourceType.Dvd;
|
||||
// IconName = "Bluray";
|
||||
// HasPowerOnFeedback = new BoolFeedback(CommonBoolCue.HasPowerFeedback, () => false);
|
||||
|
||||
// HdmiOut = new RoutingOutputPort("HDMI", eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, 0, this);
|
||||
// OutputPorts = new RoutingPortCollection<RoutingOutputPort>()
|
||||
// {
|
||||
// HdmiOut
|
||||
// };
|
||||
// CueActionList = IrPort.GetUOsForIrCommands(driverInfo.IrMap);
|
||||
// }
|
||||
|
||||
// public IrDvdBase(string key, string name, IROutputPort port, string irDriverFilepath)
|
||||
// : base(key, name)
|
||||
// {
|
||||
// IrPort = new IrOutputPortController("ir-" + key, port, irDriverFilepath);
|
||||
// Type = PresentationSourceType.Dvd;
|
||||
// IconName = "Bluray";
|
||||
// HasPowerOnFeedback = new BoolFeedback(CommonBoolCue.HasPowerFeedback, () => false);
|
||||
|
||||
// HdmiOut = new RoutingOutputPort("HDMI", eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, 0, this);
|
||||
// OutputPorts = new RoutingPortCollection<RoutingOutputPort>()
|
||||
// {
|
||||
// HdmiOut
|
||||
// };
|
||||
// var numToIr = new Dictionary<Cue, string>
|
||||
// {
|
||||
// { CommonBoolCue.Power, IROutputStandardCommands.IROut_POWER },
|
||||
// { CommonBoolCue.PowerOff, IROutputStandardCommands.IROut_POWER_OFF },
|
||||
// { CommonBoolCue.PowerOn, IROutputStandardCommands.IROut_POWER_ON },
|
||||
// { CommonBoolCue.Replay, IROutputStandardCommands.IROut_REPLAY },
|
||||
// { CommonBoolCue.Play, IROutputStandardCommands.IROut_PLAY },
|
||||
// { CommonBoolCue.Pause, IROutputStandardCommands.IROut_PAUSE },
|
||||
// { CommonBoolCue.Stop, IROutputStandardCommands.IROut_STOP },
|
||||
// { CommonBoolCue.ChapPrevious, IROutputStandardCommands.IROut_TRACK_MINUS },
|
||||
// { CommonBoolCue.ChapNext, IROutputStandardCommands.IROut_TRACK_PLUS },
|
||||
// { CommonBoolCue.Rewind, IROutputStandardCommands.IROut_RSCAN },
|
||||
// { CommonBoolCue.Ffwd, IROutputStandardCommands.IROut_FSCAN },
|
||||
// { CommonBoolCue.RStep, IROutputStandardCommands.IROut_R_STEP },
|
||||
// { CommonBoolCue.FStep, IROutputStandardCommands.IROut_F_STEP },
|
||||
// { CommonBoolCue.Exit, IROutputStandardCommands.IROut_EXIT },
|
||||
// { CommonBoolCue.Home, IROutputStandardCommands.IROut_HOME },
|
||||
// { CommonBoolCue.Menu, IROutputStandardCommands.IROut_MENU },
|
||||
// { CommonBoolCue.PopUp, IROutputStandardCommands.IROut_POPUPMENU },
|
||||
// { CommonBoolCue.Up, IROutputStandardCommands.IROut_UP_ARROW },
|
||||
// { CommonBoolCue.Down, IROutputStandardCommands.IROut_DN_ARROW },
|
||||
// { CommonBoolCue.Left, IROutputStandardCommands.IROut_LEFT_ARROW },
|
||||
// { CommonBoolCue.Right, IROutputStandardCommands.IROut_RIGHT_ARROW },
|
||||
// { CommonBoolCue.Select, IROutputStandardCommands.IROut_ENTER },
|
||||
// { CommonBoolCue.Info, IROutputStandardCommands.IROut_INFO },
|
||||
// { CommonBoolCue.Red, IROutputStandardCommands.IROut_RED },
|
||||
// { CommonBoolCue.Green, IROutputStandardCommands.IROut_GREEN },
|
||||
// { CommonBoolCue.Yellow, IROutputStandardCommands.IROut_YELLOW },
|
||||
// { CommonBoolCue.Blue, IROutputStandardCommands.IROut_BLUE },
|
||||
// { CommonBoolCue.Digit0, IROutputStandardCommands.IROut_0 },
|
||||
// { CommonBoolCue.Digit1, IROutputStandardCommands.IROut_1 },
|
||||
// { CommonBoolCue.Digit2, IROutputStandardCommands.IROut_2 },
|
||||
// { CommonBoolCue.Digit3, IROutputStandardCommands.IROut_3 },
|
||||
// { CommonBoolCue.Digit4, IROutputStandardCommands.IROut_4 },
|
||||
// { CommonBoolCue.Digit5, IROutputStandardCommands.IROut_5 },
|
||||
// { CommonBoolCue.Digit6, IROutputStandardCommands.IROut_6 },
|
||||
// { CommonBoolCue.Digit7, IROutputStandardCommands.IROut_7 },
|
||||
// { CommonBoolCue.Digit8, IROutputStandardCommands.IROut_8 },
|
||||
// { CommonBoolCue.Digit9, IROutputStandardCommands.IROut_9 },
|
||||
// { CommonBoolCue.Audio, "AUDIO" },
|
||||
// { CommonBoolCue.Subtitle, "SUBTITLE" },
|
||||
// { CommonBoolCue.Setup, "SETUP" },
|
||||
// };
|
||||
// CueActionList = IrPort.GetUOsForIrCommands(numToIr);
|
||||
// }
|
||||
|
||||
|
||||
// public List<Feedback> Feedbacks
|
||||
// {
|
||||
// get { return this.GetVideoStatuses().ToList(); }
|
||||
// }
|
||||
|
||||
|
||||
// #region IFunctionList Members
|
||||
|
||||
// public List<CueActionPair> CueActionList { get; set; }
|
||||
|
||||
// #endregion
|
||||
// }
|
||||
|
||||
// public class IrDriverInfo
|
||||
// {
|
||||
// public Dictionary<Cue, string> IrMap { get; set; }
|
||||
// public string FileName { get; set; }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,143 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Crestron.SimplSharpPro;
|
||||
|
||||
//using PepperDash.Essentials.Core;
|
||||
//using PepperDash.Essentials.Core.Presets;
|
||||
|
||||
//using PepperDash.Core;
|
||||
|
||||
|
||||
//namespace PepperDash.Essentials.Core
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// This DVD class should cover most IR, one-way DVD and Bluray fuctions
|
||||
// /// </summary>
|
||||
// public class IrSetTopBoxBase : Device, IHasCueActionList,
|
||||
// IPresentationSource, IAttachVideoStatus, IHasFeedback, IRoutingOutputs, IHasSetTopBoxProperties
|
||||
// {
|
||||
// public PresentationSourceType Type { get; protected set; }
|
||||
// public string IconName { get; set; }
|
||||
|
||||
// public BoolFeedback HasPowerOnFeedback { get; private set; }
|
||||
// public IrOutputPortController IrPort { get; private set; }
|
||||
|
||||
// public DevicePresetsModel PresetsModel { get; private set; }
|
||||
|
||||
// #region IRoutingOutputs Members
|
||||
|
||||
// /// <summary>
|
||||
// /// Options: hdmi
|
||||
// /// </summary>
|
||||
// public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; private set; }
|
||||
|
||||
// #endregion
|
||||
|
||||
// public IrSetTopBoxBase(string key, string name, IROutputPort port, string irDriverFilepath)
|
||||
// : base(key, name)
|
||||
// {
|
||||
// IrPort = new IrOutputPortController("ir-" + key, port, irDriverFilepath);
|
||||
// Type = PresentationSourceType.SetTopBox;
|
||||
// IconName = "TV";
|
||||
// HasPowerOnFeedback = new BoolFeedback(CommonBoolCue.HasPowerFeedback, () => false);
|
||||
// OutputPorts = new RoutingPortCollection<RoutingOutputPort>()
|
||||
// {
|
||||
// new RoutingOutputPort("HDMI", eRoutingSignalType.AudioVideo, eRoutingPortConnectionType.Hdmi, 0, this)
|
||||
// };
|
||||
// }
|
||||
|
||||
// public void LoadPresets(string filePath)
|
||||
// {
|
||||
// //PresetsModel = new DevicePresetsModel(Key + "-presets", this, filePath);
|
||||
// //DeviceManager.AddDevice(PresetsModel);
|
||||
// }
|
||||
|
||||
// #region IDeviceWithOutputs Members
|
||||
|
||||
// public List<Feedback> Feedbacks
|
||||
// {
|
||||
// get { return this.GetVideoStatuses().ToList(); }
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region IFunctionList Members
|
||||
|
||||
// public List<CueActionPair> CueActionList
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// // This might be the best way to get the words back into functions
|
||||
// new BoolCueActionPair(CommonBoolCue.Power, b => IrPort.PressRelease(IROutputStandardCommands.IROut_POWER, b));
|
||||
// new BoolCueActionPair(CommonBoolCue.PowerOn, b => IrPort.PressRelease(IROutputStandardCommands.IROut_POWER_ON, b));
|
||||
// new BoolCueActionPair(CommonBoolCue.PowerOff, b => IrPort.PressRelease(IROutputStandardCommands.IROut_POWER_OFF, b));
|
||||
// new BoolCueActionPair(CommonBoolCue.ChannelUp, b => IrPort.PressRelease(IROutputStandardCommands.IROut_CH_PLUS, b));
|
||||
|
||||
// var numToIr = new Dictionary<Cue, string>
|
||||
// {
|
||||
// { CommonBoolCue.Power, IROutputStandardCommands.IROut_POWER },
|
||||
// { CommonBoolCue.PowerOn, IROutputStandardCommands.IROut_POWER_ON },
|
||||
// { CommonBoolCue.PowerOff, IROutputStandardCommands.IROut_POWER_OFF },
|
||||
// { CommonBoolCue.ChannelUp, IROutputStandardCommands.IROut_CH_PLUS },
|
||||
// { CommonBoolCue.ChannelDown, IROutputStandardCommands.IROut_CH_MINUS },
|
||||
// { CommonBoolCue.Last, IROutputStandardCommands.IROut_LAST },
|
||||
// { CommonBoolCue.Play, IROutputStandardCommands.IROut_PLAY },
|
||||
// { CommonBoolCue.Pause, IROutputStandardCommands.IROut_PAUSE },
|
||||
// { CommonBoolCue.Stop, IROutputStandardCommands.IROut_STOP },
|
||||
// { CommonBoolCue.ChapPrevious, IROutputStandardCommands.IROut_TRACK_MINUS },
|
||||
// { CommonBoolCue.ChapNext, IROutputStandardCommands.IROut_TRACK_PLUS },
|
||||
// { CommonBoolCue.Rewind, IROutputStandardCommands.IROut_RSCAN },
|
||||
// { CommonBoolCue.Ffwd, IROutputStandardCommands.IROut_FSCAN },
|
||||
// { CommonBoolCue.Replay, IROutputStandardCommands.IROut_REPLAY },
|
||||
// { CommonBoolCue.Advance, "ADVANCE" },
|
||||
// { CommonBoolCue.Record, IROutputStandardCommands.IROut_RECORD },
|
||||
// { CommonBoolCue.Exit, IROutputStandardCommands.IROut_EXIT },
|
||||
// { CommonBoolCue.Menu, IROutputStandardCommands.IROut_MENU },
|
||||
// { CommonBoolCue.List, IROutputStandardCommands.IROut_DVR },
|
||||
// { CommonBoolCue.Dvr, IROutputStandardCommands.IROut_DVR },
|
||||
// { CommonBoolCue.Back, IROutputStandardCommands.IROut_BACK },
|
||||
// { CommonBoolCue.Up, IROutputStandardCommands.IROut_UP_ARROW },
|
||||
// { CommonBoolCue.Down, IROutputStandardCommands.IROut_DN_ARROW },
|
||||
// { CommonBoolCue.Left, IROutputStandardCommands.IROut_LEFT_ARROW },
|
||||
// { CommonBoolCue.Right, IROutputStandardCommands.IROut_RIGHT_ARROW },
|
||||
// { CommonBoolCue.Select, IROutputStandardCommands.IROut_ENTER },
|
||||
// { CommonBoolCue.Guide, IROutputStandardCommands.IROut_GUIDE },
|
||||
// { CommonBoolCue.PageUp, IROutputStandardCommands.IROut_PAGE_UP },
|
||||
// { CommonBoolCue.PageDown, IROutputStandardCommands.IROut_PAGE_DOWN },
|
||||
// { CommonBoolCue.Info, IROutputStandardCommands.IROut_INFO },
|
||||
// { CommonBoolCue.Red, IROutputStandardCommands.IROut_RED },
|
||||
// { CommonBoolCue.Green, IROutputStandardCommands.IROut_GREEN },
|
||||
// { CommonBoolCue.Yellow, IROutputStandardCommands.IROut_YELLOW },
|
||||
// { CommonBoolCue.Blue, IROutputStandardCommands.IROut_BLUE },
|
||||
// { CommonBoolCue.Digit0, IROutputStandardCommands.IROut_0 },
|
||||
// { CommonBoolCue.Digit1, IROutputStandardCommands.IROut_1 },
|
||||
// { CommonBoolCue.Digit2, IROutputStandardCommands.IROut_2 },
|
||||
// { CommonBoolCue.Digit3, IROutputStandardCommands.IROut_3 },
|
||||
// { CommonBoolCue.Digit4, IROutputStandardCommands.IROut_4 },
|
||||
// { CommonBoolCue.Digit5, IROutputStandardCommands.IROut_5 },
|
||||
// { CommonBoolCue.Digit6, IROutputStandardCommands.IROut_6 },
|
||||
// { CommonBoolCue.Digit7, IROutputStandardCommands.IROut_7 },
|
||||
// { CommonBoolCue.Digit8, IROutputStandardCommands.IROut_8 },
|
||||
// { CommonBoolCue.Digit9, IROutputStandardCommands.IROut_9 },
|
||||
// { CommonBoolCue.Dash, "DASH" },
|
||||
// };
|
||||
// return IrPort.GetUOsForIrCommands(numToIr);
|
||||
// }
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region IHasSetTopBoxProperties Members
|
||||
|
||||
// public bool HasDpad { get; set; }
|
||||
|
||||
// public bool HasPreset { get; set; }
|
||||
|
||||
// public bool HasDvr { get; set; }
|
||||
|
||||
// public bool HasNumbers { get; set; }
|
||||
|
||||
// #endregion
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class SmartObjectJoinOffsets
|
||||
{
|
||||
public const ushort Dpad = 1;
|
||||
public const ushort Numpad = 2;
|
||||
|
||||
public const ushort PresetList = 6;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using Crestron.SimplSharpPro;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum eSourceListItemType
|
||||
{
|
||||
Route, Off, Other, SomethingAwesomerThanThese
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an item in a source list - can be deserialized into.
|
||||
/// </summary>
|
||||
public class SourceListItem
|
||||
{
|
||||
public string SourceKey { get; set; }
|
||||
/// <summary>
|
||||
/// Returns the source Device for this, if it exists in DeviceManager
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Device SourceDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_SourceDevice == null)
|
||||
_SourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as Device;
|
||||
return _SourceDevice;
|
||||
}
|
||||
}
|
||||
Device _SourceDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Gets either the source's Name or this AlternateName property, if
|
||||
/// defined. If source doesn't exist, returns "Missing source"
|
||||
/// </summary>
|
||||
public string PreferredName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Name))
|
||||
{
|
||||
if (SourceDevice == null)
|
||||
return "---";
|
||||
return SourceDevice.Name;
|
||||
}
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A name that will override the source's name on the UI
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
public string Icon { get; set; }
|
||||
public string AltIcon { get; set; }
|
||||
public bool IncludeInSourceList { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string VolumeControlKey { get; set; }
|
||||
public eSourceListItemType Type { get; set; }
|
||||
public List<SourceRouteListItem> RouteList { get; set; }
|
||||
|
||||
public SourceListItem()
|
||||
{
|
||||
Icon = "Blank";
|
||||
}
|
||||
}
|
||||
|
||||
public class SourceRouteListItem
|
||||
{
|
||||
[JsonProperty("sourceKey")]
|
||||
public string SourceKey { get; set; }
|
||||
|
||||
[JsonProperty("destinationKey")]
|
||||
public string DestinationKey { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public eRoutingSignalType Type { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user