Révision 0875d625 TestTeoBluetooth/TestTeoBluetooth.Android/Services/BluetoothService.cs
TestTeoBluetooth/TestTeoBluetooth.Android/Services/BluetoothService.cs | ||
---|---|---|
33 | 33 |
private BluetoothSocket socket; |
34 | 34 |
private readonly string sppUUID = "00001101-0000-1000-8000-00805f9b34fb"; |
35 | 35 |
|
36 |
public ObservableCollection<BTDevice> FoundDevices = new ObservableCollection<BTDevice>();
|
|
36 |
public ObservableCollection<Device> FoundDevices = new ObservableCollection<Device>();
|
|
37 | 37 |
public BluetoothService() |
38 | 38 |
{ |
39 |
FoundDevices = new ObservableCollection<BTDevice>();
|
|
39 |
FoundDevices = new ObservableCollection<Device>(); |
|
40 | 40 |
bluetoothAdapter = BluetoothAdapter.DefaultAdapter; |
41 | 41 |
bluetoothReceiver = new BluetoothReceiver(); |
42 | 42 |
bluetoothReceiver.OnBluetoothDeviceDiscovered += DeviceDiscovered; |
... | ... | |
50 | 50 |
Application.Context.RegisterReceiver(bluetoothReceiver, intentFilter); |
51 | 51 |
} |
52 | 52 |
|
53 |
public async Task<bool> Connect(BTDevice btDevice)
|
|
53 |
public async Task<bool> Connect(Device btDevice) |
|
54 | 54 |
{ |
55 | 55 |
try |
56 | 56 |
{ |
... | ... | |
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
// Fonction d'écoute pour le Thread d'écoute |
99 |
private async Task ListeningAsync(BTDevice btDevice)
|
|
99 |
private async Task ListeningAsync(Device btDevice) |
|
100 | 100 |
{ |
101 | 101 |
try |
102 | 102 |
{ |
... | ... | |
176 | 176 |
if (discoveredDevices.FirstOrDefault(x => x.Address == e.Address) is null) |
177 | 177 |
{ |
178 | 178 |
discoveredDevices.Add(e); |
179 |
FoundDevices.Add(new BTDevice() { Name = e.Name, MACAddress = e.Address });
|
|
179 |
FoundDevices.Add(new Device() { Name = e.Name, MACAddress = e.Address }); |
|
180 | 180 |
} |
181 | 181 |
} |
182 | 182 |
|
183 |
public ObservableCollection<BTDevice> DeviceList { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
183 |
public ObservableCollection<Device> DeviceList { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
|
184 | 184 |
|
185 | 185 |
public Task StartScan() |
186 | 186 |
{ |
... | ... | |
199 | 199 |
return scanCompletionSource.Task; |
200 | 200 |
} |
201 | 201 |
|
202 |
public Task<bool> Pair(BTDevice bluetoothDevice)
|
|
202 |
public Task<bool> Pair(Device bluetoothDevice) |
|
203 | 203 |
{ |
204 | 204 |
throw new NotImplementedException(); |
205 | 205 |
} |
206 | 206 |
|
207 |
public Task<bool> Disconnect(BTDevice bluetoothDevice)
|
|
207 |
public Task<bool> Disconnect(Device bluetoothDevice) |
|
208 | 208 |
{ |
209 | 209 |
while (socket.IsConnected) socket.Close(); |
210 | 210 |
return Task.FromResult(true); |
... | ... | |
225 | 225 |
return Task.FromResult(true); |
226 | 226 |
} |
227 | 227 |
|
228 |
public ICollection<BTDevice> GetBondedDevices()
|
|
228 |
public ICollection<Device> GetBondedDevices() |
|
229 | 229 |
{ |
230 |
ICollection<BTDevice> ret = new ObservableCollection<BTDevice>();
|
|
230 |
ICollection<Device> ret = new ObservableCollection<Device>();
|
|
231 | 231 |
foreach (BluetoothDevice bondedDevice in bluetoothAdapter.BondedDevices) |
232 | 232 |
{ |
233 |
BTDevice toAddItem = new BTDevice
|
|
233 |
Device toAddItem = new Device
|
|
234 | 234 |
{ |
235 | 235 |
MACAddress = bondedDevice.Address, |
236 | 236 |
Name = bondedDevice.Name |
Formats disponibles : Unified diff