-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpheroControl.pde
More file actions
72 lines (59 loc) · 1.73 KB
/
SpheroControl.pde
File metadata and controls
72 lines (59 loc) · 1.73 KB
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
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Logger rootLogger = LoggerFactory.getLogger("root");
static public class GatewayServerImpl extends GatewayServerManager {
static Logger logger = LoggerFactory.getLogger(GatewayServerImpl.class);
protected Sphero sphero = null;
public GatewayServerImpl() {
super();
}
public void register (Sphero sphero) {
this.sphero = sphero;
}
};
GatewayServerImpl manager = null;
void setup () {
try {
size(640, 480);
frameRate(10);
manager = new GatewayServerImpl();
manager.setExecLocation(sketchPath + "/engine");
manager.setExecScript("./gateway.py");
manager.start();
while (manager.sphero == null) Thread.sleep(100);
Sphero s = manager.sphero;
// println ("paired_spheros: ");
// List<String> spheros = s.paired_spheros();
// for (String sname: spheros) println ("\t" + sname);
println ("gonna ping ...");
s.ping();
println ("rgb info: " + Integer.toString(s.get_rgb()));
println ("setting spheros name as hoge ...");
s.set_device_name("hoge");
print ("device name: " + s.get_device_name());
println ("bluetooth info: " + s.get_bluetooth_info());
println ("setting head as 30");
s.set_heading(30);
println ("set_stabilization as 1");
s.set_stabilization(1);
println ("set rotation rate as 0x20");
s.set_rotation_rate(0x20);
println ("set back led output as 0x20");
s.set_back_led_output(0x20);
} catch (Exception e) {
rootLogger.error ("Error: {}", e);
}
}
void draw () {
try {
if (manager.sphero != null) {
manager.sphero.set_rgb((int)random(0,255), (int)random(0, 255), (int)random(0, 255), false);
}
} catch (Exception e) {
rootLogger.error ("Error: {}", e);
}
}
void dispose() {
manager.terminate();
super.dispose();
}