refactor: remove direct trainer address assignment
This commit is contained in:
@ -657,18 +657,6 @@ class CentralStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> parseMacToLittleEndianBytes(String macAddress) {
|
|
||||||
final compact = macAddress.replaceAll(':', '').replaceAll('-', '');
|
|
||||||
if (compact.length != 12) {
|
|
||||||
throw FormatException('Invalid MAC address format: $macAddress');
|
|
||||||
}
|
|
||||||
final bytes = <int>[];
|
|
||||||
for (int i = 0; i < compact.length; i += 2) {
|
|
||||||
bytes.add(int.parse(compact.substring(i, i + 2), radix: 16));
|
|
||||||
}
|
|
||||||
return bytes.reversed.toList(growable: false);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<int> encodeTrainerAddress(TrainerAddress address) {
|
List<int> encodeTrainerAddress(TrainerAddress address) {
|
||||||
if (address.flags < 0 || address.flags > 0xff) {
|
if (address.flags < 0 || address.flags > 0xff) {
|
||||||
throw FormatException('Invalid trainer address flags: ${address.flags}');
|
throw FormatException('Invalid trainer address flags: ${address.flags}');
|
||||||
|
|||||||
@ -46,22 +46,6 @@ class ShifterService {
|
|||||||
static const int _gearRatioPayloadBytes = _gearRatioSlots + 1;
|
static const int _gearRatioPayloadBytes = _gearRatioSlots + 1;
|
||||||
static const int _gearRatioWriteMtu = 64;
|
static const int _gearRatioWriteMtu = 64;
|
||||||
|
|
||||||
Future<Result<void>> writeConnectToAddress(String bikeDeviceId) async {
|
|
||||||
try {
|
|
||||||
final payload = parseMacToLittleEndianBytes(bikeDeviceId);
|
|
||||||
return _requireBluetooth.writeCharacteristic(
|
|
||||||
buttonDeviceId,
|
|
||||||
universalShifterControlServiceUuid,
|
|
||||||
universalShifterConnectToAddrCharacteristicUuid,
|
|
||||||
payload,
|
|
||||||
);
|
|
||||||
} on FormatException catch (e) {
|
|
||||||
return bail('Could not parse bike address "$bikeDeviceId": $e');
|
|
||||||
} catch (e) {
|
|
||||||
return bail('Failed writing connect address: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Result<void>> writeConnectToTrainerAddress(
|
Future<Result<void>> writeConnectToTrainerAddress(
|
||||||
TrainerAddress trainerAddress,
|
TrainerAddress trainerAddress,
|
||||||
) async {
|
) async {
|
||||||
@ -107,14 +91,6 @@ class ShifterService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<void>> connectButtonToBike(String bikeDeviceId) async {
|
|
||||||
final addrRes = await writeConnectToAddress(bikeDeviceId);
|
|
||||||
if (addrRes.isErr()) {
|
|
||||||
return addrRes;
|
|
||||||
}
|
|
||||||
return writeCommand(UniversalShifterCommand.connectToDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Result<void>> connectButtonToTrainer(
|
Future<Result<void>> connectButtonToTrainer(
|
||||||
TrainerAddress trainerAddress,
|
TrainerAddress trainerAddress,
|
||||||
) async {
|
) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user