Created
April 27, 2014 00:30
-
-
Save Hasufel/11334707 to your computer and use it in GitHub Desktop.
getting controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getControllers():Void { | |
var a = JNI.createStaticMethod ("org.haxe.lime.MainView", "getControllersList", "()Ljava/lang/String;", true); | |
var b:String = a(); | |
var c:Array<String> = b.split(';'); | |
_controllers = new Array<Array<String>>(); | |
var i:Int = 0; | |
while(i < c.length) { | |
if (Std.parseInt(c[i])!=null) { | |
_controllers.push([c[i], c[i+1]]); | |
} | |
i+=2; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getControllersList() { | |
int[] devices = InputDevice.getDeviceIds(); | |
ArrayList<String> controllerDevices = new ArrayList<String>(); | |
for (int i = 0; i < devices.length; i++) { | |
InputDevice mDevice = InputDevice.getDevice(devices[i]); | |
int numAxes = 0; | |
for (InputDevice.MotionRange range : mDevice.getMotionRanges()) { | |
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { | |
numAxes += 1; | |
} | |
} | |
if (numAxes>0) { | |
controllerDevices.add(Integer.toString(devices[i])); | |
controllerDevices.add(mDevice.getName()); | |
} | |
} | |
String c = ""; | |
int j = 0; | |
for (String i : controllerDevices){ | |
c+=i; | |
j++; | |
if (j < controllerDevices.size()) { | |
c+=";"; | |
} | |
} | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment