From f5d6a076ad0becd0d73488a7f3befb6a00beedb1 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 11:22:03 -0400 Subject: [PATCH 1/8] feat: Add Mpc4TouchpanelController for MPC4 processors Introduced Mpc4TouchpanelController to manage touchpanel behavior for MPC4 class processors, including button initialization, feedback, and event handling. Updated ControlSystem.cs to detect MPC4 models, deserialize button configs, and register the controller with DeviceManager. --- .../Touchpanels/Mpc4Touchpanel.cs | 307 ++++++++++++++++++ src/PepperDash.Essentials/ControlSystem.cs | 19 ++ 2 files changed, 326 insertions(+) create mode 100644 src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs new file mode 100644 index 00000000..cb9db34a --- /dev/null +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -0,0 +1,307 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using Crestron.SimplSharpPro; +using PepperDash.Core; +using PepperDash.Core.Logging; +using Serilog.Events; + +namespace PepperDash.Essentials.Core.Touchpanels +{ + /// + /// A wrapper class for the touchpanel portion of an MPC4 class process to allow for configurable + /// behavior of the keypad buttons + /// + public class Mpc4TouchpanelController : Device + { + readonly MPC4x3XXBase _touchpanel; + + readonly Dictionary _buttons; + + /// + /// Constructor + /// + /// device key + /// device name + /// control system processor + /// dictionary of keypad buttons + public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary buttons) + : base(key, name) + { + _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC4x3XXBase; + if (_touchpanel == null) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.GetType().FullName); + return; + } + + if (_touchpanel.Registerable) + { + var registrationResponse = _touchpanel.Register(); + Debug.LogMessage(LogEventLevel.Information, this, "touchpanel registration response: {0}", registrationResponse); + } + + _touchpanel.BaseEvent += Touchpanel_BaseEvent; + _touchpanel.ButtonStateChange += Touchpanel_ButtonStateChange; + _touchpanel.PanelStateChange += Touchpanel_PanelStateChange; + + _buttons = buttons; + if (_buttons == null) + { + Debug.LogMessage(LogEventLevel.Debug, this, + "Button properties are null, failed to setup MPC4 Touch Controller, check configuration"); + return; + } + + AddPostActivationAction(() => + { + foreach (var button in _buttons) + { + var buttonKey = button.Key.ToLower(); + var buttonConfig = button.Value; + + InitializeButton(buttonKey, buttonConfig); + InitializeButtonFeedback(buttonKey, buttonConfig); + } + + ListButtons(); + }); + } + + /// + /// Enables/disables buttons based on event type configuration + /// + /// + /// + public void InitializeButton(string key, KeypadButton config) + { + if (config == null) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' config is null, unable to initialize", key); + return; + } + + TryParseInt(key, out int buttonNumber); + + var buttonEventTypes = config.EventTypes; + BoolOutputSig enabledFb = null; + BoolOutputSig disabledFb = null; + + switch (key) + { + case ("power"): + { + if (buttonEventTypes == null || buttonEventTypes.Keys == null) + _touchpanel.DisablePowerButton(); + else + _touchpanel.EnablePowerButton(); + + + enabledFb = _touchpanel.PowerButtonEnabledFeedBack; + disabledFb = _touchpanel.PowerButtonDisabledFeedBack; + + break; + } + case ("mute"): + { + if (buttonEventTypes == null || buttonEventTypes.Keys == null) + _touchpanel.DisableMuteButton(); + else + _touchpanel.EnableMuteButton(); + + + enabledFb = _touchpanel.MuteButtonEnabledFeedBack; + disabledFb = _touchpanel.MuteButtonDisabledFeedBack; + + break; + } + default: + { + if (buttonNumber == 0 || buttonNumber > 9) + break; + + 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.LogMessage(LogEventLevel.Information, this, "InitializeButton: key-'{0}' enabledFb-'{1}', disabledFb-'{2}'", + key, enabledFb ?? (object)"null", disabledFb ?? (object)"null"); + } + + /// + /// Links button feedback if configured + /// + /// + /// + public void InitializeButtonFeedback(string key, KeypadButton config) + { + if (config == null) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' config is null, skipping.", key); + return; + } + + TryParseInt(key, out int buttonNumber); + + // Link up the button feedbacks to the specified device feedback + var buttonFeedback = config.Feedback; + if (buttonFeedback == null || string.IsNullOrEmpty(buttonFeedback.DeviceKey)) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedback not configured, skipping.", + key); + return; + } + + Feedback deviceFeedback; + + try + { + if (!(DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) is Device device)) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedback deviceKey '{1}' not found.", + key, buttonFeedback.DeviceKey); + return; + } + + deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName); + if (deviceFeedback == null) + { + Debug.LogMessage(LogEventLevel.Debug, this, "Button '{0}' feedbackName property '{1}' not found.", + key, buttonFeedback.FeedbackName); + return; + } + } + catch (Exception ex) + { + Debug.LogMessage(LogEventLevel.Debug, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception Message: {0}", + ex.Message, key, buttonFeedback.DeviceKey); + Debug.LogMessage(LogEventLevel.Verbose, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception StackTrace: {0}", + ex.StackTrace, key, buttonFeedback.DeviceKey); + if (ex.InnerException != null) Debug.LogMessage(LogEventLevel.Verbose, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') InnerException: {0}", + ex.InnerException, key, buttonFeedback.DeviceKey); + + return; + } + + var boolFeedback = deviceFeedback as BoolFeedback; + + switch (key) + { + case ("power"): + { + boolFeedback?.LinkCrestronFeedback(_touchpanel.FeedbackPower); + break; + } + case ("volumeup"): + case ("volumedown"): + case ("volumefeedback"): + { + if (deviceFeedback is IntFeedback intFeedback) + { + var volumeFeedback = intFeedback; + volumeFeedback.LinkInputSig(_touchpanel.VolumeBargraph); + } + break; + } + case ("mute"): + { + boolFeedback?.LinkCrestronFeedback(_touchpanel.FeedbackMute); + break; + } + default: + { + boolFeedback?.LinkCrestronFeedback(_touchpanel.Feedbacks[(uint)buttonNumber]); + break; + } + } + } + + /// + /// Try parse int helper method + /// + /// + /// + /// + public bool TryParseInt(string str, out int result) + { + try + { + result = int.Parse(str); + return true; + } + catch + { + result = 0; + return false; + } + } + + private void Touchpanel_BaseEvent(GenericBase device, BaseEventArgs args) + { + Debug.LogMessage(LogEventLevel.Debug, this, "BaseEvent: eventId-'{0}', index-'{1}'", args.EventId, args.Index); + } + + private void Touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args) + { + Debug.LogMessage(LogEventLevel.Debug, 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))) + { + Press(args.Button.Number.ToString(CultureInfo.InvariantCulture), type); + } + else if (_buttons.ContainsKey(args.Button.Name.ToString())) + { + Press(args.Button.Name.ToString(), type); + } + } + + private void Touchpanel_PanelStateChange(GenericBase device, BaseEventArgs args) + { + Debug.LogMessage(LogEventLevel.Debug, 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 + /// + /// + /// + public void Press(string buttonKey, string type) + { + this.LogVerbose("Press: buttonKey-'{buttonKey}', type-'{type}'", buttonKey, type); + + if (!_buttons.ContainsKey(buttonKey)) return; + + var button = _buttons[buttonKey]; + if (!button.EventTypes.ContainsKey(type)) return; + + foreach (var eventType in button.EventTypes[type]) DeviceJsonApi.DoDeviceAction(eventType); + } + + /// + /// ListButtons method + /// + public void ListButtons() + { + this.LogVerbose("MPC4 Controller {0} - Available Buttons", Key); + + foreach (var button in _buttons) + { + this.LogVerbose("Key: {key}", button.Key); + } + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 47de4d3e..f2888b8a 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -436,6 +436,25 @@ namespace PepperDash.Essentials "WARNING: Config file defines processor type as '{deviceType:l}' but actual processor is '{processorType:l}'! Some ports may not be available", devConf.Type.ToUpper(), Global.ControlSystem.ControllerPrompt.ToUpper()); + // Check if the processor is an MPC4 model + if (prompt.IndexOf("mpc4", StringComparison.OrdinalIgnoreCase) > -1) + { + Debug.LogMessage(LogEventLevel.Information, "MPC4 processor type detected. Adding Mpc4TouchpanelController."); + + var butToken = devConf.Properties["buttons"]; + if (butToken == null) + { + Debug.LogMessage(LogEventLevel.Warning, + "Error: Unable to deserialize buttons collection for device: {deviceKey}", devConf.Key); + continue; + } + + var buttons = Newtonsoft.Json.JsonConvert.DeserializeObject>(butToken.ToString()); + var tpController = new Core.Touchpanels.Mpc4TouchpanelController( + string.Format("{0}-keypadButtons", devConf.Key), devConf.Name, Global.ControlSystem, buttons); + + DeviceManager.AddDevice(tpController); + } continue; } From d713d65c7aeabcef5d93e707a45ab592c79e85ae Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 12:35:21 -0400 Subject: [PATCH 2/8] fix: Refactor touchpanel init and error logging Change _touchpanel type to MPC3Basic. Update constructor to select touchscreen slot by TouchscreenType using switch. Improve error logging with error level and detailed type info. --- .../Touchpanels/Mpc4Touchpanel.cs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index cb9db34a..19eb0d87 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -14,7 +14,7 @@ namespace PepperDash.Essentials.Core.Touchpanels /// public class Mpc4TouchpanelController : Device { - readonly MPC4x3XXBase _touchpanel; + readonly MPC3Basic _touchpanel; readonly Dictionary _buttons; @@ -28,10 +28,32 @@ namespace PepperDash.Essentials.Core.Touchpanels public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary buttons) : base(key, name) { - _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC4x3XXBase; + switch (processor.TouchscreenType) + { + case eTouchscreenType.MPC4x102: + _touchpanel = processor.MPC4x102TouchscreenSlot; + break; + + case eTouchscreenType.MPC4x201: + _touchpanel = processor.MPC4x201TouchscreenSlot; + break; + + case eTouchscreenType.MPC4x301: + _touchpanel = processor.MPC4x301TouchscreenSlot; + break; + + case eTouchscreenType.MPC4x302: + _touchpanel = processor.MPC4x302TouchscreenSlot; + break; + + default: + Debug.LogMessage(LogEventLevel.Error, this, "Unsupported touchpanel type '{0}' for MPC4 Touch Controller", processor.TouchscreenType); + break; + } + if (_touchpanel == null) { - Debug.LogMessage(LogEventLevel.Debug, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.GetType().FullName); + Debug.LogMessage(LogEventLevel.Error, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.ControllerTouchScreenSlotDevice?.GetType().FullName ?? "null"); return; } From 31fd66559411065e379a834f18441e215cd95b36 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 12:44:43 -0400 Subject: [PATCH 3/8] fix: Simplify touchscreen slot selection logic Replaced switch statement for touchscreen type selection with a single cast assignment to MPC3Basic. This streamlines initialization and removes explicit handling for each touchscreen type. Error logging is retained for failed casts. --- .../Touchpanels/Mpc4Touchpanel.cs | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index 19eb0d87..4d16f184 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -28,28 +28,7 @@ namespace PepperDash.Essentials.Core.Touchpanels public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary buttons) : base(key, name) { - switch (processor.TouchscreenType) - { - case eTouchscreenType.MPC4x102: - _touchpanel = processor.MPC4x102TouchscreenSlot; - break; - - case eTouchscreenType.MPC4x201: - _touchpanel = processor.MPC4x201TouchscreenSlot; - break; - - case eTouchscreenType.MPC4x301: - _touchpanel = processor.MPC4x301TouchscreenSlot; - break; - - case eTouchscreenType.MPC4x302: - _touchpanel = processor.MPC4x302TouchscreenSlot; - break; - - default: - Debug.LogMessage(LogEventLevel.Error, this, "Unsupported touchpanel type '{0}' for MPC4 Touch Controller", processor.TouchscreenType); - break; - } + _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic; if (_touchpanel == null) { From 8c56623641dc694ad04b8fbb053a958f96b0d686 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 14:17:50 -0400 Subject: [PATCH 4/8] fix: Support multiple MPC4 touchscreen slot types in ctor Updated Mpc4TouchpanelController constructor to assign _touchpanel from the first available slot among MPC4x102, MPC4x201, MPC4x301, or MPC4x302 touchscreen slots, improving compatibility with various MPC4 touchscreen models. --- .../Touchpanels/Mpc4Touchpanel.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index 4d16f184..85a7b987 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -28,7 +28,22 @@ namespace PepperDash.Essentials.Core.Touchpanels public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary buttons) : base(key, name) { - _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic; + if (processor.MPC4x102TouchscreenSlot != null) + { + _touchpanel = processor.MPC4x102TouchscreenSlot; + } + else if (processor.MPC4x201TouchscreenSlot != null) + { + _touchpanel = processor.MPC4x201TouchscreenSlot; + } + else if (processor.MPC4x301TouchscreenSlot != null) + { + _touchpanel = processor.MPC4x301TouchscreenSlot; + } + else if (processor.MPC4x302TouchscreenSlot != null) + { + _touchpanel = processor.MPC4x302TouchscreenSlot; + } if (_touchpanel == null) { From 25693c7071ab655fe3f63cba826c1bbc6b7cd7b5 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 14:40:54 -0400 Subject: [PATCH 5/8] fix: Add debug logs for touchscreen slot selection in controller Improved logging to indicate which touchscreen slot is used during Mpc4TouchpanelController initialization. Updated error log to report processor.TouchscreenType for clearer diagnostics. --- .../Touchpanels/Mpc4Touchpanel.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index 85a7b987..5de2f69a 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -30,24 +30,33 @@ namespace PepperDash.Essentials.Core.Touchpanels { if (processor.MPC4x102TouchscreenSlot != null) { + Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x102TouchscreenSlot"); _touchpanel = processor.MPC4x102TouchscreenSlot; } else if (processor.MPC4x201TouchscreenSlot != null) { + Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x201TouchscreenSlot"); _touchpanel = processor.MPC4x201TouchscreenSlot; } else if (processor.MPC4x301TouchscreenSlot != null) { + Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x301TouchscreenSlot"); _touchpanel = processor.MPC4x301TouchscreenSlot; } else if (processor.MPC4x302TouchscreenSlot != null) { + Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x302TouchscreenSlot"); _touchpanel = processor.MPC4x302TouchscreenSlot; } + else + { + Debug.LogMessage(LogEventLevel.Information, this, "Using ControllerTouchScreenSlotDevice"); + _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic; + } if (_touchpanel == null) { - Debug.LogMessage(LogEventLevel.Error, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.ControllerTouchScreenSlotDevice?.GetType().FullName ?? "null"); + Debug.LogMessage(LogEventLevel.Error, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.TouchscreenType); return; } From 83bf40491b966a7252ba50e4d5ee7be9f74a7a43 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Wed, 12 Aug 2026 14:55:04 -0400 Subject: [PATCH 6/8] fix: Refine touchpanel device selection and logging Improve logic to check for MPC3Basic type using pattern matching. Update debug and error messages to report actual device type. Clarify conditional structure for better readability. --- .../Touchpanels/Mpc4Touchpanel.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index 5de2f69a..ef9df608 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -48,15 +48,14 @@ namespace PepperDash.Essentials.Core.Touchpanels Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x302TouchscreenSlot"); _touchpanel = processor.MPC4x302TouchscreenSlot; } + else if (processor.ControllerTouchScreenSlotDevice != null && processor.ControllerTouchScreenSlotDevice is MPC3Basic mpc) + { + Debug.LogMessage(LogEventLevel.Information, this, "Using ControllerTouchScreenSlotDevice:{0}", processor.ControllerTouchScreenSlotDevice.GetType().Name); + _touchpanel = mpc; + } else { - Debug.LogMessage(LogEventLevel.Information, this, "Using ControllerTouchScreenSlotDevice"); - _touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic; - } - - if (_touchpanel == null) - { - Debug.LogMessage(LogEventLevel.Error, this, "Failed to construct MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.TouchscreenType); + Debug.LogMessage(LogEventLevel.Error, this, "Failed to find MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.ControllerTouchScreenSlotDevice?.GetType().Name ?? "unknown"); return; } From cdabbdb164836c492bf2d936bee00b5ee08bfddc Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Fri, 14 Aug 2026 09:17:47 -0400 Subject: [PATCH 7/8] fix: Refactor Mpc4TouchpanelController initialization logic Refactored Mpc4TouchpanelController to store the processor as a private readonly field and moved button dictionary initialization to the constructor. Moved touchpanel slot selection logic from the constructor to an overridden Initialize() method, now using the _processor field and removing fallback to ControllerTouchScreenSlotDevice. Improved error logging by removing references to processor type and key variables. Changed button initialization to occur in Initialize() with a foreach loop, eliminating AddPostActivationAction and null checks for the button dictionary. --- .../Touchpanels/Mpc4Touchpanel.cs | 63 ++++++++----------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs index ef9df608..a8fa268a 100644 --- a/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs +++ b/src/PepperDash.Essentials.Core/Touchpanels/Mpc4Touchpanel.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Globalization; using Crestron.SimplSharpPro; using PepperDash.Core; using PepperDash.Core.Logging; using Serilog.Events; +using System; +using System.Collections.Generic; +using System.Globalization; namespace PepperDash.Essentials.Core.Touchpanels { @@ -14,7 +14,8 @@ namespace PepperDash.Essentials.Core.Touchpanels /// public class Mpc4TouchpanelController : Device { - readonly MPC3Basic _touchpanel; + private readonly CrestronControlSystem _processor; + private MPC3Basic _touchpanel; readonly Dictionary _buttons; @@ -28,34 +29,35 @@ namespace PepperDash.Essentials.Core.Touchpanels public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary buttons) : base(key, name) { - if (processor.MPC4x102TouchscreenSlot != null) + _processor = processor; + _buttons = buttons ?? new Dictionary(); + } + + public override void Initialize() + { + if (_processor.MPC4x102TouchscreenSlot != null) { Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x102TouchscreenSlot"); - _touchpanel = processor.MPC4x102TouchscreenSlot; + _touchpanel = _processor.MPC4x102TouchscreenSlot; } - else if (processor.MPC4x201TouchscreenSlot != null) + else if (_processor.MPC4x201TouchscreenSlot != null) { Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x201TouchscreenSlot"); - _touchpanel = processor.MPC4x201TouchscreenSlot; + _touchpanel = _processor.MPC4x201TouchscreenSlot; } - else if (processor.MPC4x301TouchscreenSlot != null) + else if (_processor.MPC4x301TouchscreenSlot != null) { Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x301TouchscreenSlot"); - _touchpanel = processor.MPC4x301TouchscreenSlot; + _touchpanel = _processor.MPC4x301TouchscreenSlot; } - else if (processor.MPC4x302TouchscreenSlot != null) + else if (_processor.MPC4x302TouchscreenSlot != null) { Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x302TouchscreenSlot"); - _touchpanel = processor.MPC4x302TouchscreenSlot; - } - else if (processor.ControllerTouchScreenSlotDevice != null && processor.ControllerTouchScreenSlotDevice is MPC3Basic mpc) - { - Debug.LogMessage(LogEventLevel.Information, this, "Using ControllerTouchScreenSlotDevice:{0}", processor.ControllerTouchScreenSlotDevice.GetType().Name); - _touchpanel = mpc; + _touchpanel = _processor.MPC4x302TouchscreenSlot; } else { - Debug.LogMessage(LogEventLevel.Error, this, "Failed to find MPC4 Touchpanel Controller with key {0}, check configuration, processor is type: {1}", key, processor.ControllerTouchScreenSlotDevice?.GetType().Name ?? "unknown"); + Debug.LogMessage(LogEventLevel.Error, this, "Failed to find MPC4 Touchpanel Controller with key {0}, check configuration", Key); return; } @@ -69,27 +71,16 @@ namespace PepperDash.Essentials.Core.Touchpanels _touchpanel.ButtonStateChange += Touchpanel_ButtonStateChange; _touchpanel.PanelStateChange += Touchpanel_PanelStateChange; - _buttons = buttons; - if (_buttons == null) + foreach (var button in _buttons) { - Debug.LogMessage(LogEventLevel.Debug, this, - "Button properties are null, failed to setup MPC4 Touch Controller, check configuration"); - return; + var buttonKey = button.Key.ToLower(); + var buttonConfig = button.Value; + + InitializeButton(buttonKey, buttonConfig); + InitializeButtonFeedback(buttonKey, buttonConfig); } - AddPostActivationAction(() => - { - foreach (var button in _buttons) - { - var buttonKey = button.Key.ToLower(); - var buttonConfig = button.Value; - - InitializeButton(buttonKey, buttonConfig); - InitializeButtonFeedback(buttonKey, buttonConfig); - } - - ListButtons(); - }); + ListButtons(); } /// From 1eed8a5c34431b56223e1516d1583e19b44f9145 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Fri, 14 Aug 2026 10:17:02 -0400 Subject: [PATCH 8/8] feat: Update Crestron.SimplSharp.SDK NuGet packages Upgraded Crestron.SimplSharp.SDK.Library, ProgramLibrary, and Program package versions from 2.21.90 to 2.21.274 across multiple project files. No other code or configuration changes were made. --- src/PepperDash.Core/PepperDash.Core.csproj | 2 +- .../PepperDash.Essentials.Core.csproj | 2 +- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- .../PepperDash.Essentials.MobileControl.Messengers.csproj | 2 +- .../PepperDash.Essentials.MobileControl.csproj | 2 +- src/PepperDash.Essentials/PepperDash.Essentials.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PepperDash.Core/PepperDash.Core.csproj b/src/PepperDash.Core/PepperDash.Core.csproj index daa5c6da..747aefb6 100644 --- a/src/PepperDash.Core/PepperDash.Core.csproj +++ b/src/PepperDash.Core/PepperDash.Core.csproj @@ -43,7 +43,7 @@ - + diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 251ba316..b7f333bd 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -25,7 +25,7 @@ bin\$(Configuration)\PepperDash_Essentials_Core.xml - + diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 7be4372d..317fa2d3 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -29,6 +29,6 @@ - + \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj b/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj index d13d1a09..a9223061 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj +++ b/src/PepperDash.Essentials.MobileControl.Messengers/PepperDash.Essentials.MobileControl.Messengers.csproj @@ -33,7 +33,7 @@ - + diff --git a/src/PepperDash.Essentials.MobileControl/PepperDash.Essentials.MobileControl.csproj b/src/PepperDash.Essentials.MobileControl/PepperDash.Essentials.MobileControl.csproj index 235e0899..b0e2dd9f 100644 --- a/src/PepperDash.Essentials.MobileControl/PepperDash.Essentials.MobileControl.csproj +++ b/src/PepperDash.Essentials.MobileControl/PepperDash.Essentials.MobileControl.csproj @@ -38,7 +38,7 @@ - + diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 20a42ffd..cb83bf84 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -48,7 +48,7 @@ - +