Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1,432 changed files
with
35,071 additions
and 17,189 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,13 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace InTheHand.AppBluetooth.Tests | ||
{ | ||
[TestClass] | ||
public class BluetoothTests | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\InTheHand.AppBluetooth\InTheHand.AppBluetooth.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,65 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="Bluetooth.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace InTheHand.Bluetooth | ||
{ | ||
public sealed partial class Bluetooth | ||
{ | ||
/// <summary> | ||
/// Returns true if Bluetooth is physically available and user has given the app permission. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Task<bool> GetAvailability() | ||
{ | ||
return DoGetAvailability(); | ||
} | ||
|
||
/// <summary> | ||
/// Performs a device lookup and prompts the user for permission if required. | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <returns>A BluetoothDevice or null if unsuccessful.</returns> | ||
public async Task<BluetoothDevice> RequestDevice(RequestDeviceOptions options) | ||
{ | ||
return await DoRequestDevice(options); | ||
} | ||
|
||
private event EventHandler _availabilityChanged; | ||
/// <summary> | ||
/// Bluetooth availability has changed, for example by disabling the radio or revoking user permission. | ||
/// </summary> | ||
public event EventHandler AvailabilityChanged | ||
{ | ||
add | ||
{ | ||
if (_availabilityChanged == null) | ||
{ | ||
AddAvailabilityChanged(); | ||
} | ||
|
||
_availabilityChanged += value; | ||
} | ||
remove | ||
{ | ||
_availabilityChanged -= value; | ||
|
||
if (_availabilityChanged == null) | ||
{ | ||
RemoveAvailabilityChanged(); | ||
} | ||
} | ||
} | ||
|
||
private void OnAvailabilityChanged() | ||
{ | ||
_availabilityChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,37 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothAdvertisingEvent.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace InTheHand.Bluetooth | ||
{ | ||
public sealed partial class BluetoothAdvertisingEvent | ||
{ | ||
internal BluetoothAdvertisingEvent(BluetoothDevice device) | ||
{ | ||
Device = device; | ||
} | ||
|
||
public BluetoothDevice Device { get; private set; } | ||
|
||
public Guid[] Uuids { get { return GetUuids(); } } | ||
|
||
public string Name { get { return GetName(); } } | ||
|
||
public ushort Appearance { get { return GetAppearance(); } } | ||
|
||
/*public byte TxPower { get; private set; } | ||
public byte Rssi { get { return GetRssi(); } }*/ | ||
|
||
public IReadOnlyDictionary<ushort,byte[]> ManufacturerData { get { return GetManufacturerData(); } } | ||
|
||
public IReadOnlyDictionary<Guid, byte[]> ServiceData { get { return GetServiceData(); } } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,50 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothDevice.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using InTheHand.Bluetooth.GenericAttributeProfile; | ||
using System; | ||
|
||
namespace InTheHand.Bluetooth | ||
{ | ||
public sealed partial class BluetoothDevice | ||
{ | ||
public string Id { get { return GetId(); } } | ||
public string Name { get { return GetName(); } } | ||
public BluetoothRemoteGATTServer Gatt { get { return GetGatt(); } } | ||
|
||
/* | ||
public Task WatchAdvertisementsAsync() | ||
{ | ||
return DoWatchAdvertisements(); | ||
} | ||
public void UnwatchAdvertisements() | ||
{ | ||
DoUnwatchAdvertisements(); | ||
} | ||
public bool WatchingAdvertisements { get { return GetWatchingAdvertisements(); } } | ||
internal void OnAdvertismentReceived(BluetoothAdvertisingEvent advertisement) | ||
{ | ||
AdvertisementReceived?.Invoke(this, advertisement); | ||
} | ||
public event EventHandler<BluetoothAdvertisingEvent> AdvertisementReceived; | ||
*/ | ||
|
||
internal void OnGattServerDisconnected() | ||
{ | ||
GattServerDisconnected?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Fired when an active GATT connection is lost. | ||
/// </summary> | ||
public event EventHandler GattServerDisconnected; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,21 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothLEScanFilterInit.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace InTheHand.Bluetooth | ||
{ | ||
public sealed class BluetoothLEScanFilterInit | ||
{ | ||
public IList<Guid> Services { get; } = new List<Guid>(); | ||
|
||
public string Name { get; set; } | ||
|
||
public string NamePrefix { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,47 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothRemoteGATTServer.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace InTheHand.Bluetooth.GenericAttributeProfile | ||
{ | ||
public sealed partial class BluetoothRemoteGATTServer | ||
{ | ||
internal BluetoothRemoteGATTServer(BluetoothDevice device) | ||
{ | ||
Device = device; | ||
} | ||
|
||
public BluetoothDevice Device { get; private set; } | ||
|
||
public bool Connected { get { return GetConnected(); } } | ||
|
||
public Task Connect() | ||
{ | ||
return DoConnect(); | ||
} | ||
|
||
public void Disconnect() | ||
{ | ||
DoDisconnect(); | ||
Device.OnGattServerDisconnected(); | ||
} | ||
|
||
public Task<BluetoothRemoteGATTService> GetPrimaryService(Guid? service) | ||
{ | ||
return DoGetPrimaryService(service); | ||
} | ||
|
||
public Task<List<BluetoothRemoteGATTService>> GetPrimaryServices(Guid? service = null) | ||
{ | ||
return DoGetPrimaryServices(service); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,54 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothRemoteGATTService.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace InTheHand.Bluetooth.GenericAttributeProfile | ||
{ | ||
public sealed partial class BluetoothRemoteGATTService | ||
{ | ||
internal BluetoothRemoteGATTService(BluetoothDevice device) | ||
{ | ||
Device = device; | ||
} | ||
|
||
public BluetoothDevice Device { get; private set; } | ||
|
||
public Guid Uuid { get { return GetUuid(); } } | ||
|
||
public bool IsPrimary { get { return GetIsPrimary(); } } | ||
|
||
public Task<GattCharacteristic> GetCharacteristicAsync(Guid characteristic) | ||
{ | ||
return DoGetCharacteristic(characteristic); | ||
} | ||
|
||
public async Task<IReadOnlyList<GattCharacteristic>> GetCharacteristicsAsync() | ||
{ | ||
return await DoGetCharacteristics(); | ||
} | ||
|
||
public async Task<BluetoothRemoteGATTService> GetIncludedServiceAsync(Guid service) | ||
{ | ||
return new BluetoothRemoteGATTService(Device); | ||
} | ||
|
||
public async Task<IReadOnlyList<BluetoothRemoteGATTService>> GetIncludedServicesAsync() | ||
{ | ||
List<BluetoothRemoteGATTService> services = new List<BluetoothRemoteGATTService>(); | ||
|
||
return services.AsReadOnly(); | ||
} | ||
|
||
public event EventHandler ServiceAdded; | ||
public event EventHandler ServiceChanged; | ||
public event EventHandler ServiceRemoved; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,31 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="BluetoothUtiAttribute.cs" company="In The Hand Ltd"> | ||
// Copyright (c) 2018-19 In The Hand Ltd, All rights reserved. | ||
// This source code is licensed under the MIT License - see License.txt | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace InTheHand.Bluetooth | ||
{ | ||
/// <summary> | ||
/// Attribute to attach a Uniform Type Identifier to a Bluetooth UUID. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public sealed class BluetoothUtiAttribute : Attribute | ||
{ | ||
public BluetoothUtiAttribute() { } | ||
|
||
public BluetoothUtiAttribute(string uti) | ||
{ | ||
Uti = uti; | ||
} | ||
|
||
public string Uti | ||
{ | ||
get; | ||
private set; | ||
} | ||
} | ||
} |
Oops, something went wrong.