From 6698dcb46e7cdc6824d5725ecf9528385e5fe03a Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 25 Oct 2023 15:26:42 -0500 Subject: [PATCH] refactor: update init methods and add events - Updated InitializeButton method to enable/disable buttons based on config. - Updated InitializeButtonFeedback method debug statements. - Added BaseEvent event subscription. - Added PanelStateChnage event subscription. --- .../Touchpanels/Mpc3Touchpanel.cs | 109 +++++++++++------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Touchpanels/Mpc3Touchpanel.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Touchpanels/Mpc3Touchpanel.cs index 296965f9..2d36fe49 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Touchpanels/Mpc3Touchpanel.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Touchpanels/Mpc3Touchpanel.cs @@ -27,7 +27,15 @@ namespace PepperDash.Essentials.Core.Touchpanels return; } + if (_touchpanel.Registerable) + { + _touchpanel.Register(); + Debug.Console(0, this, ""); + } + + _touchpanel.BaseEvent += _touchpanel_BaseEvent; _touchpanel.ButtonStateChange += _touchpanel_ButtonStateChange; + _touchpanel.PanelStateChange += _touchpanel_PanelStateChange; _buttons = buttons; if (_buttons == null) @@ -57,8 +65,6 @@ namespace PepperDash.Essentials.Core.Touchpanels /// public void InitializeButton(string key, KeypadButton config) { - Debug.Console(1, this, "Initializing button '{0}'...", key); - if (config == null) { Debug.Console(1, this, "Button '{0}' config is null, unable to initialize", key); @@ -69,63 +75,72 @@ namespace PepperDash.Essentials.Core.Touchpanels TryParseInt(key, out buttonNumber); var buttonEventTypes = config.EventTypes; + BoolOutputSig enabledFb = null; + BoolOutputSig disabledFb = null; switch (key) { case ("power"): { - if (buttonEventTypes == null) + if (buttonEventTypes == null || buttonEventTypes.Keys == null) _touchpanel.DisablePowerButton(); else _touchpanel.EnablePowerButton(); - break; - } - case ("volumeup"): - { - if (buttonEventTypes == null) - _touchpanel.DisableVolumeUpButton(); - - break; - } - case ("volumedown"): - { - if (buttonEventTypes == null) - _touchpanel.DisableVolumeDownButton(); - - break; - } - case ("volumefeedback"): - { + + enabledFb = _touchpanel.PowerButtonEnabledFeedBack; + disabledFb = _touchpanel.PowerButtonDisabledFeedBack; break; } + //case ("volumeup"): + // { + // break; + // } + //case ("volumedown"): + // { + // break; + // } + //case ("volumefeedback"): + // { + // break; + // } case ("mute"): { - if (buttonEventTypes == null) + if (buttonEventTypes == null || buttonEventTypes.Keys == null) _touchpanel.DisableMuteButton(); else _touchpanel.EnableMuteButton(); + + enabledFb = _touchpanel.MuteButtonEnabledFeedBack; + disabledFb = _touchpanel.MuteButtonDisabledFeedBack; + break; } default: { - if (buttonNumber == 0) + if (buttonNumber == 0 || buttonNumber > 9) break; - if (buttonEventTypes == null) + if (buttonEventTypes == null || buttonEventTypes.Keys == null) _touchpanel.DisableNumericalButton((uint)buttonNumber); else _touchpanel.EnableNumericalButton((uint)buttonNumber); + + if (_touchpanel.NumericalButtonEnabledFeedBack != null) + enabledFb = _touchpanel.NumericalButtonEnabledFeedBack[(uint)buttonNumber]; + + if (_touchpanel.NumericalButtonDisabledFeedBack != null) + disabledFb = _touchpanel.NumericalButtonDisabledFeedBack[(uint)buttonNumber]; + break; } } - Debug.Console(1, this, "Button '{0}' {1}", key, buttonEventTypes == null - ? "is disabled, verify eventTypes are configured." - : "is enabled"); + Debug.Console(0, this, "InitializeButton: key-'{0}' enabledFb-'{1}', disabledFb-'{2}'", + key, enabledFb ?? (object)"null", disabledFb ?? (object)"null"); } /// @@ -135,11 +150,11 @@ namespace PepperDash.Essentials.Core.Touchpanels /// public void InitializeButtonFeedback(string key, KeypadButton config) { - Debug.Console(1, this, "Initializing button '{0}' feedback...", key); + //Debug.Console(1, this, "Initializing button '{0}' feedback...", key); if (config == null) { - Debug.Console(1, this, "Button '{0}' config is null, unable to initialize feedback", key); + Debug.Console(1, this, "Button '{0}' config is null, skipping.", key); return; } @@ -148,9 +163,9 @@ namespace PepperDash.Essentials.Core.Touchpanels // Link up the button feedbacks to the specified device feedback var buttonFeedback = config.Feedback; - if (buttonFeedback == null) + if (buttonFeedback == null || string.IsNullOrEmpty(buttonFeedback.DeviceKey)) { - Debug.Console(1, this, "Button '{0}' feedback not configured and will not be implemented. If feedback is required, verify configuration.", + Debug.Console(1, this, "Button '{0}' feedback not configured, skipping.", key); return; } @@ -162,15 +177,15 @@ namespace PepperDash.Essentials.Core.Touchpanels var device = DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) as Device; if (device == null) { - Debug.Console(1, this, "Button '{0}' feedback with deviceKey '{1}' not found, feedback will not be implemented. Verify feedback deviceKey is properly configured.", + Debug.Console(1, this, "Button '{0}' feedback deviceKey '{1}' not found.", key, buttonFeedback.DeviceKey); return; } - + deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName); if (deviceFeedback == null) { - Debug.Console(1, this, "Button '{0}' feedback failed to get feedback property for '{1}', feedback will not be implemented. Verify feedback deviceKey is properly configured.", + Debug.Console(1, this, "Button '{0}' feedbackName property '{1}' not found.", key, buttonFeedback.FeedbackName); return; } @@ -195,12 +210,12 @@ namespace PepperDash.Essentials.Core.Touchpanels } catch (Exception ex) { - Debug.Console(0, this, "Failed to initialize button '{0}' feedback with deviceKey '{1}'. If feedback is required, verify configuration.", - key, buttonFeedback.DeviceKey); - - Debug.Console(1, this, "InitializeButtonFeedback Exception Message: {0}", ex.Message); - Debug.Console(2, this, "InitializeButtonFeedback Exception StackTrace: {0}", ex.StackTrace); - if (ex.InnerException != null) Debug.Console(2, this, "InitializeButtonFeedback Exception InnerExceptioni: {0}", ex.InnerException); + Debug.Console(1, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception Message: {0}", + ex.Message, key, buttonFeedback.DeviceKey); + Debug.Console(2, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception StackTrace: {0}", + ex.StackTrace, key, buttonFeedback.DeviceKey); + if (ex.InnerException != null) Debug.Console(2, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') InnerException: {0}", + ex.InnerException, key, buttonFeedback.DeviceKey); return; } @@ -259,9 +274,14 @@ namespace PepperDash.Essentials.Core.Touchpanels } } + private void _touchpanel_BaseEvent(GenericBase device, BaseEventArgs args) + { + Debug.Console(1, this, "BaseEvent: eventId-'{0}', index-'{1}'", args.EventId, args.Index); + } + private 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); + Debug.Console(1, this, "ButtonStateChange: buttonNumber-'{0}' buttonName-'{1}', buttonState-'{2}'", args.Button.Number, args.Button.Name, args.NewButtonState); var type = args.NewButtonState.ToString(); if (_buttons.ContainsKey(args.Button.Number.ToString(CultureInfo.InvariantCulture))) @@ -274,6 +294,11 @@ namespace PepperDash.Essentials.Core.Touchpanels } } + private void _touchpanel_PanelStateChange(GenericBase device, BaseEventArgs args) + { + Debug.Console(1, this, "PanelStateChange: eventId-'{0}', index-'{1}'", args.EventId, args.Index); + } + /// /// Runs the function associated with this button/type. One of the following strings: /// Pressed, Released, Tapped, DoubleTapped, Held, HeldReleased @@ -282,6 +307,8 @@ namespace PepperDash.Essentials.Core.Touchpanels /// public void Press(string buttonKey, string type) { + Debug.Console(2, this, "Press: buttonKey-'{0}', type-'{1}'", buttonKey, 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(buttonKey)) return;