Skip to content

Commit

Permalink
add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Aug 9, 2024
1 parent ff90bee commit 66f6ed9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
_bluetoothPlusLogger.info('${event.device.advName} RSSI:${event.rssi}');
BaseStatefulDevice? statefulDevice = ref.read(knownDevicesProvider)[event.device.remoteId.str];
statefulDevice?.rssi.value = event.rssi;
});
}, onError: (e, s) => _bluetoothPlusLogger.warning("Unable to read rssi: $e", e, s));
_onMtuChanged = flutterBluePlus.events.onMtuChanged.listen((event) {
_bluetoothPlusLogger.info('${event.device.advName} MTU:${event.mtu}');
BaseStatefulDevice? statefulDevice = ref.read(knownDevicesProvider)[event.device.remoteId.str];
statefulDevice?.mtu.value = event.mtu;
});
}, onError: (e, s) => _bluetoothPlusLogger.warning("Unable to read mtu: $e", e, s));
_onDiscoveredServicesStreamSubscription = flutterBluePlus.events.onDiscoveredServices.listen((event) async {
//_bluetoothPlusLogger.info('${event.device} ${event.services}');
//Subscribes to all characteristics
Expand All @@ -194,7 +194,7 @@ Future<void> initFlutterBluePlus(InitFlutterBluePlusRef ref) async {
await characteristic.setNotifyValue(true);
}
}
});
}, onError: (e, s) => _bluetoothPlusLogger.warning("Unable to discover services: $e", e, s));
_onCharacteristicReceivedStreamSubscription = flutterBluePlus.events.onCharacteristicReceived.listen((event) async {
_bluetoothPlusLogger.info('onCharacteristicReceived ${event.device.advName} ${event.characteristic.uuid.str} ${event.value}');

Expand Down Expand Up @@ -408,9 +408,10 @@ Future<void> sendMessage(BaseStatefulDevice device, List<int> message, {bool wit
return;
}

Future<void> future = bluetoothCharacteristic.write(message, withoutResponse: withoutResponse && bluetoothCharacteristic.properties.writeWithoutResponse).catchError((e) {
_bluetoothPlusLogger.severe("Unable to send message to ${device.baseDeviceDefinition.btName} $e", e);
});
Future<void> future = bluetoothCharacteristic
.write(message, withoutResponse: withoutResponse && bluetoothCharacteristic.properties.writeWithoutResponse)
.catchError((e) => _bluetoothPlusLogger.warning("Unable to send message to ${device.baseDeviceDefinition.btName} $e", e))
.onError((e, s) => _bluetoothPlusLogger.severe("Unable to send message to ${device.baseDeviceDefinition.btName} $e", e));
await future;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/Definitions/Device/device_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class CommandQueue {
StreamSubscription<BluetoothMessage>? messageQueueStreamSubscription;

void addCommand(BluetoothMessage bluetoothMessage) {
bluetoothLog.info("Adding commands to queue $bluetoothMessage");
if (device.deviceConnectionState.value != ConnectivityState.connected || device.baseStoredDevice.btMACAddress.startsWith("DEV")) {
device.deviceState.value = DeviceState.standby; //Mainly for dev gear. Marks the gear as being idle
return;
Expand Down

0 comments on commit 66f6ed9

Please sign in to comment.