Skip to content

Commit

Permalink
[Fix] autoconnect was connecting too much for multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Feb 14, 2024
1 parent c5fa070 commit 95869c0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/src/flutter_blue_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,15 @@ class FlutterBluePlus {
_connectionStates[r.remoteId] = r;
if (r.connectionState == BmConnectionStateEnum.disconnected) {
// reset known mtu
_mtuValues.remove(r.remoteId);
_mtuValues.remove(r.remoteId);

// clear lastDescs so that 'isNotifying' is reset
_lastDescs.remove(r.remoteId);
_lastDescs.remove(r.remoteId);

// clear chr values, for api consistency
_lastChrs.remove(r.remoteId);
_lastChrs.remove(r.remoteId);

// Note: to make FBP easier to use, we purposely
// Note: to make FBP easier to use, we purposely
// do not clear `knownServices` or `bondState`.
// to make FBP easier to use, we purposely do not clear knownServices,
// otherwise `servicesList` would be annoying to use.
Expand All @@ -459,9 +459,10 @@ class FlutterBluePlus {
_lastChrs.remove(r.remoteId); // for api consistency, clear characteristic values

// autoconnect
for (DeviceIdentifier d in _autoConnect) {
if (_adapterStateNow == BmAdapterStateEnum.on) {
BluetoothDevice(remoteId: d).connect(autoConnect: true, mtu: null);
if (_adapterStateNow == BmAdapterStateEnum.on) {
var device = BluetoothDevice(remoteId: r.remoteId);
if (_autoConnect.contains(device)) {
device.connect(autoConnect: true, mtu: null);
}
}
}
Expand Down

0 comments on commit 95869c0

Please sign in to comment.