-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbluetooth.repy
216 lines (135 loc) · 4.39 KB
/
bluetooth.repy
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
"""
<Program>
bluetooth.repy
Variables are mostly from:
http://www.mithril.com.au/android/doc/BluetoothFacade.html
<Date Started>
December 19th, 2013
<Author>
Yanyan Zhuang
<Purpose>
Trying to use the SL4A JSON bridge to read Bluetooth info
"""
dy_import_module_symbols("sensorutil")
def bluetooth_check_state(sl4a_socket):
"""
<Purpose>
Checks Bluetooth state.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
returns: (Boolean) True if Bluetooth is enabled.
"""
result = json_rpc(sl4a_socket, "checkBluetoothState")
return result
def bluetooth_discovery_start(sl4a_socket):
"""
<Purpose>
Start the remote device discovery process.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
(Boolean) true on success, false on error
E.g., {"error":null,"id":0,"result":true}
"""
result = json_rpc(sl4a_socket, "bluetoothDiscoveryStart")
return result
def bluetooth_get_local_address(sl4a_socket):
"""
<Purpose>
Returns the hardware address of the local Bluetooth adapter.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
E.g., {"error":null,"id":0,"result":"60:A1:0A:90:E9:D7"}
"""
result = json_rpc(sl4a_socket, "bluetoothGetLocalAddress")
return result
def bluetooth_get_local_name(sl4a_socket):
"""
<Purpose>
Gets the Bluetooth visible device name
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
E.g., {"error":null,"id":0,"result":"GT-P1000"}
"""
result = json_rpc(sl4a_socket, "bluetoothGetLocalName")
return result
def bluetooth_set_local_name(sl4a_socket, name):
"""
<Purpose>
Sets the Bluetooth Visible device name, returns True on success
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
(Boolean) true on success, false on error
E.g., {"error":null,"id":0,"result":true}
"""
result = json_rpc(sl4a_socket, "bluetoothSetLocalName", name)
return result
def bluetooth_is_discovering(sl4a_socket):
"""
<Purpose>
Return true if the local Bluetooth adapter is currently in the
device discovery process.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
E.g., {"error":null,"id":0,"result":true}
"""
result = json_rpc(sl4a_socket, "bluetoothIsDiscovering")
return result
def bluetooth_get_scan_mode(sl4a_socket):
"""
<Purpose>
Gets the scan mode for the local dongle.
Return values:
-1 when Bluetooth is disabled.
0 if non discoverable and non connectable.
1 connectable non discoverable.
3 connectable and discoverable.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
{"error":null,"id":0,"result":1}
"""
result = json_rpc(sl4a_socket, "bluetoothGetScanMode")
return result
def bluetooth_make_discoverable(sl4a_socket, duration = None):
"""
<Purpose>
Requests that the device be discoverable for Bluetooth connections.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
duration (Integer) period of time, in seconds, during which the
device should be discoverable (default=300)
<Return>
{"error":null,"id":0,"result":null}
"""
if duration == None:
result = json_rpc(sl4a_socket, "bluetoothMakeDiscoverable", 300)
else:
result = json_rpc(sl4a_socket, "bluetoothMakeDiscoverable", duration)
return result
def bluetooth_discovery_cancel(sl4a_socket):
"""
<Purpose>
Cancel the current device discovery process.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
(Boolean) true on success, false on error
E.g., {"error":null,"id":0,"result":true}
"""
result = json_rpc(sl4a_socket, "bluetoothDiscoveryCancel")
return result