mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 04:34:56 +00:00
Merge pull request #61 from PepperDash/feature/add-mpc3-keypad-support
Feature/add mpc3 keypad support
This commit is contained in:
@@ -428,11 +428,30 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
DeviceManager.AddDevice(dmpsRoutingController);
|
DeviceManager.AddDevice(dmpsRoutingController);
|
||||||
}
|
}
|
||||||
|
else if (this.ControllerPrompt.IndexOf("mpc3", StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "MPC3 processor type detected. Adding Mpc3TouchpanelController.");
|
||||||
|
|
||||||
|
var butToken = devConf.Properties["buttons"];
|
||||||
|
if (butToken != null)
|
||||||
|
{
|
||||||
|
var buttons = butToken.ToObject<Dictionary<uint, Essentials.Core.Touchpanels.KeypadButton>>();
|
||||||
|
var tpController = new Essentials.Core.Touchpanels.Mpc3TouchpanelController(devConf.Key, devConf.Name, Global.ControlSystem, buttons);
|
||||||
|
DeviceManager.AddDevice(tpController);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Unable to deserialize buttons collection for device: {0}", devConf.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(2, "************Processor is not DMPS type***************");
|
Debug.Console(2, "************Processor is not DMPS type***************");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
public static class DeviceFeedbackExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to get and return a feedback property from a device by name.
|
||||||
|
/// If unsuccessful, returns null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device"></param>
|
||||||
|
/// <param name="propertyName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Feedback GetFeedbackProperty(this Device device, string propertyName)
|
||||||
|
{
|
||||||
|
var feedback = DeviceJsonApi.GetPropertyByName(device.Key, propertyName) as Feedback;
|
||||||
|
|
||||||
|
if (feedback != null)
|
||||||
|
{
|
||||||
|
return feedback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets the properties on a device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -75,8 +75,34 @@ namespace PepperDash.Essentials.Core
|
|||||||
return JsonConvert.SerializeObject(props, Formatting.Indented);
|
return JsonConvert.SerializeObject(props, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a property from a device path by name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceObjectPath"></param>
|
||||||
|
/// <param name="propertyName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static object GetPropertyByName(string deviceObjectPath, string propertyName)
|
||||||
|
{
|
||||||
|
var obj = FindObjectOnPath(deviceObjectPath);
|
||||||
|
if(obj == null)
|
||||||
|
return "{ \"error\":\"No Device\"}";
|
||||||
|
|
||||||
|
CType t = obj.GetType();
|
||||||
|
|
||||||
|
var prop = t.GetProperty(propertyName);
|
||||||
|
if (prop != null)
|
||||||
|
{
|
||||||
|
return prop;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, "Unable to find Property: {0} on Device with path: {1}", propertyName, deviceObjectPath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets the methods on a device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using PepperDash.Core;
|
|||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
using PepperDash.Essentials.Core.CrestronIO;
|
using PepperDash.Essentials.Core.CrestronIO;
|
||||||
|
using PepperDash.Essentials.Core.Touchpanels;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
@@ -47,13 +48,21 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
var typeName = dc.Type.ToLower();
|
var typeName = dc.Type.ToLower();
|
||||||
|
|
||||||
// Check "core" types first
|
|
||||||
|
// Check for types that have been added by plugin dlls.
|
||||||
|
if (FactoryMethods.ContainsKey(typeName))
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading '{0}' from plugin", dc.Type);
|
||||||
|
return FactoryMethods[typeName](dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check "core" types
|
||||||
if (typeName == "genericcomm")
|
if (typeName == "genericcomm")
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||||
return new GenericComm(dc);
|
return new GenericComm(dc);
|
||||||
}
|
}
|
||||||
else if (typeName == "ceniodigin104")
|
if (typeName == "ceniodigin104")
|
||||||
{
|
{
|
||||||
var control = CommFactory.GetControlPropertiesConfig(dc);
|
var control = CommFactory.GetControlPropertiesConfig(dc);
|
||||||
var ipid = control.IpIdInt;
|
var ipid = control.IpIdInt;
|
||||||
@@ -75,13 +84,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
return new C2nRthsController(key, name, new C2nRths(cresnetId, Global.ControlSystem));
|
return new C2nRthsController(key, name, new C2nRths(cresnetId, Global.ControlSystem));
|
||||||
}
|
}
|
||||||
|
|
||||||
// then check for types that have been added by plugin dlls.
|
|
||||||
if (FactoryMethods.ContainsKey(typeName))
|
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading '{0}' from plugin", dc.Type);
|
|
||||||
return FactoryMethods[typeName](dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
List<BoolInputSig> LinkedInputSigs = new List<BoolInputSig>();
|
List<BoolInputSig> LinkedInputSigs = new List<BoolInputSig>();
|
||||||
List<BoolInputSig> LinkedComplementInputSigs = new List<BoolInputSig>();
|
List<BoolInputSig> LinkedComplementInputSigs = new List<BoolInputSig>();
|
||||||
|
|
||||||
|
List<Crestron.SimplSharpPro.DeviceSupport.Feedback> LinkedCrestronFeedbacks = new List<Crestron.SimplSharpPro.DeviceSupport.Feedback>();
|
||||||
|
|
||||||
public BoolFeedback(Func<bool> valueFunc)
|
public BoolFeedback(Func<bool> valueFunc)
|
||||||
: this(null, valueFunc)
|
: this(null, valueFunc)
|
||||||
{
|
{
|
||||||
@@ -56,28 +58,63 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links an input sig
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sig"></param>
|
||||||
public void LinkInputSig(BoolInputSig sig)
|
public void LinkInputSig(BoolInputSig sig)
|
||||||
{
|
{
|
||||||
LinkedInputSigs.Add(sig);
|
LinkedInputSigs.Add(sig);
|
||||||
UpdateSig(sig);
|
UpdateSig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unlinks an inputs sig
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sig"></param>
|
||||||
public void UnlinkInputSig(BoolInputSig sig)
|
public void UnlinkInputSig(BoolInputSig sig)
|
||||||
{
|
{
|
||||||
LinkedInputSigs.Remove(sig);
|
LinkedInputSigs.Remove(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links an input sig to the complement value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sig"></param>
|
||||||
public void LinkComplementInputSig(BoolInputSig sig)
|
public void LinkComplementInputSig(BoolInputSig sig)
|
||||||
{
|
{
|
||||||
LinkedComplementInputSigs.Add(sig);
|
LinkedComplementInputSigs.Add(sig);
|
||||||
UpdateComplementSig(sig);
|
UpdateComplementSig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unlinks an input sig to the complement value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sig"></param>
|
||||||
public void UnlinkComplementInputSig(BoolInputSig sig)
|
public void UnlinkComplementInputSig(BoolInputSig sig)
|
||||||
{
|
{
|
||||||
LinkedComplementInputSigs.Remove(sig);
|
LinkedComplementInputSigs.Remove(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links a Crestron Feedback object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="feedback"></param>
|
||||||
|
public void LinkCrestronFeedback(Crestron.SimplSharpPro.DeviceSupport.Feedback feedback)
|
||||||
|
{
|
||||||
|
LinkedCrestronFeedbacks.Add(feedback);
|
||||||
|
UpdateCrestronFeedback(feedback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="feedback"></param>
|
||||||
|
public void UnlinkCrestronFeedback(Crestron.SimplSharpPro.DeviceSupport.Feedback feedback)
|
||||||
|
{
|
||||||
|
LinkedCrestronFeedbacks.Remove(feedback);
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return (InTestMode ? "TEST -- " : "") + BoolValue.ToString();
|
return (InTestMode ? "TEST -- " : "") + BoolValue.ToString();
|
||||||
@@ -103,6 +140,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
sig.BoolValue = !_BoolValue;
|
sig.BoolValue = !_BoolValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateCrestronFeedback(Crestron.SimplSharpPro.DeviceSupport.Feedback feedback)
|
||||||
|
{
|
||||||
|
feedback.State = _BoolValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -131,6 +131,7 @@
|
|||||||
<Compile Include="Devices\CodecInterfaces.cs" />
|
<Compile Include="Devices\CodecInterfaces.cs" />
|
||||||
<Compile Include="Devices\CrestronProcessor.cs" />
|
<Compile Include="Devices\CrestronProcessor.cs" />
|
||||||
<Compile Include="Devices\DeviceApiBase.cs" />
|
<Compile Include="Devices\DeviceApiBase.cs" />
|
||||||
|
<Compile Include="Devices\DeviceFeedbackExtensions.cs" />
|
||||||
<Compile Include="Devices\PC\InRoomPc.cs" />
|
<Compile Include="Devices\PC\InRoomPc.cs" />
|
||||||
<Compile Include="Devices\PC\Laptop.cs" />
|
<Compile Include="Devices\PC\Laptop.cs" />
|
||||||
<Compile Include="Devices\ReconfigurableDevice.cs" />
|
<Compile Include="Devices\ReconfigurableDevice.cs" />
|
||||||
@@ -236,6 +237,7 @@
|
|||||||
<Compile Include="Touchpanels\CrestronTouchpanelPropertiesConfig.cs" />
|
<Compile Include="Touchpanels\CrestronTouchpanelPropertiesConfig.cs" />
|
||||||
<Compile Include="Touchpanels\Interfaces.cs" />
|
<Compile Include="Touchpanels\Interfaces.cs" />
|
||||||
<Compile Include="Touchpanels\Keyboards\HabaneroKeyboardController.cs" />
|
<Compile Include="Touchpanels\Keyboards\HabaneroKeyboardController.cs" />
|
||||||
|
<Compile Include="Touchpanels\Mpc3Touchpanel.cs" />
|
||||||
<Compile Include="Touchpanels\TriListExtensions.cs" />
|
<Compile Include="Touchpanels\TriListExtensions.cs" />
|
||||||
<Compile Include="UI PageManagers\BlurayPageManager.cs" />
|
<Compile Include="UI PageManagers\BlurayPageManager.cs" />
|
||||||
<Compile Include="UI PageManagers\SetTopBoxThreePanelPageManager.cs" />
|
<Compile Include="UI PageManagers\SetTopBoxThreePanelPageManager.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharpPro;
|
||||||
|
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Essentials.Core;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core.Touchpanels
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper class for the touchpanel portion of an MPC3 class process to allow for configurable
|
||||||
|
/// behavior of the keybad buttons
|
||||||
|
/// </summary>
|
||||||
|
public class Mpc3TouchpanelController : Device
|
||||||
|
{
|
||||||
|
MPC3Basic _Touchpanel;
|
||||||
|
|
||||||
|
Dictionary<uint, KeypadButton> _Buttons;
|
||||||
|
|
||||||
|
public Mpc3TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary<uint, KeypadButton> buttons)
|
||||||
|
: base(key, name)
|
||||||
|
{
|
||||||
|
_Touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic;
|
||||||
|
_Buttons = buttons;
|
||||||
|
|
||||||
|
_Touchpanel.ButtonStateChange += new Crestron.SimplSharpPro.DeviceSupport.ButtonEventHandler(_Touchpanel_ButtonStateChange);
|
||||||
|
|
||||||
|
|
||||||
|
AddPostActivationAction(() =>
|
||||||
|
{
|
||||||
|
// Link up the button feedbacks to the specified BoolFeedbacks
|
||||||
|
foreach (var button in _Buttons)
|
||||||
|
{
|
||||||
|
var feedbackConfig = button.Value.Feedback;
|
||||||
|
var device = DeviceManager.GetDeviceForKey(feedbackConfig.DeviceKey) as Device;
|
||||||
|
if (device != null)
|
||||||
|
{
|
||||||
|
var feedback = device.GetFeedbackProperty(feedbackConfig.BoolFeedbackName) as BoolFeedback;
|
||||||
|
if (feedback != null)
|
||||||
|
{
|
||||||
|
// Link to the Crestron Feedback corresponding to the button number
|
||||||
|
feedback.LinkCrestronFeedback(_Touchpanel.Feedbacks[button.Key]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Unable to get BoolFeedback with name: {0} from device: {1}", feedbackConfig.BoolFeedbackName, device.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Unable to get device with key: {0}", feedbackConfig.DeviceKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _Touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Button {0} ({1}), {2}", args.Button.Number, args.Button.Name, args.NewButtonState);
|
||||||
|
if (_Buttons.ContainsKey(args.Button.Number))
|
||||||
|
{
|
||||||
|
var type = args.NewButtonState.ToString();
|
||||||
|
Press(args.Button.Number, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the function associated with this button/type. One of the following strings:
|
||||||
|
/// Pressed, Released, Tapped, DoubleTapped, Held, HeldReleased
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public void Press(uint number, string type)
|
||||||
|
{
|
||||||
|
// TODO: In future, consider modifying this to generate actions at device activation time
|
||||||
|
// to prevent the need to dynamically call the method via reflection on each button press
|
||||||
|
if (!_Buttons.ContainsKey(number)) { return; }
|
||||||
|
var but = _Buttons[number];
|
||||||
|
if (but.EventTypes.ContainsKey(type))
|
||||||
|
{
|
||||||
|
foreach (var a in but.EventTypes[type]) { DeviceJsonApi.DoDeviceAction(a); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the configuration of a keybad buggon
|
||||||
|
/// </summary>
|
||||||
|
public class KeypadButton
|
||||||
|
{
|
||||||
|
public Dictionary<string, DeviceActionWrapper[]> EventTypes { get; set; }
|
||||||
|
public KeypadButtonFeedback Feedback { get; set; }
|
||||||
|
|
||||||
|
public KeypadButton()
|
||||||
|
{
|
||||||
|
EventTypes = new Dictionary<string, DeviceActionWrapper[]>();
|
||||||
|
Feedback = new KeypadButtonFeedback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class KeypadButtonFeedback
|
||||||
|
{
|
||||||
|
public string DeviceKey { get; set; }
|
||||||
|
public string BoolFeedbackName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user