-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Bluetooth #1245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth #1245
Conversation
* added minimalistic documentation
…ated properly with Sample app
|
@drache42, It will cover your contributions to all .NET Foundation-managed open source projects. |
|
@drache42, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
nmetulev
left a comment
There was a problem hiding this 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 @@ | |||
| // ****************************************************************** | |||
There was a problem hiding this comment.
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 @@ | |||
| // ****************************************************************** | |||
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
docs/helpers/BluetoothLEHelper.md
Outdated
|
|
||
| ## API | ||
|
|
||
| TODO: * [BluetoothLEHelper source code]() |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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
| <ComboBox.ItemTemplate> | ||
| <DataTemplate x:DataType="bt:ObservableGattCharacteristics" > | ||
| <TextBlock > | ||
| <Run Text="Service Name: " /> |
There was a problem hiding this comment.
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, () => |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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".
Created BluetoothLEHelper and samples pages