mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-29 21:50:32 +10:00
Merge pull request #117 from wel97459/dev-reconnection
This cures a race condition that was messing up the disconnection handler. Before the bluetooth device was fully connected _handleDisconnection() was being called from the lisener.
This commit is contained in:
@@ -706,7 +706,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
_connectionSubscription = device.connectionState.listen((state) {
|
_connectionSubscription = device.connectionState.listen((state) {
|
||||||
if (state == BluetoothConnectionState.disconnected) {
|
if (state == BluetoothConnectionState.disconnected && isConnected) {
|
||||||
_handleDisconnection();
|
_handleDisconnection();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -959,12 +959,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
if (!isConnected) return;
|
if (!isConnected) return;
|
||||||
if (_batteryRequested && !force) return;
|
if (_batteryRequested && !force) return;
|
||||||
_batteryRequested = true;
|
_batteryRequested = true;
|
||||||
try {
|
await sendFrame(buildGetBattAndStorageFrame());
|
||||||
await sendFrame(buildGetBattAndStorageFrame());
|
|
||||||
} catch (e) {
|
|
||||||
// Connection likely lost - trigger disconnection handling
|
|
||||||
_handleDisconnection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startBatteryPolling() {
|
void _startBatteryPolling() {
|
||||||
@@ -995,6 +990,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _requestDeviceInfo() async {
|
Future<void> _requestDeviceInfo() async {
|
||||||
|
if (!isConnected || _awaitingSelfInfo) return;
|
||||||
_awaitingSelfInfo = true;
|
_awaitingSelfInfo = true;
|
||||||
await sendFrame(buildDeviceQueryFrame());
|
await sendFrame(buildDeviceQueryFrame());
|
||||||
await sendFrame(buildAppStartFrame());
|
await sendFrame(buildAppStartFrame());
|
||||||
|
|||||||
Reference in New Issue
Block a user