mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-28 11:54:57 +00:00
Combining repos
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
namespace PepperDash.Essentials.Core.SmartObjects
|
||||
{
|
||||
public class SmartObjectDPad : SmartObjectHelperBase
|
||||
{
|
||||
public BoolOutputSig SigUp { get { return GetBoolOutputNamed("Up"); } }
|
||||
public BoolOutputSig SigDown { get { return GetBoolOutputNamed("Down"); } }
|
||||
public BoolOutputSig SigLeft { get { return GetBoolOutputNamed("Left"); } }
|
||||
public BoolOutputSig SigRight { get { return GetBoolOutputNamed("Right"); } }
|
||||
public BoolOutputSig SigCenter { get { return GetBoolOutputNamed("Center"); } }
|
||||
|
||||
public SmartObjectDPad(SmartObject so, bool useUserObjectHandler)
|
||||
: base(so, useUserObjectHandler)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
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.SmartObjects
|
||||
{
|
||||
public class SmartObjectDynamicList : SmartObjectHelperBase
|
||||
{
|
||||
public const string SigNameScrollToItem = "Scroll To Item";
|
||||
public const string SigNameSetNumberOfItems = "Set Number of Items";
|
||||
|
||||
public uint NameSigOffset { get; private set; }
|
||||
|
||||
public ushort Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return SmartObject.UShortInput[SigNameSetNumberOfItems].UShortValue;
|
||||
}
|
||||
set { SmartObject.UShortInput[SigNameSetNumberOfItems].UShortValue = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The limit of the list object, as defined by VTPro settings. Zero if object
|
||||
/// is not a list
|
||||
/// </summary>
|
||||
public int MaxCount { get; private set; }
|
||||
|
||||
public SmartObjectDynamicList(SmartObject so, bool useUserObjectHandler, uint nameSigOffset) : base(so, useUserObjectHandler)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Just try to touch the count signal to make sure this is indeed a dynamic list
|
||||
var c = Count;
|
||||
NameSigOffset = nameSigOffset;
|
||||
MaxCount = SmartObject.BooleanOutput.Count(s => s.Name.EndsWith("Pressed"));
|
||||
//Debug.Console(2, "Smart object {0} has {1} max", so.ID, MaxCount);
|
||||
}
|
||||
catch
|
||||
{
|
||||
var msg = string.Format("SmartObjectDynamicList: Smart Object {0:X2}-{1} is not a dynamic list. Ignoring", so.Device.ID, so.ID);
|
||||
Debug.Console(0, Debug.ErrorLogLevel.Error, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a new list item
|
||||
/// </summary>
|
||||
public void SetItem(uint index, string mainText, string iconName, Action<bool> action)
|
||||
{
|
||||
SetItemMainText(index, mainText);
|
||||
SetItemIcon(index, iconName);
|
||||
SetItemButtonAction(index, action);
|
||||
//try
|
||||
//{
|
||||
// SetMainButtonText(index, text);
|
||||
// SetIcon(index, iconName);
|
||||
// SetButtonAction(index, action);
|
||||
//}
|
||||
//catch(Exception e)
|
||||
//{
|
||||
// Debug.Console(1, "Cannot set Dynamic List item {0} on smart object {1}", index, SmartObject.ID);
|
||||
// ErrorLog.Warn(e.ToString());
|
||||
//}
|
||||
}
|
||||
|
||||
public void SetItemMainText(uint index, string text)
|
||||
{
|
||||
if (index > MaxCount) return;
|
||||
// The list item template defines CIPS tags that refer to standard joins
|
||||
(SmartObject.Device as BasicTriList).StringInput[NameSigOffset + index].StringValue = text;
|
||||
}
|
||||
|
||||
public void SetItemIcon(uint index, string iconName)
|
||||
{
|
||||
if (index > MaxCount) return;
|
||||
SmartObject.StringInput[string.Format("Set Item {0} Icon Serial", index)].StringValue = iconName;
|
||||
}
|
||||
|
||||
public void SetItemButtonAction(uint index, Action<bool> action)
|
||||
{
|
||||
if (index > MaxCount) return;
|
||||
SmartObject.BooleanOutput[string.Format("Item {0} Pressed", index)].UserObject = action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the feedback on the given line, clearing others when interlocked is set
|
||||
/// </summary>
|
||||
public void SetFeedback(uint index, bool interlocked)
|
||||
{
|
||||
if (interlocked)
|
||||
ClearFeedbacks();
|
||||
SmartObject.BooleanInput[string.Format("Item {0} Selected", index)].BoolValue = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all button feedbacks
|
||||
/// </summary>
|
||||
public void ClearFeedbacks()
|
||||
{
|
||||
for(int i = 1; i<= Count; i++)
|
||||
SmartObject.BooleanInput[string.Format("Item {0} Selected", i)].BoolValue = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes Action object from all buttons
|
||||
/// </summary>
|
||||
public void ClearActions()
|
||||
{
|
||||
Debug.Console(2, "SO CLEAR");
|
||||
for(ushort i = 1; i <= MaxCount; i++)
|
||||
SmartObject.BooleanOutput[string.Format("Item {0} Pressed", i)].UserObject = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
using PepperDash.Core;
|
||||
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public class SmartObjectHelper
|
||||
{
|
||||
public static uint GetSmartObjectJoinForTypeAndObject(uint sourceType, uint typeOffset)
|
||||
{
|
||||
return (uint)(10000 + (sourceType * 100) + typeOffset);
|
||||
}
|
||||
|
||||
//public static void DumpSmartObject(SmartGraphicsTouchpanelControllerBase tp, uint id)
|
||||
//{
|
||||
// if (!tp.TriList.SmartObjects.Contains(id))
|
||||
// {
|
||||
// Debug.Console(0, tp, "does not contain smart object ID {0}", id);
|
||||
// return;
|
||||
// }
|
||||
// var so = tp.TriList.SmartObjects[id];
|
||||
// Debug.Console(0, tp, "Signals for smart object ID {0}", id);
|
||||
// Debug.Console(0, "BooleanInput -------------------------------");
|
||||
// foreach (var s in so.BooleanInput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
// Debug.Console(0, "UShortInput -------------------------------");
|
||||
// foreach (var s in so.UShortInput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
// Debug.Console(0, "StringInput -------------------------------");
|
||||
// foreach (var s in so.StringInput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
// Debug.Console(0, "BooleanOutput -------------------------------");
|
||||
// foreach (var s in so.BooleanOutput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
// Debug.Console(0, "UShortOutput -------------------------------");
|
||||
// foreach (var s in so.UShortOutput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
// Debug.Console(0, "StringOutput -------------------------------");
|
||||
// foreach (var s in so.StringOutput)
|
||||
// Debug.Console(0, " {0,5} {1}", s.Number, s.Name);
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// Inserts/removes the appropriate UO's onto sigs
|
||||
///// </summary>
|
||||
///// <param name="triList"></param>
|
||||
///// <param name="smartObjectId"></param>
|
||||
///// <param name="deviceUserObjects"></param>
|
||||
///// <param name="state"></param>
|
||||
//public static void LinkNumpadWithUserObjects(BasicTriListWithSmartObject triList,
|
||||
// uint smartObjectId, List<CueActionPair> deviceUserObjects, Cue Misc_1Function, Cue Misc_2Function, bool state)
|
||||
//{
|
||||
// var sigDict = new Dictionary<string, Cue>
|
||||
// {
|
||||
// { "0", CommonBoolCue.Digit0 },
|
||||
// { "1", CommonBoolCue.Digit1 },
|
||||
// { "2", CommonBoolCue.Digit2 },
|
||||
// { "3", CommonBoolCue.Digit3 },
|
||||
// { "4", CommonBoolCue.Digit4 },
|
||||
// { "5", CommonBoolCue.Digit5 },
|
||||
// { "6", CommonBoolCue.Digit6 },
|
||||
// { "7", CommonBoolCue.Digit7 },
|
||||
// { "8", CommonBoolCue.Digit8 },
|
||||
// { "9", CommonBoolCue.Digit9 },
|
||||
// { "Misc_1", Misc_1Function },
|
||||
// { "Misc_2", Misc_2Function },
|
||||
// };
|
||||
// LinkSmartObjectWithUserObjects(triList, smartObjectId, deviceUserObjects, sigDict, state);
|
||||
//}
|
||||
|
||||
//public static void LinkDpadWithUserObjects(BasicTriListWithSmartObject triList,
|
||||
// uint smartObjectId, List<CueActionPair> deviceUserObjects, bool state)
|
||||
//{
|
||||
// var sigDict = new Dictionary<string, Cue>
|
||||
// {
|
||||
// { "Up", CommonBoolCue.Up },
|
||||
// { "Down", CommonBoolCue.Down },
|
||||
// { "Left", CommonBoolCue.Left },
|
||||
// { "Right", CommonBoolCue.Right },
|
||||
// { "OK", CommonBoolCue.Select },
|
||||
// };
|
||||
// LinkSmartObjectWithUserObjects(triList, smartObjectId, deviceUserObjects, sigDict, state);
|
||||
//}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// MOVE TO HELPER CLASS
|
||||
///// </summary>
|
||||
///// <param name="triList"></param>
|
||||
///// <param name="smartObjectId"></param>
|
||||
///// <param name="deviceUserObjects"></param>
|
||||
///// <param name="smartObjectSigMap"></param>
|
||||
///// <param name="state"></param>
|
||||
//public static void LinkSmartObjectWithUserObjects(BasicTriListWithSmartObject triList,
|
||||
// uint smartObjectId, List<CueActionPair> deviceUserObjects, Dictionary<string, Cue> smartObjectSigMap, bool state)
|
||||
//{
|
||||
// // Hook up smart objects if applicable
|
||||
// if (triList.SmartObjects.Contains(smartObjectId))
|
||||
// {
|
||||
// var smartObject = triList.SmartObjects[smartObjectId];
|
||||
// foreach (var kvp in smartObjectSigMap)
|
||||
// {
|
||||
// if (smartObject.BooleanOutput.Contains(kvp.Key))
|
||||
// {
|
||||
// if (state)
|
||||
// {
|
||||
// // look for a user object and if so, attach/detach it to/from the sig.
|
||||
// var uo = deviceUserObjects.FirstOrDefault(ao => ao.Cue == kvp.Value);
|
||||
// if (uo != null)
|
||||
// smartObject.BooleanOutput[kvp.Key].UserObject = uo;
|
||||
// }
|
||||
// else
|
||||
// smartObject.BooleanOutput[kvp.Key].UserObject = null;
|
||||
// }
|
||||
// else
|
||||
// Debug.Console(0, "Smart object {0} does not contain Sig {1}", smartObject.ID, kvp.Key);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// Debug.Console(0, "ERROR Smart object {0} not found on {1:X2}", smartObjectId, triList.ID);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
namespace PepperDash.Essentials.Core.SmartObjects
|
||||
{
|
||||
public class SmartObjectHelperBase
|
||||
{
|
||||
public SmartObject SmartObject { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// This should be set by all inheriting classes, after the class has verified that it is linked to the right object.
|
||||
/// </summary>
|
||||
public bool Validated { get; protected set; }
|
||||
|
||||
public SmartObjectHelperBase(SmartObject so, bool useUserObjectHandler)
|
||||
{
|
||||
SmartObject = so;
|
||||
if (useUserObjectHandler)
|
||||
{
|
||||
// Prevent this from double-registering
|
||||
SmartObject.SigChange -= this.SmartObject_SigChange;
|
||||
SmartObject.SigChange += this.SmartObject_SigChange;
|
||||
}
|
||||
}
|
||||
|
||||
~SmartObjectHelperBase()
|
||||
{
|
||||
SmartObject.SigChange -= this.SmartObject_SigChange;
|
||||
}
|
||||
|
||||
public BoolOutputSig GetBoolOutputNamed(string name)
|
||||
{
|
||||
if (SmartObject.BooleanOutput.Contains(name))
|
||||
return SmartObject.BooleanOutput[name];
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Standard Action listener
|
||||
/// </summary>
|
||||
/// <param name="currentDevice"></param>
|
||||
/// <param name="args"></param>
|
||||
void SmartObject_SigChange(GenericBase currentDevice, SmartObjectEventArgs args)
|
||||
{
|
||||
var uo = args.Sig.UserObject;
|
||||
if (uo is Action<bool>)
|
||||
(uo as Action<bool>)(args.Sig.BoolValue);
|
||||
else if (uo is Action<ushort>)
|
||||
(uo as Action<ushort>)(args.Sig.UShortValue);
|
||||
else if (uo is Action<string>)
|
||||
(uo as Action<string>)(args.Sig.StringValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
namespace PepperDash.Essentials.Core.SmartObjects
|
||||
{
|
||||
public class SmartObjectNumeric : SmartObjectHelperBase
|
||||
{
|
||||
|
||||
public BoolOutputSig Digit1 { get { return GetBoolOutputNamed("1"); } }
|
||||
public BoolOutputSig Digit2 { get { return GetBoolOutputNamed("2"); } }
|
||||
public BoolOutputSig Digit3 { get { return GetBoolOutputNamed("3"); } }
|
||||
public BoolOutputSig Digit4 { get { return GetBoolOutputNamed("4"); } }
|
||||
public BoolOutputSig Digit5 { get { return GetBoolOutputNamed("5"); } }
|
||||
public BoolOutputSig Digit6 { get { return GetBoolOutputNamed("6"); } }
|
||||
public BoolOutputSig Digit7 { get { return GetBoolOutputNamed("7"); } }
|
||||
public BoolOutputSig Digit8 { get { return GetBoolOutputNamed("8"); } }
|
||||
public BoolOutputSig Digit9 { get { return GetBoolOutputNamed("9"); } }
|
||||
public BoolOutputSig Digit0 { get { return GetBoolOutputNamed("0"); } }
|
||||
public BoolOutputSig Misc1 { get { return GetBoolOutputNamed("Misc_1"); } }
|
||||
public BoolOutputSig Misc2 { get { return GetBoolOutputNamed("Misc_2"); } }
|
||||
|
||||
public SmartObjectNumeric(SmartObject so, bool useUserObjectHandler) : base(so, useUserObjectHandler)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user