Created
February 3, 2016 20:51
-
-
Save acamilo/d7ea411fd5507b157696 to your computer and use it in GitHub Desktop.
Bowler Studio Game 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
import com.neuronrobotics.sdk.addons.gamepad.IJInputEventListener; | |
import com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice; | |
import net.java.games.input.Component; | |
import net.java.games.input.Event; | |
import net.java.games.input.Controller; | |
import net.java.games.input.ControllerEnvironment; | |
BowlerJInputDevice g=null;// Create a variable to store the device | |
//Check if the device already exists in the device Manager | |
if(DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "jogController")==null){ | |
BowlerStudio.speak("I did not find a device named jogController. Select a port to connect to the device."); | |
//If the device does not exist, prompt for the connection | |
g = new BowlerJInputDevice(ControllerEnvironment.getDefaultEnvironment().getControllers()[0]); // This is the DyIO to talk to. | |
g.connect(); // Connect to it. | |
// add the device to the maager | |
DeviceManager.addConnection(g,"jogController"); | |
}else{ | |
//the device is already present on the system, load the one that exists. | |
g=(BowlerJInputDevice)DeviceManager.getSpecificDevice(BowlerJInputDevice.class, "jogController") | |
} | |
DyIOChannel servo = dyio.getChannel(4); | |
boolean initialCachedMode = servo.getCachedMode(); | |
DyIOChannel mouth = dyio.getChannel(9); | |
DyIOChannel lean = dyio.getChannel(11); | |
DyIOChannel look = dyio.getChannel(10); | |
DyIOChannel lsx = dyio.getChannel(7); | |
DyIOChannel lsy = dyio.getChannel(8); | |
DyIOChannel rsx = dyio.getChannel(6); | |
DyIOChannel rsy = dyio.getChannel(5); | |
IJInputEventListener listener = new IJInputEventListener() { | |
@Override public void onEvent(Component comp, Event event1,float value, String eventString) { | |
int val=(255* (value+1)/2); | |
if(comp.getName().equals("Base 2")){ | |
servo.setCachedMode(false); | |
servo.setValue(val); | |
} | |
if(comp.getName().equals("Base")){ | |
mouth.setCachedMode(false); | |
mouth.setValue(val); | |
} | |
if(comp.getName().equals("slider")){ | |
lean.setCachedMode(false); | |
lean.setValue(val); | |
} | |
if(comp.getName().equals("rz")){ | |
look.setCachedMode(false); | |
look.setValue(val); | |
} | |
if(comp.getName().equals("x")){ | |
lsx.setCachedMode(false); | |
lsx.setValue(val); | |
rsx.setCachedMode(false); | |
rsx.setValue(val); | |
} | |
if(comp.getName().equals("y")){ | |
rsy.setCachedMode(false); | |
rsy.setValue(val); | |
lsy.setCachedMode(false); | |
lsy.setValue(val); | |
} | |
} | |
} | |
// gamepad is a BowlerJInputDevice | |
g.addListeners(listener); | |
// wait while the application is not stopped | |
while(!Thread.interrupted()){ | |
ThreadUtil.wait(10) | |
} | |
//remove listener and exit | |
g.removeListeners(listener); | |
servo.setCachedMode(initialCachedMode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment