-
Notifications
You must be signed in to change notification settings - Fork 482
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
[Feature] Support multiple service/characteristic instances with same UUID #1042
Open
nebkat
wants to merge
1
commit into
chipweinberger:master
Choose a base branch
from
nebkat:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
380 changes: 149 additions & 231 deletions
380
android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2017-2023, Charles Weinberger & Paul DeMarco. | ||
// All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
part of flutter_blue_plus; | ||
|
||
abstract class BluetoothAttribute { | ||
final BluetoothDevice device; | ||
final Guid uuid; | ||
final int? index; | ||
|
||
BluetoothAttribute({ | ||
required this.device, | ||
required this.uuid, | ||
this.index, | ||
}); | ||
|
||
DeviceIdentifier get remoteId => device.remoteId; | ||
|
||
@Deprecated('Use remoteId instead') | ||
DeviceIdentifier get deviceId => remoteId; | ||
|
||
BluetoothAttribute? get _parentAttribute => null; | ||
|
||
String get identifier => "$uuid:$index"; | ||
|
||
String get identifierPath => | ||
_parentAttribute != null ? "${_parentAttribute!.identifierPath}/$identifier" : identifier; | ||
} | ||
|
||
abstract class BluetoothValueAttribute extends BluetoothAttribute { | ||
List<int> _lastValue = []; | ||
|
||
BluetoothValueAttribute({ | ||
required BluetoothDevice device, | ||
required Guid uuid, | ||
int? index, | ||
}) : super(device: device, uuid: uuid, index: index); | ||
|
||
/// this variable is updated: | ||
/// - anytime `read()` is called | ||
/// - anytime `write()` is called | ||
/// - anytime a notification arrives (characteristics, if subscribed) | ||
/// - when the device is disconnected it is cleared | ||
List<int> get lastValue => _lastValue; | ||
|
||
/// this stream emits values: | ||
/// - anytime `read()` is called | ||
/// - anytime `write()` is called | ||
/// - anytime a notification arrives (characteristics, if subscribed) | ||
/// - and when first listened to, it re-emits the last value for convenience | ||
Stream<List<int>> get lastValueStream => FlutterBluePlus._methodStream.stream | ||
.where((e) => | ||
e is OnCharacteristicReceivedEvent || | ||
e is OnCharacteristicWrittenEvent || | ||
e is OnDescriptorReadEvent || | ||
e is OnDescriptorWrittenEvent) | ||
.map((e) => e as GetAttributeValueMixin) | ||
.where((e) => e.attribute == this) | ||
.map((e) => e.value) | ||
.newStreamWithInitialValue(lastValue); | ||
|
||
/// this stream emits values: | ||
/// - anytime `read()` is called | ||
/// - anytime a notification arrives (if subscribed) | ||
Stream<List<int>> get onValueReceived => FlutterBluePlus._methodStream.stream | ||
.where((e) => e is OnCharacteristicReceivedEvent || e is OnDescriptorReadEvent) | ||
.map((e) => e as GetAttributeValueMixin) | ||
.where((e) => e.attribute == this) | ||
.map((e) => e.value); | ||
|
||
@Deprecated('Use onValueReceived instead') | ||
Stream<List<int>> get value => onValueReceived; | ||
|
||
@Deprecated('Use onValueReceived instead') | ||
Stream<List<int>> get onValueChangedStream => onValueReceived; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 variable should only exist for services. Not chrs & descs. It's just confusing otherwise.
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 was mainly for identifier path generation, so will be removed if we are using a map instead.