Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4ffb1a9
feat: Added next gen profile
samruddhi-Rahegaonkar Aug 27, 2025
b362f54
fix: updated the logics
samruddhi-Rahegaonkar Aug 28, 2025
f34fbc3
fix: added logs and removed comments
samruddhi-Rahegaonkar Aug 28, 2025
9a7b4b3
fix: added toast for the firmware which does not support next-gen
samruddhi-Rahegaonkar Aug 28, 2025
3f5d401
MTU negotiation has been added
samruddhi-Rahegaonkar Aug 28, 2025
dabc1ee
fix: enable live bitmap streaming for next-gen badges
samruddhi-Rahegaonkar Aug 28, 2025
2e41803
fix: added configuration above settings
samruddhi-Rahegaonkar Aug 30, 2025
b391391
fix: make the textcolor white
samruddhi-Rahegaonkar Aug 30, 2025
8a74318
fix: fixing the failing screenshots
samruddhi-Rahegaonkar Sep 3, 2025
50a7bb7
Merge branch 'development' into streaming_feature
samruddhi-Rahegaonkar Sep 3, 2025
468dbf0
fix: added upstream and fixing errors
samruddhi-Rahegaonkar Sep 3, 2025
f125af2
fix: formatted changed files
samruddhi-Rahegaonkar Sep 3, 2025
72aa317
fix: fixed the errors
samruddhi-Rahegaonkar Sep 3, 2025
2d623be
fix: screenshot tests
samruddhi-Rahegaonkar Sep 3, 2025
8b6c251
fix: screenshot tests
samruddhi-Rahegaonkar Sep 3, 2025
69dc2b6
fix: kept original order to fix screenshot error
samruddhi-Rahegaonkar Sep 4, 2025
d254f23
Merge branch 'development' into streaming_feature
mariobehling Sep 4, 2025
5d510e1
fix: resolve conflicts
samruddhi-Rahegaonkar Sep 7, 2025
41cf81d
fix: resolve screenshot errors
samruddhi-Rahegaonkar Sep 7, 2025
b22b7ce
Merge branch 'development' into streaming_feature
samruddhi-Rahegaonkar Sep 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/bademagic_module/bluetooth/base_ble_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ abstract class NormalBleState extends BleState {
return await processState();
} on Exception catch (e) {
String errorMessage = e.toString().replaceFirst('Exception: ', '');
return CompletedState(isSuccess: false, message: errorMessage);
return CompletedState(
isSuccess: false,
message: errorMessage,
shouldDisconnect: true,
);
}
}
}

abstract class RetryBleState extends BleState {
final logger = Logger();
final toast = ToastUtils();

final _maxRetries = 3;

Future<BleState?> processState();
Expand All @@ -43,6 +46,7 @@ abstract class RetryBleState extends BleState {
logger.e(e);
lastException = e;
attempt++;

if (attempt < _maxRetries) {
logger.d("Retrying ($attempt/$_maxRetries)...");
} else {
Expand All @@ -53,9 +57,10 @@ abstract class RetryBleState extends BleState {
}
}

// After max retries, return a CompletedState indicating failure.
return CompletedState(
isSuccess: false,
message: lastException?.toString() ?? "Unknown error");
isSuccess: false,
message: lastException?.toString() ?? "Unknown error",
shouldDisconnect: true,
);
}
}
31 changes: 30 additions & 1 deletion lib/bademagic_module/bluetooth/completed_state.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
import 'package:badgemagic/bademagic_module/bluetooth/base_ble_state.dart';
import 'package:badgemagic/bademagic_module/bluetooth/datagenerator.dart';

class CompletedState extends NormalBleState {
final bool isSuccess;
final String message;
final TransferMode? mode;
final bool shouldDisconnect;
final DataTransferManager? manager;

CompletedState({required this.isSuccess, required this.message});
CompletedState({
required this.isSuccess,
required this.message,
this.mode,
this.shouldDisconnect = false,
this.manager,
});

@override
Future<BleState?> processState() async {
if (shouldDisconnect && manager?.connectedDevice != null) {
try {
logger.d("Disconnecting device as requested...");

if (mode == TransferMode.streaming && manager!.isStreamingActive) {
await manager!.exitStreamingMode();
await Future.delayed(const Duration(milliseconds: 200));
}

await manager!.connectedDevice!.disconnect();
await Future.delayed(const Duration(milliseconds: 700));
manager!.clearConnectedDevice();

logger.d("Device disconnected successfully");
} catch (e) {
logger.e("Error during disconnection: $e");
}
}
if (isSuccess) {
toast.showToast(message);
} else {
toast.showErrorToast(message);
}

return null;
}
}
51 changes: 22 additions & 29 deletions lib/bademagic_module/bluetooth/connect_state.dart
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
import 'package:badgemagic/bademagic_module/bluetooth/base_ble_state.dart';
import 'package:badgemagic/bademagic_module/bluetooth/completed_state.dart';
import 'package:badgemagic/bademagic_module/bluetooth/datagenerator.dart';
import 'package:badgemagic/bademagic_module/bluetooth/write_state.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'base_ble_state.dart';

class ConnectState extends RetryBleState {
class ConnectState extends NormalBleState {
final ScanResult scanResult;
final DataTransferManager manager;

ConnectState({required this.manager, required this.scanResult});
ConnectState({required this.scanResult, required this.manager});

@override
Future<BleState?> processState() async {
try {
try {
await scanResult.device.disconnect();
logger.d("Pre-emptive disconnect for clean state");
await Future.delayed(const Duration(seconds: 1));
} catch (_) {
logger.d("No existing connection to disconnect");
}

await scanResult.device.connect(autoConnect: false);
BluetoothConnectionState connectionState =
await scanResult.device.connectionState.first;
BluetoothDevice device = scanResult.device;
manager.connectedDevice = device;

if (connectionState == BluetoothConnectionState.connected) {
logger.d("Device connected successfully");
toast.showToast('Device connected successfully.');
try {
toast.showToast("Connecting to ${device.platformName}...");
logger.d("Attempting to connect to ${device.platformName}...");

manager.connectedDevice = scanResult.device;
await device.connect(autoConnect: false);
await Future.delayed(const Duration(milliseconds: 500));

final writeState = WriteState(
device: scanResult.device,
manager: manager,
);
logger.d("Connected to device: ${device.platformName}");
toast.showToast("Connected to ${device.platformName}");

return await writeState.process();
} else {
throw Exception("Failed to connect to the device");
}
return WriteState(manager: manager, device: device);
} catch (e) {
toast.showErrorToast('Failed to connect. Retrying...');
rethrow;
logger.e("Connection failed: $e");
return CompletedState(
isSuccess: false,
message: "Failed to connect to device. Please retry.",
mode: manager.mode,
shouldDisconnect: true,
manager: manager,
);
}
}
}
Loading
Loading