Skip to content

Conversation

@drache42
Copy link
Contributor

Created BluetoothLEHelper and samples pages

@dnfclas
Copy link

dnfclas commented Jun 27, 2017

@drache42,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla2.dotnetfoundation.org.

It will cover your contributions to all .NET Foundation-managed open source projects.
Thanks,
.NET Foundation Pull Request Bot

@dnfclas
Copy link

dnfclas commented Jun 27, 2017

@drache42, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

@nmetulev nmetulev added this to the v1.5 milestone Jun 27, 2017
Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing, thank you for submitting. Please resolve changes and we can merge as soon as those are fixed


// Connect to a device if your choice
ObservableBluetoothLEDevice device =
bluetoothLEHelper.BluetoothLeDevices[<Device you choose>].Connect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing, can we expand on this? How do I chose a device?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you want me to do this? bluetoothLEHelper.BluetoothLeDevices is a collection of all LE devices in the area that are connectable. The device that the user wants to connect to has to be choosen somehow, but I thought the UI and such were out of scope for these code sample files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that as a comment, or even add the code in a "click handler". The way it is right now, it looks one code block and I would expect to simply copy and paste for it work. However, if I run those two lines one after the other, it will probably not work as BluetoothDevices will most likely be empty. Does that make sense?

{
"Name": "BluetoothLEHelper",
"Type": "BluetoothLEHelperPage",
"About": "The Bluetooth LE helper class is used to connect and interact with bluetooth LE devices.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these commented out and pointing to the wrong link?

/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The args.</param>
private void _deviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must begin with Uppercase

/// <summary>
/// Gets a value indicating whether the Bluetooth LE Helper is supported.
/// </summary>
public bool IsBluetoothLeSupported => ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To continue the same naming convention, should this be IsBluetoothLESupported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should be cached and only ran once

/// </summary>
public void StartEnumeration()
{
if (_advertisementWatcher?.Status == BluetoothLEAdvertisementWatcherStatus.Started)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the method could be called multiple times and subscribe to the same events all over again creating a memory leak. Should check if Status is Stopped, etc, and react appropriately

@@ -0,0 +1,579 @@
// ******************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several stylecop warnings in this file, please resolve

@@ -0,0 +1,175 @@
// ******************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several stylecop warnings in this file, please resolve

<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary since all the code is in the Microsoft.Toolkit.Uwp project


## API

TODO: * [BluetoothLEHelper source code]()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix TODO

@@ -0,0 +1,32 @@
# BluetoothLEHelper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more information about public properties, events, and methods

@azchohfi azchohfi self-requested a review June 28, 2017 22:38
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="bt:ObservableGattCharacteristics" >
<TextBlock >
<Run Text="Service Name: " />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be "Characteristic Name: "?


private async void BluetoothLEHelper_EnumerationCompleted(object sender, EventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it really need a dispatcher? Shouldn't the EnumerationCompleted event be raised on the UI thread?

Copy link
Contributor

@nmetulev nmetulev Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EnumerationCompleted comes from a different thread than the UI thread due to how a DeviceWatcher works so this is required


if (characteristic != null)
{
characteristic.ReadValueAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is async but not awaited? Method is not returning Task. I think it should.

/// <summary>
/// Reads the value of the Characteristic
/// </summary>
public async void ReadValueAsync()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If method is async, it should return a Task.

/// <summary>
/// Gets the app context
/// </summary>
public static BluetoothLEHelper Context { get; private set; } = new BluetoothLEHelper();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context is never being set again. Would be better to use a get only property, not a private set;

if (_readerWriterLockSlim.TryEnterWriteLock(TimeSpan.FromSeconds(1)))
{
var device = BluetoothLeDevices.FirstOrDefault(i => i.DeviceInfo.Id == deviceInfoUpdate.Id);
BluetoothLeDevices?.Remove(device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object is never null. Remove the "?".

/// <summary>
/// Helper class used to pad bytes
/// </summary>
public static class BytePadder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this class included in this PR? It's not being used anywhere else.

bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}

var writer = new DataWriter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this a possible leak? Why are these 3 methods (ToIBuffer, ToIBufferFromHexString, ToIBuffer) added if they are not being used? Should the toolkit expose them?

return _services;
}

private set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to expose the private set if it's not being used. It's the same instance all the time.

/// </summary>
/// <returns>Task.</returns>
/// <exception cref="Exception">The status of the pairing.</exception>
public async Task DoInAppPairing()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many methods are returning Task but doesn't end with "async".

@azchohfi azchohfi merged commit adb28fd into CommunityToolkit:dev Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants