-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBluetoothCursors.pde
85 lines (64 loc) · 2.14 KB
/
BluetoothCursors.pde
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
79
80
81
82
83
84
85
//********************************************************************
// The following code is required to enable bluetooth at startup.
//********************************************************************
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bt = new KetaiBluetooth(this);
println("Creating KetaiBluetooth");
}
void onActivityResult(int requestCode, int resultCode, Intent data) {
bt.onActivityResult(requestCode, resultCode, data);
}
//********************************************************************
//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data)
{
if (isConfiguring)
return;
//KetaiOSCMessage is the same as OscMessage
// but allows construction by byte array
KetaiOSCMessage m = new KetaiOSCMessage(data);
if (m.isValid())
{
if (m.checkAddrPattern("/remoteMouse/"))
{
if (m.checkTypetag("ii"))
{
remoteMouse.x = m.get(0).intValue();
remoteMouse.y = m.get(1).intValue();
}
}
else if(m.checkAddrPattern("/size/")){
if(m.checkTypetag("ii")){
if(otherSize.size() == 0){
otherSize.add(m.get(0).intValue());
otherSize.add(m.get(1).intValue());
ratio.add(1.0*otherSize.get(0)/width);
ratio.add(1.0*otherSize.get(1)/height);
}
else{
otherSize.set(0, m.get(0).intValue());
otherSize.set(1, m.get(1).intValue());
ratio.set(0, 1.0*otherSize.get(0)/width);
ratio.set(1, 1.0*otherSize.get(1)/height);
}
println(otherSize);
println(ratio);
}
}
}
}
String getBluetoothInformation()
{
String btInfo = "Server Running: ";
btInfo += bt.isStarted() + "\n";
btInfo += "Discovering: " + bt.isDiscovering() + "\n";
btInfo += "Device Discoverable: "+bt.isDiscoverable() + "\n";
btInfo += "\nConnected Devices: \n";
ArrayList<String> devices = bt.getConnectedDeviceNames();
for (String device : devices)
{
btInfo+= device+"\n";
}
return btInfo;
}