Example #1
0
        /// <summary>
        /// Function that listens for the given key to change and then calls
        /// the given function when it changes within the smart dashboard table.
        /// </summary>
        /// <param name="key">The key location to monitor. The format should be [sub table key]/[value key]</param>
        /// <param name="functionToExecute">The function to fire when the value changes.</param>
        private void AddKeyListenerInternal <T>(string key, Action <string, T> functionToExecute)
        {
            // TODO Don't allow the same key to have two listeners TODO allow this functionality later on?
            if (ListenerFunctions.ContainsKey(key))
            {
                return;
            }
            string subtablePath = GetSubTablePath(key);

            // Add it to the listener array
            ListenerFunctions.Add(key, functionToExecute);

            // If we're not connected, we'll add the key but keep the table null. It will be filled in when we connect.
            if (!IsConnected)
            {
                if (!Tables.ContainsKey(subtablePath))
                {
                    Tables.Add(subtablePath, null);
                }
                return;
            }

            ITable table = GetTable(subtablePath);

            // If the table is not on our list, add it and subscribe to its change event.
            if (!Tables.ContainsKey(subtablePath))
            {
                Tables.Add(subtablePath, table);
                table.AddTableListener(OnTableValuesChanged);
            }
        }
Example #2
0
 /// <inheritdoc/>
 public virtual void InitTable(ITable subtable)
 {
     Table?.RemoveTableListener(this);
     Table = subtable;
     if (Table != null)
     {
         Table.PutString("name", Name);
         Table.PutBoolean("running", IsRunning());
         Table.PutBoolean("isParented", m_parent != null);
         Table.AddTableListener("running", this, false);
     }
 }
        private static Tuple <ITable, string> NormalizeKey(string key)
        {
            ITable t = NetworkUtil.SmartDashboard;

            char[]   sep   = new char[] { '/' };
            string[] parts = key.Split(sep, 2);
            while (parts.Length > 1)
            {
                key   = parts[1];
                t     = t.GetSubTable(parts[0]);
                parts = key.Split(sep, 2);
            }
            t.AddTableListener(key, OnNetworkTableChange);
            return(new Tuple <ITable, string>(t, key));
        }
Example #4
0
 ///<inheritdoc/>
 public void InitTable(ITable subtable)
 {
     Table?.RemoveTableListener(this);
     Table = subtable;
     if (Table != null)
     {
         Table.PutNumber("p", P);
         Table.PutNumber("i", I);
         Table.PutNumber("d", D);
         Table.PutNumber("f", F);
         Table.PutNumber("setpoint", Setpoint);
         Table.PutBoolean("enabled", Enabled);
         Table.AddTableListener(this, false);
     }
 }
 public static void AddTableListenerOnSynchronizationContext(this ITable table, SynchronizationContext context, Action <ITable, string, object, NotifyFlags> callback, bool immediateNotify = false)
 {
     if (callback == null)
     {
         throw new ArgumentNullException(nameof(callback));
     }
     table.AddTableListener((tbl, name, value, flags) =>
     {
         if (context != null)
         {
             context.Post(state => callback(tbl, name, value, flags), null);
         }
         else
         {
             ThreadPool.QueueUserWorkItem(state => callback(tbl, name, value, flags), null);
         }
     }, immediateNotify);
 }
Example #6
0
        /// <summary>
        /// Populates tables in the Tables dictionary asynchronously so that they're not null
        /// </summary>
        private async Task PopulateTablesAsync()
        {
            List <string> keys = new List <string>(Tables.Keys);

            // Add the connection listeners to the tables in the Tables dictionary and add the table to the Tables Dictionary
            foreach (string key in keys)
            {
                if (Tables[key] != null)
                {
                    continue;
                }
                ITable table = GetTable(key);
                table.AddTableListener(OnTableValuesChanged);
                Tables[key] = table;
            }

            await Task.Delay(0);
        }
Example #7
0
 /// <inheritdoc/>
 public virtual void InitTable(ITable subtable)
 {
     Table?.RemoveTableListener(this);
     Table = subtable;
     if (Table != null)
     {
         Table.PutString("name", Name);
         Table.PutBoolean("running", IsRunning());
         Table.PutBoolean("isParented", m_parent != null);
         Table.AddTableListener("running", this, false);
     }
 }
Example #8
0
 public RootTableContext(string tableName, ITable table) : base(tableName, table)
 {
     statusTable = table.GetSubTable("~STATUS~");
     statusTable.AddTableListener("LW Enabled", (changedTable, _, value, flags) =>
                                  Enabled = value.GetBoolean(), true);
 }
Example #9
0
 ///<inheritdoc/>
 public void InitTable(ITable subtable)
 {
     Table?.RemoveTableListener(this);
     Table = subtable;
     if (Table != null)
     {
         Table.PutNumber("p", P);
         Table.PutNumber("i", I);
         Table.PutNumber("d", D);
         Table.PutNumber("f", F);
         Table.PutNumber("setpoint", Setpoint);
         Table.PutBoolean("enabled", Enabled);
         Table.AddTableListener(this, false);
     }
 }
Example #10
0
 ///<inheritdoc />
 public void StartLiveWindowMode()
 {
     Table.AddTableListener("Value", this, true);
 }