mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-10 18:24:50 +00:00
Adds necessary updates to allow feedback for keypad buttons to be defined in config and linked up at runtime
This commit is contained in:
@@ -6,9 +6,14 @@ 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;
|
||||
@@ -21,13 +26,40 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||
_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}", args.Button.Number, args.NewButtonState);
|
||||
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();
|
||||
@@ -37,12 +69,14 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||
|
||||
/// <summary>
|
||||
/// Runs the function associated with this button/type. One of the following strings:
|
||||
/// Pressed, Released, Tapped, DoubleTapped, Held, HeldReleased
|
||||
/// 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))
|
||||
@@ -55,7 +89,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Represents the configuration of a keybad buggon
|
||||
/// </summary>
|
||||
public class KeypadButton
|
||||
{
|
||||
@@ -74,7 +108,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||
/// </summary>
|
||||
public class KeypadButtonFeedback
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string LinkToKey { get; set; }
|
||||
public string DeviceKey { get; set; }
|
||||
public string BoolFeedbackName { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user