refactor: rearrange and add solution for 4-series

This commit is contained in:
Andrew Welker
2023-02-07 15:45:01 -07:00
parent 7a9f76ee12
commit 0d515e5f0a
649 changed files with 45907 additions and 105752 deletions

View File

@@ -0,0 +1,54 @@
namespace PepperDash.Essentials.Core
{
public class CrestronTouchpanelPropertiesConfig
{
public string IpId { get; set; }
public string DefaultRoomKey { get; set; }
public string RoomListKey { get; set; }
public string SgdFile { get; set; }
public string ProjectName { get; set; }
public bool ShowVolumeGauge { get; set; }
public bool UsesSplashPage { get; set; }
public bool ShowDate { get; set; }
public bool ShowTime { get; set; }
public UiSetupPropertiesConfig Setup { get; set; }
public string HeaderStyle { get; set; }
public bool IncludeInFusionRoomHealth { get; set; }
public uint ScreenSaverTimeoutMin { get; set; }
public uint ScreenSaverMovePositionIntervalMs { get; set; }
/// <summary>
/// The count of sources that will trigger the "additional" arrows to show on the SRL.
/// Defaults to 5
/// </summary>
public int SourcesOverflowCount { get; set; }
public CrestronTouchpanelPropertiesConfig()
{
SourcesOverflowCount = 5;
HeaderStyle = CrestronTouchpanelPropertiesConfig.Habanero;
// Default values
ScreenSaverTimeoutMin = 5;
ScreenSaverMovePositionIntervalMs = 15000;
}
/// <summary>
/// "habanero"
/// </summary>
public const string Habanero = "habanero";
/// <summary>
/// "verbose"
/// </summary>
public const string Verbose = "verbose";
}
/// <summary>
///
/// </summary>
public class UiSetupPropertiesConfig
{
public bool IsVisible { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
namespace PepperDash.Essentials.Core
{
public interface IHasBasicTriListWithSmartObject
{
BasicTriListWithSmartObject Panel { get; }
}
}

View File

@@ -0,0 +1,436 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
namespace PepperDash.Essentials.Core.Touchpanels.Keyboards
{
public class HabaneroKeyboardController
{
/// <summary>
/// Single-key press events, rather than using a built-up text string on the OutputFeedback
/// </summary>
public event EventHandler<KeyboardControllerPressEventArgs> KeyPress;
public BasicTriList TriList { get; private set; }
public StringFeedback OutputFeedback { get; private set; }
public bool IsVisible { get; private set; }
public string DotComButtonString { get; set; }
public string GoButtonText { get; set; }
public string SecondaryButtonText { get; set; }
public bool GoButtonVisible { get; set; }
public bool SecondaryButtonVisible { get; set; }
int ShiftMode = 0;
StringBuilder Output;
public Action HideAction { get; set; }
CTimer BackspaceTimer;
/// <summary>
///
/// </summary>
/// <param name="trilist"></param>
public HabaneroKeyboardController(BasicTriList trilist)
{
TriList = trilist;
Output = new StringBuilder();
OutputFeedback = new StringFeedback(() => Output.ToString());
DotComButtonString = ".com";
}
/// <summary>
/// Shows the keyboard and attaches sig handlers in the range of 2901-2969
/// </summary>
public void Show()
{
if (IsVisible)
return;
TriList.SetSigTrueAction(ClosePressJoin, Hide);
TriList.SetSigTrueAction(GoButtonPressJoin, () => OnKeyPress(KeyboardSpecialKey.GoButton));
TriList.SetSigTrueAction(SecondaryButtonPressJoin, () => OnKeyPress(KeyboardSpecialKey.SecondaryButton));
TriList.SetSigTrueAction(2921, () => Press(A(ShiftMode)));
TriList.SetSigTrueAction(2922, () => Press(B(ShiftMode)));
TriList.SetSigTrueAction(2923, () => Press(C(ShiftMode)));
TriList.SetSigTrueAction(2924, () => Press(D(ShiftMode)));
TriList.SetSigTrueAction(2925, () => Press(E(ShiftMode)));
TriList.SetSigTrueAction(2926, () => Press(F(ShiftMode)));
TriList.SetSigTrueAction(2927, () => Press(G(ShiftMode)));
TriList.SetSigTrueAction(2928, () => Press(H(ShiftMode)));
TriList.SetSigTrueAction(2929, () => Press(I(ShiftMode)));
TriList.SetSigTrueAction(2930, () => Press(J(ShiftMode)));
TriList.SetSigTrueAction(2931, () => Press(K(ShiftMode)));
TriList.SetSigTrueAction(2932, () => Press(L(ShiftMode)));
TriList.SetSigTrueAction(2933, () => Press(M(ShiftMode)));
TriList.SetSigTrueAction(2934, () => Press(N(ShiftMode)));
TriList.SetSigTrueAction(2935, () => Press(O(ShiftMode)));
TriList.SetSigTrueAction(2936, () => Press(P(ShiftMode)));
TriList.SetSigTrueAction(2937, () => Press(Q(ShiftMode)));
TriList.SetSigTrueAction(2938, () => Press(R(ShiftMode)));
TriList.SetSigTrueAction(2939, () => Press(S(ShiftMode)));
TriList.SetSigTrueAction(2940, () => Press(T(ShiftMode)));
TriList.SetSigTrueAction(2941, () => Press(U(ShiftMode)));
TriList.SetSigTrueAction(2942, () => Press(V(ShiftMode)));
TriList.SetSigTrueAction(2943, () => Press(W(ShiftMode)));
TriList.SetSigTrueAction(2944, () => Press(X(ShiftMode)));
TriList.SetSigTrueAction(2945, () => Press(Y(ShiftMode)));
TriList.SetSigTrueAction(2946, () => Press(Z(ShiftMode)));
TriList.SetSigTrueAction(2947, () => Press('.'));
TriList.SetSigTrueAction(2948, () => Press('@'));
TriList.SetSigTrueAction(2949, () => Press(' '));
TriList.SetSigHeldAction(2950, 500, StartBackspaceRepeat, StopBackspaceRepeat, Backspace);
//TriList.SetSigTrueAction(2950, Backspace);
TriList.SetSigTrueAction(2951, Shift);
TriList.SetSigTrueAction(2952, NumShift);
TriList.SetSigTrueAction(2953, Clear);
TriList.SetSigTrueAction(2954, () => Press(DotComButtonString));
TriList.SetBool(GoButtonVisibleJoin, GoButtonVisible);
TriList.SetString(GoButtonTextJoin, GoButtonText);
TriList.SetBool(SecondaryButtonVisibleJoin, SecondaryButtonVisible);
TriList.SetString(SecondaryButtonTextJoin, SecondaryButtonText);
TriList.SetBool(KeyboardVisible, true);
ShowKeys();
IsVisible = true;
}
/// <summary>
/// Hides the keyboard and disconnects ALL sig handlers from 2901 - 2969
/// </summary>
public void Hide()
{
if (!IsVisible)
return;
for (uint i = 2901; i < 2970; i++)
TriList.ClearBoolSigAction(i);
// run attached actions
if(HideAction != null)
HideAction();
TriList.SetBool(KeyboardVisible, false);
IsVisible = false;
}
/// <summary>
///
/// </summary>
/// <param name="c"></param>
public void Press(char c)
{
OnKeyPress(c.ToString());
Output.Append(c);
OutputFeedback.FireUpdate();
ResetShift();
}
/// <summary>
///
/// </summary>
/// <param name="s"></param>
public void Press(string s)
{
OnKeyPress(s);
Output.Append(s);
OutputFeedback.FireUpdate();
ResetShift();
}
/// <summary>
///
/// </summary>
public void EnableGoButton()
{
TriList.SetBool(GoButtonEnableJoin, true);
}
/// <summary>
///
/// </summary>
public void DisableGoButton()
{
TriList.SetBool(GoButtonEnableJoin, false);
}
void ResetShift()
{
if (ShiftMode == 1)
{
ShiftMode = 0;
ShowKeys();
}
else if (ShiftMode == 3)
{
ShiftMode = 2;
ShowKeys();
}
}
char A(int i) { return new char[] { 'a', 'A', '?', '?' }[i]; }
char B(int i) { return new char[] { 'b', 'B', ':', ':' }[i]; }
char C(int i) { return new char[] { 'c', 'C', '>', '>' }[i]; }
char D(int i) { return new char[] { 'd', 'D', '_', '_' }[i]; }
char E(int i) { return new char[] { 'e', 'E', '3', '#' }[i]; }
char F(int i) { return new char[] { 'f', 'F', '=', '=' }[i]; }
char G(int i) { return new char[] { 'g', 'G', '+', '+' }[i]; }
char H(int i) { return new char[] { 'h', 'H', '[', '[' }[i]; }
char I(int i) { return new char[] { 'i', 'I', '8', '*' }[i]; }
char J(int i) { return new char[] { 'j', 'J', ']', ']' }[i]; }
char K(int i) { return new char[] { 'k', 'K', '/', '/' }[i]; }
char L(int i) { return new char[] { 'l', 'L', '\\', '\\' }[i]; }
char M(int i) { return new char[] { 'm', 'M', '"', '"' }[i]; }
char N(int i) { return new char[] { 'n', 'N', '\'', '\'' }[i]; }
char O(int i) { return new char[] { 'o', 'O', '9', '(' }[i]; }
char P(int i) { return new char[] { 'p', 'P', '0', ')' }[i]; }
char Q(int i) { return new char[] { 'q', 'Q', '1', '!' }[i]; }
char R(int i) { return new char[] { 'r', 'R', '4', '$' }[i]; }
char S(int i) { return new char[] { 's', 'S', '-', '-' }[i]; }
char T(int i) { return new char[] { 't', 'T', '5', '%' }[i]; }
char U(int i) { return new char[] { 'u', 'U', '7', '&' }[i]; }
char V(int i) { return new char[] { 'v', 'V', ';', ';' }[i]; }
char W(int i) { return new char[] { 'w', 'W', '2', '@' }[i]; }
char X(int i) { return new char[] { 'x', 'X', '<', '<' }[i]; }
char Y(int i) { return new char[] { 'y', 'Y', '6', '^' }[i]; }
char Z(int i) { return new char[] { 'z', 'Z', ',', ',' }[i]; }
/// <summary>
/// Does what it says
/// </summary>
void StartBackspaceRepeat()
{
if (BackspaceTimer == null)
{
BackspaceTimer = new CTimer(o => Backspace(), null, 0, 175);
}
}
/// <summary>
/// Does what it says
/// </summary>
void StopBackspaceRepeat()
{
if (BackspaceTimer != null)
{
BackspaceTimer.Stop();
BackspaceTimer = null;
}
}
void Backspace()
{
OnKeyPress(KeyboardSpecialKey.Backspace);
if (Output.Length > 0)
{
Output.Remove(Output.Length - 1, 1);
OutputFeedback.FireUpdate();
}
}
void Clear()
{
OnKeyPress(KeyboardSpecialKey.Clear);
Output.Remove(0, Output.Length);
OutputFeedback.FireUpdate();
}
/* When in mode 0 (lowercase):
* shift button: up arrow 0
* numShift button: 123/#$@#$ 0
*
* - shift --> mode 1
* - double-tap shift --> caps lock
* - numShift --> mode 2
*
* mode 1 (uppercase)
* shift button: down arrow 1
* numShift button: 123/##$# 0
*
* - shift --> mode 0
* - numShift --> mode 2
*
* - Tapping any key will go back to mode 0
*
* mode 2 (numbers-sym)
* Shift button: #$#$#$ 2
* numShift: ABC 1
*
* - shift --> mode 3
* - double-tap shift --> caps lock
* - numShift --> mode 0
*
* mode 3 (sym)
* Shift button: 123 3
* numShift: ABC 1
*
* - shift --> mode 2
* - numShift --> mode 0
*
* - Tapping any key will go back to mode 2
*/
void Shift()
{
if (ShiftMode == 0)
ShiftMode = 1;
else if (ShiftMode == 1)
ShiftMode = 0;
else if (ShiftMode == 2)
ShiftMode = 3;
else
ShiftMode = 2;
ShowKeys();
}
void NumShift()
{
if (ShiftMode == 0 || ShiftMode == 1)
ShiftMode = 2;
else if (ShiftMode == 2 || ShiftMode == 3)
ShiftMode = 0;
ShowKeys();
}
void ShowKeys()
{
TriList.SetString(2921, A(ShiftMode).ToString());
TriList.SetString(2922, B(ShiftMode).ToString());
TriList.SetString(2923, C(ShiftMode).ToString());
TriList.SetString(2924, D(ShiftMode).ToString());
TriList.SetString(2925, E(ShiftMode).ToString());
TriList.SetString(2926, F(ShiftMode).ToString());
TriList.SetString(2927, G(ShiftMode).ToString());
TriList.SetString(2928, H(ShiftMode).ToString());
TriList.SetString(2929, I(ShiftMode).ToString());
TriList.SetString(2930, J(ShiftMode).ToString());
TriList.SetString(2931, K(ShiftMode).ToString());
TriList.SetString(2932, L(ShiftMode).ToString());
TriList.SetString(2933, M(ShiftMode).ToString());
TriList.SetString(2934, N(ShiftMode).ToString());
TriList.SetString(2935, O(ShiftMode).ToString());
TriList.SetString(2936, P(ShiftMode).ToString());
TriList.SetString(2937, Q(ShiftMode).ToString());
TriList.SetString(2938, R(ShiftMode).ToString());
TriList.SetString(2939, S(ShiftMode).ToString());
TriList.SetString(2940, T(ShiftMode).ToString());
TriList.SetString(2941, U(ShiftMode).ToString());
TriList.SetString(2942, V(ShiftMode).ToString());
TriList.SetString(2943, W(ShiftMode).ToString());
TriList.SetString(2944, X(ShiftMode).ToString());
TriList.SetString(2945, Y(ShiftMode).ToString());
TriList.SetString(2946, Z(ShiftMode).ToString());
TriList.SetString(2954, DotComButtonString);
TriList.SetUshort(2951, (ushort)ShiftMode); // 0 = up, 1 = down, 2 = #, 3 = 123
TriList.SetUshort(2952, (ushort)(ShiftMode < 2 ? 0 : 1)); // 0 = #, 1 = abc
}
/// <summary>
/// Event fire helper for text
/// </summary>
/// <param name="text"></param>
void OnKeyPress(string text)
{
var handler = KeyPress;
if (handler != null)
KeyPress(this, new KeyboardControllerPressEventArgs(text));
}
/// <summary>
/// event helper for special keys
/// </summary>
/// <param name="key"></param>
void OnKeyPress(KeyboardSpecialKey key)
{
var handler = KeyPress;
if (handler != null)
KeyPress(this, new KeyboardControllerPressEventArgs(key));
}
/// <summary>
/// 2901
/// </summary>
public const uint KeyboardVisible = 2901;
/// <summary>
/// 2902
/// </summary>
public const uint ClosePressJoin = 2902;
/// <summary>
/// 2903
/// </summary>
public const uint GoButtonPressJoin = 2903;
/// <summary>
/// 2903
/// </summary>
public const uint GoButtonTextJoin = 2903;
/// <summary>
/// 2904
/// </summary>
public const uint SecondaryButtonPressJoin = 2904;
/// <summary>
/// 2904
/// </summary>
public const uint SecondaryButtonTextJoin = 2904;
/// <summary>
/// 2905
/// </summary>
public const uint GoButtonVisibleJoin = 2905;
/// <summary>
/// 2906
/// </summary>
public const uint SecondaryButtonVisibleJoin = 2906;
/// <summary>
/// 2907
/// </summary>
public const uint GoButtonEnableJoin = 2907;
/// <summary>
/// 2910
/// </summary>
public const uint ClearPressJoin = 2910;
/// <summary>
/// 2911
/// </summary>
public const uint ClearVisibleJoin = 2911;
}
/// <summary>
///
/// </summary>
public class KeyboardControllerPressEventArgs : EventArgs
{
public string Text { get; private set; }
public KeyboardSpecialKey SpecialKey { get; private set; }
public KeyboardControllerPressEventArgs(string text)
{
Text = text;
}
public KeyboardControllerPressEventArgs(KeyboardSpecialKey key)
{
SpecialKey = key;
}
}
public enum KeyboardSpecialKey
{
None = 0, Backspace, Clear, GoButton, SecondaryButton
}
}

View File

@@ -0,0 +1,211 @@
using System;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
public class ModalDialog
{
/// <summary>
/// Bool press 3991
/// </summary>
public const uint Button1Join = 3991;
/// <summary>
/// Bool press 3992
/// </summary>
public const uint Button2Join = 3992;
/// <summary>
/// 3993
/// </summary>
public const uint CancelButtonJoin = 3993;
/// <summary>
///For visibility of single button. Bool feedback 3994
/// </summary>
public const uint OneButtonVisibleJoin = 3994;
/// <summary>
/// For visibility of two buttons. Bool feedback 3995.
/// </summary>
public const uint TwoButtonVisibleJoin = 3995;
/// <summary>
/// Shows the timer guage if in use. Bool feedback 3996
/// </summary>
public const uint TimerVisibleJoin = 3996;
/// <summary>
/// Visibility join to show "X" button 3997
/// </summary>
public const uint CancelVisibleJoin = 3997;
/// <summary>
/// Shows the modal subpage. Boolean feeback join 3999
/// </summary>
public const uint ModalVisibleJoin = 3999;
/// <summary>
/// The seconds value of the countdown timer. Ushort join 3991
/// </summary>
//public const uint TimerSecondsJoin = 3991;
/// <summary>
/// The full ushort value of the countdown timer for a gauge. Ushort join 3992
/// </summary>
public const uint TimerGaugeJoin = 3992;
/// <summary>
/// Text on button one. String join 3991
/// </summary>
public const uint Button1TextJoin = 3991;
/// <summary>
/// Text on button two. String join 3992
/// </summary>
public const uint Button2TextJoin = 3992;
/// <summary>
/// Message text. String join 3994
/// </summary>
public const uint MessageTextJoin = 3994;
/// <summary>
/// Title text. String join 3995
/// </summary>
public const uint TitleTextJoin = 3995;
/// <summary>
/// Icon name. String join 3996
/// </summary>
public const uint IconNameJoin = 3996;
/// <summary>
/// Returns true when modal is showing
/// </summary>
public bool ModalIsVisible
{
get { return TriList.BooleanInput[ModalVisibleJoin].BoolValue; }
}
/// <summary>
///
/// </summary>
public bool CanCancel { get; private set; }
BasicTriList TriList;
Action<uint> ModalCompleteAction;
static object CompleteActionLock = new object();
/// <summary>
/// Creates a new modal to be shown on provided TriList
/// </summary>
/// <param name="triList"></param>
public ModalDialog(BasicTriList triList)
{
TriList = triList;
// Attach actions to buttons
triList.SetSigFalseAction(Button1Join, () => OnModalComplete(1));
triList.SetSigFalseAction(Button2Join, () => OnModalComplete(2));
triList.SetSigFalseAction(CancelButtonJoin, () => { if (CanCancel) CancelDialog(); });
CanCancel = true;
}
/// <summary>
/// Shows the dialog
/// </summary>
/// <param name="numberOfButtons">Number of buttons to show. 0, 1, 2</param>
/// <param name="timeMs">The amount of time to show the dialog. Use 0 for no timeout.</param>
/// <param name="decreasingGauge">If the progress bar gauge needs to count down instead of up</param>
/// <param name="completeAction">The action to run when the dialog is dismissed. Parameter will be 1 or 2 if button pressed, or 0 if dialog times out</param>
/// <returns>True when modal is created.</returns>
public bool PresentModalDialog(uint numberOfButtons, string title, string iconName,
string message, string button1Text,
string button2Text, bool showGauge, bool showCancel, Action<uint> completeAction)
{
// Don't reset dialog if visible now
if (!ModalIsVisible)
{
ModalCompleteAction = completeAction;
TriList.StringInput[TitleTextJoin].StringValue = title;
if (string.IsNullOrEmpty(iconName)) iconName = "Blank";
TriList.StringInput[IconNameJoin].StringValue = iconName;
TriList.StringInput[MessageTextJoin].StringValue = message;
if (numberOfButtons == 0)
{
// Show no buttons
TriList.BooleanInput[OneButtonVisibleJoin].BoolValue = false;
TriList.BooleanInput[TwoButtonVisibleJoin].BoolValue = false;
}
else if (numberOfButtons == 1)
{
// Show one button
TriList.BooleanInput[OneButtonVisibleJoin].BoolValue = true;
TriList.BooleanInput[TwoButtonVisibleJoin].BoolValue = false;
TriList.StringInput[Button1TextJoin].StringValue = button1Text;
}
else if (numberOfButtons == 2)
{
// Show two
TriList.BooleanInput[OneButtonVisibleJoin].BoolValue = false;
TriList.BooleanInput[TwoButtonVisibleJoin].BoolValue = true;
TriList.StringInput[Button1TextJoin].StringValue = button1Text;
TriList.StringInput[Button2TextJoin].StringValue = button2Text;
}
// Show/hide guage
TriList.BooleanInput[TimerVisibleJoin].BoolValue = showGauge;
CanCancel = showCancel;
TriList.BooleanInput[CancelVisibleJoin].BoolValue = showCancel;
//Reveal and activate
TriList.BooleanInput[ModalVisibleJoin].BoolValue = true;
WakePanel();
return true;
}
return false;
}
/// <summary>
/// Wakes the panel by turning on the backlight if off
/// </summary>
public void WakePanel()
{
try
{
var panel = TriList as TswFt5Button;
if (panel != null && panel.ExtenderSystemReservedSigs.BacklightOffFeedback.BoolValue)
panel.ExtenderSystemReservedSigs.BacklightOn();
}
catch
{
Debug.Console(1, "Error Waking Panel. Maybe testing with Xpanel?");
}
}
/// <summary>
/// Hide dialog from elsewhere, fires CompleteAction
/// </summary>
public void CancelDialog()
{
OnModalComplete(0);
}
/// <summary>
/// Hides dialog. Fires no action
/// </summary>
public void HideDialog()
{
TriList.BooleanInput[ModalVisibleJoin].BoolValue = false;
}
// When the modal is cleared or times out, clean up the various bits
void OnModalComplete(uint buttonNum)
{
TriList.BooleanInput[ModalVisibleJoin].BoolValue = false;
var action = ModalCompleteAction;
if (action != null)
action(buttonNum);
}
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Touchpanels
{
/// <summary>
/// A wrapper class for the touchpanel portion of an MPC3 class process to allow for configurable
/// behavior of the keybad buttons
/// </summary>
public class Mpc3TouchpanelController : Device
{
MPC3Basic _Touchpanel;
Dictionary<string, KeypadButton> _Buttons;
public Mpc3TouchpanelController(string key, string name, CrestronControlSystem processor, Dictionary<string, KeypadButton> buttons)
: base(key, name)
{
_Touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic;
_Buttons = buttons;
_Touchpanel.ButtonStateChange += new Crestron.SimplSharpPro.DeviceSupport.ButtonEventHandler(_Touchpanel_ButtonStateChange);
AddPostActivationAction(() =>
{
// Link up the button feedbacks to the specified BoolFeedbacks
foreach (var button in _Buttons)
{
var feedbackConfig = button.Value.Feedback;
var device = DeviceManager.GetDeviceForKey(feedbackConfig.DeviceKey) as Device;
if (device != null)
{
var bKey = button.Key.ToLower();
var feedback = device.GetFeedbackProperty(feedbackConfig.FeedbackName);
var bFeedback = feedback as BoolFeedback;
var iFeedback = feedback as IntFeedback;
if (bFeedback != null)
{
if (bKey == "power")
{
bFeedback.LinkCrestronFeedback(_Touchpanel.FeedbackPower);
continue;
}
else if (bKey == "mute")
{
bFeedback.LinkCrestronFeedback(_Touchpanel.FeedbackMute);
continue;
}
// Link to the Crestron Feedback corresponding to the button number
bFeedback.LinkCrestronFeedback(_Touchpanel.Feedbacks[UInt16.Parse(button.Key)]);
}
else if (iFeedback != null)
{
if (bKey == "volumefeedback")
{
var volFeedback = feedback as IntFeedback;
// TODO: Figure out how to subsribe to a volume IntFeedback and link it to the voluem
volFeedback.LinkInputSig(_Touchpanel.VolumeBargraph);
}
}
else
{
Debug.Console(1, this, "Unable to get BoolFeedback with name: {0} from device: {1}", feedbackConfig.FeedbackName, device.Key);
}
}
else
{
Debug.Console(1, this, "Unable to get device with key: {0}", feedbackConfig.DeviceKey);
}
}
});
}
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);
var type = args.NewButtonState.ToString();
if (_Buttons.ContainsKey(args.Button.Number.ToString()))
{
Press(args.Button.Number.ToString(), type);
}
else if(_Buttons.ContainsKey(args.Button.Name.ToString()))
{
Press(args.Button.Name.ToString(), type);
}
}
/// <summary>
/// Runs the function associated with this button/type. One of the following strings:
/// Pressed, Released, Tapped, DoubleTapped, Held, HeldReleased
/// </summary>
/// <param name="number"></param>
/// <param name="type"></param>
public void Press(string number, string 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(number)) { return; }
var but = _Buttons[number];
if (but.EventTypes.ContainsKey(type))
{
foreach (var a in but.EventTypes[type]) { DeviceJsonApi.DoDeviceAction(a); }
}
}
}
/// <summary>
/// Represents the configuration of a keybad buggon
/// </summary>
public class KeypadButton
{
public Dictionary<string, DeviceActionWrapper[]> EventTypes { get; set; }
public KeypadButtonFeedback Feedback { get; set; }
public KeypadButton()
{
EventTypes = new Dictionary<string, DeviceActionWrapper[]>();
Feedback = new KeypadButtonFeedback();
}
}
/// <summary>
///
/// </summary>
public class KeypadButtonFeedback
{
public string DeviceKey { get; set; }
public string FeedbackName { get; set; }
}
}

View File

@@ -0,0 +1,314 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Extensions used for more-clear attachment of Actions to user objects on sigs
/// </summary>
public static class SigAndTriListExtensions
{
/// <summary>
/// Attaches Action to Sig's user object and returns the same Sig. This provides no protection
/// from null sigs
/// </summary>
/// <param name="sig">The BoolOutputSig to attach the Action to</param>
/// <param name="a">An action to run when sig is pressed and when released</param>
/// <returns>The Sig, sig</returns>
public static BoolOutputSig SetBoolSigAction(this BoolOutputSig sig, Action<bool> a)
{
sig.UserObject = a;
return sig;
}
/// <summary>
/// Attaches Action to Sig's user object and returns the same Sig.
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <param name="a"></param>
/// <returns></returns>
public static BoolOutputSig SetBoolSigAction(this BasicTriList tl, uint sigNum, Action<bool> a)
{
return tl.BooleanOutput[sigNum].SetBoolSigAction(a);
}
public static BoolOutputSig SetSigTrueAction(this BasicTriList tl, uint sigNum, Action a)
{
return tl.BooleanOutput[sigNum].SetBoolSigAction(b => { if(b) a(); });
}
/// <summary>
/// Attaches a void Action to a TriList's output sig's UserObject, to be run on release
/// </summary>
/// <returns>The sig</returns>
public static BoolOutputSig SetSigFalseAction(this BasicTriList tl, uint sigNum, Action a)
{
return tl.BooleanOutput[sigNum].SetBoolSigAction(b => { if (!b) a(); });
}
/// <summary>
/// Attaches a void Action to an output sig's UserObject, to be run on release
/// </summary>
/// <returns>The Sig</returns>
public static BoolOutputSig SetSigFalseAction(this BoolOutputSig sig, Action a)
{
return sig.SetBoolSigAction(b => { if (!b) a(); });
}
/// <summary>
/// Sets an action to a held sig
/// </summary>
/// <returns>The sig</returns>
public static BoolOutputSig SetSigHeldAction(this BasicTriList tl, uint sigNum, uint heldMs, Action heldAction)
{
return SetSigHeldAction(tl, sigNum, heldMs, heldAction, null);
}
/// <summary>
/// Sets an action to a held sig as well as a released-without-hold action
/// </summary>
/// <returns></returns>
public static BoolOutputSig SetSigHeldAction(this BoolOutputSig sig, uint heldMs, Action heldAction, Action holdReleasedAction, Action releaseAction)
{
CTimer heldTimer = null;
bool wasHeld = false;
return sig.SetBoolSigAction(press =>
{
if (press)
{
wasHeld = false;
// Could insert a pressed action here
heldTimer = new CTimer(o =>
{
// if still held and there's an action
if (sig.BoolValue && heldAction != null)
{
wasHeld = true;
// Hold action here
heldAction();
}
}, heldMs);
}
else if (!press && !wasHeld) // released, no hold
{
heldTimer.Stop();
if (releaseAction != null)
releaseAction();
}
else // !press && wasHeld // released after held
{
heldTimer.Stop();
if (holdReleasedAction != null)
holdReleasedAction();
}
});
}
/// <summary>
/// Sets an action to a held sig as well as a released-without-hold action
/// </summary>
/// <returns>The sig</returns>
public static BoolOutputSig SetSigHeldAction(this BasicTriList tl, uint sigNum, uint heldMs, Action heldAction, Action releaseAction)
{
return tl.BooleanOutput[sigNum].SetSigHeldAction(heldMs, heldAction, null, releaseAction);
}
/// <summary>
/// Sets an action to a held sig, an action for the release of hold, as well as a released-without-hold action
/// </summary>
/// <returns></returns>
public static BoolOutputSig SetSigHeldAction(this BasicTriList tl, uint sigNum, uint heldMs, Action heldAction,
Action holdReleasedAction, Action releaseAction)
{
return tl.BooleanOutput[sigNum].SetSigHeldAction(heldMs, heldAction, holdReleasedAction, releaseAction);
}
/// <summary>
///
/// </summary>
/// <param name="sig"></param>
/// <param name="a"></param>
/// <returns>The Sig</returns>
public static UShortOutputSig SetUShortSigAction(this UShortOutputSig sig, Action<ushort> a)
{
sig.UserObject = a;
return sig;
}
/// <summary>
///
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <param name="a"></param>
/// <returns></returns>
public static UShortOutputSig SetUShortSigAction(this BasicTriList tl, uint sigNum, Action<ushort> a)
{
return tl.UShortOutput[sigNum].SetUShortSigAction(a);
}
/// <summary>
///
/// </summary>
/// <param name="sig"></param>
/// <param name="a"></param>
/// <returns></returns>
public static StringOutputSig SetStringSigAction(this StringOutputSig sig, Action<string> a)
{
sig.UserObject = a;
return sig;
}
/// <summary>
///
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <param name="a"></param>
/// <returns></returns>
public static StringOutputSig SetStringSigAction(this BasicTriList tl, uint sigNum, Action<string> a)
{
return tl.StringOutput[sigNum].SetStringSigAction(a);
}
/// <summary>
///
/// </summary>
/// <param name="sig"></param>
/// <returns></returns>
public static Sig ClearSigAction(this Sig sig)
{
sig.UserObject = null;
return sig;
}
public static BoolOutputSig ClearBoolSigAction(this BasicTriList tl, uint sigNum)
{
return ClearSigAction(tl.BooleanOutput[sigNum]) as BoolOutputSig;
}
public static UShortOutputSig ClearUShortSigAction(this BasicTriList tl, uint sigNum)
{
return ClearSigAction(tl.UShortOutput[sigNum]) as UShortOutputSig;
}
public static StringOutputSig ClearStringSigAction(this BasicTriList tl, uint sigNum)
{
return ClearSigAction(tl.StringOutput[sigNum]) as StringOutputSig;
}
/// <summary>
/// Clears all actions on all sigs
/// </summary>
public static void ClearAllSigActions(this BasicTriList t1)
{
foreach (var sig in t1.BooleanOutput)
{
ClearSigAction(sig);
}
foreach (var sig in t1.UShortOutput)
{
ClearSigAction(sig);
}
foreach (var sig in t1.StringOutput)
{
ClearSigAction(sig);
}
}
/// <summary>
/// Helper method to set the value of a bool Sig on TriList
/// </summary>
public static void SetBool(this BasicTriList tl, uint sigNum, bool value)
{
tl.BooleanInput[sigNum].BoolValue = value;
}
/// <summary>
/// Sends an true-false pulse to the sig
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
public static void PulseBool(this BasicTriList tl, uint sigNum)
{
tl.BooleanInput[sigNum].Pulse();
}
/// <summary>
/// Sends a timed pulse to the sig
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <param name="ms"></param>
public static void PulseBool(this BasicTriList tl, uint sigNum, int ms)
{
tl.BooleanInput[sigNum].Pulse(ms);
}
/// <summary>
/// Helper method to set the value of a ushort Sig on TriList
/// </summary>
public static void SetUshort(this BasicTriList tl, uint sigNum, ushort value)
{
tl.UShortInput[sigNum].UShortValue = value;
}
/// <summary>
/// Helper method to set the value of a string Sig on TriList
/// </summary>
public static void SetString(this BasicTriList tl, uint sigNum, string value)
{
tl.StringInput[sigNum].StringValue = value;
}
public static void SetString(this BasicTriList tl, uint sigNum, string value, eStringEncoding encoding)
{
tl.StringInput[sigNum].StringEncoding = encoding;
tl.StringInput[sigNum].StringValue = value;
}
/// <summary>
/// Returns bool value of trilist sig
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <returns></returns>
public static bool GetBool(this BasicTriList tl, uint sigNum)
{
return tl.BooleanOutput[sigNum].BoolValue;
}
/// <summary>
/// Returns ushort value of trilist sig
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <returns></returns>
public static ushort GetUshort(this BasicTriList tl, uint sigNum)
{
return tl.UShortOutput[sigNum].UShortValue;
}
/// <summary>
/// Returns string value of trilist sig.
/// </summary>
/// <param name="tl"></param>
/// <param name="sigNum"></param>
/// <returns></returns>
public static string GetString(this BasicTriList tl, uint sigNum)
{
return tl.StringOutput[sigNum].StringValue;
}
}
}