onEvent method
Called when an event is received by the FSM
Implementation
@override
Future<bool> onEvent(
{required FsmEvent event, required FsmOwner owner}) async {
BleDeviceOwner deviceOwner = owner as BleDeviceOwner;
debugPrintSynchronously("OnEvent: BleDeviceReadyState ${deviceOwner.device.getId()} - Event $event");
if (event is BleDeviceConnectionStateChangedEvent) {
if (event.newState == BleConnectionState.disconnected) {
// Transition to the disconnected state.
await owner
.getFsm()
?.changeState(nextState: BleDeviceDisconnectedState());
}
return true;
}
if (event is BleWriteCharacteristicEvent) {
//await deviceOwner.device.writeCharacteristic(
deviceOwner.device.writeCharacteristic(
serviceUuid: event.serviceUuid,
charUuid: event.charUuid,
value: event.value);
return true;
}
if (event is BleDisconnectDeviceEvent) {
// Transition to disconnecting state to handle user request to disconnect.
//await owner
owner
.getFsm()
?.changeState(nextState: BleDeviceDisconnectingState());
return true;
}
else if (event is BleEnableCharacteristicNotifyEvent) {
//await deviceOwner.device.enableCharacteristicIndicate(serviceUuid: event.serviceUuid, charUuid: event.charUuid);
deviceOwner.device.enableCharacteristicIndicate(serviceUuid: event.serviceUuid, charUuid: event.charUuid);
return true;
}
else if (event is BleDisableCharacteristicNotifyEvent) {
//await deviceOwner.device.disableCharacteristicNotify(serviceUuid: event.serviceUuid, charUuid: event.charUuid);
deviceOwner.device.disableCharacteristicNotify(serviceUuid: event.serviceUuid, charUuid: event.charUuid);
}
return false;
}