HI, Well I am experimenting with the API on Windows Systems, but may be you should try to aks these guy's
https://jinput.dev.java.net/
they wrote the api
Hope it helps
Example in JAVA
Moderator: Moderators
Hi, for those interested in linux, i've find a way to make brupbacher code work on linux ubuntu, just some small modifications are making his code working both on linux and window.
Anyway many thank to you brupbacher, great work. I hope you don't mind that i modified it.
here is my code, very similar to brupbacher code :
This code was tested with a SpaceNavigator and a SpaceTraveler, one linux Ubuntu 6.10, 7.04, 7.10, 8.04, and on Windows Vista pro 32bit, and Windows XP pro 32bit
Note that on linux ubuntu, you have to be root to connect to the device, or at least do "sudo chmod 777 /dev/input/*" after you plugged in your SpaceNavigator.
Thanks again to brupbacher,
Estraven
Anyway many thank to you brupbacher, great work. I hope you don't mind that i modified it.
here is my code, very similar to brupbacher code :
Code: Select all
package org.egl.spaceControler;
import java.util.Timer;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
/**
* Details for: SpaceNavigator, Stick, Unknown
* Components: (8)
* 0. Z Axis, z, relative, analog, 0.0
* 1. Y Axis, y, relative, analog, 0.0
* 2. X Axis, x, relative, analog, 0.0
* 3. Z Rotation, rz, relative, analog, 0.0
* 4. Y Rotation, ry, relative, analog, 0.0
* 5. X Rotation, rx, relative, analog, 0.0
* 6. Button 0, 0, absolute, digital, 0.0
* 7. Button 1, 1, absolute, digital, 0.0
* No Rumblers
* No subcontrollers
*/
public class SpaceControlerConnexion {
public static final int NUM_BUTTONS = 2;
public static final int ZAXIS = 0;
public static final int YAXIS = 1;
public static final int XAXIS = 2;
public static final int ZROTATION = 3;
public static final int YROTATION = 4; // default value
public static final int XROTATION = 5;
public static final int BUTTON0 = 6;
public static final int BUTTON1 = 7;
private int xAxisIdx, yAxisIdx, zAxisIdx, rxAxisIdx, ryAxisIdx, rzAxisIdx;
private int buttonsIdx[];
private Controller controller;
private Component[] comps;
public SpaceControlerConnexion () throws Exception {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
if (cs.length == 0) {
System.out.println("No controller found");
throw new Exception("No Controller");
} else System.out.println("Num. controllers: " + cs.length);
controller = findSpaceNavigator(cs);
System.out.println("Space Navigator controller: " + controller.getName() + ", " + controller.getType());
findCompIndices(controller);
}
private Controller findSpaceNavigator (Controller[] cs) throws Exception {
Controller.Type type;
int i = 0;
while (i < cs.length) {
type = cs[i].getType();
System.out.println("Name : "+cs[i].getName());
System.out.println("\tType : "+cs[i].getType());
System.out.println("\tPort : "+cs[i].getPortNumber());
if (cs[i].getName().contains("3Dconnexion")) break;
i++;
}
if (i == cs.length) {
System.out.println("No Space Navigator found");
throw new Exception("No Space Controler available.");
} else System.out.println("No Space Navigator index: " + i);
return cs[i];
}
private void findCompIndices (Controller controller)
/* Store the indices for the analog sticks axes
(x,y) and (z,rz), POV hat, and
button components of the controller.
*/ {
comps = controller.getComponents();
if (comps.length == 0) {
System.out.println("No Components found");
System.exit(0);
} else System.out.println("Num. Components: " + comps.length);
showCompNames(comps);
// get the indices for the axes of the analog sticks: (x,y) and (z,rz)
xAxisIdx = findCompIndex(comps, Component.Identifier.Axis.X, "x",1);
yAxisIdx = findCompIndex(comps, Component.Identifier.Axis.Y, "y",1);
zAxisIdx = findCompIndex(comps, Component.Identifier.Axis.Z, "z",1);
rxAxisIdx = findCompIndex(comps, Component.Identifier.Axis.RX, "rx",1);
if (rxAxisIdx==-1)
rxAxisIdx = findCompIndex(comps, Component.Identifier.Axis.SLIDER_VELOCITY, "slider-velocity",1);
ryAxisIdx = findCompIndex(comps, Component.Identifier.Axis.RY, "ry",1);
if (ryAxisIdx==-1)
ryAxisIdx = findCompIndex(comps, Component.Identifier.Axis.SLIDER_VELOCITY, "slider-velocity",2);
rzAxisIdx = findCompIndex(comps, Component.Identifier.Axis.RZ, "rz",1);
if (rzAxisIdx==-1)
rzAxisIdx = findCompIndex(comps, Component.Identifier.Axis.SLIDER_VELOCITY, "slider-velocity",3);
findButtons(comps);
}
private void showCompNames (Component[] comps) {
Component c;
System.out.println("Components : ");
for (int i = 0; i < comps.length; i++) {
c = comps[i];
System.out.println( "\t"+c.getName() + " ID :" + c.getIdentifier().getName());
}
}
private int findCompIndex (Component[] comps, Component.Identifier id, String nm, int index) {
int counter = 1;
Component c;
for (int i = 0; i < comps.length; i++) {
c = comps[i];
if ((c.getIdentifier() == id))
if ((counter==index)) {
System.out.println("Found " + c.getName() + "; index: " + i);
return i;
}
else
counter ++;
}
System.out.println("No " + nm + " component found");
return -1;
}
/**
* Search through comps[] for NUM_BUTTONS buttons, storing
* their indices in buttonsIdx[]. Ignore excessive buttons.
* If there aren't enough buttons, then fill the empty spots in
* buttonsIdx[] with -1's.
*/
private void findButtons (Component[] comps) {
buttonsIdx = new int[NUM_BUTTONS];
int numButtons = 0;
Component c;
for (int i = 0; i < comps.length; i++) {
c = comps[i];
if (isButton(c)) { // deal with a button
if (numButtons == NUM_BUTTONS) // already enough buttons
System.out.println("Found an extra button; index: " + i + ". Ignoring it");
else {
buttonsIdx[numButtons] = i; // store button index
System.out.println("Found " + c.getName() + "; index: " + i);
numButtons++;
}
}
}
// fill empty spots in buttonsIdx[] with -1's
if (numButtons < NUM_BUTTONS) {
System.out.println("Too few buttons (" + numButtons + "); expecting " + NUM_BUTTONS);
while (numButtons < NUM_BUTTONS) {
buttonsIdx[numButtons] = -1;
numButtons++;
}
}
} // end of findButtons()
/**
* Return true if the component is a digital/absolute button, and
* its identifier name ends with "Button" (i.e. the
* identifier class is Component.Identifier.Button).
*/
private boolean isButton (Component c) {
if (!c.isAnalog() && !c.isRelative()) { // digital and absolute
String className = c.getIdentifier().getClass().getName();
// System.out.println(c.getName() + " identifier: " + className);
if (className.endsWith("Button")) return true;
}
return false;
}
/**
* Return all the buttons in a single array. Each button value is
* a boolean.
*/
public boolean[] getButtons () {
boolean[] buttons = new boolean[NUM_BUTTONS];
float value;
for (int i = 0; i <NUM_BUTTONS> NUM_BUTTONS)) {
System.out.println("Button position out of range (1-" + NUM_BUTTONS + "): " + pos);
return false;
}
if (buttonsIdx[pos - 1] == -1) // no button found at that pos
return false;
float value = comps[buttonsIdx[pos - 1]].getPollData();
// array range is 0-NUM_BUTTONS-1
return ( (value == 0.0f) ? false : true);
} // end of isButtonPressed()
public void poll () {
controller.poll();
}
/**
* X Translation
*
* @return float value between 1613 and -1613
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getTX () {
return comps[xAxisIdx].getPollData();
}
/**
* Y Translation
*
* @return float value between 1613 and -1613
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getTY () {
return comps[yAxisIdx].getPollData();
}
/**
* Z Translation
*
* @return float value between 1613 and -1613
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getTZ () {
return comps[zAxisIdx].getPollData();
}
/**
* X Rotation
*
* @return float value between 1560 and -1560
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getRX () {
return comps[rxAxisIdx].getPollData();
}
/**
* Y Rotation
*
* @return float value between 1560 and -1560
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getRY () {
return comps[ryAxisIdx].getPollData();
}
/**
* Z Rotation
*
* @return float value between 1560 and -1560
* <p>
* Note: the returned value my not be very logic and correct, I just measured them during pooling
*/
public float getRZ () {
return comps[rzAxisIdx].getPollData();
}
}
Note that on linux ubuntu, you have to be root to connect to the device, or at least do "sudo chmod 777 /dev/input/*" after you plugged in your SpaceNavigator.
Thanks again to brupbacher,
Estraven
Estraven
-
- Posts: 13
- Joined: Tue Oct 02, 2007 1:35 pm
i am trying too
I switched to mac and i am currently porting my spacemouse supported application to mac OS x
I have the same issues with detecting the spacemouse....
does HIDWrapper.jar say any thing to you?
I found this in some tutorial in the web, but can't find it...
cheers,
Oliver
I have the same issues with detecting the spacemouse....
does HIDWrapper.jar say any thing to you?
I found this in some tutorial in the web, but can't find it...
cheers,
Oliver
SpaceNav, Java, and OSX
In case it's still an issue, I have got the SpaceNavigator working with jinput on OSX.
I had to add 2 lines of code in a class in the jinput jar.
I can either post the patch, or post a modified binary, whichever people would like.
So as of this moment, I have the SpaceNav working with the same Java app under linux, Windows and OSX
Cheers!
Nik
I had to add 2 lines of code in a class in the jinput jar.
I can either post the patch, or post a modified binary, whichever people would like.
So as of this moment, I have the SpaceNav working with the same Java app under linux, Windows and OSX
Cheers!
Nik
I would not be a member of any club which would have me as a member - Groucho Marx
-
- Posts: 1
- Joined: Thu Jun 18, 2009 5:43 am
relative to absolute?
I am currently using JInput for some interfacing with the space navigator. My question is: Is there any way to make the components absolute instead of relative? Relative components are rather hard to work with as I don't know how to get max and min values. Any help would be appreciated.