Skip to content
Permalink
Browse files

Added the IoT Bluetooth framework

  • Loading branch information...
COM8 committed Sep 10, 2019
1 parent 79ccc2e commit 965f4cfe60ea0ad80cf9d03954cf7987ea6230c1
Showing with 1,109 additions and 27 deletions.
  1. +22 −0 UWPX-Client.sln
  2. +10 −0 UWPX_UI/Controls/IoT/BluetoothScannerControl.xaml
  3. +71 −0 UWPX_UI/Controls/IoT/BluetoothScannerControl.xaml.cs
  4. +1 −0 UWPX_UI/Package.appxmanifest
  5. +68 −1 UWPX_UI/Pages/RegisterIoTDevicePage.xaml
  6. +18 −6 UWPX_UI/Pages/RegisterIoTDevicePage.xaml.cs
  7. +8 −0 UWPX_UI/UWPX_UI.csproj
  8. +98 −0 UWPX_UI_Context/Classes/DataContext/Controls/IoT/BluetoothScannerControlContext.cs
  9. +14 −3 UWPX_UI_Context/Classes/DataContext/Pages/RegisterIoTDevicePageContext.cs
  10. +43 −0 UWPX_UI_Context/Classes/DataTemplates/Controls/IoT/BluetoothScannerControlDataTemplate.cs
  11. +7 −1 UWPX_UI_Context/Classes/DataTemplates/Pages/RegisterIoTDevicePageDataTemplate.cs
  12. +6 −0 UWPX_UI_Context/UWPX_UI_Context.csproj
  13. +48 −0 XMPP_API/Classes/XmppUri/RegisterIoTUriAction.cs
  14. +42 −16 XMPP_API/Classes/XmppUri/UriUtils.cs
  15. +1 −0 XMPP_API/XMPP_API.csproj
  16. +86 −0 XMPP_API_IoT/Classes/Bluetooth/BLEDevice.cs
  17. +8 −0 XMPP_API_IoT/Classes/Bluetooth/BLEDeviceState.cs
  18. +181 −0 XMPP_API_IoT/Classes/Bluetooth/BLEScanner.cs
  19. +11 −0 XMPP_API_IoT/Classes/Bluetooth/BLEScannerState.cs
  20. +46 −0 XMPP_API_IoT/Classes/Bluetooth/Events/BLEDeviceFoundEventArgs.cs
  21. +48 −0 XMPP_API_IoT/Classes/Bluetooth/Events/BLEDeviceStateChangedEventArgs.cs
  22. +48 −0 XMPP_API_IoT/Classes/Bluetooth/Events/BLEScannerStateChangedEventArgs.cs
  23. +29 −0 XMPP_API_IoT/Properties/AssemblyInfo.cs
  24. +33 −0 XMPP_API_IoT/Properties/XMPP_API_IoT.rd.xml
  25. +162 −0 XMPP_API_IoT/XMPP_API_IoT.csproj
@@ -32,6 +32,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMPP_API_IoT", "XMPP_API_IoT\XMPP_API_IoT.csproj", "{85CE85C2-F71E-4F58-9631-95D3B99EAC69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -294,6 +296,26 @@ Global
{0E93F94C-A663-4EB6-A6DE-6A853D162375}.Release|x64.Build.0 = Release|x64
{0E93F94C-A663-4EB6-A6DE-6A853D162375}.Release|x86.ActiveCfg = Release|x86
{0E93F94C-A663-4EB6-A6DE-6A853D162375}.Release|x86.Build.0 = Release|x86
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|ARM.ActiveCfg = Debug|ARM
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|ARM.Build.0 = Debug|ARM
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|ARM64.ActiveCfg = Debug|ARM64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|ARM64.Build.0 = Debug|ARM64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|x64.ActiveCfg = Debug|x64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|x64.Build.0 = Debug|x64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|x86.ActiveCfg = Debug|x86
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Debug|x86.Build.0 = Debug|x86
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|Any CPU.Build.0 = Release|Any CPU
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|ARM.ActiveCfg = Release|ARM
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|ARM.Build.0 = Release|ARM
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|ARM64.ActiveCfg = Release|ARM64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|ARM64.Build.0 = Release|ARM64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|x64.ActiveCfg = Release|x64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|x64.Build.0 = Release|x64
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|x86.ActiveCfg = Release|x86
{85CE85C2-F71E-4F58-9631-95D3B99EAC69}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -0,0 +1,10 @@
<UserControl x:Class="UWPX_UI.Controls.IoT.BluetoothScannerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Unloaded="UserControl_Unloaded"
mc:Ignorable="d">

<Grid/>
</UserControl>
@@ -0,0 +1,71 @@
using System.Threading.Tasks;
using UWPX_UI_Context.Classes.DataContext.Controls.IoT;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using XMPP_API.Classes.XmppUri;

namespace UWPX_UI.Controls.IoT
{
public sealed partial class BluetoothScannerControl: UserControl
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
public readonly BluetoothScannerControlContext VIEW_MODEL = new BluetoothScannerControlContext();

public RegisterIoTUriAction RegisterIoTUriAction
{
get { return (RegisterIoTUriAction)GetValue(RegisterIoTUriActionProperty); }
set { SetValue(RegisterIoTUriActionProperty, value); }
}
public static readonly DependencyProperty RegisterIoTUriActionProperty = DependencyProperty.Register(nameof(RegisterIoTUriAction), typeof(RegisterIoTUriAction), typeof(BluetoothScannerControl), new PropertyMetadata(null, OnRegisterIoTUriActionChanged));

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
public BluetoothScannerControl()
{
InitializeComponent();
}

#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--
public async Task StartAsync()
{
await VIEW_MODEL.StartAsync(RegisterIoTUriAction.MAC);
}

#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--
private async static void OnRegisterIoTUriActionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is BluetoothScannerControl bluetoothScannerControl && e.NewValue is RegisterIoTUriAction)
{
await bluetoothScannerControl.StartAsync();
}
}

private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
VIEW_MODEL.Stop();
}

#endregion
}
}
@@ -41,5 +41,6 @@
<Capability Name="privateNetworkClientServer" />
<uap:Capability Name="picturesLibrary" />
<DeviceCapability Name="webcam" />
<DeviceCapability Name="bluetooth" />
</Capabilities>
</Package>
@@ -5,6 +5,7 @@
xmlns:controls="using:UWPX_UI.Controls"
xmlns:controls1="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iot="using:UWPX_UI.Controls.IoT"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource AppBackgroundAcrylicWindowBrush}"
mc:Ignorable="d">
@@ -84,7 +85,8 @@
<StackPanel Padding="10"
Background="{ThemeResource AppBackgroundAcrylicElementBrush}">
<TextBlock Text="Scan a QR Code to continue"/>
<controls:QrCodeScannerControl x:Uid="RegisterIoTDevicePage_qr_code_scanner"
<controls:QrCodeScannerControl x:Name="qrCodeScanner"
x:Uid="RegisterIoTDevicePage_qr_code_scanner"
Margin="0,10,0,0"
NewValidQrCode="QrCodeScannerControl_NewValidQrCode"/>
<HyperlinkButton x:Name="whatIsAnIoTDevice_link"
@@ -108,7 +110,72 @@
</StackPanel>
</Border>
</controls1:DropShadowPanel>

<!-- Step 2: -->
<controls1:DropShadowPanel x:Name="step2Bluetooth_dsp"
Grid.Row="1"
MaxWidth="400"
HorizontalContentAlignment="Stretch"
Visibility="Collapsed">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation From="{StaticResource AnimationOpacityMin}"
To="{StaticResource AnimationOpacityMax}"
Duration="{StaticResource OpacityAnimationDuration}"/>
<animations:TranslationAnimation From="{StaticResource AnimationPositionShowSource}"
To="{StaticResource AnimationPositionShowTarget}"
Duration="{StaticResource TranslationAnimationDuration}"/>
</animations:Implicit.ShowAnimations>

