Rename pairState and improve readme (#1)
* Improve readme * rename OnPairStateChange api --------- Co-authored-by: Rohit Sangwan <rohitsangwan647@gmail.com>
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
name: Code Review
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: anc95/ChatGPT-CodeReview@main
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
# Optional
|
||||
OPENAI_API_ENDPOINT: https://api.openai.com/v1
|
||||
MODEL: gpt-3.5-turbo-1106 # https://platform.openai.com/docs/models
|
||||
PROMPT: "Please check if there are any bugs, confusions, or irregularities in the following code diff: "
|
||||
top_p: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p
|
||||
temperature: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature
|
||||
max_tokens: 4096
|
||||
MAX_PATCH_LENGTH: 10000 # if the patch/diff length is large than MAX_PATCH_LENGTH, will be ignored and won't review. By default, with no MAX_PATCH_LENGTH set, there is also no limit for the patch/diff length.
|
||||
+7
-6
@@ -1,11 +1,12 @@
|
||||
## 0.8.2
|
||||
## 0.8.3
|
||||
* Rename onPairStateChange -> onPairingStateChange
|
||||
* Improve readme
|
||||
|
||||
* Improve readme.
|
||||
## 0.8.2
|
||||
* Improve readme
|
||||
|
||||
## 0.8.1
|
||||
|
||||
* Update supported platforms.
|
||||
* Update supported platforms
|
||||
|
||||
## 0.8.0
|
||||
|
||||
* Initial release.
|
||||
* Initial release
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
# Universal BLE
|
||||
|
||||
[](https://pub.dev/packages/universal_ble)
|
||||
|
||||
A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE) plugin for Flutter
|
||||
|
||||
## Features
|
||||
|
||||
- [Scanning for BLE Peripherals](#scanning-for-ble-peripherals)
|
||||
- [Connecting to BLE Peripheral](#connecting-to-ble-peripheral)
|
||||
- [Discovering Services of BLE Peripheral](#discovering-services-of-ble-peripheral)
|
||||
- [Transferring Data between BLE Central & Peripheral](#transferring-data-between-ble-central--peripheral)
|
||||
- [Pairing BLE Peripheral](#pairing-ble-central--peripheral)
|
||||
- [Receiving BLE Availability Changes](#receiving-ble-availability-changes)
|
||||
- [Scanning](#scanning)
|
||||
- [Connecting](#connecting)
|
||||
- [Discovering Services](#discovering-services)
|
||||
- [Reading & Writing data](#reading--writing-data)
|
||||
- [Pairing](#pairing)
|
||||
- [Bluetooth Availability](#bluetooth-availability)
|
||||
|
||||
### API Support Matrix
|
||||
|
||||
@@ -23,14 +25,25 @@ A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE
|
||||
| writeValue | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| setNotifiable | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| pair/unPair | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ |
|
||||
| onPairStateChange | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ |
|
||||
| onPairingStateChange | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ |
|
||||
| enableBluetooth | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ |
|
||||
| onAvailabilityChange | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
||||
| requestMtu | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | 🚧 |
|
||||
| requestMtu | ✔️ | ✔️ | ✔️ | ✔️ | 🚧 | ❌ |
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Scanning for BLE Peripherals
|
||||
Add universal_ble in your pubspec.yaml:
|
||||
```yaml
|
||||
dependencies:
|
||||
universal_ble:
|
||||
```
|
||||
|
||||
and import it wherever you want to use it:
|
||||
```dart
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
```
|
||||
|
||||
### Scanning
|
||||
|
||||
```dart
|
||||
// Set a scan result handler
|
||||
@@ -41,33 +54,26 @@ UniversalBle.onScanResult = (scanResult) {
|
||||
// Perform a scan
|
||||
UniversalBle.startScan();
|
||||
|
||||
// On web, you can add filters and specify optional services to discover after connection. The parameter is ignored on other platforms.
|
||||
UniversalBle.startScan(
|
||||
webRequestOptions: WebRequestOptionsBuilder.acceptAllDevices(
|
||||
optionalServices: ["SERVICE_UUID"],
|
||||
),
|
||||
);
|
||||
|
||||
// Stop scanning
|
||||
UniversalBle.stopScan();
|
||||
```
|
||||
|
||||
Already connected devices won't show up as scan results.
|
||||
You can list the already connected devices using `getConnectedDevices()`. You still need to explicitly connect before using them.
|
||||
Already connected devices, either through previous sessions or connected through system settings, won't show up as scan results.
|
||||
You can list those devices using `getConnectedDevices()`. You still need to explicitly connect before using them.
|
||||
|
||||
```dart
|
||||
// You can set `withServices` to narrow down the results
|
||||
await UniversalBle.getConnectedDevices(withServices: []);
|
||||
```
|
||||
|
||||
### Connecting to BLE Peripheral
|
||||
### Connecting
|
||||
|
||||
```dart
|
||||
// Connect to a peripheral using the `deviceId` of the scanResult received from `UniversalBle.onScanResult`
|
||||
// Connect to a device using the `deviceId` of the scanResult received from `UniversalBle.onScanResult`
|
||||
String deviceId = scanResult.deviceId;
|
||||
UniversalBle.connect(deviceId);
|
||||
|
||||
// Disconnect from a peripheral
|
||||
// Disconnect from a device
|
||||
UniversalBle.disconnect(deviceId);
|
||||
|
||||
// Get notified for connection state changes
|
||||
@@ -76,14 +82,14 @@ UniversalBle.onConnectionChanged = (String deviceId, BleConnectionState state) {
|
||||
}
|
||||
```
|
||||
|
||||
### Discovering Services of BLE Peripheral
|
||||
### Discovering Services
|
||||
|
||||
```dart
|
||||
// Discover services of a specific `deviceId`
|
||||
// Discover services of a specific device
|
||||
UniversalBle.discoverServices(deviceId);
|
||||
```
|
||||
|
||||
### Transferring Data between BLE Central & Peripheral
|
||||
### Reading & Writing data
|
||||
|
||||
```dart
|
||||
// Read data from a characteristic
|
||||
@@ -104,37 +110,37 @@ UniversalBle.onValueChanged = (String deviceId, String characteristicId, Uint8Li
|
||||
UniversalBle.setNotifiable(deviceId, serviceId, characteristicId, BleInputProperty.disabled);
|
||||
```
|
||||
|
||||
### Pairing BLE Central & Peripheral
|
||||
### Pairing
|
||||
|
||||
```dart
|
||||
// Pair
|
||||
UniversalBle.pair(deviceId);
|
||||
|
||||
// Get the pairing result
|
||||
UniversalBle.onPairStateChange = (String deviceId, bool isPaired, String? error) {
|
||||
UniversalBle.onPairingStateChange = (String deviceId, bool isPaired, String? error) {
|
||||
// Handle Pairing state change
|
||||
}
|
||||
|
||||
// Unpair
|
||||
UniversalBle.unPair(deviceId);
|
||||
|
||||
// Check current pairing status
|
||||
// Check current pairing state
|
||||
bool isPaired = UniversalBle.isPaired(deviceId);
|
||||
```
|
||||
|
||||
### Enable Bluetooth Programmatically
|
||||
### Bluetooth Availability
|
||||
|
||||
```dart
|
||||
UniversalBle.enableBluetooth();
|
||||
```
|
||||
// Get current Bluetooth availability state
|
||||
AvailabilityState availabilityState = UniversalBle.getBluetoothAvailabilityState(); // e.g. poweredOff or poweredOn,
|
||||
|
||||
### Receiving BLE Availability Changes
|
||||
|
||||
```dart
|
||||
// Receive Bluetooth availability changes
|
||||
UniversalBle.onAvailabilityChange = (state) {
|
||||
// Handle BLE availability states
|
||||
// e.g. poweredOff or poweredOn,
|
||||
// Handle the new Bluetooth availability state
|
||||
};
|
||||
|
||||
// Enable Bluetooth programmatically
|
||||
UniversalBle.enableBluetooth();
|
||||
```
|
||||
|
||||
## Platform-Specific Setup
|
||||
@@ -164,6 +170,18 @@ Add `NSBluetoothPeripheralUsageDescription` and `NSBluetoothAlwaysUsageDescripti
|
||||
|
||||
Add the `Bluetooth` capability to the macOS app from Xcode.
|
||||
|
||||
### Web
|
||||
|
||||
On web, you have to add filters and specify optional services when scanning for devices. The parameter is ignored on other platforms.
|
||||
|
||||
```dart
|
||||
UniversalBle.startScan(
|
||||
webRequestOptions: WebRequestOptionsBuilder.acceptAllDevices(
|
||||
optionalServices: ["SERVICE_UUID"],
|
||||
),
|
||||
);
|
||||
```
|
||||
|
||||
## Customizing Platform Implementation of UniversalBle
|
||||
|
||||
```dart
|
||||
|
||||
@@ -39,9 +39,9 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
super.initState();
|
||||
UniversalBle.onConnectionChanged = _handleConnectionChange;
|
||||
UniversalBle.onValueChanged = _handleValueChange;
|
||||
UniversalBle.onPairStateChange =
|
||||
UniversalBle.onPairingStateChange =
|
||||
(String deviceId, bool isPaired, String? error) {
|
||||
print('OnPairStateChange $deviceId, $isPaired');
|
||||
print('OnPairingStateChange $deviceId, $isPaired');
|
||||
setState(() {
|
||||
if (error != null) {
|
||||
results.add("PairStateChangeError (Paired: $isPaired): $error ");
|
||||
|
||||
@@ -378,7 +378,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
version: "0.8.3"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -154,8 +154,8 @@ class UniversalBle {
|
||||
_platform.onValueChanged = onValueChanged;
|
||||
|
||||
/// To get pair state changes,
|
||||
static set onPairStateChange(OnPairStateChange pairStateChange) =>
|
||||
_platform.onPairStateChange = pairStateChange;
|
||||
static set onPairingStateChange(OnPairingStateChange pairingStateChange) =>
|
||||
_platform.onPairingStateChange = pairingStateChange;
|
||||
|
||||
static UniversalBlePlatform _defaultPlatform() {
|
||||
if (kIsWeb) return UniversalBleWeb.instance;
|
||||
@@ -175,5 +175,5 @@ typedef OnScanResult = void Function(BleScanResult scanResult);
|
||||
|
||||
typedef OnAvailabilityChange = void Function(AvailabilityState state);
|
||||
|
||||
typedef OnPairStateChange = void Function(
|
||||
typedef OnPairingStateChange = void Function(
|
||||
String deviceId, bool isPaired, String? error);
|
||||
|
||||
@@ -314,7 +314,7 @@ class UniversalBleLinux extends UniversalBlePlatform {
|
||||
onScanResult?.call(device.toBleScanResult());
|
||||
break;
|
||||
case BluezProperty.paired:
|
||||
onPairStateChange?.call(device.address, device.paired, null);
|
||||
onPairingStateChange?.call(device.address, device.paired, null);
|
||||
break;
|
||||
case BluezProperty.legacyPairing:
|
||||
case BluezProperty.servicesResolved:
|
||||
|
||||
@@ -122,7 +122,7 @@ class UniversalBlePigeonChannel extends UniversalBlePlatform {
|
||||
(String deviceId, String characteristicId, Uint8List value) =>
|
||||
onValueChanged?.call(deviceId, characteristicId, value),
|
||||
pairStateChange: (String deviceId, bool isPaired, String? error) =>
|
||||
onPairStateChange?.call(deviceId, isPaired, error),
|
||||
onPairingStateChange?.call(deviceId, isPaired, error),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class _UniversalBleCallbackHandler extends UniversalBleCallbackChannel {
|
||||
OnScanResult scanResult;
|
||||
OnConnectionChanged connectionChanged;
|
||||
OnValueChanged valueChanged;
|
||||
OnPairStateChange pairStateChange;
|
||||
OnPairingStateChange pairStateChange;
|
||||
|
||||
_UniversalBleCallbackHandler({
|
||||
required this.availabilityChange,
|
||||
|
||||
@@ -48,5 +48,5 @@ abstract class UniversalBlePlatform {
|
||||
OnScanResult? onScanResult;
|
||||
OnConnectionChanged? onConnectionChanged;
|
||||
OnValueChanged? onValueChanged;
|
||||
OnPairStateChange? onPairStateChange;
|
||||
OnPairingStateChange? onPairingStateChange;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
name: universal_ble
|
||||
description: A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE) plugin for Flutter
|
||||
version: 0.8.2
|
||||
version: 0.8.3
|
||||
homepage: https://navideck.com
|
||||
repository: https://github.com/Navideck/universal_ble
|
||||
issue_tracker: https://github.com/Navideck/universal_ble/issues
|
||||
|
||||
Reference in New Issue
Block a user