void ISendable.InitSendable(ISendableBuilder builder) { builder.SmartDashboardType = "Scheduler"; NetworkTableEntry namesEntry = builder.GetEntry("Names"); NetworkTableEntry idsEntry = builder.GetEntry("Ids"); NetworkTableEntry cancelEntry = builder.GetEntry("Cancel"); builder.UpdateTable = () => { var ids = new Dictionary <double, ICommand>(); foreach (var command in m_scheduledCommands.Keys) { ids.Add(command.GetHashCode(), command); } var toCancel = cancelEntry.GetDoubleArray(ReadOnlySpan <double> .Empty); foreach (var hash in toCancel) { if (ids.TryGetValue(hash, out var command)) { Cancel(command); ids.Remove(hash); } cancelEntry.SetDoubleArray(ReadOnlySpan <double> .Empty); } var names = new List <string>(); foreach (var command in ids.Values) { names.Add(command.Name); } namesEntry.SetStringArray(names.ToArray()); idsEntry.SetDoubleArray(ids.Keys.ToArray()); }; }
void ISendable.InitSendable(ISendableBuilder builder) { builder.SmartDashboardType = "String Chooser"; builder.GetEntry(INSTANCE).SetDouble(m_instance); builder.AddStringProperty(DEFAULT, () => m_defaultChoice, null); builder.AddStringArrayProperty(OPTIONS, () => m_map.Keys.ToArray(), null); builder.AddStringProperty(ACTIVE, () => { lock (m_mutex) { if (m_selected != null) { return(m_selected); } else { return(m_defaultChoice); } } }, null); lock (m_mutex) { m_activeEntries.Add(builder.GetEntry(ACTIVE)); } builder.AddStringProperty(SELECTED, null, val => { lock (m_mutex) { m_selected = val; foreach (var entry in m_activeEntries) { entry.SetString(val); } } }); }