mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 10:58:28 +00:00
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.
This commit is contained in:
parent
83bf40491b
commit
cdabbdb164
1 changed files with 27 additions and 36 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Touchpanels
|
namespace PepperDash.Essentials.Core.Touchpanels
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +14,8 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Mpc4TouchpanelController : Device
|
public class Mpc4TouchpanelController : Device
|
||||||
{
|
{
|
||||||
readonly MPC3Basic _touchpanel;
|
private readonly CrestronControlSystem _processor;
|
||||||
|
private MPC3Basic _touchpanel;
|
||||||
|
|
||||||
readonly Dictionary<string, KeypadButton> _buttons;
|
readonly Dictionary<string, KeypadButton> _buttons;
|
||||||
|
|
||||||
|
|
@ -28,34 +29,35 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||||
public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary<string, KeypadButton> buttons)
|
public Mpc4TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary<string, KeypadButton> buttons)
|
||||||
: base(key, name)
|
: base(key, name)
|
||||||
{
|
{
|
||||||
if (processor.MPC4x102TouchscreenSlot != null)
|
_processor = processor;
|
||||||
|
_buttons = buttons ?? new Dictionary<string, KeypadButton>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
if (_processor.MPC4x102TouchscreenSlot != null)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x102TouchscreenSlot");
|
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");
|
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");
|
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");
|
Debug.LogMessage(LogEventLevel.Information, this, "Using MPC4x302TouchscreenSlot");
|
||||||
_touchpanel = processor.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
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,27 +71,16 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
||||||
_touchpanel.ButtonStateChange += Touchpanel_ButtonStateChange;
|
_touchpanel.ButtonStateChange += Touchpanel_ButtonStateChange;
|
||||||
_touchpanel.PanelStateChange += Touchpanel_PanelStateChange;
|
_touchpanel.PanelStateChange += Touchpanel_PanelStateChange;
|
||||||
|
|
||||||
_buttons = buttons;
|
foreach (var button in _buttons)
|
||||||
if (_buttons == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, this,
|
var buttonKey = button.Key.ToLower();
|
||||||
"Button properties are null, failed to setup MPC4 Touch Controller, check configuration");
|
var buttonConfig = button.Value;
|
||||||
return;
|
|
||||||
|
InitializeButton(buttonKey, buttonConfig);
|
||||||
|
InitializeButtonFeedback(buttonKey, buttonConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPostActivationAction(() =>
|
ListButtons();
|
||||||
{
|
|
||||||
foreach (var button in _buttons)
|
|
||||||
{
|
|
||||||
var buttonKey = button.Key.ToLower();
|
|
||||||
var buttonConfig = button.Value;
|
|
||||||
|
|
||||||
InitializeButton(buttonKey, buttonConfig);
|
|
||||||
InitializeButtonFeedback(buttonKey, buttonConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
ListButtons();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue