feat: working connection, conn setting, and gear ratio setting for universal shifters
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
import 'package:abawo_bt_app/util/constants.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart' show DeviceIdentifier;
|
||||
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'bluetooth_device_model.freezed.dart';
|
||||
@ -12,6 +15,24 @@ enum DeviceType {
|
||||
other,
|
||||
}
|
||||
|
||||
DeviceType deviceTypeFromUuids(List<Uuid> uuids) {
|
||||
if (uuids.any((uuid) => isAbawoUniversalShiftersDeviceGuid(uuid))) {
|
||||
return DeviceType.universalShifters;
|
||||
}
|
||||
return DeviceType.other;
|
||||
}
|
||||
|
||||
DeviceType deviceTypeFromString(String type) {
|
||||
return DeviceType.values.firstWhere(
|
||||
(e) => e.toString().split('.').last == type,
|
||||
orElse: () => DeviceType.other,
|
||||
);
|
||||
}
|
||||
|
||||
String deviceTypeToString(DeviceType type) {
|
||||
return type.toString().split('.').last;
|
||||
}
|
||||
|
||||
/// Model representing a Bluetooth device
|
||||
@freezed
|
||||
abstract class BluetoothDeviceModel with _$BluetoothDeviceModel {
|
||||
@ -25,23 +46,28 @@ abstract class BluetoothDeviceModel with _$BluetoothDeviceModel {
|
||||
/// MAC address of the device
|
||||
required String address,
|
||||
|
||||
/// Signal strength indicator (RSSI)
|
||||
int? rssi,
|
||||
|
||||
/// Type of the device
|
||||
@Default(DeviceType.other) DeviceType type,
|
||||
|
||||
/// Whether the device is currently connected
|
||||
@Default(false) bool isConnected,
|
||||
|
||||
/// Additional device information
|
||||
Map<String, dynamic>? manufacturerData,
|
||||
|
||||
/// Service UUIDs advertised by the device
|
||||
List<String>? serviceUuids,
|
||||
/// Identifier of the device
|
||||
@DeviceIdentJsonConverter() required DeviceIdentifier deviceIdent,
|
||||
}) = _BluetoothDeviceModel;
|
||||
|
||||
/// Create a BluetoothDeviceModel from JSON
|
||||
factory BluetoothDeviceModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$BluetoothDeviceModelFromJson(json);
|
||||
}
|
||||
|
||||
class DeviceIdentJsonConverter
|
||||
implements JsonConverter<DeviceIdentifier, String> {
|
||||
const DeviceIdentJsonConverter();
|
||||
|
||||
@override
|
||||
DeviceIdentifier fromJson(String json) => DeviceIdentifier(json);
|
||||
|
||||
@override
|
||||
String toJson(DeviceIdentifier object) => object.str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user