vtj_bluetooth_package 1.0.0
vtj_bluetooth_package: ^1.0.0 copied to clipboard
A Flutter package for seamless Bluetooth Low Energy (BLE) communication with Ventriject medical devices. Provides easy-to-use APIs for device discovery, connection management, and data exchange.
Ventriject Bluetooth Package #
A Flutter package that provides seamless Bluetooth Low Energy (BLE) communication with Ventriject medical devices. This package handles device discovery, connection management, and data exchange with Ventriject's proprietary BLE protocol.
Features #
- 🔍 Easy device discovery and filtering for Ventriject devices
- 🔄 Automatic connection management and state handling
- 📶 Signal strength monitoring
- 🔒 Secure communication with Ventriject devices
- 📊 Data parsing and validation
- 🔄 Automatic reconnection capabilities
- 📱 Platform support: Android and iOS
Getting Started #
Prerequisites #
Add the package to your pubspec.yaml:
dependencies:
vtj_bluetooth_package: ^1.0.0
Android Configuration #
Add these permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
iOS Configuration #
Add these entries to your Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need BLE permission to connect to Ventriject devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need BLE permission to connect to Ventriject devices</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location permission to scan for BLE devices</string>
Usage #
1. Initialize the Repository #
import 'package:vtj_bluetooth_package/vtj_bluetooth_package.dart';
final vtjRepository = VtjDevicesRepositoryImpl(BluePlusVtjDatasource());
2. Scan for Ventriject Devices #
// Start scanning for devices
await vtjRepository.startScan();
// Listen for scan results
final subscription = vtjRepository.getScanResults().listen((result) {
result.fold(
(failure) => print('Error: ${failure.message}'),
(devices) {
for (var device in devices) {
print('Found device: ${device.name} (${device.id})');
}
},
);
});
// Don't forget to cancel the subscription when done
// subscription.cancel();
3. Connect to a Device #
final result = await vtjRepository.connectToDevice(selectedDevice);
result.fold(
(failure) => print('Connection failed: ${failure.message}'),
(connectedDevice) {
print('Connected to ${connectedDevice.name}');
print('Firmware version: ${connectedDevice.firmwareVersion}');
},
);
4. Execute Commands #
Get Device Version
final versionResult = await vtjRepository.getVersion(device);
versionResult.fold(
(error) => print('Error: $error'),
(version) => print('Device version: ${version.version}'),
);
Run Battery Self-Test
final result = await vtjRepository.performBattSelfTest(device);
result.fold(
(failure) => print('Test failed: ${failure.message}'),
(testResult) => print('Battery status: ${testResult.status}'),
);
Run Accelerometer Self-Test
final result = await vtjRepository.performAccelSelfTest(device);
result.fold(
(failure) => print('Test failed: ${failure.message}'),
(testResult) => print('Accelerometer status: ${testResult.status}'),
);
5. Disconnect from Device #
final result = await vtjRepository.disconnect(device);
result.fold(
(failure) => print('Disconnection failed: ${failure.message}'),
(_) => print('Successfully disconnected'),
);
Error Handling #
All operations return Either<VtjFailure, T> where:
VtjFailurecontains error details if the operation failedTis the success result type
Example error handling:
final result = await vtjRepository.connectToDevice(device);
result.fold(
(failure) {
if (failure is PermissionNotGranted) {
// Handle permission errors
} else if (failure is ConnectionError) {
// Handle connection errors
} else {
// Handle other errors
}
},
(device) {
// Handle success
},
);
Troubleshooting #
Common Issues #
-
Bluetooth not enabled:
if (await FlutterBluePlus.isAvailable) { // Bluetooth is available } -
Location Services: On Android, ensure location services are enabled for BLE scanning.
-
Permissions: Always check and request necessary permissions before scanning or connecting.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Support #
For support, please open an issue in the GitHub repository or contact support@ventriject.com.