hisasann (owner)

Revisions

gist: 82868 Download_button fork
public
Public Clone URL: git://gist.github.com/82868.git
Embed All Files: show embed
WiiTransferTwitter.java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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() + "].");
}
};
}