Skip to content

Commit

Permalink
Fix the bugs
Browse files Browse the repository at this point in the history
mini firmware
tailcontrol uuids
  • Loading branch information
Codel1417 committed Dec 15, 2024
1 parent 54ae3bc commit 67c3b67
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
29 changes: 16 additions & 13 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class initFlutterBluePlus extends _$initFlutterBluePlus {
return;
}


_onServicesResetStreamSubscription = flutterBluePlus.events.onServicesReset.listen((event) async {
_bluetoothPlusLogger.info("${event.device.advName} onServicesReset");
await event.device.discoverServices();
Expand Down Expand Up @@ -124,15 +123,16 @@ class _MTUChanged extends _$MTUChanged {
statefulDevice?.mtu.value = event.mtu;
}
}

@Riverpod(keepAlive: true)
class _OnDiscoveredServices extends _$OnDiscoveredServices {
StreamSubscription<OnDiscoveredServicesEvent>? streamSubscription;

@override
void build() {
streamSubscription = flutterBluePlus.events.onDiscoveredServices.listen(listener,onError: (e, s) => _bluetoothPlusLogger.warning("Unable to discover services: $e", e, s));
streamSubscription = flutterBluePlus.events.onDiscoveredServices.listen(listener, onError: (e, s) => _bluetoothPlusLogger.warning("Unable to discover services: $e", e, s));
ref.onDispose(
() => streamSubscription?.cancel(),
() => streamSubscription?.cancel(),
);
}

Expand All @@ -141,7 +141,7 @@ class _OnDiscoveredServices extends _$OnDiscoveredServices {
//Subscribes to all characteristics
for (BluetoothService service in event.services) {
BluetoothUartService? bluetoothUartService = uartServices.firstWhereOrNull(
(element) => element.bleDeviceService == service.serviceUuid.str,
(element) => element.bleDeviceService == service.serviceUuid.str,
);
if (bluetoothUartService != null) {
BaseStatefulDevice? statefulDevice = ref.read(knownDevicesProvider)[event.device.remoteId.str];
Expand All @@ -153,6 +153,7 @@ class _OnDiscoveredServices extends _$OnDiscoveredServices {
}
}
}

@Riverpod(keepAlive: true)
class _RSSIChanged extends _$RSSIChanged {
StreamSubscription<OnReadRssiEvent>? streamSubscription;
Expand All @@ -161,7 +162,7 @@ class _RSSIChanged extends _$RSSIChanged {
void build() {
streamSubscription = flutterBluePlus.events.onReadRssi.listen(listener, onError: (e, s) => _bluetoothPlusLogger.warning("Unable to read rssi: $e", e, s));
ref.onDispose(
() => streamSubscription?.cancel(),
() => streamSubscription?.cancel(),
);
}

Expand All @@ -171,6 +172,7 @@ class _RSSIChanged extends _$RSSIChanged {
statefulDevice?.rssi.value = event.rssi;
}
}

@Riverpod(keepAlive: true)
class _OnConnectionStateChanged extends _$OnConnectionStateChanged {
StreamSubscription<OnConnectionStateChangedEvent>? streamSubscription;
Expand All @@ -179,7 +181,7 @@ class _OnConnectionStateChanged extends _$OnConnectionStateChanged {
void build() {
streamSubscription = flutterBluePlus.events.onConnectionStateChanged.listen(listener);
ref.onDispose(
() => streamSubscription?.cancel(),
() => streamSubscription?.cancel(),
);
}

Expand Down Expand Up @@ -218,7 +220,7 @@ class _OnConnectionStateChanged extends _$OnConnectionStateChanged {
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
bluetoothDevice.readRssi().catchError((e) => -1).onError(
(error, stackTrace) => -1,
);
);
BaseDeviceDefinition? baseDeviceDefinition = DeviceRegistry.getByName(event.device.advName);
if (baseDeviceDefinition == null) {
return;
Expand Down Expand Up @@ -276,7 +278,7 @@ class _OnConnectionStateChanged extends _$OnConnectionStateChanged {
_bluetoothPlusLogger.fine('Last gear detected');
// Disable all triggers on last device
ref.read(triggerListProvider).where((element) => element.enabled).forEach(
(element) {
(element) {
element.enabled = false;
},
);
Expand All @@ -297,6 +299,7 @@ class _OnConnectionStateChanged extends _$OnConnectionStateChanged {
}
}
}

@Riverpod(keepAlive: true)
class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
StreamSubscription<OnCharacteristicReceivedEvent>? streamSubscription;
Expand Down Expand Up @@ -328,17 +331,17 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
String value = const Utf8Decoder().convert(values);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value));
statefulDevice.batteryCharging.value = value == "CHARGE ON";
} catch (e, s) {
_bluetoothPlusLogger.warning("Unable to read values: $values", e, s);
} catch (e) {
_bluetoothPlusLogger.warning("Unable to read values: $values", e);
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}"));
return;
}
} else if (statefulDevice.bluetoothUartService.value != null || bluetoothCharacteristic.characteristicUuid == Guid(statefulDevice.bluetoothUartService.value!.bleRxCharacteristic)) {
String value = "";
try {
value = const Utf8Decoder().convert(values);
} catch (e, s) {
_bluetoothPlusLogger.warning("Unable to read values: $values $e", e);
} catch (e) {
_bluetoothPlusLogger.warning("Unable to read values: $values $e");
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}"));
return;
}
Expand Down Expand Up @@ -385,7 +388,7 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
}
}

