mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
refactor(wip): updates constructor postActiviate call to seperate methods for enabling/disabling buttons and feedbacks
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
@@ -22,7 +23,7 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
_touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic;
|
_touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic;
|
||||||
if (_touchpanel == null)
|
if (_touchpanel == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Failed to construct {0}, check configuration", key);
|
Debug.Console(1, this, "Failed to construct MPC3 Touchpanel Controller with key {0}, check configuration", key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,166 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
|
|
||||||
AddPostActivationAction(() =>
|
AddPostActivationAction(() =>
|
||||||
{
|
{
|
||||||
// Link up the button feedbacks to the specified BoolFeedbacks
|
SetupButtonsForEvents();
|
||||||
|
SetupButtonFeedbacks();
|
||||||
|
|
||||||
|
// check button config
|
||||||
|
//foreach (var button in _buttons)
|
||||||
|
//{
|
||||||
|
// var buttonKey = button.Key.ToLower();
|
||||||
|
// var buttonConfig = button.Value;
|
||||||
|
// if (buttonConfig == null)
|
||||||
|
// {
|
||||||
|
// Debug.Console(1, this, "Unable to get button config for {0}-{1}", Key, button.Key);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int buttonNumber;
|
||||||
|
// if (TryParseInt(buttonKey, out buttonNumber))
|
||||||
|
// Debug.Console(0, this, "buttonFeedback: tryIntParse successful, buttonNumber = {0}", buttonNumber);
|
||||||
|
// else
|
||||||
|
// Debug.Console(0, this, "buttonFeedback: tryIntParse failed, buttonKey = {0}", buttonKey);
|
||||||
|
|
||||||
|
|
||||||
|
// // button event type configuration enables/disables keypad button
|
||||||
|
// var buttonEventTypes = buttonConfig.EventTypes;
|
||||||
|
// switch (buttonKey)
|
||||||
|
// {
|
||||||
|
// case ("power"):
|
||||||
|
// {
|
||||||
|
// if (buttonEventTypes == 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"):
|
||||||
|
// {
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case ("mute"):
|
||||||
|
// {
|
||||||
|
// if(buttonEventTypes == null)
|
||||||
|
// _touchpanel.DisableMuteButton();
|
||||||
|
// else
|
||||||
|
// _touchpanel.EnableMuteButton();
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// default:
|
||||||
|
// {
|
||||||
|
// if(buttonNumber == 0)
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// if (buttonEventTypes == null)
|
||||||
|
// _touchpanel.DisableNumericalButton((uint)buttonNumber);
|
||||||
|
// else
|
||||||
|
// _touchpanel.EnableNumericalButton((uint)buttonNumber);
|
||||||
|
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// // Link up the button feedbacks to the specified device feedback
|
||||||
|
// var buttonFeedback = buttonConfig.Feedback;
|
||||||
|
// if (buttonFeedback == null)
|
||||||
|
// {
|
||||||
|
// Debug.Console(1, this, "Button '{0}' feedback not configured, feedback will not be implemented", buttonKey);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var device = DeviceManager.GetDeviceForKey(buttonFeedback.DeviceKey) as Device;
|
||||||
|
// if (device == null)
|
||||||
|
// {
|
||||||
|
// Debug.Console(1, this, "Unable to get device with key {0}, feedback will not be implemented",
|
||||||
|
// buttonFeedback.DeviceKey);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var deviceFeedback = device.GetFeedbackProperty(buttonFeedback.FeedbackName);
|
||||||
|
// Debug.Console(0, this, "deviceFeedback.GetType().Name: {0}", deviceFeedback.GetType().Name);
|
||||||
|
// //switch (feedback.GetType().Name.ToLower())
|
||||||
|
// //{
|
||||||
|
// // case("boolfeedback"):
|
||||||
|
// // {
|
||||||
|
|
||||||
|
// // break;
|
||||||
|
// // }
|
||||||
|
// // case("intfeedback"):
|
||||||
|
// // {
|
||||||
|
|
||||||
|
// // break;
|
||||||
|
// // }
|
||||||
|
// //}
|
||||||
|
|
||||||
|
// var boolFeedback = deviceFeedback as BoolFeedback;
|
||||||
|
// var intFeedback = deviceFeedback as IntFeedback;
|
||||||
|
|
||||||
|
// switch (buttonKey)
|
||||||
|
// {
|
||||||
|
// case ("power"):
|
||||||
|
// {
|
||||||
|
// if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.FeedbackPower);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case ("volumeup"):
|
||||||
|
// {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case ("volumedown"):
|
||||||
|
// {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case ("volumefeedback"):
|
||||||
|
// {
|
||||||
|
// if (intFeedback != null)
|
||||||
|
// {
|
||||||
|
// var volumeFeedback = intFeedback;
|
||||||
|
// volumeFeedback.LinkInputSig(_touchpanel.VolumeBargraph);
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// case ("mute"):
|
||||||
|
// {
|
||||||
|
// if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.FeedbackMute);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// default:
|
||||||
|
// {
|
||||||
|
// if (boolFeedback != null) boolFeedback.LinkCrestronFeedback(_touchpanel.Feedbacks[(uint)buttonNumber]);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetupButtonsForEvents()
|
||||||
|
{
|
||||||
|
if (_buttons == null)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Button properties are null, failed to setup buttons for events. Verify button configuraiton.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check button config
|
||||||
foreach (var button in _buttons)
|
foreach (var button in _buttons)
|
||||||
{
|
{
|
||||||
var buttonKey = button.Key.ToLower();
|
var buttonKey = button.Key.ToLower();
|
||||||
@@ -44,17 +204,94 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
|
|
||||||
int buttonNumber;
|
int buttonNumber;
|
||||||
if (TryParseInt(buttonKey, out buttonNumber))
|
if (TryParseInt(buttonKey, out buttonNumber))
|
||||||
{
|
|
||||||
Debug.Console(0, this, "buttonFeedback: tryIntParse successful, buttonNumber = {0}", buttonNumber);
|
Debug.Console(0, this, "buttonFeedback: tryIntParse successful, buttonNumber = {0}", buttonNumber);
|
||||||
_touchpanel.EnableNumericalButton((uint)buttonNumber);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
Debug.Console(0, this, "buttonFeedback: tryIntParse failed, buttonKey = {0}", buttonKey);
|
Debug.Console(0, this, "buttonFeedback: tryIntParse failed, buttonKey = {0}", buttonKey);
|
||||||
|
|
||||||
|
|
||||||
|
// button event type configuration enables/disables keypad button
|
||||||
|
var buttonEventTypes = buttonConfig.EventTypes;
|
||||||
|
switch (buttonKey)
|
||||||
|
{
|
||||||
|
case ("power"):
|
||||||
|
{
|
||||||
|
if (buttonEventTypes == 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"):
|
||||||
|
{
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ("mute"):
|
||||||
|
{
|
||||||
|
if (buttonEventTypes == null)
|
||||||
|
_touchpanel.DisableMuteButton();
|
||||||
|
else
|
||||||
|
_touchpanel.EnableMuteButton();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (buttonNumber == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (buttonEventTypes == null)
|
||||||
|
_touchpanel.DisableNumericalButton((uint) buttonNumber);
|
||||||
|
else
|
||||||
|
_touchpanel.EnableNumericalButton((uint) buttonNumber);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var buttonEventTypes = buttonConfig.EventTypes;
|
public void SetupButtonFeedbacks()
|
||||||
|
{
|
||||||
|
if (_buttons == null)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Button properties are null, failed to setup buttons for events. Verify button configuraiton.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check button config
|
||||||
|
foreach (var button in _buttons)
|
||||||
|
{
|
||||||
|
var buttonKey = button.Key.ToLower();
|
||||||
|
var buttonConfig = button.Value;
|
||||||
|
if (buttonConfig == null)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Unable to get button config for {0}-{1}", Key, button.Key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int buttonNumber;
|
||||||
|
if (TryParseInt(buttonKey, out buttonNumber))
|
||||||
|
Debug.Console(0, this, "buttonFeedback: tryIntParse successful, buttonNumber = {0}", buttonNumber);
|
||||||
|
else
|
||||||
|
Debug.Console(0, this, "buttonFeedback: tryIntParse failed, buttonKey = {0}", buttonKey);
|
||||||
|
|
||||||
|
// Link up the button feedbacks to the specified device feedback
|
||||||
var buttonFeedback = buttonConfig.Feedback;
|
var buttonFeedback = buttonConfig.Feedback;
|
||||||
if (buttonFeedback == null)
|
if (buttonFeedback == null)
|
||||||
{
|
{
|
||||||
@@ -125,22 +362,37 @@ namespace PepperDash.Essentials.Core.Touchpanels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryParseInt(string str, out int result)
|
public bool TryParseInt(string str, out int result)
|
||||||
{
|
{
|
||||||
result = 0;
|
try
|
||||||
|
|
||||||
foreach (var c in str)
|
|
||||||
{
|
{
|
||||||
if(c < '0' || c > '9')
|
result = int.Parse(str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
result = result*10 + (c - '0');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
public bool TryExtractInt(string str, out int result)
|
||||||
|
{
|
||||||
|
result = str.Where(c => c >= '0' && c <= '9').Aggregate(0, (current, c) => current * 10 + (c - '0'));
|
||||||
|
|
||||||
|
//foreach (var c in str)
|
||||||
|
//{
|
||||||
|
// if(c < '0' || c > '9')
|
||||||
|
// //return false
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// result = result*10 + (c - '0');
|
||||||
|
//}
|
||||||
|
|
||||||
|
Debug.Console(0, this, "TryParseInt: str-'{0}', result-'{1}'", str, result);
|
||||||
|
return result != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args)
|
void _touchpanel_ButtonStateChange(GenericBase device, Crestron.SimplSharpPro.DeviceSupport.ButtonEventArgs args)
|
||||||
|
|||||||
Reference in New Issue
Block a user