-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,199 additions
and
1,884 deletions.
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.