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 { public override string SerialValue { get { return _SerialValue; } } string _SerialValue; //public override eCueType Type { get { return eCueType.Serial; } } /// /// Used in testing. Set/Clear functions /// public string TestValue { get; private set; } List LinkedInputSigs = new List(); public SerialFeedback() { } public SerialFeedback(string key) : base(key) { } public override void FireUpdate() { throw new NotImplementedException("This feedback type does not use Funcs"); } public void FireUpdate(string newValue) { _SerialValue = newValue; LinkedInputSigs.ForEach(s => UpdateSig(s, newValue)); OnOutputChange(newValue); } public void LinkInputSig(StringInputSig sig) { LinkedInputSigs.Add(sig); UpdateSig(sig); } public void UnlinkInputSig(StringInputSig sig) { LinkedInputSigs.Remove(sig); } public override string ToString() { return (InTestMode ? "TEST -- " : "") + SerialValue; } /// /// Puts this in test mode, sets the test value and fires an update. /// /// 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; } } }