mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
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.
This commit is contained in:
@@ -27,7 +27,15 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_touchpanel.Registerable)
|
||||||
|
{
|
||||||
|
_touchpanel.Register();
|
||||||
|
Debug.Console(0, this, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
_touchpanel.BaseEvent += _touchpanel_BaseEvent;
|
||||||
_touchpanel.ButtonStateChange += _touchpanel_ButtonStateChange;
|
_touchpanel.ButtonStateChange += _touchpanel_ButtonStateChange;
|
||||||
|
_touchpanel.PanelStateChange += _touchpanel_PanelStateChange;
|
||||||
|
|
||||||
_buttons = buttons;
|
_buttons = buttons;
|
||||||
if (_buttons == null)
|
if (_buttons == null)
|
||||||
@@ -57,8 +65,6 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
public void InitializeButton(string key, KeypadButton config)
|
public void InitializeButton(string key, KeypadButton config)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Initializing button '{0}'...", key);
|
|
||||||
|
|
||||||
if (config == null)
|
if (config == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Button '{0}' config is null, unable to initialize", key);
|
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);
|
TryParseInt(key, out buttonNumber);
|
||||||
|
|
||||||
var buttonEventTypes = config.EventTypes;
|
var buttonEventTypes = config.EventTypes;
|
||||||
|
BoolOutputSig enabledFb = null;
|
||||||
|
BoolOutputSig disabledFb = null;
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case ("power"):
|
case ("power"):
|
||||||
{
|
{
|
||||||
if (buttonEventTypes == null)
|
if (buttonEventTypes == null || buttonEventTypes.Keys == null)
|
||||||
_touchpanel.DisablePowerButton();
|
_touchpanel.DisablePowerButton();
|
||||||
else
|
else
|
||||||
_touchpanel.EnablePowerButton();
|
_touchpanel.EnablePowerButton();
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
enabledFb = _touchpanel.PowerButtonEnabledFeedBack;
|
||||||
case ("volumeup"):
|
disabledFb = _touchpanel.PowerButtonDisabledFeedBack;
|
||||||
{
|
|
||||||
if (buttonEventTypes == null)
|
|
||||||
_touchpanel.DisableVolumeUpButton();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ("volumedown"):
|
|
||||||
{
|
|
||||||
if (buttonEventTypes == null)
|
|
||||||
_touchpanel.DisableVolumeDownButton();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ("volumefeedback"):
|
|
||||||
{
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//case ("volumeup"):
|
||||||
|
// {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//case ("volumedown"):
|
||||||
|
// {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//case ("volumefeedback"):
|
||||||
|
// {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
case ("mute"):
|
case ("mute"):
|
||||||
{
|
{
|
||||||
if (buttonEventTypes == null)
|
if (buttonEventTypes == null || buttonEventTypes.Keys == null)
|
||||||
_touchpanel.DisableMuteButton();
|
_touchpanel.DisableMuteButton();
|
||||||
else
|
else
|
||||||
_touchpanel.EnableMuteButton();
|
_touchpanel.EnableMuteButton();
|
||||||
|
|
||||||
|
|
||||||
|
enabledFb = _touchpanel.MuteButtonEnabledFeedBack;
|
||||||
|
disabledFb = _touchpanel.MuteButtonDisabledFeedBack;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (buttonNumber == 0)
|
if (buttonNumber == 0 || buttonNumber > 9)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (buttonEventTypes == null)
|
if (buttonEventTypes == null || buttonEventTypes.Keys == null)
|
||||||
_touchpanel.DisableNumericalButton((uint)buttonNumber);
|
_touchpanel.DisableNumericalButton((uint)buttonNumber);
|
||||||
else
|
else
|
||||||
_touchpanel.EnableNumericalButton((uint)buttonNumber);
|
_touchpanel.EnableNumericalButton((uint)buttonNumber);
|
||||||
|
|
||||||
|
|
||||||
|
if (_touchpanel.NumericalButtonEnabledFeedBack != null)
|
||||||
|
enabledFb = _touchpanel.NumericalButtonEnabledFeedBack[(uint)buttonNumber];
|
||||||
|
|
||||||
|
if (_touchpanel.NumericalButtonDisabledFeedBack != null)
|
||||||
|
disabledFb = _touchpanel.NumericalButtonDisabledFeedBack[(uint)buttonNumber];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(1, this, "Button '{0}' {1}", key, buttonEventTypes == null
|
Debug.Console(0, this, "InitializeButton: key-'{0}' enabledFb-'{1}', disabledFb-'{2}'",
|
||||||
? "is disabled, verify eventTypes are configured."
|
key, enabledFb ?? (object)"null", disabledFb ?? (object)"null");
|
||||||
: "is enabled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -135,11 +150,11 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
public void InitializeButtonFeedback(string key, KeypadButton config)
|
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)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,9 +163,9 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
|
|
||||||
// Link up the button feedbacks to the specified device feedback
|
// Link up the button feedbacks to the specified device feedback
|
||||||
var buttonFeedback = config.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);
|
key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -162,15 +177,15 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
var device = DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) as Device;
|
var device = DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) as Device;
|
||||||
if (device == null)
|
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);
|
key, buttonFeedback.DeviceKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName);
|
deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName);
|
||||||
if (deviceFeedback == null)
|
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);
|
key, buttonFeedback.FeedbackName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,12 +210,12 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Failed to initialize button '{0}' feedback with deviceKey '{1}'. If feedback is required, verify configuration.",
|
Debug.Console(1, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception Message: {0}",
|
||||||
key, buttonFeedback.DeviceKey);
|
ex.Message, key, buttonFeedback.DeviceKey);
|
||||||
|
Debug.Console(2, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') Exception StackTrace: {0}",
|
||||||
Debug.Console(1, this, "InitializeButtonFeedback Exception Message: {0}", ex.Message);
|
ex.StackTrace, key, buttonFeedback.DeviceKey);
|
||||||
Debug.Console(2, this, "InitializeButtonFeedback Exception StackTrace: {0}", ex.StackTrace);
|
if (ex.InnerException != null) Debug.Console(2, this, "InitializeButtonFeedback (button '{1}', deviceKey '{2}') InnerException: {0}",
|
||||||
if (ex.InnerException != null) Debug.Console(2, this, "InitializeButtonFeedback Exception InnerExceptioni: {0}", ex.InnerException);
|
ex.InnerException, key, buttonFeedback.DeviceKey);
|
||||||
|
|
||||||
return;
|
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)
|
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();
|
var type = args.NewButtonState.ToString();
|
||||||
|
|
||||||
if (_buttons.ContainsKey(args.Button.Number.ToString(CultureInfo.InvariantCulture)))
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs the function associated with this button/type. One of the following strings:
|
/// 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
|
||||||
@@ -282,6 +307,8 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
public void Press(string buttonKey, string type)
|
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
|
// 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
|
// to prevent the need to dynamically call the method via reflection on each button press
|
||||||
if (!_buttons.ContainsKey(buttonKey)) return;
|
if (!_buttons.ContainsKey(buttonKey)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user