From cb5cf7d9fcc17f44ed7b6e5305442eff0a8213e7 Mon Sep 17 00:00:00 2001 From: Paul-Winpenny <92634321+Paul-Winpenny@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:41:22 +0100 Subject: [PATCH] Working on the uni wifi --- .../Platforms/Windows/Package.appxmanifest | 1 - App/RobobinApp/RobobinApp.csproj | 147 +++++++----------- App/RobobinApp/RobobinApp.csproj.user | 4 +- .../ViewModels/ConnectionPageViewModel.cs | 12 +- App/RobobinApp/Views/ConnectionPage.xaml | 1 - 5 files changed, 68 insertions(+), 97 deletions(-) diff --git a/App/RobobinApp/Platforms/Windows/Package.appxmanifest b/App/RobobinApp/Platforms/Windows/Package.appxmanifest index 150668e9..ed36aadd 100644 --- a/App/RobobinApp/Platforms/Windows/Package.appxmanifest +++ b/App/RobobinApp/Platforms/Windows/Package.appxmanifest @@ -41,7 +41,6 @@ <Capabilities> <rescap:Capability Name="runFullTrust" /> - <DeviceCapability Name="bluetooth" /> </Capabilities> </Package> diff --git a/App/RobobinApp/RobobinApp.csproj b/App/RobobinApp/RobobinApp.csproj index 03a33ca2..421fce80 100644 --- a/App/RobobinApp/RobobinApp.csproj +++ b/App/RobobinApp/RobobinApp.csproj @@ -1,89 +1,62 @@ <Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> - <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> - <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> - <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> --> - - <!-- Note for MacCatalyst: - The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64. - When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>. - The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated; - either BOTH runtimes must be indicated or ONLY macatalyst-x64. --> - <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> --> - - <OutputType>Exe</OutputType> - <RootNamespace>RobobinApp</RootNamespace> - <UseMaui>true</UseMaui> - <SingleProject>true</SingleProject> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - - <!-- Display name --> - <ApplicationTitle>RobobinApp</ApplicationTitle> - - <!-- App Identifier --> - <ApplicationId>com.companyname.robobinapp</ApplicationId> - - <!-- Versions --> - <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> - <ApplicationVersion>1</ApplicationVersion> - - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> - <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> - </PropertyGroup> - - <ItemGroup> - <!-- App Icon --> - <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> - - <!-- Splash Screen --> - <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> - - <!-- Images --> - <MauiImage Include="Resources\Images\*" /> - <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> - - <!-- Custom Fonts --> - <MauiFont Include="Resources\Fonts\*" /> - - <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> - <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> - </ItemGroup> - - <ItemGroup> - <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" /> - <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" /> - <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" /> - <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" /> - <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.91" /> - <PackageReference Include="Plugin.BLE" Version="3.1.0" /> - <PackageReference Include="Shiny" Version="2.7.3" /> - <PackageReference Include="Shiny.BluetoothLE" Version="3.3.3" /> - <PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" /> - </ItemGroup> - - <ItemGroup> - <Compile Update="LeftBox.xaml.cs"> - <DependentUpon>LeftBox.xaml</DependentUpon> - </Compile> - <Compile Update="Views\ConnectionPage.xaml.cs"> - <DependentUpon>ConnectionPage.xaml</DependentUpon> - </Compile> - </ItemGroup> - - <ItemGroup> - <MauiXaml Update="LeftBox.xaml"> - <Generator>MSBuild:Compile</Generator> - </MauiXaml> - <MauiXaml Update="Views\ConnectionPage.xaml"> - <Generator>MSBuild:Compile</Generator> - </MauiXaml> - </ItemGroup> - + <PropertyGroup> + <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> + <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> + <OutputType>Exe</OutputType> + <RootNamespace>MauiApp1</RootNamespace> + <UseMaui>true</UseMaui> + <SingleProject>true</SingleProject> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + <ApplicationTitle>MauiApp1</ApplicationTitle> + <ApplicationId>com.companyname.mauiapp1</ApplicationId> + <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> + <ApplicationVersion>1</ApplicationVersion> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> + <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> + </PropertyGroup> + + <ItemGroup> + <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> + <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> + <MauiImage Include="Resources\Images\*" /> + <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> + <MauiFont Include="Resources\Fonts\*" /> + <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" /> + <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" /> + <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" /> + <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" /> + <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.91" /> + <PackageReference Include="Microsoft.Maui.Resizetizer" Version="8.0.91" /> + <PackageReference Include="Plugin.BLE" Version="3.1.0" /> + <PackageReference Include="Shiny" Version="2.7.3" /> + <PackageReference Include="Shiny.BluetoothLE" Version="3.3.3" /> + <PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" /> + </ItemGroup> + + <ItemGroup> + <Compile Update="LeftBox.xaml.cs"> + <DependentUpon>LeftBox.xaml</DependentUpon> + </Compile> + <Compile Update="Views\ConnectionPage.xaml.cs"> + <DependentUpon>ConnectionPage.xaml</DependentUpon> + </Compile> + </ItemGroup> + + <ItemGroup> + <MauiXaml Update="LeftBox.xaml"> + <Generator>MSBuild:Compile</Generator> + </MauiXaml> + <MauiXaml Update="Views\ConnectionPage.xaml"> + <Generator>MSBuild:Compile</Generator> + </MauiXaml> + </ItemGroup> </Project> diff --git a/App/RobobinApp/RobobinApp.csproj.user b/App/RobobinApp/RobobinApp.csproj.user index 22f9757c..4aca8770 100644 --- a/App/RobobinApp/RobobinApp.csproj.user +++ b/App/RobobinApp/RobobinApp.csproj.user @@ -2,8 +2,8 @@ <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen> - <ActiveDebugFramework>net8.0-android</ActiveDebugFramework> - <ActiveDebugProfile>Pixel 5 - API 34 (Android 14.0 - API 34)</ActiveDebugProfile> + <ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework> + <ActiveDebugProfile>Windows Machine</ActiveDebugProfile> <SelectedPlatformGroup>Emulator</SelectedPlatformGroup> <DefaultDevice>pixel_5_-_api_34</DefaultDevice> </PropertyGroup> diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index f3d231fc..3bea0065 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -118,18 +118,17 @@ namespace RobobinApp.ViewModels // New method to handle discovered devices private void OnDeviceDiscovered(object sender, DeviceEventArgs e) { - Debug.WriteLine($"Discovered device: {e.Device.Name} ({e.Device.Id})"); + Debug.WriteLine($"Discovered device: ID={e.Device.Id}, Name={e.Device.Name}, State={e.Device.State}, RSSI={e.Device.Rssi}"); + var bluetoothDevice = new BluetoothDevice { - Name = e.Device.Name, - MacAddress = e.Device.Id.ToString() // Ensure this aligns with how you handle MAC addresses + Name = string.IsNullOrWhiteSpace(e.Device.Name) ? e.Device.Id.ToString() : e.Device.Name, + MacAddress = e.Device.Id.ToString() }; - // Check if the device is already in the list to avoid duplicates if (!BluetoothDevices.Any(d => d.MacAddress == bluetoothDevice.MacAddress)) { - // Use the Device.BeginInvokeOnMainThread to add the device on the UI thread Device.BeginInvokeOnMainThread(() => { BluetoothDevices.Add(bluetoothDevice); @@ -140,6 +139,7 @@ namespace RobobinApp.ViewModels + private async void OnConnect() { if (SelectedDevice == null) @@ -184,4 +184,4 @@ namespace RobobinApp.ViewModels public string Name { get; set; } public string MacAddress { get; set; } } -} +} \ No newline at end of file diff --git a/App/RobobinApp/Views/ConnectionPage.xaml b/App/RobobinApp/Views/ConnectionPage.xaml index c52c682a..cf108b67 100644 --- a/App/RobobinApp/Views/ConnectionPage.xaml +++ b/App/RobobinApp/Views/ConnectionPage.xaml @@ -16,7 +16,6 @@ HorizontalOptions="Center" VerticalOptions="Start" /> - <!-- ListView to display available Bluetooth devices --> <ListView x:Name="DeviceListView" ItemsSource="{Binding BluetoothDevices}" SelectedItem="{Binding SelectedDevice}" -- GitLab