Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions BrickController2.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public Task DisconnectAsync()
{
Disconnect();
}

return Task.CompletedTask;
}

Expand Down
7 changes: 7 additions & 0 deletions BrickController2/BrickController2.UWP/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application
x:Class="BrickController2.Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BrickController2.Windows">

</Application>
83 changes: 83 additions & 0 deletions BrickController2/BrickController2.UWP/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using BrickController2.Helpers;
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace BrickController2.Windows
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
// workaround resource loading for EN language
// enforce blocking of modern resource loading so as EN resources are properly loaded
var location = System.IO.Path.GetDirectoryName(typeof(ResourceHelper).Assembly.Location);
AppDomain.CurrentDomain.SetData("PLATFORM_RESOURCE_ROOTS", location);


this.InitializeComponent();
this.Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();


Xamarin.Forms.Forms.Init(e);

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

if (rootFrame.Content == null)
{
// navigate to the first page
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}


/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
deferral.Complete();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
173 changes: 173 additions & 0 deletions BrickController2/BrickController2.UWP/BrickController2.UWP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{DC1AE8D2-77CD-4C25-8E43-D2D3F3E68339}</ProjectGuid>
<TemplateGuid>{98C37F10-6541-44BE-B1E6-7EB3EB8C08F1}</TemplateGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrickController2.Windows</RootNamespace>
<AssemblyName>BrickController2.UWP</AssemblyName>
<DefaultLanguage>en</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>portable</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>portable</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>portable</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\AdvertismentExtensions.cs" />
<Compile Include="Extensions\ControllerExtensions.cs" />
<Compile Include="Extensions\ConvertExtensions.cs" />
<Compile Include="Extensions\IBufferExtensions.cs" />
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="PlatformServices\BluetoothLE\BleDevice.cs" />
<Compile Include="PlatformServices\BluetoothLE\BleGattCharacteristic.cs" />
<Compile Include="PlatformServices\BluetoothLE\BleGattService.cs" />
<Compile Include="PlatformServices\BluetoothLE\BleScanner.cs" />
<Compile Include="PlatformServices\BluetoothLE\BleService.cs" />
<Compile Include="PlatformServices\DI\PlatformServicesModule.cs" />
<Compile Include="PlatformServices\GameController\GameControllerService.cs" />
<Compile Include="PlatformServices\GameController\GamepadController.cs" />
<Compile Include="PlatformServices\GameController\GamepadMapping.cs" />
<Compile Include="PlatformServices\Infrared\InfraredService.cs" />
<Compile Include="PlatformServices\Localization\LocalizationService.cs" />
<Compile Include="PlatformServices\Permission\BluetoothPermission.cs" />
<Compile Include="PlatformServices\Permission\ReadWriteExternalStoragePermission.cs" />
<Compile Include="PlatformServices\SharedFileStorage\SharedFileStorageService.cs" />
<Compile Include="PlatformServices\Versioning\VersionService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\CustomRenderers\ExtendedSwipeViewRenderer.cs" />
<Compile Include="UI\CustomRenderers\ExtendedSliderRenderer.cs" />
<Compile Include="UI\CustomRenderers\NavPageOverrideRenderer.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\SplashScreen.scale-100.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-400.png" />
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-16.png" />
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-256.png" />
<Content Include="Assets\Square44x44Logo.altform-unplated_targetsize-48.png" />
<Content Include="Assets\Square44x44Logo.scale-100.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-400.png" />
<Content Include="Assets\Square44x44Logo.targetsize-16.png" />
<Content Include="Assets\Square44x44Logo.targetsize-256.png" />
<Content Include="Assets\Square44x44Logo.targetsize-48.png" />
<Content Include="Assets\StoreLogo.scale-100.png" />
<Content Include="Assets\StoreLogo.scale-200.png" />
<Content Include="Assets\StoreLogo.scale-400.png" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Essentials" Version="1.7.2" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2401" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BrickController2\BrickController2.csproj">
<Project>{B1508B2C-0A46-4407-9984-D4412DEF337F}</Project>
<Name>BrickController2</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Windows.Devices.Bluetooth.Advertisement;

namespace BrickController2.Windows.Extensions
{
public static class AdvertismentExtensions
{
public static string GetLocalName(this BluetoothLEAdvertisementReceivedEventArgs args)
{
return args.Advertisement.LocalName.TrimEnd();
}

public static bool IsValidDeviceName(this string deviceName)
{
return !string.IsNullOrEmpty(deviceName);
}

public static bool CanCarryData(this BluetoothLEAdvertisementReceivedEventArgs args)
{
return args.AdvertisementType == BluetoothLEAdvertisementType.ScanResponse ||
args.AdvertisementType == BluetoothLEAdvertisementType.ConnectableUndirected;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Windows.Gaming.Input;

namespace BrickController2.Windows.Extensions
{
public static class ControllerExtensions
{
public static string GetDeviceId(this Gamepad gamepad)
{
// kinda hack
return gamepad.User.NonRoamableId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace BrickController2.Windows.Extensions
{
public static class ConvertExtensions
{
public static string ToBluetoothAddressString(this ulong bluetoothAddress)
{
// 48bit physical BT address
var a = (byte)((bluetoothAddress >> 40) & 0xFF);
var b = (byte)((bluetoothAddress >> 32) & 0xFF);
var c = (byte)((bluetoothAddress >> 24) & 0xFF);
var d = (byte)((bluetoothAddress >> 16) & 0xFF);
var e = (byte)((bluetoothAddress >> 8) & 0xFF);
var f = (byte)(bluetoothAddress & 0xFF);

return $"{a:X2}:{b:X2}:{c:X2}:{d:X2}:{e:X2}:{f:X2}";
}

public static bool TryParseBluetoothAddressString(this string stringValue, out ulong bluetoothAddress)
{
bluetoothAddress = default;

if (string.IsNullOrEmpty(stringValue) || stringValue.Length != 17)
{
return false;
}

ulong value = 0;

for (int i = 1; i <= stringValue.Length; i++)
{
var ch = (uint)stringValue[i - 1];
if (i % 3 == 0)
{
if (ch != '-' && ch != ':')
{
// missing dash
return false;
}
}
else if (ch >= 0x30 && ch <= 0x39)
{
value = (value << 4) + ch - 0x30;
}
else if (ch >= 0x41 && ch <= 0x46)
{
value = (value << 4) + ch - 0x37;
}
else
{
// wrong character
return false;
}
}

bluetoothAddress = value;
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Windows.Storage.Streams;

namespace BrickController2.Windows.Extensions
{
public static class IBufferExtensions
{
public static IBuffer ToBuffer(this byte[] data)
{
var writer = new DataWriter();
writer.WriteBytes(data);

return writer.DetachBuffer();
}

public static byte[] ToByteArray(this IBuffer buffer)
{
using (var reader = DataReader.FromBuffer(buffer))
{
byte[] input = new byte[reader.UnconsumedBufferLength];
reader.ReadBytes(input);

return input;
}
}
}
}
Loading