/// <summary> /// Removes all existing commands from the scheduler. /// </summary> public void RemoveAll() { while (m_firstCommand != null) { Remove(m_firstCommand.GetData()); } }
private void UpdateTable() { if (Table == null) { return; } double[] toCancel = Table.GetNumberArray("Cancel", new double[0]); if (toCancel.Length > 0) { for (LinkedListElement e = m_firstCommand; e != null; e = e.GetNext()) { for (int i = 0; i < toCancel.Length; i++) { if (e.GetData().GetHashCode() == toCancel[i]) { e.GetData().Cancel(); } } } Table.PutNumberArray("Cancel", new double[0]); } if (m_runningCommandsChanged) { int n = 0; for (LinkedListElement e = m_firstCommand; e != null; e = e.GetNext()) { n++; } string[] commands = new string[n]; double[] ids = new double[n]; n = 0; for (LinkedListElement e = m_firstCommand; e != null; e = e.GetNext()) { commands[n] = e.GetData().Name; ids[n] = e.GetNext().GetHashCode(); n++; } Table.PutStringArray("Names", commands); Table.PutNumberArray("Ids", ids); } }
/// <summary> /// Runs a single iteration of the scheduler loop. /// </summary> /// <remarks>This method should be called often in order to have a functioning /// <see cref="Command"/> system. The loop has 5 stages /// <list type="ordered"> /// <listItem><para>Poll the buttons.</para></listItem> /// <listItem><para>Execute/Remove the commands.</para></listItem> /// <listItem><para>Send values to the <see cref="SmartDashboard.SmartDashboard"/>.</para></listItem> /// <listItem><para>Add Commands.</para></listItem> /// <listItem><para>Add Defaults.</para></listItem> /// </list></remarks> public void Run() { m_runningCommandsChanged = false; if (!m_enabled) { return; } if (m_buttons != null) { for (int i = m_buttons.Count - 1; i >= 0; i--) { m_buttons[i].Execute(); } } LinkedListElement e = m_firstCommand; while (e != null) { Command c = e.GetData(); e = e.GetNext(); if (!c.Run()) { Remove(c); m_runningCommandsChanged = true; } } foreach (Command t in m_additions) { _Add(t); } m_additions.Clear(); foreach (var subsystem in m_subsystems) { if (subsystem.GetCurrentCommand() == null) { _Add(subsystem.GetDefaultCommand()); } subsystem.ConfirmCommand(); } UpdateTable(); }