forked from TheWalkingDead2/flutter_blue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pauldemarco#12 from pauldemarco/simplify
Simplified plugin substantially
Showing
107 changed files
with
3,728 additions
and
5,156 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## [0.0.1] - TODO: Add release date. | ||
## [0.0.1] - September 1st, 2017 | ||
|
||
* TODO: Describe initial release. | ||
* Initial Release. |
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 |
---|---|---|
@@ -1,10 +1,40 @@ | ||
# flutter_blue | ||
<br> | ||
<p align="center"> | ||
<img alt="FlutterBlue" src="site/flutterblue.png" /> | ||
</p> | ||
<br><br> | ||
|
||
A new flutter plugin project. | ||
## Introduction | ||
|
||
## Getting Started | ||
FlutterBlue is a bluetooth plugin for [Flutter](http://www.flutter.io), a new mobile SDK to help developers build modern apps for iOS and Android. | ||
|
||
For help getting started with Flutter, view our online | ||
[documentation](http://flutter.io/). | ||
## Cross-Platform Bluetooth LE | ||
FlutterBlue aims to offer the most from both platforms (iOS and Android). | ||
|
||
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code). | ||
Using the FlutterBlue instance, you can scan for and connect to nearby devices ([BluetoothDevice](#bluetoothdevice-api)). | ||
Once connected to a device, the BluetoothDevice object can discover services ([BluetoothService](lib/src/bluetooth_service.dart)), characteristics ([BluetoothCharacteristic](lib/src/bluetooth_characteristic.dart)), and descriptors ([BluetoothDescriptor](lib/src/bluetooth_descriptor.dart)). | ||
The BluetoothDevice object is then used to directly interact with characteristics and descriptors. | ||
|
||
### FlutterBlue API | ||
| | Android | iOS | Description | | ||
| :--------------- | :----------------: | :------------------: | :-------------------------------- | | ||
| startScan | :white_check_mark: | :white_large_square: | Starts a scan for Bluetooth Low Energy devices. | | ||
| stopScan | :white_check_mark: | :white_large_square: | Stops a scan for Bluetooth Low Energy devices. | | ||
| connect | :white_check_mark: | :white_large_square: | Establishes a connection to the Bluetooth Device. | | ||
| cancelConnection | :white_check_mark: | :white_large_square: | Cancels a connection to the Bluetooth Device. | | ||
| state | :white_check_mark: | :white_large_square: | Gets the current state of the Bluetooth Adapter. | | ||
| onStateChanged | :white_check_mark: | :white_large_square: | Stream of state changes for the Bluetooth Adapter. | | ||
|
||
### BluetoothDevice API | ||
| | Android | iOS | Description | | ||
| :-------------------------- | :------------------: | :------------------: | :-------------------------------- | | ||
| discoverServices | :white_check_mark: | :white_large_square: | Discovers services offered by the remote device as well as their characteristics and descriptors. | | ||
| services | :white_check_mark: | :white_large_square: | Gets a list of services. Requires that discoverServices() has completed. | | ||
| readCharacteristic | :white_check_mark: | :white_large_square: | Retrieves the value of a specified characteristic. | | ||
| readDescriptor | :white_check_mark: | :white_large_square: | Retrieves the value of a specified descriptor. | | ||
| writeCharacteristic | :white_check_mark: | :white_large_square: | Writes the value of a characteristic. | | ||
| writeDescriptor | :white_check_mark: | :white_large_square: | Writes the value of a descriptor. | | ||
| setNotifyValue | :white_large_square: | :white_large_square: | Sets notifications or indications for the value of a specified characteristic. | | ||
| canSendWriteWithoutResponse | :white_large_square: | :white_large_square: | Indicates whether the Bluetooth Device can send a write without response. | | ||
| state | :white_large_square: | :white_large_square: | Gets the current state of the Bluetooth Device. | | ||
| onStateChanged | :white_large_square: | :white_large_square: | Stream of state changes for the Bluetooth Device. | |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.pauldemarco.flutterblue" | ||
android:versionCode="1" | ||
android:versionName="0.0.1"> | ||
|
||
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="21" /> | ||
package="com.pauldemarco.flutterblue"> | ||
<uses-permission android:name="android.permission.BLUETOOTH" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | ||
</manifest> |
45 changes: 0 additions & 45 deletions
45
android/src/main/java/com/pauldemarco/flutterblue/Adapter.java
This file was deleted.
Oops, something went wrong.
129 changes: 129 additions & 0 deletions
129
android/src/main/java/com/pauldemarco/flutterblue/AdvertisementParser.java
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,129 @@ | ||
// Copyright 2017, the Flutter project authors. 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 Google 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. | ||
|
||
package com.pauldemarco.flutterblue; | ||
|
||
import com.google.protobuf.ByteString; | ||
import com.pauldemarco.flutterblue.Protos.AdvertisementData; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Parser of Bluetooth Advertisement packets. | ||
*/ | ||
class AdvertisementParser { | ||
|
||
/** | ||
* Parses packet data into {@link AdvertisementData} structure. | ||
* | ||
* @param rawData The scan record data. | ||
* @return An AdvertisementData proto object. | ||
* @throws ArrayIndexOutOfBoundsException if the input is truncated. | ||
*/ | ||
static AdvertisementData parse(byte[] rawData) { | ||
ByteBuffer data = ByteBuffer.wrap(rawData).asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN); | ||
AdvertisementData.Builder ret = AdvertisementData.newBuilder(); | ||
boolean seenLongLocalName = false; | ||
do { | ||
int length = data.get() & 0xFF; | ||
if (length == 0) { | ||
break; | ||
} | ||
if (length > data.remaining()) { | ||
throw new ArrayIndexOutOfBoundsException("Not enough data."); | ||
} | ||
|
||
int type = data.get() & 0xFF; | ||
length--; | ||
|
||
switch (type) { | ||
case 0x08: // Short local name. | ||
case 0x09: { // Long local name. | ||
if (seenLongLocalName) { | ||
// Prefer the long name over the short. | ||
break; | ||
} | ||
byte[] name = new byte[length]; | ||
data.get(name); | ||
try { | ||
ret.setLocalName(new String(name, "UTF-8")); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
if (type == 0x09) { | ||
seenLongLocalName = true; | ||
} | ||
break; | ||
} | ||
case 0x0A: { // Power level. | ||
ret.setTxPowerLevel(data.get()); | ||
break; | ||
} | ||
case 0x16: // Service Data with 16 bit UUID. | ||
case 0x20: // Service Data with 32 bit UUID. | ||
case 0x21: { // Service Data with 128 bit UUID. | ||
UUID uuid; | ||
int remainingDataLength = 0; | ||
if (type == 0x16 || type == 0x20) { | ||
long uuidValue; | ||
if (type == 0x16) { | ||
uuidValue = data.getShort() & 0xFFFF; | ||
remainingDataLength = length - 2; | ||
} else { | ||
uuidValue = data.getInt() & 0xFFFFFFFF; | ||
remainingDataLength = length - 4; | ||
} | ||
uuid = UUID.fromString(String.format("%08x-0000-1000-8000-00805f9b34fb", uuidValue)); | ||
} else { | ||
long msb = data.getLong(); | ||
long lsb = data.getLong(); | ||
uuid = new UUID(msb, lsb); | ||
remainingDataLength = length - 16; | ||
} | ||
byte[] remainingData = new byte[remainingDataLength]; | ||
data.get(remainingData); | ||
ret.putServiceData(uuid.toString(), ByteString.copyFrom(remainingData)); | ||
break; | ||
} | ||
case 0xFF: {// Manufacturer specific data. | ||
byte[] msd = new byte[length]; | ||
data.get(msd); | ||
ret.setManufacturerData(ByteString.copyFrom(msd)); | ||
break; | ||
} | ||
default: { | ||
data.position(data.position() + length); | ||
break; | ||
} | ||
} | ||
} while (true); | ||
return ret.build(); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
android/src/main/java/com/pauldemarco/flutterblue/AdvertisementRecord.java
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
android/src/main/java/com/pauldemarco/flutterblue/BluetoothLe.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.