using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; namespace PepperDash.Essentials.Core { /// /// To be used for serial data feedback where the event chain / asynchronicity must be maintained /// and calculating the value based on a Func when it is needed will not suffice. /// public class SerialFeedback : Feedback { /// /// Gets the SerialValue /// public override string SerialValue { get { return _SerialValue; } } string _SerialValue; //public override eCueType Type { get { return eCueType.Serial; } } /// /// Gets or sets the TestValue /// public string TestValue { get; private set; } List LinkedInputSigs = new List(); /// /// Constructor /// [Obsolete("use constructor with Key parameter. This constructor will be removed in a future version")] public SerialFeedback() { } /// /// Constructor with Key parameter /// /// Key to find this Feedback public SerialFeedback(string key) : base(key) { } /// /// FireUpdate method /// /// public override void FireUpdate() { throw new NotImplementedException("This feedback type does not use Funcs"); } /// /// FireUpdate method /// public void FireUpdate(string newValue) { _SerialValue = newValue; LinkedInputSigs.ForEach(s => UpdateSig(s, newValue)); OnOutputChange(newValue); } /// /// LinkInputSig method /// public void LinkInputSig(StringInputSig sig) { LinkedInputSigs.Add(sig); UpdateSig(sig); } /// /// UnlinkInputSig method /// public void UnlinkInputSig(StringInputSig sig) { LinkedInputSigs.Remove(sig); } /// /// ToString method /// public override string ToString() { return (InTestMode ? "TEST -- " : "") + SerialValue; } /// /// Puts this in test mode, sets the test value and fires an update. /// /// /// /// SetTestValue method /// public void SetTestValue(string value) { TestValue = value; InTestMode = true; FireUpdate(TestValue); } void UpdateSig(StringInputSig sig) { sig.StringValue = _SerialValue; } void UpdateSig(StringInputSig sig, string value) { sig.StringValue = value; } } }