import 'package:control_pad/control_pad.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
final flutterReactiveBle = FlutterReactiveBle();
late QualifiedCharacteristic c;
Future<void> main() async {
runApp(const MaterialApp(
title: 'Control Pad Example',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
const FirstRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('car'),
actions: [
IconButton(
constraints: BoxConstraints.expand(width: 80),
onPressed: () async {
print("pressed");
var serviceUuid =
Uuid.parse("0000180a-0000-1000-8000-00805f9b34fb");
var characteristicUuid =
Uuid.parse("00002a57-0000-1000-8000-00805f9b34fb");
var foundDeviceId = 'FB:DF:BF:CD:83:26';
flutterReactiveBle.connectToDevice(id: foundDeviceId,
connectionTimeout: const Duration(seconds: 5),
).listen((state) async {
if (state.connectionState == DeviceConnectionState.connected) {
print("connected");
await flutterReactiveBle.requestConnectionPriority(deviceId: foundDeviceId, priority: ConnectionPriority.highPerformance);
c = QualifiedCharacteristic(
serviceId: serviceUuid,
characteristicId: characteristicUuid,
deviceId: foundDeviceId);
}
});
},
icon: const Text("BLE", textAlign: TextAlign.center),
),
],
),
body: JoystickView(
onDirectionChanged: (double x, double y) async {
print('$x, $y');
flutterReactiveBle.writeCharacteristicWithoutResponse(c, value: [0x01]);
},
),
);
}
}
我从 Arduino 得到连接确认,但是当尝试使用 writeCharacteristicWithoutResponse 时,Arduino 似乎没有收到任何东西。使用 LightBlue 等应用程序,我可以轻松编写十六进制输入,而 Arduino 接收它们。我对蓝牙没有太多先验知识,想了解我在这里缺少什么。Arduino 代码似乎运行良好,所以问题出在颤振应用程序方面。