Search in sources :

Example 1 with Controller

use of net.java.games.input.Controller in project JMRI by JMRI.

the class TreeModel method loadSystem.

/**
     * @return true for success
     */
boolean loadSystem() {
    // Get a list of the controllers JInput knows about and can interact with
    log.debug("start looking for controllers");
    try {
        ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
        log.debug("Found " + ca.length + " controllers");
    } catch (Exception ex) {
        // this is probably ClassNotFoundException, but that's not part of the interface
        // could not load some component(s)
        log.debug("Found no controllers, handled Exception", ex);
        ca = null;
        return false;
    }
    for (int i = 0; i < ca.length; i++) {
        // Get this controllers components (buttons and axis)
        Component[] components = ca[i].getComponents();
        log.info("Controller " + ca[i].getName() + " has " + components.length + " components");
        for (int j = 0; j < components.length; j++) {
            Controller controller = ca[i];
            Component component = components[j];
            // ensure controller node exists directly under root
            String cname = controller.getName() + " [" + controller.getType().toString() + "]";
            UsbNode cNode = UsbNode.getNode(cname, controller, null);
            cNode = (UsbNode) insertNode(cNode, dRoot);
            // Device (component) node
            String dname = component.getName() + " [" + component.getIdentifier().toString() + "]";
            UsbNode dNode = UsbNode.getNode(dname, controller, component);
            dNode = (UsbNode) insertNode(dNode, cNode);
            dNode.setValue(0.0f);
        }
    }
    return true;
}
Also used : Component(net.java.games.input.Component) Controller(net.java.games.input.Controller)

Example 2 with Controller

use of net.java.games.input.Controller in project Terasology by MovingBlocks.

the class JInputControllerDevice method getInputQueue.

@Override
public Queue<ControllerAction> getInputQueue() {
    Queue<ControllerAction> result = new ArrayDeque<>();
    Event event = new Event();
    Iterator<Controller> it = controllers.iterator();
    while (it.hasNext()) {
        Controller c = it.next();
        if (c.poll()) {
            EventQueue queue = c.getEventQueue();
            while (queue.getNextEvent(event)) {
                ControllerAction action = convertEvent(c, event);
                if (action != null) {
                    result.add(action);
                }
            }
        } else {
            removeController(c);
        }
    }
    return result;
}
Also used : Event(net.java.games.input.Event) ControllerEvent(net.java.games.input.ControllerEvent) Controller(net.java.games.input.Controller) ControllerAction(org.terasology.input.device.ControllerAction) ArrayDeque(java.util.ArrayDeque) EventQueue(net.java.games.input.EventQueue)

Example 3 with Controller

use of net.java.games.input.Controller in project Terasology by MovingBlocks.

the class JInputControllerDevice method addController.

private void addController(Controller c) {
    if (filter.contains(c.getType())) {
        logger.debug("Ignoring controller: " + c.getName());
        return;
    }
    if (c.getControllers().length == 0) {
        controllers.add(c);
        logger.info("Registered controller: " + c.getName());
    } else {
        for (Controller sub : c.getControllers()) {
            addController(sub);
        }
    }
}
Also used : Controller(net.java.games.input.Controller)

Example 4 with Controller

use of net.java.games.input.Controller in project j6dof-flight-sim by chris-ali.

the class Keyboard method searchForControlDevices.

/**
 * Search for and add controllers of type Controller.Type.KEYBOARD to controlDeviceList
 */
@Override
public void searchForControlDevices() {
    Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
    controlDeviceList = new ArrayList<>();
    for (Controller controller : controllers) {
        if (controller.getType() == Controller.Type.KEYBOARD) {
            controlDeviceList.add(controller);
            logger.debug("Found a keyboard: " + controller.getName());
        }
    }
    if (controlDeviceList.isEmpty()) {
        logger.error("No keyboard found!");
        return;
    }
}
Also used : Controller(net.java.games.input.Controller)

Example 5 with Controller

use of net.java.games.input.Controller in project litiengine by gurkenlabs.

the class GamepadManager method updateGamepads.

private void updateGamepads() {
    this.handleHotPluggedControllers = true;
    try {
        this.hackTheShitOutOfJInputBecauseItSucksHard();
        // update plugged in gamepads
        for (int i = 0; i < ControllerEnvironment.getDefaultEnvironment().getControllers().length; i++) {
            final Controller controller = ControllerEnvironment.getDefaultEnvironment().getControllers()[i];
            final Type type = controller.getType();
            if (!type.equals(Type.GAMEPAD)) {
                continue;
            }
            final IGamepad existing = Input.getGamepad(i);
            if (existing != null && existing.getName().equals(controller.getName())) {
                // already added
                continue;
            }
            // add new gamepads
            final IGamepad newGamepad = new Gamepad(i, controller);
            Input.gamepads().add(newGamepad);
            for (final Consumer<IGamepad> cons : this.gamepadAddedConsumer) {
                cons.accept(newGamepad);
            }
        }
    } catch (IllegalStateException e) {
        this.hotPlugThread.interrupt();
    } finally {
        this.handleHotPluggedControllers = false;
    }
}
Also used : Type(net.java.games.input.Controller.Type) Controller(net.java.games.input.Controller)

Aggregations

Controller (net.java.games.input.Controller)7 ArrayDeque (java.util.ArrayDeque)1 Component (net.java.games.input.Component)1 Type (net.java.games.input.Controller.Type)1 ControllerEvent (net.java.games.input.ControllerEvent)1 Event (net.java.games.input.Event)1 EventQueue (net.java.games.input.EventQueue)1 ControllerAction (org.terasology.input.device.ControllerAction)1