public static void saveDeadZones(int joyId) { Controller controller = Controllers.getController(joyId); DecimalFormat df = new DecimalFormat("#0.00"); for (int i = 0; i < controller.getAxisCount(); i++) { config.setConfigFileSetting( "-Deadzones-." + controller.getName(), controller.getAxisName(i), df.format(controller.getDeadZone(i))); } config.addComment( "-Deadzones-", "Deadzone values here will override values in individual bindings"); LogHelper.Info("Saved deadzones for " + controller.getName()); }
private int detectControllers() { validControllers.clear(); inValidControllers.clear(); try { if (!Controllers.isCreated()) Controllers.create(); if (Controllers.getControllerCount() > 0) { LogHelper.Info("Found " + Controllers.getControllerCount() + " controller(s) in total."); for (int joyIndex = 0; joyIndex < Controllers.getControllerCount(); joyIndex++) { Controller thisController = Controllers.getController(joyIndex); logControllerInfo(thisController); if (controllerUtils.meetsInputRequirements( thisController, requiredButtonCount, requiredMinButtonCount, requiredAxisCount)) { LogHelper.Info( "Controller #" + joyIndex + " ( " + thisController.getName() + ") meets the input requirements"); addControllerToList(validControllers, thisController.getName(), joyIndex); } else { LogHelper.Info("This controller does not meet the input requirements"); addControllerToList(inValidControllers, thisController.getName(), joyIndex); } LogHelper.Info("---"); } } } catch (org.lwjgl.LWJGLException e) { System.err.println("Couldn't initialize Controllers: " + e.getMessage()); } LogHelper.Info("Found " + validControllers.size() + " valid controllers!"); return validControllers.size(); }
// Constructor - Creates a Controller object for every controller detected public TestControllers(int index) { // Get the controller index from the Controllers group controller = Controllers.getController(index); // Gui LayoutManager setLayout(null); // Get the number of buttons on the controller buttonCount = controller.getButtonCount(); // Get the number of buttons + the number of hat pads itemCount = controller.getButtonCount() + controller.getAxisCount() + 2; // Create a Gui Box for every button / hat pad values = new JTextField[itemCount]; names = new JTextField[itemCount]; for (int i = 0; i < controller.getButtonCount(); i++) { names[i] = new JTextField(); names[i].setEditable(false); names[i].setBounds(0, i * 30, 100, 30); names[i].setText(controller.getButtonName(i)); add(names[i]); values[i] = new JTextField(); values[i].setEditable(false); values[i].setBounds(100, i * 30, 100, 30); add(values[i]); } for (int i = buttonCount; i < buttonCount + controller.getAxisCount(); i++) { names[i] = new JTextField(); names[i].setEditable(false); names[i].setBounds(0, i * 30, 100, 30); names[i].setText(controller.getAxisName(i - buttonCount)); add(names[i]); values[i] = new JTextField(); values[i].setEditable(false); values[i].setBounds(100, i * 30, 100, 30); add(values[i]); } int i = itemCount - 2; names[i] = new JTextField(); names[i].setEditable(false); names[i].setBounds(0, i * 30, 100, 30); names[i].setText("POV X"); add(names[i]); values[i] = new JTextField(); values[i].setEditable(false); values[i].setBounds(100, i * 30, 100, 30); add(values[i]); i = itemCount - 1; names[i] = new JTextField(); names[i].setEditable(false); names[i].setBounds(0, i * 30, 100, 30); names[i].setText("POV Y"); add(names[i]); values[i] = new JTextField(); values[i].setEditable(false); values[i].setBounds(100, i * 30, 100, 30); add(values[i]); total++; setPreferredSize(new Dimension(200, 30 * itemCount)); JFrame frame = new JFrame(controller.getName()); frame.setContentPane(new JScrollPane(this)); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { total--; if (total == 0) { System.exit(0); } } }); frame.setSize(230, 400); frame.setLocation(index * 30, index * 30); frame.setVisible(true); }
public static void main(String[] argv) { // Create the environment of controllers try { Controllers.create(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } // Print how many controllers there are int count = Controllers.getControllerCount(); System.out.println(count + " Controllers Found"); // Print the name of each controller for (int i = 0; i < count; i++) { Controller controller = Controllers.getController(i); System.out.println(controller.getName() + " "); System.out.println("Number of Rumblers " + controller.getRumblerCount()); System.out.println("Index Number " + controller.getIndex()); } // If there are no controllers, exit program if (count == 0) { System.exit(0); } TestControllers[] controllerWindows = new TestControllers[count]; for (int i = 0; i < count; i++) { controllerWindows[i] = new TestControllers(i); } // Start the "Game" boolean running = true; while (running) { // Sleep for 100 milliseonds, no need to poll too fast try { Thread.sleep(100); } catch (Exception e) { } ; // Poll all the controllers Controllers.poll(); /* * Controllers have an event listener * Whenever a button is pushed it add the event * it to the buffer of the controller instance * As long as the buffer has something in it * we print it out * */ while (Controllers.next()) { // System.out.println("Event Fired: "); // // System.out.println("\t"+Controllers.getEventNanoseconds()); // // System.out.println("\t"+Controllers.getEventSource()+":"+Controllers.getEventControlIndex()+":"+Controllers.isEventButton()); // // System.out.println("\t"+Controllers.isEventXAxis()+":"+Controllers.isEventYAxis()); // Controller number int controllerNumber = Controllers.getEventSource().getIndex(); // Button number int buttonNumber = Controllers.getEventControlIndex(); /* * Pressing a button on an xBox controller slightly alters the analog values * This causes multiple unwanted events on button push * By checking to see if the event was a button we can strip out the uneeded events */ if (Controllers.isEventButton() == true) { handleButtonPush(controllerNumber, buttonNumber); } } for (int i = 0; i < count; i++) { controllerWindows[i].updateDetails(); } } } // end main
private void logControllerInfo(Controller controller) { LogHelper.Info("Found controller " + controller.getName() + " (" + controller.getIndex() + ")"); LogHelper.Info("It has " + controller.getButtonCount() + " buttons."); LogHelper.Info("It has " + controller.getAxisCount() + " axes."); }