@Riverpod(keepAlive: true,dependencies: [initFlutterBluePlus])
@Riverpod(keepAlive: true, dependencies: [initFlutterBluePlus])
class _KeepGearAwake extends _$KeepGearAwake {
StreamSubscription? streamSubscription;

Expand Down
8 changes: 4 additions & 4 deletions lib/Backend/Definitions/Device/device_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ final List<BluetoothUartService> uartServices = const [
),
// TailCoNTROL uuids
BluetoothUartService(
bleDeviceService: "19F8ADE2-D0C6-4C0A-912A-30601D9B3060",
bleRxCharacteristic: "5E4D86AC-EF2F-466F-A857-8776D45FFBC2",
bleTxCharacteristic: "567A99D6-A442-4AC0-B676-4993BF95F805",
bleDeviceService: "19f8ade2-d0c6-4c0a-912a-30601d9b3060",
bleRxCharacteristic: "567a99d6-a442-4ac0-b676-4993bf95f805",
bleTxCharacteristic: "5e4d86ac-ef2f-466f-a857-8776d45ffbc2",
),
];

Expand Down Expand Up @@ -234,7 +234,7 @@ class BaseStatefulDevice {

isTailCoNTROL.value = bluetoothUartService.value ==
uartServices.firstWhere(
(element) => element.bleDeviceService == "19F8ADE2-D0C6-4C0A-912A-30601D9B3060",
(element) => element.bleDeviceService == "19f8ade2-d0c6-4c0a-912a-30601d9b3060",
)
? tailControlStatus.tailControl
: tailControlStatus.legacy;
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/device_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DeviceRegistry {
uuid: "5fb21175-fef4-448a-a38b-c472d935abab",
btName: "minitail",
deviceType: DeviceType.miniTail,
fwURL: "https://thetailcompany.com/fw/mini",
fwURL: "https://thetailcompany.com/fw/mini.json",
minVersion: Version(major: 5, minor: 0, patch: 0),
),
BaseDeviceDefinition(
Expand Down
15 changes: 7 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,11 @@ packages:
file_picker:
dependency: "direct main"
description:
path: "."
ref: "3b299bb0cf7f553a150f9074168e9a53155d2a51"
resolved-ref: "3b299bb0cf7f553a150f9074168e9a53155d2a51"
url: "https://github.com/abdelaziz-mahdy/flutter_file_picker"
source: git
version: "8.1.6"
name: file_picker
sha256: "16dc141db5a2ccc6520ebb6a2eb5945b1b09e95085c021d9f914f8ded7f1465c"
url: "https://pub.dev"
source: hosted
version: "8.1.4"
firebase_app_installations:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1025,10 +1024,10 @@ packages:
dependency: transitive
description:
name: image
sha256: "599d08e369969bdf83138f5b4e0a7e823d3f992f23b8a64dd626877c37013533"
sha256: "20842a5ad1555be624c314b0c0cc0566e8ece412f61e859a42efeb6d4101a26c"
url: "https://pub.dev"
source: hosted
version: "4.4.0"
version: "4.5.0"
image_size_getter:
dependency: transitive
description:
Expand Down
6 changes: 1 addition & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies:
# Platform Interfaces
device_info_plus: ^11.2.0
wakelock_plus: ^1.2.8 # Keeps the screen awake
file_picker: ^8.1.5 # used to manually select firmware file
file_picker: 8.1.4 # used to manually select firmware file
path_provider: ^2.1.5 # used to get paths for app storage and cache storage
package_info_plus: ^8.1.2
permission_handler: ^11.3.1
Expand Down Expand Up @@ -150,10 +150,6 @@ dev_dependencies:

dependency_overrides:
collection: 1.19.1
file_picker:
git:
url: https://github.com/abdelaziz-mahdy/flutter_file_picker
ref: 3b299bb0cf7f553a150f9074168e9a53155d2a51
#analyzer: 6.7.0

flutter:
Expand Down

0 comments on commit 67c3b67

Please sign in to comment.