/** * Adds a button to the {@link Scheduler}. The {@link Scheduler} will poll the button during its * {@link Scheduler#run()}. * * @param button the button to add */ public void addButton(ButtonScheduler button) { if (m_buttons == null) { m_buttons = new Vector(); } m_buttons.addElement(button); }
/** * Adds a button to the {@link Scheduler}. The {@link Scheduler} will poll * the button during its {@link Scheduler#run()}. * * @param button the button to add */ public void addButton(ButtonScheduler button) { if (buttons == null) { buttons = new Vector(); } buttons.addElement(button); }
/** * Runs a single iteration of the loop. This method should be called often in order to have a * functioning {@link Command} system. The loop has five stages: * * <ol> <li>Poll the Buttons</li> <li>Execute/Remove the Commands</li> <li>Send values to * SmartDashboard</li> <li>Add Commands</li> <li>Add Defaults</li> </ol> */ public void run() { m_runningCommandsChanged = false; if (m_disabled) { return; } // Don't run when m_disabled // Get button input (going backwards preserves button priority) if (m_buttons != null) { for (int i = m_buttons.size() - 1; i >= 0; i--) { ((ButtonScheduler) m_buttons.elementAt(i)).execute(); } } // Loop through the commands LinkedListElement element = m_firstCommand; while (element != null) { Command command = element.getData(); element = element.getNext(); if (!command.run()) { remove(command); m_runningCommandsChanged = true; } } // Add the new things for (int i = 0; i < m_additions.size(); i++) { _add((Command) m_additions.elementAt(i)); } m_additions.removeAllElements(); // Add in the defaults Enumeration locks = m_subsystems.getElements(); while (locks.hasMoreElements()) { Subsystem lock = (Subsystem) locks.nextElement(); if (lock.getCurrentCommand() == null) { _add(lock.getDefaultCommand()); } lock.confirmCommand(); } updateTable(); }
/** * Runs a single iteration of the loop. This method should be called often * in order to have a functioning {@link Command} system. The loop has five * stages: * * <ol> <li> Poll the Buttons </li> <li> Execute/Remove the Commands </li> * <li> Send values to SmartDashboard </li> <li> Add Commands </li> <li> Add * Defaults </li> </ol> */ public void run() { m_runningCommandsChanged = false; if (disabled) { return; } // Don't run when disabled // Get button input (going backwards preserves button priority) if (buttons != null) { for (int i = buttons.size() - 1; i >= 0; i--) { ((ButtonScheduler) buttons.elementAt(i)).execute(); } } // Loop through the commands LinkedListElement e = firstCommand; while (e != null) { Command c = e.getData(); e = e.getNext(); if (!c.run()) { remove(c); m_runningCommandsChanged = true; } } // Add the new things for (int i = 0; i < additions.size(); i++) { _add((Command) additions.elementAt(i)); } additions.removeAllElements(); // Add in the defaults Enumeration locks = subsystems.getElements(); while (locks.hasMoreElements()) { Subsystem lock = (Subsystem) locks.nextElement(); if (lock.getCurrentCommand() == null) { _add(lock.getDefaultCommand()); } lock.confirmCommand(); } updateTable(); }