diff --git a/packages/flutter_blue_plus_platform_interface/.gitignore b/packages/flutter_blue_plus_platform_interface/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/flutter_blue_plus_platform_interface/.metadata b/packages/flutter_blue_plus_platform_interface/.metadata new file mode 100644 index 00000000..3bb479b8 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "b864805a681ae6bb7d7f6cafb7a5a21489819bcf" + channel: "beta" + +project_type: package diff --git a/packages/flutter_blue_plus_platform_interface/CHANGELOG.md b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..0d8803f9 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +* Initial release. diff --git a/packages/flutter_blue_plus_platform_interface/LICENSE b/packages/flutter_blue_plus_platform_interface/LICENSE new file mode 100644 index 00000000..2658ac71 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/LICENSE @@ -0,0 +1,28 @@ +Copyright 2017-2024, Charles Weinberger & Thomas Clark. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Buffalo PC Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/flutter_blue_plus_platform_interface/README.md b/packages/flutter_blue_plus_platform_interface/README.md new file mode 100644 index 00000000..1a9cac80 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/README.md @@ -0,0 +1,18 @@ +# flutter_blue_plus_platform_interface + +A common platform interface for the [`flutter_blue_plus`][1] plugin. + +This interface allows platform-specific implementations of the `flutter_blue_plus` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `flutter_blue_plus`, extend +[`FlutterBluePlusPlatform`][2] with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`FlutterBluePlusPlatform` by calling +`FlutterBluePlusPlatform.instance = MyPlatformFlutterBluePlus()`. + +[1]: ../flutter_blue_plus +[2]: lib/flutter_blue_plus_platform_interface.dart diff --git a/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart new file mode 100644 index 00000000..a3ecf666 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/flutter_blue_plus_platform_interface.dart @@ -0,0 +1 @@ +export 'src/platform_interface/flutter_blue_plus_platform.dart'; diff --git a/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart new file mode 100644 index 00000000..1833c1fb --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/lib/src/platform_interface/flutter_blue_plus_platform.dart @@ -0,0 +1,308 @@ +/// The interface that implementations of flutter_blue_plus must implement. +abstract base class FlutterBluePlusPlatform { + static FlutterBluePlusPlatform? _instance; + + /// The default instance of [FlutterBluePlusPlatform] to use. Throws an [UnsupportedError] if flutter_blue_plus is unsupported on this platform. + static FlutterBluePlusPlatform get instance { + if (_instance case final instance?) { + return instance; + } else { + throw UnsupportedError( + 'flutter_blue_plus is unsupported on this platform', + ); + } + } + + /// Platform-specific plugins should set this with their own platform-specific class that extends [FlutterBluePlusPlatform] when they register themselves. + static set instance( + FlutterBluePlusPlatform instance, + ) { + _instance = instance; + } + + /// Returns a stream of adapter state changed events. + Stream get onAdapterStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of bond state changed events. + Stream get onBondStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic received events. + Stream get onCharacteristicReceived { + throw UnimplementedError(); + } + + /// Returns a stream of characteristic written events. + Stream get onCharacteristicWritten { + throw UnimplementedError(); + } + + /// Returns a stream of connection state changed events. + Stream get onConnectionStateChanged { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor read events. + Stream get onDescriptorRead { + throw UnimplementedError(); + } + + /// Returns a stream of descriptor written events. + Stream get onDescriptorWritten { + throw UnimplementedError(); + } + + /// Returns a stream of device scanned events. + Stream get onDeviceScanned { + throw UnimplementedError(); + } + + /// Returns a stream of Maximum Transmission Unit (MTU) changed events. + Stream get onMtuChanged { + throw UnimplementedError(); + } + + /// Returns a stream of name changed events. + Stream get onNameChanged { + throw UnimplementedError(); + } + + /// Returns a stream of Physical Layer (PHY) changed events. + Stream get onPhyChanged { + throw UnimplementedError(); + } + + /// Returns a stream of Physical Layer (PHY) read events. + Stream get onPhyRead { + throw UnimplementedError(); + } + + /// Returns a stream of Received Signal Strength Indicator (RSSI) read events. + Stream get onRssiRead { + throw UnimplementedError(); + } + + /// Returns a stream of services changed events. + Stream get onServicesChanged { + throw UnimplementedError(); + } + + /// Returns a stream of services discovered events. + Stream get onServicesDiscovered { + throw UnimplementedError(); + } + + /// Clears the Generic Attribute Profile (GATT) cache for a [remoteId]. + Future clearGattCache( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Connects to a [remoteId]. + Future connect( + DeviceIdentifier remoteId, { + bool autoConnect = false, + }) { + throw UnimplementedError(); + } + + /// Creates a bond to a [remoteId]. + Future createBond( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Disconnects from a [remoteId]. + Future disconnect( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Discovers the services for a [remoteId]. + Future> discoverServices( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Returns the adapter name. + Future getAdapterName() { + throw UnimplementedError(); + } + + /// Returns the bonded devices. + Future> getBondedDevices() { + throw UnimplementedError(); + } + + /// Returns the system devices. + Future> getSystemDevices() { + throw UnimplementedError(); + } + + /// Returns [true] if Bluetooth is supported on the hardware. + Future isSupported() { + throw UnimplementedError(); + } + + /// Reads the value for a [characteristicUuid]. + /// + /// Returns the value as a list of bytes. + Future> readCharacteristic( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, { + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } + + /// Reads the value for a [descriptorUuid]. + /// + /// Returns the value as a list of bytes. + Future> readDescriptor( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + Guid descriptorUuid, { + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } + + /// Reads the transmitter and receiver Physical Layer (PHY). + Future readPhy() { + throw UnimplementedError(); + } + + /// Reads the Received Signal Strength Indicator (RSSI) for a [remoteId]. + Future readRssi( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Removes the bond to a [remoteId]. + Future removeBond( + DeviceIdentifier remoteId, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the connection priority for a [remoteId]. + Future requestConnectionPriority( + DeviceIdentifier remoteId, + ConnectionPriority connectionPriority, + ) { + throw UnimplementedError(); + } + + /// Requests a change to the Maximum Transmission Unit (MTU) for a [remoteId]. + Future requestMtu( + DeviceIdentifier remoteId, + int mtu, + ) { + throw UnimplementedError(); + } + + /// Sets the log level. + Future setLogLevel( + LogLevel level, + ) { + throw UnimplementedError(); + } + + /// Sets the notify and/or indicate value for a [characteristicUuid]. + Future setNotifyValue( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + bool enable, { + bool androidForceIndications = false, + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } + + /// Sets the options. + Future setOptions({ + bool darwinShowPowerAlert = true, + }) { + throw UnimplementedError(); + } + + /// Sets the preferred transmitter and receiver Physical Layer (PHY). + Future setPreferredPhy( + Phy phy, + PhyOptions phyOptions, + ) { + throw UnimplementedError(); + } + + /// Starts scanning for devices. + Future startScan({ + List withServices = const [], + List withRemoteIds = const [], + List withNames = const [], + List withKeywords = const [], + List withMsd = const [], + List withServiceData = const [], + bool continuousUpdates = false, + int continuousDivisor = 1, + bool androidLegacy = false, + AndroidScanMode androidScanMode = AndroidScanMode.lowLatency, + bool androidUsesFineLocation = false, + }) { + throw UnimplementedError(); + } + + /// Stops scanning for devices. + Future stopScan() { + throw UnimplementedError(); + } + + /// Turns off the adapter. + Future turnOff() { + throw UnimplementedError(); + } + + /// Turns on the adapter. + Future turnOn() { + throw UnimplementedError(); + } + + /// Writes a [value] to a [characteristicUuid]. + /// + /// The [value] must be a list of bytes. + Future writeCharacteristic( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + List value, + WriteType writeType, { + bool allowLongWrite = false, + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } + + /// Writes a [value] to a [descriptorUuid]. + /// + /// The [value] must be a list of bytes. + Future writeDescriptor( + DeviceIdentifier remoteId, + Guid serviceUuid, + Guid characteristicUuid, + Guid descriptorUuid, + List value, { + Guid? secondaryServiceUuid, + }) { + throw UnimplementedError(); + } +} diff --git a/packages/flutter_blue_plus_platform_interface/pubspec.yaml b/packages/flutter_blue_plus_platform_interface/pubspec.yaml new file mode 100644 index 00000000..2911cec0 --- /dev/null +++ b/packages/flutter_blue_plus_platform_interface/pubspec.yaml @@ -0,0 +1,16 @@ +name: flutter_blue_plus_platform_interface +description: A common platform interface for the flutter_blue_plus plugin. +version: 1.0.0 +homepage: https://github.com/chipweinberger/flutter_blue_plus + +environment: + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter