-
Notifications
You must be signed in to change notification settings - Fork 292
feat: next-gen protocol commands (streaming function) #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ctrlVnt
wants to merge
26
commits into
fossasia:development
Choose a base branch
from
ctrlVnt:next-gen-protocol-commands
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6a9d363
feat: next-gen protocol commands (streaming function) - #1808
ctrlVnt dccd4ce
dart format .
ctrlVnt d7af22f
workflow issues
ctrlVnt 70977b3
restore pubspec.lock
ctrlVnt 7cfdb79
pubspeck.lock reset
ctrlVnt 43a6eb1
dart format .
ctrlVnt 16f8473
workflow issues
ctrlVnt a050bc8
Fixed a bug variable
ctrlVnt 57a34d6
Fixed, it works now
ctrlVnt d5a8bbd
Merge branch 'development' into next-gen-protocol-commands
ctrlVnt da538a8
Merge branch 'development' into next-gen-protocol-commands
ctrlVnt 16ef9d0
resolved conflicts
ctrlVnt 78fdee6
Merge branch 'development' into next-gen-protocol-commands
ctrlVnt 4452b58
dart format .
ctrlVnt 4faa761
dart format .
ctrlVnt a83ff11
UI corrections
ctrlVnt 8a47245
Some corrections
ctrlVnt 457f812
Some corrections
ctrlVnt 49c7a7d
restore logic
ctrlVnt 7908ce9
Moved _safeDisconnect when is not nextGeneration
ctrlVnt 952e01e
Merge branch 'development' into next-gen-protocol-commands
ctrlVnt 1f0a078
Added exception for unexpected disconnection
ctrlVnt ab2ebf3
Merge remote-tracking branch 'origin/next-gen-protocol-commands' into…
ctrlVnt af14fb1
Added exception for unexpected disconnection
ctrlVnt 40dea18
Changed commands order
ctrlVnt d07b0d6
changed order of commands
ctrlVnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import 'dart:async'; | ||
| import 'dart:typed_data'; | ||
| import 'package:badgemagic/others/globals.dart'; | ||
| import 'package:universal_ble/universal_ble.dart'; | ||
| import 'base_ble_state.dart'; | ||
| import 'completed_state.dart'; | ||
|
|
||
| class NgCommandState extends NormalBleState { | ||
| final BleDevice device; | ||
| final List<int> command; | ||
|
|
||
| NgCommandState({required this.device, required this.command}); | ||
|
|
||
| @override | ||
| Future<BleState?> processState() async { | ||
| final deviceId = device.deviceId; | ||
| final completer = Completer<int>(); | ||
|
|
||
| await UniversalBle.discoverServices(deviceId); | ||
|
|
||
| await UniversalBle.setNotifiable( | ||
| deviceId, | ||
| ngServiceUuid, | ||
| ngNotifyCharUuid, | ||
| BleInputProperty.notification, | ||
| ); | ||
|
|
||
| late final StreamSubscription sub; | ||
| sub = UniversalBle.characteristicValueStream(deviceId, ngNotifyCharUuid) | ||
| .listen( | ||
| (Uint8List value) { | ||
| if (!completer.isCompleted) { | ||
| completer.complete(value.isNotEmpty ? value[0] : 0xff); | ||
| } | ||
| }, | ||
| onError: (error) { | ||
| if (!completer.isCompleted) { | ||
| completer.completeError(error); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| try { | ||
| await UniversalBle.write( | ||
| deviceId, | ||
| ngServiceUuid, | ||
| ngWriteCharUuid, | ||
| Uint8List.fromList(command), | ||
| withoutResponse: false, | ||
| ); | ||
|
|
||
| final code = await completer.future.timeout(const Duration(seconds: 5)); | ||
|
|
||
| if (code != 0x00) { | ||
| throw Exception( | ||
| "Command rejected by badge (code 0x${code.toRadixString(16)})"); | ||
| } | ||
|
|
||
| return CompletedState( | ||
| isSuccess: true, message: "Command executed", isNextGen: true); | ||
|
ctrlVnt marked this conversation as resolved.
|
||
| } finally { | ||
| await sub.cancel(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.