Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nebkat committed Nov 18, 2024
1 parent f1a2f31 commit b7d5345
Show file tree
Hide file tree
Showing 11 changed files with 1,199 additions and 1,884 deletions.

Large diffs are not rendered by default.

455 changes: 200 additions & 255 deletions ios/Classes/FlutterBluePlusPlugin.m

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lib/flutter_blue_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
library flutter_blue_plus;

import 'dart:async';
import 'dart:io';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/services.dart';

part 'src/bluetooth_attribute.dart';
part 'src/bluetooth_characteristic.dart';
part 'src/bluetooth_descriptor.dart';
part 'src/bluetooth_device.dart';
part 'src/bluetooth_msgs.dart';
part 'src/bluetooth_events.dart';
part 'src/bluetooth_msgs.dart';
part 'src/bluetooth_service.dart';
part 'src/bluetooth_utils.dart';
part 'src/flutter_blue_plus.dart';
Expand Down
77 changes: 77 additions & 0 deletions lib/src/bluetooth_attribute.dart
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;
}
Loading

0 comments on commit b7d5345

Please sign in to comment.