Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created March 21, 2009 14:46
Show Gist options
  • Save hisasann/82868 to your computer and use it in GitHub Desktop.
Save hisasann/82868 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import wiiremotej.WiiRemote;
import wiiremotej.WiiRemoteJ;
import wiiremotej.event.WRButtonEvent;
import wiiremotej.event.WRIREvent;
import wiiremotej.event.WiiRemoteAdapter;
import wiiremotej.event.WiiRemoteListener;
public class WiiSample2 {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
System.setProperty("bluecove.jsr82.psm_minimum_off", "true");
WiiRemoteJ.setConsoleLoggingAll();
WiiRemote remote = null;
while (remote == null) {
try {
remote = WiiRemoteJ.findRemote();
}
catch(Exception e) {
remote = null;
e.printStackTrace();
System.out.println("Failed to connect remote. Trying again.");
}
}
remote.addWiiRemoteListener(simpleEventLisntener);
remote.setAccelerometerEnabled(true);
remote.setSpeakerEnabled(true);
remote.setIRSensorEnabled(true, WRIREvent.BASIC);
remote.setLEDIlluminated(0, true);
}
private static WiiRemoteListener simpleEventLisntener = new WiiRemoteAdapter() {
public void disconnected() {
System.out.println("Remote disconnected... Please Wii again.");
System.exit(0);
}
public void buttonInputReceived(WRButtonEvent evt) {
String message = "";
if (evt.wasPressed(WRButtonEvent.TWO)) message="2";
if (evt.wasPressed(WRButtonEvent.ONE)) message="1";
if (evt.wasPressed(WRButtonEvent.B)) message="B";
if (evt.wasPressed(WRButtonEvent.A)) message="A";
if (evt.wasPressed(WRButtonEvent.MINUS)) message="Minus";
if (evt.wasPressed(WRButtonEvent.HOME)) message="Home";
if (evt.wasPressed(WRButtonEvent.LEFT)) message="Left";
if (evt.wasPressed(WRButtonEvent.RIGHT)) message="Right";
if (evt.wasPressed(WRButtonEvent.DOWN)) message="Down";
if (evt.wasPressed(WRButtonEvent.UP)) message="Up";
if (evt.wasPressed(WRButtonEvent.PLUS)) message="Plus";
send(message);
}
// Twitter Post Method
private void send(String message) {
if(message == null || "".equals(message)) return;
Twitter twitter = new Twitter("id", "pass);
Status status = null;
try {
status = twitter.update("WiiリモコンからPost - " + message + "ボタンクリック");
} catch (TwitterException e) {
e.printStackTrace();
}
System.out.println("Successfully updated the status to ["
+ status.getText() + "].");
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment