commit 4c7eec22e9da69767d770220b66f9eddc4152425
Author: Martin Toutant <martin.toutant@inrae.fr>
Date:   Thu Aug 25 14:57:59 2022 +0200

    Add connection to bluetooth readers

diff --git a/TestXamConnections/TestXamConnections.Android/Helper/ConnectionServiceProvider.cs b/TestXamConnections/TestXamConnections.Android/Helper/ConnectionServiceProvider.cs
index b345630..d851d8f 100644
--- a/TestXamConnections/TestXamConnections.Android/Helper/ConnectionServiceProvider.cs
+++ b/TestXamConnections/TestXamConnections.Android/Helper/ConnectionServiceProvider.cs
@@ -19,7 +19,7 @@ namespace TestBLE.Droid.Helper
 {
     public class ConnectionServiceProvider : IConnectionServiceProvider
     {
-        public IConnectionService GetConnectionInstance(ConnectionType ct)
+        public IConnectionService GetConnectionServiceInstance(ConnectionType ct)
         {
             IConnectionService instance = null;
             switch (ct)
diff --git a/TestXamConnections/TestXamConnections/Helper/IConnectionServiceProvider.cs b/TestXamConnections/TestXamConnections/Helper/IConnectionServiceProvider.cs
index c30ce7a..215ee76 100644
--- a/TestXamConnections/TestXamConnections/Helper/IConnectionServiceProvider.cs
+++ b/TestXamConnections/TestXamConnections/Helper/IConnectionServiceProvider.cs
@@ -18,6 +18,6 @@ namespace TestXamConnections.Helper
 
     public interface IConnectionServiceProvider
     {
-        IConnectionService GetConnectionInstance(ConnectionType ct);
+        IConnectionService GetConnectionServiceInstance(ConnectionType ct);
     }
 }
diff --git a/TestXamConnections/TestXamConnections/Models/AgridentReader.cs b/TestXamConnections/TestXamConnections/Models/AgridentReader.cs
index 47af218..6f885b0 100644
--- a/TestXamConnections/TestXamConnections/Models/AgridentReader.cs
+++ b/TestXamConnections/TestXamConnections/Models/AgridentReader.cs
@@ -43,7 +43,7 @@ namespace TestXamConnections.Models
 
         public AgridentReader()
         {
-            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionInstance(ConnectionType.Intern);
+            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
             ConnectionService.DataReceivedEvent += InternDataReceived;
         }
 
diff --git a/TestXamConnections/TestXamConnections/Models/BluetoothReader.cs b/TestXamConnections/TestXamConnections/Models/BluetoothReader.cs
new file mode 100644
index 0000000..cee3e81
--- /dev/null
+++ b/TestXamConnections/TestXamConnections/Models/BluetoothReader.cs
@@ -0,0 +1,39 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TestXamConnections.Connection;
+using TestXamConnections.Helper;
+using Xamarin.Forms;
+
+namespace TestXamConnections.Models
+{
+    public class BluetoothReader : Device
+    {
+        private IConnectionService ConnectionService { get; set; }
+        public EventHandler<byte[]> BluetoothDataReceivedEvent { get; set; }
+
+        public BluetoothReader(Device device)
+        {
+            Name = device.Name;
+            MACAddress = device.MACAddress;
+            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
+            ConnectionService.DataReceivedEvent += BluetoothDataReceived;
+        }
+
+        private void BluetoothDataReceived(object sender, byte[] e)
+        {
+            BluetoothDataReceivedEvent.Invoke(this, e);
+        }
+
+        public async Task<bool> ConnectToBTReaderAsync()
+        {
+            Dictionary<string, string> param = new Dictionary<string, string>()
+            {
+                { ConnectionConstants.MAC_ADDR_KEY, MACAddress }
+            };
+            bool ret = await ConnectionService.Connect(param);
+            return ret;
+        }
+    }
+}
diff --git a/TestXamConnections/TestXamConnections/Models/TeoBalance.cs b/TestXamConnections/TestXamConnections/Models/TeoBalance.cs
index b580d69..e0a2515 100644
--- a/TestXamConnections/TestXamConnections/Models/TeoBalance.cs
+++ b/TestXamConnections/TestXamConnections/Models/TeoBalance.cs
@@ -48,7 +48,7 @@ namespace TestXamConnections.Models
         {
             Name = device.Name;
             MACAddress = device.MACAddress;
-            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionInstance(ConnectionType.Bluetooth);
+            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
             ConnectionService.DataReceivedEvent += TeoDataReceived;
         }
 
@@ -121,7 +121,7 @@ namespace TestXamConnections.Models
             {
                 { ConnectionConstants.MAC_ADDR_KEY, MACAddress }
             };
-            await ConnectionService.Connect(param);
+            _ = await ConnectionService.Connect(param);
             return true;
         }
 
diff --git a/TestXamConnections/TestXamConnections/TestXamConnections.csproj b/TestXamConnections/TestXamConnections/TestXamConnections.csproj
index 274a433..0ebd4f6 100644
--- a/TestXamConnections/TestXamConnections/TestXamConnections.csproj
+++ b/TestXamConnections/TestXamConnections/TestXamConnections.csproj
@@ -22,6 +22,9 @@
     <Compile Update="Views\AccueilView.xaml.cs">
       <DependentUpon>AccueilView.xaml</DependentUpon>
     </Compile>
+    <Compile Update="Views\BluetoothReaderView.xaml.cs">
+      <DependentUpon>BluetoothReaderView.xaml</DependentUpon>
+    </Compile>
     <Compile Update="Views\TeoDeviceView.xaml.cs">
       <DependentUpon>TeoDeviceView.xaml</DependentUpon>
     </Compile>
@@ -31,6 +34,9 @@
     <EmbeddedResource Update="Views\AccueilView.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
+    <EmbeddedResource Update="Views\BluetoothReaderView.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
     <EmbeddedResource Update="Views\InternServiceView.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
diff --git a/TestXamConnections/TestXamConnections/ViewModels/AccueilViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/AccueilViewModel.cs
index f6e5e3d..9ebc052 100644
--- a/TestXamConnections/TestXamConnections/ViewModels/AccueilViewModel.cs
+++ b/TestXamConnections/TestXamConnections/ViewModels/AccueilViewModel.cs
@@ -67,7 +67,7 @@ namespace TestXamConnections.ViewModels
 
         public override async void OnActivated()
         {
-            await CheckAndRequestLocationPermission();
+            _ = await CheckAndRequestLocationPermission();
         }
 
         public async Task NavigateToInternService()
diff --git a/TestXamConnections/TestXamConnections/ViewModels/BluetoothReaderViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/BluetoothReaderViewModel.cs
new file mode 100644
index 0000000..db8ee4a
--- /dev/null
+++ b/TestXamConnections/TestXamConnections/ViewModels/BluetoothReaderViewModel.cs
@@ -0,0 +1,83 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using TestXamConnections.Models;
+using Xamarin.Forms;
+
+namespace TestXamConnections.ViewModels
+{
+    public class BluetoothReaderViewModel : ViewModelBase
+    {
+        private BluetoothReader btReader;
+        private bool isVisibleData;
+        private string data;
+        private string connectionIndicator;
+        private string ciColor;
+
+        public string CIColor
+        {
+            get => ciColor;
+            set => SetProperty(ref ciColor, value);
+        }
+
+        public string ConnectionIndicator
+        {
+            get => connectionIndicator;
+            set => SetProperty(ref connectionIndicator, value);
+        }
+
+        public string Data
+        {
+            get => data;
+            set => SetProperty(ref data, value);
+        }
+
+        public bool IsVisibleData
+        {
+            get => isVisibleData;
+            set => SetProperty(ref isVisibleData, value);
+        }
+
+        public BluetoothReader BTReader
+        {
+            get => btReader;
+            set => SetProperty(ref btReader, value);
+        }
+
+        public async Task<bool> ConnectToDevice()
+        {
+            if (await BTReader.ConnectToBTReaderAsync())
+            {
+                ConnectionIndicator = "Connecté";
+                CIColor = "Green";
+                return true;
+            }
+            else
+            {
+                ConnectionIndicator = "Non Connecté";
+                CIColor = "Red";
+                return false;
+            }
+        }
+
+        public ICommand ConnectToDeviceCommand { get; private set; }
+
+        public BluetoothReaderViewModel(Models.Device device)
+        {
+            CIColor = "Red";
+            ConnectionIndicator = "Non connecté";
+            IsVisibleData = false;
+            BTReader = new BluetoothReader(device);
+            ConnectToDeviceCommand = new Command(async () => await ConnectToDevice());
+            BTReader.BluetoothDataReceivedEvent += DataReceived;
+        }
+
+        private void DataReceived(object sender, byte[] e)
+        {
+            IsVisibleData = true;
+            Data += Encoding.ASCII.GetString(e) + "\n";
+        }
+    }
+}
diff --git a/TestXamConnections/TestXamConnections/ViewModels/DeviceItemViewModel.cs b/TestXamConnections/TestXamConnections/ViewModels/DeviceItemViewModel.cs
index 39b6ca9..ad6ed2d 100644
--- a/TestXamConnections/TestXamConnections/ViewModels/DeviceItemViewModel.cs
+++ b/TestXamConnections/TestXamConnections/ViewModels/DeviceItemViewModel.cs
@@ -29,6 +29,11 @@ namespace TestXamConnections.ViewModels
             {
                 await Application.Current.MainPage.Navigation.PushAsync(new TeoDeviceView(Device));
             }
+            // Si c'est le scanner HoneyWell
+            else if (Device.MACAddress == "00:10:20:30:92:7D")
+            {
+                await Application.Current.MainPage.Navigation.PushAsync(new BluetoothReaderView(Device));
+            }
         }
 
         public ICommand NavigateToDeviceViewCommand { private set; get; }
diff --git a/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml b/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml
new file mode 100644
index 0000000..6bf3644
--- /dev/null
+++ b/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml
@@ -0,0 +1,99 @@
+﻿<?xml version="1.0" encoding="UTF-8" ?>
+<ContentPage
+    x:Class="TestXamConnections.Views.BluetoothReaderView"
+    xmlns="http://xamarin.com/schemas/2014/forms"
+    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+    xmlns:xe="clr-namespace:XamEffects;assembly=XamEffects">
+    <ContentPage.Content>
+        <StackLayout
+            Padding="10"
+            BackgroundColor="#001729"
+            VerticalOptions="FillAndExpand">
+            <StackLayout VerticalOptions="CenterAndExpand">
+
+                <Frame
+                    Padding="0"
+                    BackgroundColor="Transparent"
+                    BorderColor="#4f5a64"
+                    CornerRadius="5"
+                    HasShadow="False"
+                    HorizontalOptions="Center"
+                    VerticalOptions="CenterAndExpand"
+                    WidthRequest="250">
+                    <StackLayout Spacing="0">
+                        <StackLayout Margin="0,10">
+                            <Label
+                                Margin="0"
+                                FontAttributes="Bold"
+                                FontSize="28"
+                                HorizontalOptions="CenterAndExpand"
+                                HorizontalTextAlignment="Center"
+                                Text="{Binding BTReader.Name}"
+                                TextColor="White"
+                                VerticalOptions="CenterAndExpand" />
+                            <Label
+                                Margin="0"
+                                FontAttributes="Italic"
+                                FontSize="12"
+                                HorizontalOptions="CenterAndExpand"
+                                HorizontalTextAlignment="Center"
+                                Text="{Binding BTReader.MACAddress}"
+                                TextColor="DarkGray"
+                                VerticalOptions="CenterAndExpand" />
+                        </StackLayout>
+                        <!--  Bouton Connect  -->
+                        <xe:BorderView
+                            Margin="0,10,0,20"
+                            xe:Commands.Tap="{Binding ConnectToDeviceCommand}"
+                            xe:TouchEffect.Color="#0060a8"
+                            BackgroundColor="#003266"
+                            CornerRadius="65"
+                            HorizontalOptions="Center">
+                            <StackLayout Padding="15,10">
+                                <Label
+                                    FontSize="16"
+                                    HorizontalOptions="Center"
+                                    Text="Connect"
+                                    TextColor="#34a9ff" />
+                            </StackLayout>
+                        </xe:BorderView>
+                        <Label
+                            Margin="0,0,0,20"
+                            FontAttributes="Bold"
+                            FontSize="Medium"
+                            HorizontalOptions="CenterAndExpand"
+                            Text="{Binding ConnectionIndicator}"
+                            TextColor="{Binding CIColor}"
+                            VerticalOptions="CenterAndExpand" />
+                    </StackLayout>
+                </Frame>
+
+                <Frame
+                    Padding="0"
+                    BackgroundColor="Transparent"
+                    BorderColor="#4f5a64"
+                    CornerRadius="5"
+                    HasShadow="False"
+                    HorizontalOptions="Center"
+                    IsVisible="{Binding IsVisibleData}"
+                    VerticalOptions="CenterAndExpand"
+                    WidthRequest="200">
+                    <StackLayout HorizontalOptions="CenterAndExpand">
+                        <Label
+                            FontAttributes="Bold"
+                            FontSize="18"
+                            HorizontalTextAlignment="Center"
+                            Text="Received Data"
+                            TextColor="White" />
+                        <Label
+                            FontAttributes="Italic"
+                            FontSize="14"
+                            HorizontalTextAlignment="Center"
+                            Text="{Binding Data}"
+                            TextColor="DarkGray" />
+                    </StackLayout>
+                </Frame>
+            </StackLayout>
+        </StackLayout>
+    </ContentPage.Content>
+</ContentPage>
\ No newline at end of file
diff --git a/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml.cs b/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml.cs
new file mode 100644
index 0000000..2689992
--- /dev/null
+++ b/TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml.cs
@@ -0,0 +1,21 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TestXamConnections.ViewModels;
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace TestXamConnections.Views
+{
+    [XamlCompilation(XamlCompilationOptions.Compile)]
+    public partial class BluetoothReaderView : ContentPage
+    {
+        public BluetoothReaderView(Models.Device device)
+        {
+            InitializeComponent();
+            BindingContext = new BluetoothReaderViewModel(device);
+        }
+    }
+}
\ No newline at end of file