<animations:Implicit.HideAnimations>
<animations:OpacityAnimation From="{StaticResource AnimationOpacityMax}"
To="{StaticResource AnimationOpacityMin}"
Duration="{StaticResource OpacityAnimationDuration}"/>
<animations:TranslationAnimation From="{StaticResource AnimationPositionHideSource}"
To="{StaticResource AnimationPositionHideTarget}"
Duration="{StaticResource TranslationAnimationDuration}"/>
</animations:Implicit.HideAnimations>
<Border HorizontalAlignment="Stretch"
Background="{ThemeResource AppBackgroundAcrylicWindowBrush}">
<StackPanel Padding="10"
Background="{ThemeResource AppBackgroundAcrylicElementBrush}">
<TextBlock Text="Scanning for device"/>
<iot:BluetoothScannerControl x:Name="btScanner_btsc"
RegisterIoTUriAction="{x:Bind VIEW_MODEL.MODEL.RegisterIoTUriAction, Mode=OneWay}"/>
<Grid Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<controls:IconButtonControl x:Name="cancel2_ibtn"
Grid.Column="0"
Margin="0,0,0,1"
Click="Cancel_ibtn_Click"
Glyph="&#xE711;"
GlyphForeground="Red"
Text="Cancel"/>
</Grid>
</StackPanel>
</Border>
</controls1:DropShadowPanel>
</Grid>
</ScrollViewer>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="State_1">
<VisualState.Setters>
<Setter Target="step1ScanQrCode_dsp.Visibility" Value="Visible"/>
<Setter Target="step2Bluetooth_dsp.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="State_2">
<VisualState.Setters>
<Setter Target="step1ScanQrCode_dsp.Visibility" Value="Collapsed"/>
<Setter Target="step2Bluetooth_dsp.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Page>
@@ -1,9 +1,10 @@
using System;
using Logging;
using Shared.Classes;
using UWPX_UI.Controls;
using UWPX_UI_Context.Classes;
using UWPX_UI_Context.Classes.DataContext.Pages;
using UWPX_UI_Context.Classes.Events;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

@@ -21,6 +22,7 @@ public sealed partial class RegisterIoTDevicePage: Page
public RegisterIoTDevicePage()
{
InitializeComponent();
UpdateViewState(State_1.Name);
}

#endregion
@@ -36,7 +38,10 @@ public RegisterIoTDevicePage()
#endregion

#region --Misc Methods (Private)--

private void UpdateViewState(string state)
{
VisualStateManager.GoToState(this, state, true);
}

#endregion

@@ -56,19 +61,26 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)
titleBar.OnPageNavigatedFrom();
}

private async void WhatIsAnIoTDevice_link_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
private async void WhatIsAnIoTDevice_link_Click(object sender, RoutedEventArgs e)
{
await UiUtils.LaunchUriAsync(new Uri(Localisation.GetLocalizedString("RegisterIoTDevicePage_what_is_an_iot_device_url")));
}

private void Cancel_ibtn_Click(Controls.IconButtonControl sender, Windows.UI.Xaml.RoutedEventArgs args)
private void Cancel_ibtn_Click(IconButtonControl sender, RoutedEventArgs args)
{
titleBar.OnGoBackRequested();
}

private void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
private async void QrCodeScannerControl_NewValidQrCode(QrCodeScannerControl sender, NewQrCodeEventArgs args)
{
Logger.Info("Scanned QR Code: " + args.QR_CODE);
if (VIEW_MODEL.TryParseUri(args.QR_CODE))
{
await SharedUtils.CallDispatcherAsync(async () =>
{
await qrCodeScanner.StopAsync();
UpdateViewState(State_2.Name);
});
}
}

#endregion
@@ -217,6 +217,9 @@
<Compile Include="Controls\IconTextBlockControl.xaml.cs">
<DependentUpon>IconTextBlockControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\IoT\BluetoothScannerControl.xaml.cs">
<DependentUpon>BluetoothScannerControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\LoadingContentControl.xaml.cs">
<DependentUpon>LoadingContentControl.xaml</DependentUpon>
</Compile>
@@ -642,6 +645,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\IoT\BluetoothScannerControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\LoadingContentControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -973,6 +980,7 @@
<Name>XMPP_API</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>

0 comments on commit 965f4cf

Please sign in to comment.
You can’t perform that action at this time.