Open JS-E opened 4 years ago
ControllerIndex is a Jamepad API. Jamepad doesn't expose power level, the new features are in sdl2gdx.
There are 3 sdl2gdx methods that could be used:
Easiest high level API: https://electronstudio.github.io/sdl2gdx/uk/co/electronstudio/sdl2gdx/SDL2Controller.html#getPowerLevel--
https://electronstudio.github.io/sdl2gdx/org/libsdl/SDL_Joystick.html#currentPowerLevel--
Lowest level: https://electronstudio.github.io/sdl2gdx/org/libsdl/SDL.html#SDL_JoystickCurrentPowerLevel-long-
Here's a program that uses method 1:
import com.badlogic.gdx.controllers.Controller;
import uk.co.electronstudio.sdl2gdx.SDL2Controller;
import uk.co.electronstudio.sdl2gdx.SDL2ControllerManager;
public class SDL2Test {
public static void main(String[] arg){
SDL2ControllerManager controllerManager = new SDL2ControllerManager();
for (Controller controller : controllerManager.getControllers()) {
SDL2Controller c = (SDL2Controller) controller;
System.out.println(c.getName() + "POWERLEVEL: " +c.getPowerLevel());
}
}
}
Using method 2:
import org.libsdl.SDL;
import org.libsdl.SDL_Joystick;
public class SDL2Test {
public static void main(String[] arg){
SDL.SDL_Init( SDL.SDL_INIT_JOYSTICK );
for(int i=0; i< SDL.SDL_NumJoysticks(); i++) {
SDL_Joystick j = SDL_Joystick.JoystickOpen(i);
System.out.println(j.name() + " POWERLEVEL: "+j.currentPowerLevel());
}
}
}
Appreciate the reply, i'll get that stuffed in :D Awesome.
On another note, is there anyway to get the battery voltage? I know this hasn't been exposed at all, but does the sdl2gdx library have that potential ability? The reason i ask is because i'd like to build a little test that tracks voltage over time to see potential battery problems.
SDL doesn't get battery voltage. I would be very surprised if XInput or DirectInput did either. You'd probably be looking at writing a device-specific USB driver.
xinput has https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_battery_information but that's the same data that sdl2gdx exposes.
Hey,
Saw the update which looks awesome with the new power and the sdl wrapper, unlocking a bunch of new things.
I can't seem to get the power status from a ControllerIndex? Am i doing something wrong?