Search in sources :

Example 1 with CoreScheduler

use of com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler in project BowlerStudio by CommonWealthRobotics.

the class SchedulerGui method setConnection.

public boolean setConnection(BowlerAbstractDevice connection) {
    dyio = (DyIO) connection;
    setLayout(new MigLayout());
    setBorder(BorderFactory.createLoweredBevelBorder());
    cs = new CoreScheduler(get(), loopTime, 6000);
    cb = new SchedulerControlBar(cs);
    JPanel addBar = new JPanel(new MigLayout());
    JButton addChannel = new JButton("Add new channel");
    addChannel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                int selected = availibleChans.getSelectedInteger();
                addServoChannel(cs.addServoChannel(selected));
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Failed to select channel, " + ex.getMessage(), "Bowler ERROR", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    for (int i = 0; i < 24; i++) {
        availibleChans.addInteger(i);
    }
    addBar.add(addChannel);
    addBar.add(availibleChans);
    JButton removeChannel = new JButton("Remove channel");
    removeChannel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                int selected = usedChans.getSelectedInteger();
                for (int i = 0; i < outputs.size(); i++) {
                    ServoOutputScheduleChannelUI s = outputs.get(i);
                    if (s.getChannelNumber() == selected) {
                        rmChannel(selected);
                        return;
                    }
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Failed to select channel, " + ex.getMessage(), "Bowler ERROR", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    addBar.add(removeChannel);
    addBar.add(usedChans);
    JButton saveConfiguration = new JButton("Save Configuration");
    saveConfiguration.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            getFile();
            exportToFile();
        }
    });
    JButton loadConfiguration = new JButton("Load Configuration");
    loadConfiguration.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            rmAllChannels();
            getFile();
            importfromFile();
        }
    });
    addBar.add(saveConfiguration);
    addBar.add(loadConfiguration);
    channelBar.setBorder(BorderFactory.createRaisedBevelBorder());
    add(cb, "wrap");
    add(addBar, "wrap");
    add(channelBar, "wrap");
    return get().ping();
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) MigLayout(net.miginfocom.swing.MigLayout) JButton(javax.swing.JButton) CoreScheduler(com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler)

Example 2 with CoreScheduler

use of com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler in project java-bowler by NeuronRobotics.

the class SchedulerTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        DyIO dyio = new DyIO(ConnectionDialog.promptConnection());
        dyio.connect();
        CoreScheduler cs = new CoreScheduler(dyio, new File("SparkParty.xml"));
        cs.play();
        while (cs.isPlaying()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.exit(0);
    }
}
Also used : DyIO(com.neuronrobotics.sdk.dyio.DyIO) CoreScheduler(com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler) File(java.io.File)

Aggregations

CoreScheduler (com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler)2 DyIO (com.neuronrobotics.sdk.dyio.DyIO)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 MigLayout (net.miginfocom.swing.MigLayout)1