connect method
Implementation
Future<bool> connect(BluetoothDevice device) async {
try {
await disconnect();
_connection = await BluetoothConnection.toAddress(device.address);
print("Connected to ${device.name}");
_connection!.input!.listen((data) {
_onDataReceived(data);
}, onDone: () {
print("Bluetooth Connection Closed");
});
Timer.periodic(
const Duration(milliseconds: 10),
(timer) {
_settingBuffer();
if(timer.tick%100 == 0 && lastFhr!=null){
_dataStreamController.add(lastFhr!);
}
},
);
return true;
} catch (e) {
print('Connection error: $e');
return false;
}
}