Révision 4ca686e8
TestTeoBluetooth/TestTeoBluetooth.Android/MainActivity.cs | ||
---|---|---|
5 | 5 |
using Android.Runtime; |
6 | 6 |
using Android.OS; |
7 | 7 |
using Xamarin.Forms; |
8 |
using TestBLE.Services;
|
|
8 |
using TeoTestBluetooth.Services;
|
|
9 | 9 |
|
10 |
namespace TestBLE.Droid
|
|
10 |
namespace TeoTestBluetooth.Droid
|
|
11 | 11 |
{ |
12 | 12 |
[Activity(Label = "TestBLE", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )] |
13 | 13 |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity |
TestTeoBluetooth/TestTeoBluetooth.Android/Receivers/BluetoothReceiver.cs | ||
---|---|---|
10 | 10 |
using System.Linq; |
11 | 11 |
using System.Text; |
12 | 12 |
|
13 |
namespace TestBLE.Droid.Receivers
|
|
13 |
namespace TeoTestBluetooth.Droid.Receivers
|
|
14 | 14 |
{ |
15 | 15 |
public class BluetoothReceiver : BroadcastReceiver |
16 | 16 |
{ |
TestTeoBluetooth/TestTeoBluetooth.Android/Services/BluetoothService.cs | ||
---|---|---|
14 | 14 |
using System.Text; |
15 | 15 |
using System.Threading; |
16 | 16 |
using System.Threading.Tasks; |
17 |
using TestBLE.Droid.Receivers;
|
|
18 |
using TestBLE.Droid.Utils;
|
|
19 |
using TestBLE.Models;
|
|
20 |
using TestBLE.Services;
|
|
17 |
using TeoTestBluetooth.Droid.Receivers;
|
|
18 |
using TeoTestBluetooth.Droid.Utils;
|
|
19 |
using TeoTestBluetooth.Models;
|
|
20 |
using TeoTestBluetooth.Services;
|
|
21 | 21 |
|
22 |
namespace TestBLE.Droid.Services
|
|
22 |
namespace TeoTestBluetooth.Droid.Services
|
|
23 | 23 |
{ |
24 | 24 |
public class BluetoothService : IBluetoothService |
25 | 25 |
{ |
26 | 26 |
|
27 |
private List<BluetoothDevice> discoveredDevices = new List<BluetoothDevice>(); |
|
27 |
private readonly List<BluetoothDevice> discoveredDevices = new List<BluetoothDevice>(); |
|
28 |
private readonly BluetoothAdapter bluetoothAdapter; |
|
29 |
private readonly BluetoothReceiver bluetoothReceiver; |
|
28 | 30 |
private TaskCompletionSource<bool> scanCompletionSource; |
29 |
private BluetoothManager bluetoothManager; |
|
30 |
private BluetoothAdapter bluetoothAdapter; |
|
31 |
private BluetoothReceiver bluetoothReceiver; |
|
32 | 31 |
|
33 | 32 |
private Thread listeningThread; |
34 | 33 |
private BluetoothSocket socket; |
35 | 34 |
private readonly string sppUUID = "00001101-0000-1000-8000-00805f9b34fb"; |
36 |
private string bufferedData; |
|
37 | 35 |
|
38 | 36 |
public ObservableCollection<BTDevice> FoundDevices = new ObservableCollection<BTDevice>(); |
39 | 37 |
public BluetoothService() |
... | ... | |
212 | 210 |
return Task.FromResult(true); |
213 | 211 |
} |
214 | 212 |
|
215 |
private byte[] hexValuesToByteArray(string[] hexValues) |
|
216 |
{ |
|
217 |
byte[] ret = hexValues.Select(value => Convert.ToByte(value, 16)).ToArray(); |
|
218 |
return ret; |
|
219 |
} |
|
220 |
|
|
221 | 213 |
public Task<bool> SendHexValues(byte[] hexValues) |
222 | 214 |
{ |
223 | 215 |
if (socket.IsConnected == false) |
TestTeoBluetooth/TestTeoBluetooth.Android/Utils/TaskExtensions.cs | ||
---|---|---|
11 | 11 |
using System.Threading; |
12 | 12 |
using System.Threading.Tasks; |
13 | 13 |
|
14 |
namespace TestBLE.Droid.Utils
|
|
14 |
namespace TeoTestBluetooth.Droid.Utils
|
|
15 | 15 |
{ |
16 | 16 |
public static class TaskExtensions |
17 | 17 |
{ |
TestTeoBluetooth/TestTeoBluetooth/App.xaml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8" ?> |
2 | 2 |
<Application |
3 |
x:Class="TestBLE.App"
|
|
3 |
x:Class="TeoTestBluetooth.App"
|
|
4 | 4 |
xmlns="http://xamarin.com/schemas/2014/forms" |
5 | 5 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> |
6 | 6 |
<Application.Resources /> |
TestTeoBluetooth/TestTeoBluetooth/App.xaml.cs | ||
---|---|---|
1 | 1 |
using System; |
2 |
using TestBLE.Views;
|
|
2 |
using TeoTestBluetooth.Views;
|
|
3 | 3 |
using Xamarin.Forms; |
4 | 4 |
using Xamarin.Forms.Xaml; |
5 | 5 |
|
6 |
namespace TestBLE
|
|
6 |
namespace TeoTestBluetooth
|
|
7 | 7 |
{ |
8 | 8 |
public partial class App : Application |
9 | 9 |
{ |
TestTeoBluetooth/TestTeoBluetooth/MainPage.xaml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8" ?> |
2 | 2 |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" |
3 | 3 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
4 |
x:Class="TestBLE.MainPage">
|
|
4 |
x:Class="TeoTestBluetooth.MainPage">
|
|
5 | 5 |
|
6 | 6 |
<StackLayout> |
7 | 7 |
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0"> |
TestTeoBluetooth/TestTeoBluetooth/MainPage.xaml.cs | ||
---|---|---|
6 | 6 |
using System.Threading.Tasks; |
7 | 7 |
using Xamarin.Forms; |
8 | 8 |
|
9 |
namespace TestBLE
|
|
9 |
namespace TeoTestBluetooth
|
|
10 | 10 |
{ |
11 | 11 |
public partial class MainPage : ContentPage |
12 | 12 |
{ |
TestTeoBluetooth/TestTeoBluetooth/Models/BTDevice.cs | ||
---|---|---|
2 | 2 |
using System.Collections.Generic; |
3 | 3 |
using System.Text; |
4 | 4 |
|
5 |
namespace TestBLE.Models
|
|
5 |
namespace TeoTestBluetooth.Models
|
|
6 | 6 |
{ |
7 | 7 |
public class BTDevice |
8 | 8 |
{ |
TestTeoBluetooth/TestTeoBluetooth/Models/ReponsePesee.cs | ||
---|---|---|
3 | 3 |
using System.Linq; |
4 | 4 |
using System.Text; |
5 | 5 |
|
6 |
namespace TestBLE.Models
|
|
6 |
namespace TeoTestBluetooth.Models
|
|
7 | 7 |
{ |
8 | 8 |
public class ReponsePesee |
9 | 9 |
{ |
TestTeoBluetooth/TestTeoBluetooth/Models/TeoBluetoothCommands.cs | ||
---|---|---|
2 | 2 |
using System.Collections.Generic; |
3 | 3 |
using System.Text; |
4 | 4 |
|
5 |
namespace TestBLE.Models
|
|
5 |
namespace TeoTestBluetooth.Models
|
|
6 | 6 |
{ |
7 | 7 |
public static class TeoBluetoothCommand |
8 | 8 |
{ |
TestTeoBluetooth/TestTeoBluetooth/Services/IBluetoothService.cs | ||
---|---|---|
3 | 3 |
using System.Collections.ObjectModel; |
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 |
using TestBLE.Models;
|
|
6 |
using TeoTestBluetooth.Models;
|
|
7 | 7 |
|
8 |
namespace TestBLE.Services
|
|
8 |
namespace TeoTestBluetooth.Services
|
|
9 | 9 |
{ |
10 | 10 |
public interface IBluetoothService |
11 | 11 |
{ |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/AccueilViewModel.cs | ||
---|---|---|
5 | 5 |
using System.Text; |
6 | 6 |
using System.Threading.Tasks; |
7 | 7 |
using System.Windows.Input; |
8 |
using TestBLE.Models;
|
|
9 |
using TestBLE.Services;
|
|
8 |
using TeoTestBluetooth.Models;
|
|
9 |
using TeoTestBluetooth.Services;
|
|
10 | 10 |
using Xamarin.Essentials; |
11 | 11 |
using Xamarin.Forms; |
12 | 12 |
|
13 |
namespace TestBLE.ViewModels
|
|
13 |
namespace TeoTestBluetooth.ViewModels
|
|
14 | 14 |
{ |
15 | 15 |
public class AccueilViewModel : ViewModelBase |
16 | 16 |
{ |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/CommandItemViewModel.cs | ||
---|---|---|
1 | 1 |
using System.Threading.Tasks; |
2 | 2 |
using System.Windows.Input; |
3 |
using TestBLE.Models;
|
|
4 |
using TestBLE.Services;
|
|
3 |
using TeoTestBluetooth.Models;
|
|
4 |
using TeoTestBluetooth.Services;
|
|
5 | 5 |
using Xamarin.Forms; |
6 | 6 |
|
7 |
namespace TestBLE.ViewModels
|
|
7 |
namespace TeoTestBluetooth.ViewModels
|
|
8 | 8 |
{ |
9 | 9 |
public class CommandItemViewModel : ViewModelBase |
10 | 10 |
{ |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/DeviceItemViewModel.cs | ||
---|---|---|
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 | 6 |
using System.Windows.Input; |
7 |
using TestBLE.Models;
|
|
8 |
using TestBLE.Services;
|
|
9 |
using TestBLE.Views;
|
|
7 |
using TeoTestBluetooth.Models;
|
|
8 |
using TeoTestBluetooth.Services;
|
|
9 |
using TeoTestBluetooth.Views;
|
|
10 | 10 |
using Xamarin.Forms; |
11 | 11 |
|
12 |
namespace TestBLE.ViewModels
|
|
12 |
namespace TeoTestBluetooth.ViewModels
|
|
13 | 13 |
{ |
14 | 14 |
public class DeviceItemViewModel : ViewModelBase |
15 | 15 |
{ |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/DeviceViewModel.cs | ||
---|---|---|
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 | 6 |
using System.Windows.Input; |
7 |
using TestBLE.Models;
|
|
8 |
using TestBLE.Services;
|
|
7 |
using TeoTestBluetooth.Models;
|
|
8 |
using TeoTestBluetooth.Services;
|
|
9 | 9 |
using Xamarin.Forms; |
10 |
using static TestBLE.Models.TeoBluetoothCommand;
|
|
10 |
using static TeoTestBluetooth.Models.TeoBluetoothCommand;
|
|
11 | 11 |
|
12 |
namespace TestBLE.ViewModels
|
|
12 |
namespace TeoTestBluetooth.ViewModels
|
|
13 | 13 |
{ |
14 | 14 |
public class DeviceViewModel : ViewModelBase |
15 | 15 |
{ |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/ViewModelBase.cs | ||
---|---|---|
4 | 4 |
using System.Runtime.CompilerServices; |
5 | 5 |
using System.Text; |
6 | 6 |
|
7 |
namespace TestBLE.ViewModels
|
|
7 |
namespace TeoTestBluetooth.ViewModels
|
|
8 | 8 |
{ |
9 | 9 |
public class ViewModelBase : INotifyPropertyChanged |
10 | 10 |
{ |
TestTeoBluetooth/TestTeoBluetooth/Views/AccueilView.xaml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8" ?> |
2 | 2 |
<ContentPage |
3 |
x:Class="TestBLE.Views.AccueilView"
|
|
3 |
x:Class="TeoTestBluetooth.Views.AccueilView"
|
|
4 | 4 |
xmlns="http://xamarin.com/schemas/2014/forms" |
5 | 5 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
6 | 6 |
xmlns:xe="clr-namespace:XamEffects;assembly=XamEffects" |
TestTeoBluetooth/TestTeoBluetooth/Views/AccueilView.xaml.cs | ||
---|---|---|
3 | 3 |
using System.Linq; |
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 |
using TestBLE.ViewModels;
|
|
6 |
using TeoTestBluetooth.ViewModels;
|
|
7 | 7 |
using Xamarin.Forms; |
8 | 8 |
using Xamarin.Forms.Xaml; |
9 | 9 |
|
10 |
namespace TestBLE.Views
|
|
10 |
namespace TeoTestBluetooth.Views
|
|
11 | 11 |
{ |
12 | 12 |
[XamlCompilation(XamlCompilationOptions.Compile)] |
13 | 13 |
public partial class AccueilView : ContentPage |
TestTeoBluetooth/TestTeoBluetooth/Views/DeviceView.xaml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8" ?> |
2 | 2 |
<ContentPage |
3 |
x:Class="TestBLE.Views.DeviceView"
|
|
3 |
x:Class="TeoTestBluetooth.Views.DeviceView"
|
|
4 | 4 |
xmlns="http://xamarin.com/schemas/2014/forms" |
5 | 5 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
6 | 6 |
xmlns:xe="clr-namespace:XamEffects;assembly=XamEffects" |
TestTeoBluetooth/TestTeoBluetooth/Views/DeviceView.xaml.cs | ||
---|---|---|
3 | 3 |
using System.Linq; |
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 |
using TestBLE.Models;
|
|
7 |
using TestBLE.ViewModels;
|
|
6 |
using TeoTestBluetooth.Models;
|
|
7 |
using TeoTestBluetooth.ViewModels;
|
|
8 | 8 |
using Xamarin.Forms; |
9 | 9 |
using Xamarin.Forms.Xaml; |
10 | 10 |
|
11 |
namespace TestBLE.Views
|
|
11 |
namespace TeoTestBluetooth.Views
|
|
12 | 12 |
{ |
13 | 13 |
[XamlCompilation(XamlCompilationOptions.Compile)] |
14 | 14 |
public partial class DeviceView : ContentPage |
Formats disponibles : Unified diff