mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0996506fd1 | ||
|
|
3ee38ee1e2 | ||
|
|
cf9401d81c | ||
|
|
dbed5cc247 | ||
|
|
625a77fd74 | ||
|
|
f7856cd71a | ||
|
|
3e56c32376 | ||
|
|
56ecad07cd | ||
|
|
de8ef5f10b | ||
|
|
022df97b89 | ||
|
|
662480ef4c | ||
|
|
446743c4cf | ||
|
|
ebb670b328 | ||
|
|
74d253cdc3 | ||
|
|
a368b4a271 | ||
|
|
16a71f4c65 | ||
|
|
3790bca2e7 | ||
|
|
34fd830859 | ||
|
|
9c0be2fe7a | ||
|
|
e5f7f593b2 | ||
|
|
b189a9a435 | ||
|
|
479172f34d | ||
|
|
9eb2a43cd2 | ||
|
|
1110df67d9 | ||
|
|
9a88313199 | ||
|
|
f41560e285 | ||
|
|
4d37a1aca1 | ||
|
|
01fbb0e663 | ||
|
|
91e4bd7475 | ||
|
|
3a111499f1 | ||
|
|
4548981d1b | ||
|
|
d026d26ae9 | ||
|
|
cca7cd7962 |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
github: [jonasbark]
|
||||
open_collective: jonas-bark1
|
||||
custom: ["https://paypal.me/boni"]
|
||||
120
.github/workflows/build.yml
vendored
120
.github/workflows/build.yml
vendored
@@ -10,11 +10,40 @@ jobs:
|
||||
name: Build & Release
|
||||
runs-on: macos-latest
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
pages: write
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
#1 Checkout Repository
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install certificates
|
||||
env:
|
||||
DEVELOPER_ID_APPLICATION_P12_BASE64_MAC: ${{ secrets.DEVELOPER_ID_APPLICATION_P12_BASE64_MAC }}
|
||||
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
|
||||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
|
||||
run: |
|
||||
# create variables
|
||||
DEVELOPER_ID_APPLICATION_CERTIFICATE_PATH=$RUNNER_TEMP/build_developerID_application_certificate.p12
|
||||
KEYCHAIN_PATH=$RUNNER_TEMP/pg-signing.keychain-db
|
||||
|
||||
# import certificate and provisioning profile from secrets
|
||||
echo -n "$DEVELOPER_ID_APPLICATION_P12_BASE64_MAC" | base64 --decode --output $DEVELOPER_ID_APPLICATION_CERTIFICATE_PATH
|
||||
|
||||
# create temporary keychain
|
||||
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
|
||||
# security default-keychain -s $KEYCHAIN_PATH
|
||||
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
|
||||
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
|
||||
|
||||
# import certificate to keychain
|
||||
security import $DEVELOPER_ID_APPLICATION_CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
|
||||
security list-keychain -d user -s $KEYCHAIN_PATH
|
||||
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
|
||||
|
||||
#2 Setup Java
|
||||
- name: Set Up Java
|
||||
uses: actions/setup-java@v3.12.0
|
||||
@@ -32,16 +61,28 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: flutter pub get
|
||||
|
||||
#8 Build app ( macos Build )
|
||||
- name: Build App
|
||||
run: flutter build macos --release
|
||||
|
||||
- name: Code Signing
|
||||
run: /usr/bin/codesign --deep --force -s "$DEVELOPER_ID_APPLICATION_SIGNING_IDENTITY" --options runtime SwiftControl.app -v
|
||||
working-directory: build/macos/Build/Products/Release
|
||||
env:
|
||||
DEVELOPER_ID_APPLICATION_SIGNING_IDENTITY: ${{ secrets.DEVELOPER_ID_APPLICATION_SIGNING_IDENTITY }}
|
||||
|
||||
#6 Building APK
|
||||
- name: Build APK
|
||||
run: flutter build apk --release
|
||||
|
||||
#8 Build app ( macos Build )
|
||||
- name: Build IPA
|
||||
run: flutter build macos --release
|
||||
|
||||
- name: Build Web
|
||||
run: flutter build web --release
|
||||
run: flutter build web --release --base-href "/swiftcontrol/"
|
||||
|
||||
- name: Handle archives
|
||||
run: |
|
||||
cp build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/SwiftControl.android.apk
|
||||
cd build/macos/Build/Products/Release/
|
||||
zip -r SwiftControl.macos.zip SwiftControl.app/
|
||||
|
||||
#9 Upload Artifacts
|
||||
- name: Upload Artifacts
|
||||
@@ -49,8 +90,8 @@ jobs:
|
||||
with:
|
||||
name: Releases
|
||||
path: |
|
||||
build/app/outputs/flutter-apk/app-release.apk
|
||||
build/macos/Build/Products/Release/SwiftControl.app
|
||||
build/app/outputs/flutter-apk/SwiftControl.android.apk
|
||||
build/macos/Build/Products/Release/SwiftControl.macos.zip
|
||||
|
||||
#10 Extract Version
|
||||
- name: Extract version from pubspec.yaml
|
||||
@@ -81,7 +122,7 @@ jobs:
|
||||
- name: Create Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "build/app/outputs/flutter-apk/app-release.apk,build/macos/Build/Products/Release/SwiftControl.app"
|
||||
artifacts: "build/app/outputs/flutter-apk/SwiftControl.android.apk,build/macos/Build/Products/Release/SwiftControl.macos.zip"
|
||||
tag: v${{ env.VERSION }}
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
@@ -93,3 +134,66 @@ jobs:
|
||||
|
||||
- name: Web Deploy
|
||||
uses: actions/deploy-pages@v4
|
||||
|
||||
windows:
|
||||
needs: build
|
||||
name: Build & Release on Windows
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
#1 Checkout Repository
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
#2 Setup Java
|
||||
- name: Set Up Java
|
||||
uses: actions/setup-java@v3.12.0
|
||||
with:
|
||||
distribution: 'oracle'
|
||||
java-version: '17'
|
||||
|
||||
#3 Setup Flutter
|
||||
- name: Set Up Flutter
|
||||
uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: 'stable'
|
||||
|
||||
#4 Install Dependencies
|
||||
- name: Install Dependencies
|
||||
run: flutter pub get
|
||||
|
||||
- name: Build App
|
||||
run: flutter build windows
|
||||
|
||||
- name: Zip directory (Windows)
|
||||
shell: pwsh
|
||||
run: |
|
||||
Compress-Archive -Path "build/windows/x64/runner/Release/*" -DestinationPath "build/windows/x64/runner/Release/SwiftControl.windows.zip"
|
||||
|
||||
#9 Upload Artifacts
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
overwrite: true
|
||||
name: Releases
|
||||
path: |
|
||||
build/windows/x64/runner/Release/SwiftControl.windows.zip
|
||||
|
||||
#10 Extract Version
|
||||
- name: Extract version from pubspec.yaml (Windows)
|
||||
shell: pwsh
|
||||
run: |
|
||||
$version = Select-String '^version: ' pubspec.yaml | ForEach-Object {
|
||||
($_ -split ' ')[1].Trim()
|
||||
}
|
||||
echo "VERSION=$version" >> $env:GITHUB_ENV
|
||||
|
||||
# add artifact to release
|
||||
|
||||
- name: Create Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
allowUpdates: true
|
||||
artifacts: "build/windows/x64/runner/Release/SwiftControl.windows.zip"
|
||||
tag: v${{ env.VERSION }}
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### 1.0.0+4 (2025-03-29)
|
||||
- Zwift Ride: attempt to fix button parsing
|
||||
|
||||
### 1.0.0+3 (2025-03-29)
|
||||
|
||||
- Windows: fix connection by using a different Bluetooth stack (issue #1)
|
||||
- Android: fix non-working touch propagation (issue #2)
|
||||
29
README.md
29
README.md
@@ -2,32 +2,47 @@
|
||||
|
||||
<img src="logo.jpg" alt="SwiftControl Logo"/>
|
||||
|
||||
### Description
|
||||
## Description
|
||||
|
||||
With SwiftControl you can control your favorite trainer app using your Zwift Click, Zwift Ride or Zwift Play devices. Primarily useful to perform virtual gear shifting.
|
||||
|
||||
### Supported Apps
|
||||
|
||||
https://github.com/user-attachments/assets/1f81b674-1628-4763-ad66-5f3ed7a3f159
|
||||
|
||||
|
||||
|
||||
|
||||
## Downloads
|
||||
Get the latest version here: https://github.com/jonasbark/swiftcontrol/releases
|
||||
|
||||
## Supported Apps
|
||||
- MyWhoosh
|
||||
- indieVelo / Training Peaks
|
||||
- let me know if you know others that can benefit
|
||||
|
||||
### Supported Devices
|
||||
## Supported Devices
|
||||
- Zwift Click
|
||||
- Zwift Ride
|
||||
- Zwift Play
|
||||
|
||||
### Supported Platforms
|
||||
## Supported Platforms
|
||||
- Android
|
||||
- macOS
|
||||
- Windows
|
||||
- [Web](https://jonasbark.github.io/swiftcontrol/) (you won't be able to do much)
|
||||
|
||||
### How does it work?
|
||||
## How does it work?
|
||||
The app connects to your Zwift device automatically.
|
||||
|
||||
- When using Android a "click" on a certain part of the screen is simulated to trigger the action.
|
||||
- When using macOS or Windows a keyboard click is used to trigger the action. Typically + and - keys are used to shift gears, while MyWhoosh uses K and I keys.
|
||||
|
||||
### TODO
|
||||
## Donate
|
||||
Please consider donating to support the development of this app.
|
||||
|
||||
[](https://paypal.me/boni)
|
||||
|
||||
## TODO
|
||||
- test Zwift Ride
|
||||
- confirm that Windows release works
|
||||
- implement more actions for Play + Ride
|
||||
- shorebird?
|
||||
|
||||
@@ -45,6 +45,19 @@ class FlutterError (
|
||||
val details: Any? = null
|
||||
) : Throwable()
|
||||
|
||||
enum class MediaAction(val raw: Int) {
|
||||
PLAY_PAUSE(0),
|
||||
NEXT(1),
|
||||
VOLUME_UP(2),
|
||||
VOLUME_DOWN(3);
|
||||
|
||||
companion object {
|
||||
fun ofRaw(raw: Int): MediaAction? {
|
||||
return values().firstOrNull { it.raw == raw }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
data class WindowEvent (
|
||||
val packageName: String,
|
||||
@@ -85,6 +98,11 @@ private open class AccessibilityApiPigeonCodec : StandardMessageCodec() {
|
||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||
return when (type) {
|
||||
129.toByte() -> {
|
||||
return (readValue(buffer) as Long?)?.let {
|
||||
MediaAction.ofRaw(it.toInt())
|
||||
}
|
||||
}
|
||||
130.toByte() -> {
|
||||
return (readValue(buffer) as? List<Any?>)?.let {
|
||||
WindowEvent.fromList(it)
|
||||
}
|
||||
@@ -94,8 +112,12 @@ private open class AccessibilityApiPigeonCodec : StandardMessageCodec() {
|
||||
}
|
||||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
|
||||
when (value) {
|
||||
is WindowEvent -> {
|
||||
is MediaAction -> {
|
||||
stream.write(129)
|
||||
writeValue(stream, value.raw)
|
||||
}
|
||||
is WindowEvent -> {
|
||||
stream.write(130)
|
||||
writeValue(stream, value.toList())
|
||||
}
|
||||
else -> super.writeValue(stream, value)
|
||||
@@ -110,6 +132,7 @@ interface Accessibility {
|
||||
fun hasPermission(): Boolean
|
||||
fun openPermissions()
|
||||
fun performTouch(x: Double, y: Double)
|
||||
fun controlMedia(action: MediaAction)
|
||||
|
||||
companion object {
|
||||
/** The codec used by Accessibility. */
|
||||
@@ -170,6 +193,24 @@ interface Accessibility {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.accessibility.Accessibility.controlMedia$separatedMessageChannelSuffix", codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val args = message as List<Any?>
|
||||
val actionArg = args[0] as MediaAction
|
||||
val wrapped: List<Any?> = try {
|
||||
api.controlMedia(actionArg)
|
||||
listOf(null)
|
||||
} catch (exception: Throwable) {
|
||||
wrapError(exception)
|
||||
}
|
||||
reply.reply(wrapped)
|
||||
}
|
||||
} else {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.jonasbark.accessibility
|
||||
|
||||
import Accessibility
|
||||
import MediaAction
|
||||
import PigeonEventSink
|
||||
import StreamEventsStreamHandler
|
||||
import WindowEvent
|
||||
@@ -64,6 +65,19 @@ class AccessibilityPlugin: FlutterPlugin, MethodCallHandler, Accessibility {
|
||||
Observable.toService?.performTouch(x = x, y = y) ?: error("Service not running")
|
||||
}
|
||||
|
||||
override fun controlMedia(action: MediaAction) {
|
||||
val audioService = context.getSystemService(Context.AUDIO_SERVICE) as android.media.AudioManager
|
||||
when (action) {
|
||||
MediaAction.PLAY_PAUSE -> {
|
||||
audioService.dispatchMediaKeyEvent(android.view.KeyEvent(android.view.KeyEvent.ACTION_DOWN, android.view.KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))
|
||||
audioService.dispatchMediaKeyEvent(android.view.KeyEvent(android.view.KeyEvent.ACTION_UP, android.view.KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE))
|
||||
}
|
||||
MediaAction.NEXT -> audioService.dispatchMediaKeyEvent(android.view.KeyEvent(android.view.KeyEvent.ACTION_DOWN, android.view.KeyEvent.KEYCODE_MEDIA_NEXT))
|
||||
MediaAction.VOLUME_DOWN -> audioService.adjustVolume(android.media.AudioManager.ADJUST_LOWER, android.media.AudioManager.FLAG_SHOW_UI)
|
||||
MediaAction.VOLUME_UP -> audioService.adjustVolume(android.media.AudioManager.ADJUST_RAISE, android.media.AudioManager.FLAG_SHOW_UI)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class EventListener : StreamEventsStreamHandler(), Receiver {
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.util.Log
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_PANE_DISAPPEARED
|
||||
import android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED
|
||||
import android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
|
||||
|
||||
|
||||
@@ -26,11 +27,14 @@ class AccessibilityService : AccessibilityService(), Listener {
|
||||
Observable.toService = null
|
||||
}
|
||||
|
||||
private val ignorePackages = listOf("com.android.systemui", "com.android.launcher", "com.android.settings")
|
||||
|
||||
override fun onAccessibilityEvent(event: AccessibilityEvent) {
|
||||
Log.w("Acc", "onAccessibilityEvent: ${event.packageName} ${event.eventType} ${event.contentChangeTypes}")
|
||||
if (event.packageName == null || rootInActiveWindow == null) {
|
||||
return
|
||||
}
|
||||
if (event.contentChangeTypes == CONTENT_CHANGE_TYPE_PANE_DISAPPEARED) {
|
||||
if (event.eventType != TYPE_WINDOW_STATE_CHANGED || event.packageName in ignorePackages) {
|
||||
// we're not interested
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,8 +7,12 @@ abstract class Accessibility {
|
||||
void openPermissions();
|
||||
|
||||
void performTouch(double x, double y);
|
||||
|
||||
void controlMedia(MediaAction action);
|
||||
}
|
||||
|
||||
enum MediaAction { playPause, next, volumeUp, volumeDown }
|
||||
|
||||
class WindowEvent {
|
||||
final String packageName;
|
||||
final int windowHeight;
|
||||
|
||||
@@ -15,6 +15,13 @@ PlatformException _createConnectionError(String channelName) {
|
||||
);
|
||||
}
|
||||
|
||||
enum MediaAction {
|
||||
playPause,
|
||||
next,
|
||||
volumeUp,
|
||||
volumeDown,
|
||||
}
|
||||
|
||||
class WindowEvent {
|
||||
WindowEvent({
|
||||
required this.packageName,
|
||||
@@ -77,8 +84,11 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
if (value is int) {
|
||||
buffer.putUint8(4);
|
||||
buffer.putInt64(value);
|
||||
} else if (value is WindowEvent) {
|
||||
} else if (value is MediaAction) {
|
||||
buffer.putUint8(129);
|
||||
writeValue(buffer, value.index);
|
||||
} else if (value is WindowEvent) {
|
||||
buffer.putUint8(130);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
@@ -89,6 +99,9 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 129:
|
||||
final int? value = readValue(buffer) as int?;
|
||||
return value == null ? null : MediaAction.values[value];
|
||||
case 130:
|
||||
return WindowEvent.decode(readValue(buffer)!);
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
@@ -184,6 +197,29 @@ class Accessibility {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> controlMedia(MediaAction action) async {
|
||||
final String pigeonVar_channelName = 'dev.flutter.pigeon.accessibility.Accessibility.controlMedia$pigeonVar_messageChannelSuffix';
|
||||
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[action]);
|
||||
final List<Object?>? pigeonVar_replyList =
|
||||
await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Stream<WindowEvent> streamEvents( {String instanceName = ''}) {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Create a report to help us improve
|
||||
title: "fix: "
|
||||
labels: bug
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Steps To Reproduce**
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected Behavior**
|
||||
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional Context**
|
||||
|
||||
Add any other context about the problem here.
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Build System
|
||||
about: Changes that affect the build system or external dependencies
|
||||
title: "build: "
|
||||
labels: build
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Describe what changes need to be done to the build system and why.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] The build system is passing
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Chore
|
||||
about: Other changes that don't modify src or test files
|
||||
title: "chore: "
|
||||
labels: chore
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what change is needed and why. If this changes code then please use another issue type.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] No functional changes to the code
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Continuous Integration
|
||||
about: Changes to the CI configuration files and scripts
|
||||
title: "ci: "
|
||||
labels: ci
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Describe what changes need to be done to the ci/cd system and why.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] The ci system is passing
|
||||
@@ -1 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Documentation
|
||||
about: Improve the documentation so all collaborators have a common understanding
|
||||
title: "docs: "
|
||||
labels: documentation
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what documentation you are looking to add or improve.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] Requirements go here
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
name: Feature Request
|
||||
about: A new feature to be added to the project
|
||||
title: "feat: "
|
||||
labels: feature
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what you are looking to add. The more context the better.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] Checklist of requirements to be fulfilled
|
||||
|
||||
**Additional Context**
|
||||
|
||||
Add any other context or screenshots about the feature request go here.
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Performance Update
|
||||
about: A code change that improves performance
|
||||
title: "perf: "
|
||||
labels: performance
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what code needs to be changed and what the performance impact is going to be. Bonus point's if you can tie this directly to user experience.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] There is no drop in test coverage.
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Refactor
|
||||
about: A code change that neither fixes a bug nor adds a feature
|
||||
title: "refactor: "
|
||||
labels: refactor
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what needs to be refactored and why. Please provide links to related issues (bugs or upcoming features) in order to help prioritize.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] There is no drop in test coverage.
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
name: Revert Commit
|
||||
about: Reverts a previous commit
|
||||
title: "revert: "
|
||||
labels: revert
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Provide a link to a PR/Commit that you are looking to revert and why.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] Change has been reverted
|
||||
- [ ] No change in test coverage has happened
|
||||
- [ ] A new ticket is created for any follow on work that needs to happen
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Style Changes
|
||||
about: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc)
|
||||
title: "style: "
|
||||
labels: style
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
Clearly describe what you are looking to change and why.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] There is no drop in test coverage.
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
name: Test
|
||||
about: Adding missing tests or correcting existing tests
|
||||
title: "test: "
|
||||
labels: test
|
||||
---
|
||||
|
||||
**Description**
|
||||
|
||||
List out the tests that need to be added or changed. Please also include any information as to why this was not covered in the past.
|
||||
|
||||
**Requirements**
|
||||
|
||||
- [ ] There is no drop in test coverage.
|
||||
@@ -1,27 +0,0 @@
|
||||
<!--
|
||||
Thanks for contributing!
|
||||
|
||||
Provide a description of your changes below and a general summary in the title
|
||||
|
||||
Please look at the following checklist to ensure that your PR can be accepted quickly:
|
||||
-->
|
||||
|
||||
## Status
|
||||
|
||||
**READY/IN DEVELOPMENT/HOLD**
|
||||
|
||||
## Description
|
||||
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Type of Change
|
||||
|
||||
<!--- Put an `x` in all the boxes that apply: -->
|
||||
|
||||
- [ ] ✨ New feature (non-breaking change which adds functionality)
|
||||
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
|
||||
- [ ] 🧹 Code refactor
|
||||
- [ ] ✅ Build configuration change
|
||||
- [ ] 📝 Documentation
|
||||
- [ ] 🗑️ Chore
|
||||
21
flutter_blue_plus_windows/.github/cspell.json
vendored
21
flutter_blue_plus_windows/.github/cspell.json
vendored
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"version": "0.2",
|
||||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
|
||||
"dictionaries": ["vgv_allowed", "vgv_forbidden"],
|
||||
"dictionaryDefinitions": [
|
||||
{
|
||||
"name": "vgv_allowed",
|
||||
"path": "https://raw.githubusercontent.com/verygoodopensource/very_good_dictionaries/main/allowed.txt",
|
||||
"description": "Allowed VGV Spellings"
|
||||
},
|
||||
{
|
||||
"name": "vgv_forbidden",
|
||||
"path": "https://raw.githubusercontent.com/verygoodopensource/very_good_dictionaries/main/forbidden.txt",
|
||||
"description": "Forbidden VGV Spellings"
|
||||
}
|
||||
],
|
||||
"useGitignore": true,
|
||||
"words": [
|
||||
"flutter_blue_plus_windows"
|
||||
]
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
version: 2
|
||||
enable-beta-ecosystems: true
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
- package-ecosystem: "pub"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
12
flutter_blue_plus_windows/.gitignore
vendored
12
flutter_blue_plus_windows/.gitignore
vendored
@@ -1,12 +0,0 @@
|
||||
# See https://www.dartlang.org/guides/libraries/private-files
|
||||
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
build/
|
||||
pubspec.lock
|
||||
/.idea/
|
||||
/.flutter-plugins
|
||||
/.flutter-plugins-dependencies
|
||||
|
||||
interanl_example
|
||||
@@ -1,106 +0,0 @@
|
||||
## 1.26.1
|
||||
* Add setOptions.
|
||||
|
||||
## 1.26.0
|
||||
* Set `flutter_blue_plus` upperbound <1.35.0 (due to api changes)
|
||||
|
||||
## 1.25.0
|
||||
* Ensure tracing connection when reconnection occurs after force disconnection.
|
||||
|
||||
## 1.24.22
|
||||
* Upgrade FBP version to `>=1.32.4 <=1.40.0` #24.
|
||||
|
||||
## 1.24.21
|
||||
* fix: startScan() doesn't return correct ScanResult #25
|
||||
|
||||
## 1.24.20
|
||||
* Downgrade FBP version to `>=1.32.4 <=1.33.6` due to the breaking changes.
|
||||
* After upgrade process, the dependencies will be returned to `>=1.34.4 <1.40.0` #24.
|
||||
|
||||
## 1.24.19
|
||||
* Fix a bug with `onValueReceived` of emitting write packet #22.
|
||||
|
||||
## 1.24.18
|
||||
* Add implementation of `BluetoothDeviceWindow.fromId()` #21.
|
||||
|
||||
## 1.24.15
|
||||
* Fix a bug w.r.t. company ID in manufacturer data. (@betto-a #18)
|
||||
|
||||
## 1.24.14
|
||||
* Implement cancelOnDisconnect (@jefflongo #16)
|
||||
|
||||
## 1.24.12
|
||||
* Fix minor bug w.r.t. `characteristic.isNotifying`.
|
||||
|
||||
## 1.24.11
|
||||
* Fix breaking changes of FBP w.r.t. `systemDevices(List withServices)`.
|
||||
|
||||
## 1.24.10
|
||||
* Add support for `cancelWhenScanComplete`
|
||||
|
||||
## 1.24.9
|
||||
* Implement scan filter (including `withServices`, `withRemoteIds`, `withNames`).
|
||||
|
||||
## 1.24.8
|
||||
* Keep manufacturer data when scanning.
|
||||
|
||||
## 1.24.7
|
||||
* Keep service uuids when scanning.
|
||||
|
||||
## 1.24.0
|
||||
* Update `README.md`.
|
||||
|
||||
## 1.23.6
|
||||
* Add unimplemented notification for `read` or `write`.
|
||||
|
||||
## 1.14.0
|
||||
* Remove dependencies `ffi` and `win32` to avoid compile error for web
|
||||
|
||||
## 1.9.5
|
||||
* Apply `flutter blue plus` to `1.28.13`.
|
||||
|
||||
## 1.9.0
|
||||
* Apply a breaking changes `Guid` in `Flutter blue plus` packages.
|
||||
* Use `uuid128` instead of `toString()`.
|
||||
|
||||
## 1.8.10
|
||||
* Fix `Guid` bug related with `Flutter blue plus` packages.
|
||||
|
||||
## 1.8.0
|
||||
* Fix bug with Guid converted from string due to starting/ending with '{ }' in `WinBLE`
|
||||
|
||||
## 1.7.0
|
||||
* Apply `flutter blue plus 1.28.5` (there is several breaking changes.).
|
||||
|
||||
## 1.6.6
|
||||
* Add cache for storing characteristics.
|
||||
|
||||
## 1.6.0
|
||||
* Apply `Flutter blue plus 1.26.0`, (there is a breaking change with `connect()`).
|
||||
|
||||
## 1.5.7
|
||||
* Remove connection by OS when performing `startScan`.
|
||||
|
||||
## 1.5.3
|
||||
* Write logs when connection state stream is started/terminated.
|
||||
|
||||
## 1.5.2
|
||||
* Fix a bug of features added in `1.5.1`
|
||||
|
||||
## 1.5.1
|
||||
* Remove device from connected device list when device is disconnected.
|
||||
|
||||
## 1.5.0
|
||||
* Split functionality of `disconnect` / `removeBond`.
|
||||
|
||||
## 1.4.0
|
||||
* Implement `Subscribe/Unsubscribe Characteristic`.
|
||||
|
||||
## 1.1.0
|
||||
* Implement `Read/Write Characteristic`.
|
||||
|
||||
## 1.0.5
|
||||
* Change `rxdart` version to `0.27.7`.
|
||||
|
||||
## 1.0.0
|
||||
* Initial release (using Github action).
|
||||
@@ -1,7 +0,0 @@
|
||||
Copyright 2023 Himchan Park
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,54 +0,0 @@
|
||||
[](https://pub.dartlang.org/packages/flutter_blue_plus_windows)
|
||||
|
||||
## Flutter Blue Plus Windows
|
||||
|
||||
This project is a wrapper library for `Flutter Blue Plus` and `Win_ble`.
|
||||
It allows `Flutter_blue_plus` to operate on Windows.
|
||||
|
||||
With minimal effort, you can use Flutter Blue Plus on Windows.
|
||||
|
||||
## Usage
|
||||
Only you need to do is change the import statement.
|
||||
|
||||
```dart
|
||||
// instead of import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
// Alternatively, you can hide FlutterBluePlus when importing the FBP statement
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart' hide FlutterBluePlus;
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
```
|
||||
|
||||
### Scan devices
|
||||
```dart
|
||||
final scannedDevices = <ScanResult>{};
|
||||
|
||||
const timeout = Duration(seconds: 3);
|
||||
FlutterBluePlus.startScan(timeout: timeout);
|
||||
|
||||
final sub = FlutterBluePlus.scanResults.expand((e)=>e).listen(scannedDevices.add);
|
||||
|
||||
await Future.delayed(timeout);
|
||||
sub.cancel();
|
||||
scannedDevices.forEach(print);
|
||||
```
|
||||
|
||||
### Connect a device
|
||||
```dart
|
||||
final scannedDevice = scannedDevices
|
||||
.where((scanResult) => scanResult.device.platformName == DEVICE_NAME)
|
||||
.firstOrNull;
|
||||
final device = scannedDevice?.device;
|
||||
device?.connect();
|
||||
```
|
||||
|
||||
### Disconnect the device
|
||||
```dart
|
||||
device?.disconnect();
|
||||
```
|
||||
|
||||
Check out the usage of Flutter Blue Plus on [Flutter Blue Plus](https://pub.dev/packages/flutter_blue_plus)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
library flutter_blue_plus_windows;
|
||||
|
||||
export 'package:flutter_blue_plus/flutter_blue_plus.dart' hide FlutterBluePlus;
|
||||
export 'package:win_ble/win_ble.dart';
|
||||
export 'package:win_ble/win_file.dart';
|
||||
|
||||
export 'src/flutter_blue_plus_windows.dart';
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:win_ble/win_ble.dart';
|
||||
|
||||
extension BluetoothAdapterStateExtension on BleState {
|
||||
BluetoothAdapterState toAdapterState() {
|
||||
switch(this){
|
||||
case BleState.On:
|
||||
return BluetoothAdapterState.on;
|
||||
case BleState.Off:
|
||||
return BluetoothAdapterState.off;
|
||||
case BleState.Unknown:
|
||||
return BluetoothAdapterState.unknown;
|
||||
case BleState.Disabled:
|
||||
return BluetoothAdapterState.unavailable;
|
||||
case BleState.Unsupported:
|
||||
return BluetoothAdapterState.unauthorized;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
extension BluetoothCharacteristicExtension on BluetoothCharacteristic {
|
||||
BmBluetoothCharacteristic toProto() {
|
||||
return BmBluetoothCharacteristic(
|
||||
remoteId: DeviceIdentifier(remoteId.str),
|
||||
serviceUuid: serviceUuid,
|
||||
characteristicUuid: characteristicUuid,
|
||||
descriptors: [for (final d in descriptors) d.toProto()],
|
||||
properties: properties.toProto(),
|
||||
primaryServiceUuid: null, // TODO: API changes
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
|
||||
|
||||
extension BluetoothDescriptorExtension on BluetoothDescriptor {
|
||||
BmBluetoothDescriptor toProto() {
|
||||
return BmBluetoothDescriptor(
|
||||
remoteId: DeviceIdentifier(remoteId.str),
|
||||
serviceUuid: serviceUuid,
|
||||
characteristicUuid: characteristicUuid,
|
||||
descriptorUuid: descriptorUuid,
|
||||
primaryServiceUuid: null, // TODO: API changes
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
extension BluetoothServiceExtension on BluetoothService {
|
||||
BmBluetoothService toProto() {
|
||||
return BmBluetoothService(
|
||||
serviceUuid: serviceUuid,
|
||||
remoteId: DeviceIdentifier(remoteId.str),
|
||||
characteristics: [for (final c in characteristics) c.toProto()],
|
||||
primaryServiceUuid: null, // TODO: API changes
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
|
||||
|
||||
extension CharacteristicPropertiesExtension on CharacteristicProperties {
|
||||
BmCharacteristicProperties toProto() {
|
||||
return BmCharacteristicProperties(
|
||||
broadcast: broadcast,
|
||||
read: read,
|
||||
writeWithoutResponse: writeWithoutResponse,
|
||||
write: write,
|
||||
notify: notify,
|
||||
indicate: indicate,
|
||||
authenticatedSignedWrites: authenticatedSignedWrites,
|
||||
extendedProperties: extendedProperties,
|
||||
notifyEncryptionRequired: notifyEncryptionRequired,
|
||||
indicateEncryptionRequired: indicateEncryptionRequired,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export 'bluetooth_adapter_state_extension.dart';
|
||||
export 'bluetooth_characteristic_extension.dart';
|
||||
export 'bluetooth_descriptor_extension.dart';
|
||||
export 'bluetooth_service_extension.dart';
|
||||
export 'characteristic_properties_extension.dart';
|
||||
@@ -1,3 +0,0 @@
|
||||
export 'extension/extension.dart';
|
||||
export 'windows/windows.dart';
|
||||
export 'wrapper/wrapper.dart';
|
||||
@@ -1,160 +0,0 @@
|
||||
part of 'windows.dart';
|
||||
|
||||
class BluetoothCharacteristicWindows extends BluetoothCharacteristic {
|
||||
final DeviceIdentifier remoteId;
|
||||
final Guid serviceUuid;
|
||||
final Guid? secondaryServiceUuid;
|
||||
final Guid characteristicUuid;
|
||||
final List<BluetoothDescriptor> descriptors;
|
||||
|
||||
final Properties propertiesWinBle;
|
||||
|
||||
BluetoothCharacteristicWindows({
|
||||
required this.remoteId,
|
||||
required this.serviceUuid,
|
||||
required this.characteristicUuid,
|
||||
required this.descriptors,
|
||||
required this.propertiesWinBle,
|
||||
this.secondaryServiceUuid,
|
||||
}) : super.fromProto(
|
||||
BmBluetoothCharacteristic(
|
||||
remoteId: DeviceIdentifier(remoteId.str),
|
||||
serviceUuid: serviceUuid,
|
||||
characteristicUuid: characteristicUuid,
|
||||
descriptors: [
|
||||
for (final descriptor in descriptors)
|
||||
BmBluetoothDescriptor(
|
||||
remoteId: DeviceIdentifier(descriptor.remoteId.str),
|
||||
serviceUuid: descriptor.serviceUuid,
|
||||
characteristicUuid: descriptor.characteristicUuid,
|
||||
descriptorUuid: descriptor.uuid,
|
||||
primaryServiceUuid: null, // TODO: API changes
|
||||
),
|
||||
],
|
||||
properties: BmCharacteristicProperties(
|
||||
broadcast: propertiesWinBle.broadcast ?? false,
|
||||
read: propertiesWinBle.read ?? false,
|
||||
writeWithoutResponse: propertiesWinBle.writeWithoutResponse ?? false,
|
||||
write: propertiesWinBle.write ?? false,
|
||||
notify: propertiesWinBle.notify ?? false,
|
||||
indicate: propertiesWinBle.indicate ?? false,
|
||||
authenticatedSignedWrites: propertiesWinBle.authenticatedSignedWrites ?? false,
|
||||
// TODO: implementation missing
|
||||
extendedProperties: false,
|
||||
// TODO: implementation missing
|
||||
notifyEncryptionRequired: false,
|
||||
// TODO: implementation missing
|
||||
indicateEncryptionRequired: false,
|
||||
),
|
||||
primaryServiceUuid: null, // TODO: API changes
|
||||
),
|
||||
);
|
||||
|
||||
String get _address => remoteId.str.toLowerCase();
|
||||
|
||||
String get _key => "$serviceUuid:$characteristicUuid";
|
||||
|
||||
FBP.BluetoothDevice get device =>
|
||||
FlutterBluePlusWindows.connectedDevices.firstWhere((device) => device.remoteId == remoteId);
|
||||
|
||||
/// this variable is updated:
|
||||
/// - anytime `read()` is called
|
||||
/// - anytime `write()` is called
|
||||
/// - anytime a notification arrives (if subscribed)
|
||||
List<int> get lastValue => FlutterBluePlusWindows._lastChrs[remoteId]?[_key] ?? [];
|
||||
|
||||
/// this stream emits values:
|
||||
/// - anytime `read()` is called
|
||||
/// - anytime `write()` is called
|
||||
/// - anytime a notification arrives (if subscribed)
|
||||
/// - and when first listened to, it re-emits the last value for convenience
|
||||
Stream<List<int>> get lastValueStream => _mergeStreams(
|
||||
[
|
||||
WinBle.characteristicValueStreamOf(
|
||||
address: _address,
|
||||
serviceId: serviceUuid.str128,
|
||||
characteristicId: characteristicUuid.str128,
|
||||
),
|
||||
FlutterBluePlusWindows._charReadWriteStream.where((e) => e.$1 == _key).map((e) => e.$2)
|
||||
],
|
||||
).map((p) => <int>[...p]).newStreamWithInitialValue(lastValue).asBroadcastStream();
|
||||
|
||||
/// this stream emits values:
|
||||
/// - anytime `read()` is called
|
||||
/// - anytime a notification arrives (if subscribed)
|
||||
Stream<List<int>> get onValueReceived => _mergeStreams(
|
||||
[
|
||||
WinBle.characteristicValueStreamOf(
|
||||
address: _address,
|
||||
serviceId: serviceUuid.str128,
|
||||
characteristicId: characteristicUuid.str128,
|
||||
),
|
||||
FlutterBluePlusWindows._charReadStream.where((e) => e.$1 == _key).map((e) => e.$2)
|
||||
],
|
||||
).map((p) => <int>[...p]).asBroadcastStream();
|
||||
|
||||
// TODO: need to verify
|
||||
bool get isNotifying => FlutterBluePlusWindows._isNotifying[remoteId]?[_key] ?? false;
|
||||
|
||||
Future<List<int>> read({int timeout = 15}) async {
|
||||
final value = await WinBle.read(
|
||||
address: _address,
|
||||
serviceId: serviceUuid.str128,
|
||||
characteristicId: characteristicUuid.str128,
|
||||
);
|
||||
FlutterBluePlusWindows._charReadWriteStreamController.add((_key, value));
|
||||
FlutterBluePlusWindows._charReadStreamController.add((_key, value));
|
||||
FlutterBluePlusWindows._lastChrs[remoteId] ??= {};
|
||||
FlutterBluePlusWindows._lastChrs[remoteId]?[_key] = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
Future<void> write(List<int> value,
|
||||
{bool allowLongWrite = false, bool withoutResponse = false, int timeout = 15}) async {
|
||||
await WinBle.write(
|
||||
address: _address,
|
||||
service: serviceUuid.str128,
|
||||
characteristic: characteristicUuid.str128,
|
||||
data: Uint8List.fromList(value),
|
||||
writeWithResponse: !withoutResponse, // propertiesWinBle.writeWithoutResponse ?? false,
|
||||
);
|
||||
FlutterBluePlusWindows._charReadWriteStreamController.add((_key, value));
|
||||
FlutterBluePlusWindows._lastChrs[remoteId] ??= {};
|
||||
FlutterBluePlusWindows._lastChrs[remoteId]?[_key] = value;
|
||||
}
|
||||
|
||||
// TODO: need to verify
|
||||
Future<bool> setNotifyValue(
|
||||
bool notify, {
|
||||
int timeout = 15, // TODO: missing implementation
|
||||
bool forceIndications = false, // TODO: missing implementation
|
||||
}) async {
|
||||
/// unSubscribeFromCharacteristic
|
||||
try {
|
||||
await WinBle.unSubscribeFromCharacteristic(
|
||||
address: _address,
|
||||
serviceId: serviceUuid.str128,
|
||||
characteristicId: characteristicUuid.str128,
|
||||
);
|
||||
} catch (e) {
|
||||
log('WinBle.unSubscribeFromCharacteristic was performed '
|
||||
'before setNotifyValue()');
|
||||
}
|
||||
|
||||
/// set notify
|
||||
try {
|
||||
if (notify) {
|
||||
await WinBle.subscribeToCharacteristic(
|
||||
address: _address,
|
||||
serviceId: serviceUuid.str128,
|
||||
characteristicId: characteristicUuid.str128,
|
||||
);
|
||||
}
|
||||
FlutterBluePlusWindows._isNotifying[remoteId] ??= {};
|
||||
FlutterBluePlusWindows._isNotifying[remoteId]?[_key] = notify;
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,310 +0,0 @@
|
||||
// Bluetooth Device Page:
|
||||
// https://github.com/boskokg/flutter_blue_plus/blob/master/lib/src/bluetooth_device.dart
|
||||
|
||||
part of 'windows.dart';
|
||||
|
||||
class BluetoothDeviceWindows extends FBP.BluetoothDevice {
|
||||
BluetoothDeviceWindows({required super.remoteId});
|
||||
|
||||
// used for 'servicesStream' public api
|
||||
final _services = StreamController<List<BluetoothServiceWindows>>.broadcast();
|
||||
|
||||
// used for 'isDiscoveringServices' public api
|
||||
final _isDiscoveringServices = _StreamController(initialValue: false);
|
||||
|
||||
String get _address => remoteId.str.toLowerCase();
|
||||
|
||||
/// Create a device from an id
|
||||
/// - to connect, this device must have been discovered by your app in a previous scan
|
||||
/// - iOS uses 128-bit uuids the remoteId, e.g. e006b3a7-ef7b-4980-a668-1f8005f84383
|
||||
/// - Android uses 48-bit mac addresses as the remoteId, e.g. 06:E5:28:3B:FD:E0
|
||||
static FBP.BluetoothDevice fromId(String remoteId) {
|
||||
if (Platform.isWindows) {
|
||||
return BluetoothDeviceWindows(remoteId: DeviceIdentifier(remoteId.toUpperCase()));
|
||||
}
|
||||
return FBP.BluetoothDevice.fromId(remoteId);
|
||||
}
|
||||
|
||||
/// platform name
|
||||
/// - this name is kept track of by the platform
|
||||
/// - this name usually persist between app restarts
|
||||
/// - iOS: after you connect, iOS uses the GAP name characteristic (0x2A00)
|
||||
/// if it exists. Otherwise iOS use the advertised name.
|
||||
/// - Android: always uses the advertised name
|
||||
String get platformName => FlutterBluePlusWindows._platformNames[remoteId] ?? "";
|
||||
|
||||
/// Advertised Named
|
||||
/// - this is the name advertised by the device during scanning
|
||||
/// - it is only available after you scan with FlutterBluePlus
|
||||
/// - it is cleared when the app restarts.
|
||||
/// - not all devices advertise a name
|
||||
String get advName => FlutterBluePlusWindows._advNames[remoteId] ?? "";
|
||||
|
||||
// stream return whether or not we are currently discovering services
|
||||
@Deprecated("planed for removal (Jan 2024). It can be easily implemented yourself") // deprecated on Aug 2023
|
||||
Stream<bool> get isDiscoveringServices => _isDiscoveringServices.stream;
|
||||
|
||||
/// Get services
|
||||
/// - returns empty if discoverServices() has not been called
|
||||
/// or if your device does not have any services (rare)
|
||||
List<BluetoothServiceWindows> get servicesList => FlutterBluePlusWindows._knownServices[remoteId] ?? [];
|
||||
|
||||
/// Stream of bluetooth services offered by the remote device
|
||||
/// - this stream is only updated when you call discoverServices()
|
||||
@Deprecated("planed for removal (Jan 2024). It can be easily implemented yourself") // deprecated on Aug 2023
|
||||
Stream<List<BluetoothService>> get servicesStream {
|
||||
if (FlutterBluePlusWindows._knownServices[remoteId] != null) {
|
||||
return _services.stream.newStreamWithInitialValue(
|
||||
FlutterBluePlusWindows._knownServices[remoteId]!,
|
||||
);
|
||||
} else {
|
||||
return _services.stream;
|
||||
}
|
||||
}
|
||||
|
||||
/// Register a subscription to be canceled when the device is disconnected.
|
||||
/// This function simplifies cleanup, so you can prevent creating duplicate stream subscriptions.
|
||||
/// - this is an optional convenience function
|
||||
/// - prevents accidentally creating duplicate subscriptions on each reconnection.
|
||||
/// - [next] if true, the the stream will be canceled only on the *next* disconnection.
|
||||
/// This is useful if you setup your subscriptions before you connect.
|
||||
/// - [delayed] Note: This option is only meant for `connectionState` subscriptions.
|
||||
/// When `true`, we cancel after a small delay. This ensures the `connectionState`
|
||||
/// listener receives the `disconnected` event.
|
||||
void cancelWhenDisconnected(StreamSubscription subscription, {bool next = false, bool delayed = false}) {
|
||||
if (isConnected == false && next == false) {
|
||||
subscription.cancel(); // cancel immediately if already disconnected.
|
||||
} else if (delayed) {
|
||||
FlutterBluePlusWindows._delayedSubscriptions[remoteId] ??= [];
|
||||
FlutterBluePlusWindows._delayedSubscriptions[remoteId]!.add(subscription);
|
||||
} else {
|
||||
FlutterBluePlusWindows._deviceSubscriptions[remoteId] ??= [];
|
||||
FlutterBluePlusWindows._deviceSubscriptions[remoteId]!.add(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this device is currently connected to your app
|
||||
bool get isConnected {
|
||||
return FlutterBluePlusWindows.connectedDevices.contains(this);
|
||||
}
|
||||
|
||||
/// Returns true if this device is currently disconnected from your app
|
||||
bool get isDisconnected => isConnected == false;
|
||||
|
||||
Future<void> connect({
|
||||
Duration? timeout = const Duration(seconds: 35), // TODO: implementation missing
|
||||
bool autoConnect = false, // TODO: implementation missing
|
||||
int? mtu = 512, // TODO: implementation missing
|
||||
}) async {
|
||||
try {
|
||||
await WinBle.connect(_address);
|
||||
FlutterBluePlusWindows._deviceSet.add(this);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> disconnect({
|
||||
int androidDelay = 2000, // TODO: implementation missing
|
||||
int timeout = 35, // TODO: implementation missing
|
||||
bool queue = true, // TODO: implementation missing
|
||||
}) async {
|
||||
try {
|
||||
await WinBle.disconnect(_address);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
} finally {
|
||||
FlutterBluePlusWindows._deviceSet.remove(this);
|
||||
|
||||
FlutterBluePlusWindows._deviceSubscriptions[remoteId]?.forEach((s) => s.cancel());
|
||||
FlutterBluePlusWindows._deviceSubscriptions.remove(remoteId);
|
||||
// use delayed to update the stream before we cancel it
|
||||
Future.delayed(Duration.zero).then((_) {
|
||||
FlutterBluePlusWindows._delayedSubscriptions[remoteId]?.forEach((s) => s.cancel());
|
||||
FlutterBluePlusWindows._delayedSubscriptions.remove(remoteId);
|
||||
});
|
||||
|
||||
FlutterBluePlusWindows._lastChrs[remoteId]?.clear();
|
||||
FlutterBluePlusWindows._isNotifying[remoteId]?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<BluetoothService>> discoverServices({
|
||||
bool subscribeToServicesChanged = true, // TODO: implementation missing
|
||||
int timeout = 15, // TODO: implementation missing
|
||||
}) async {
|
||||
List<BluetoothServiceWindows> result = List.from(FlutterBluePlusWindows._knownServices[remoteId] ?? []);
|
||||
|
||||
try {
|
||||
_isDiscoveringServices.add(true);
|
||||
|
||||
final response = await WinBle.discoverServices(_address);
|
||||
FlutterBluePlusWindows._characteristicCache[remoteId] ??= <String, List<BluetoothCharacteristic>>{};
|
||||
|
||||
for (final serviceId in response) {
|
||||
final characteristic = await WinBle.discoverCharacteristics(
|
||||
address: _address,
|
||||
serviceId: serviceId,
|
||||
);
|
||||
FlutterBluePlusWindows._characteristicCache[remoteId] ??= {};
|
||||
FlutterBluePlusWindows._characteristicCache[remoteId]?[serviceId] ??= [
|
||||
...characteristic.map(
|
||||
(e) => BluetoothCharacteristicWindows(
|
||||
remoteId: remoteId,
|
||||
serviceUuid: Guid(serviceId),
|
||||
characteristicUuid: Guid(e.uuid),
|
||||
descriptors: [],
|
||||
// TODO: implementation missing
|
||||
propertiesWinBle: e.properties,
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
result = [
|
||||
...response.map(
|
||||
(p) => BluetoothServiceWindows(
|
||||
remoteId: remoteId,
|
||||
serviceUuid: Guid(p),
|
||||
// TODO: implementation missing
|
||||
isPrimary: true,
|
||||
// TODO: implementation missing
|
||||
characteristics: FlutterBluePlusWindows._characteristicCache[remoteId]![p]!,
|
||||
// TODO: implementation missing
|
||||
includedServices: [],
|
||||
),
|
||||
)
|
||||
];
|
||||
|
||||
FlutterBluePlusWindows._knownServices[remoteId] = result;
|
||||
|
||||
_services.add(result);
|
||||
} finally {
|
||||
_isDiscoveringServices.add(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
DisconnectReason? get disconnectReason {
|
||||
// TODO: nothing to do
|
||||
return null;
|
||||
}
|
||||
|
||||
Stream<BluetoothConnectionState> get connectionState async* {
|
||||
await FlutterBluePlusWindows._initialize();
|
||||
|
||||
final map = FlutterBluePlusWindows._connectionStream.latestValue;
|
||||
|
||||
if (map[_address] != null) {
|
||||
yield map[_address]!.isConnected;
|
||||
}
|
||||
|
||||
yield* WinBle.connectionStreamOf(_address).map((e) => e.isConnected);
|
||||
}
|
||||
|
||||
Stream<int> get mtu async* {
|
||||
bool isEmitted = false;
|
||||
int retryCount = 0;
|
||||
while (!isEmitted) {
|
||||
if (retryCount > 3) throw "Device not found!";
|
||||
retryCount++;
|
||||
try {
|
||||
yield await WinBle.getMaxMtuSize(_address);
|
||||
isEmitted = true;
|
||||
} catch (e) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> readRssi({int timeout = 15}) async {
|
||||
return FlutterBluePlusWindows._rssiMap[remoteId] ?? -100;
|
||||
}
|
||||
|
||||
Future<int> requestMtu(
|
||||
int desiredMtu, {
|
||||
double predelay = 0.35,
|
||||
int timeout = 15,
|
||||
}) async {
|
||||
// https://github.com/rohitsangwan01/win_ble/issues/8
|
||||
return await WinBle.getMaxMtuSize(_address);
|
||||
}
|
||||
|
||||
Future<void> requestConnectionPriority({
|
||||
required ConnectionPriority connectionPriorityRequest,
|
||||
}) async {
|
||||
// TODO: nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
/// Set the preferred connection (Android Only)
|
||||
/// - [txPhy] bitwise OR of all allowed phys for Tx, e.g. (Phy.le2m.mask | Phy.leCoded.mask)
|
||||
/// - [txPhy] bitwise OR of all allowed phys for Rx, e.g. (Phy.le2m.mask | Phy.leCoded.mask)
|
||||
/// - [option] preferred coding to use when transmitting on Phy.leCoded
|
||||
/// Please note that this is just a recommendation given to the system.
|
||||
Future<void> setPreferredPhy({
|
||||
required int txPhy,
|
||||
required int rxPhy,
|
||||
required PhyCoding option,
|
||||
}) async {
|
||||
// TODO: implementation missing
|
||||
}
|
||||
|
||||
Future<void> createBond({
|
||||
Uint8List? pin,
|
||||
int timeout = 90, // TODO: implementation missing
|
||||
}) async {
|
||||
try {
|
||||
await WinBle.pair(_address);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeBond({
|
||||
int timeout = 30, // TODO: implementation missing
|
||||
}) async {
|
||||
try {
|
||||
await WinBle.unPair(_address);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearGattCache() async {
|
||||
// TODO: implementation missing
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is BluetoothDeviceWindows && runtimeType == other.runtimeType && remoteId == other.remoteId);
|
||||
|
||||
@override
|
||||
int get hashCode => remoteId.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BluetoothDevice{'
|
||||
'remoteId: $remoteId, '
|
||||
'platformName: $platformName, '
|
||||
'services: ${FlutterBluePlusWindows._knownServices[remoteId]}'
|
||||
'}';
|
||||
}
|
||||
|
||||
@Deprecated('Use createBond() instead')
|
||||
Future<void> pair() async => await createBond();
|
||||
|
||||
@Deprecated('Use remoteId instead')
|
||||
DeviceIdentifier get id => remoteId;
|
||||
|
||||
@Deprecated('Use localName instead')
|
||||
String get name => localName;
|
||||
|
||||
@Deprecated('Use connectionState instead')
|
||||
Stream<BluetoothConnectionState> get state => connectionState;
|
||||
|
||||
@Deprecated('Use servicesStream instead')
|
||||
Stream<List<BluetoothService>> get services => servicesStream;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
part of 'windows.dart';
|
||||
|
||||
class BluetoothServiceWindows extends BluetoothService {
|
||||
final DeviceIdentifier remoteId;
|
||||
final Guid serviceUuid;
|
||||
final bool isPrimary;
|
||||
final List<BluetoothCharacteristic> characteristics;
|
||||
final List<BluetoothService> includedServices;
|
||||
|
||||
BluetoothServiceWindows({
|
||||
required this.remoteId,
|
||||
required this.serviceUuid,
|
||||
required this.isPrimary,
|
||||
required this.characteristics,
|
||||
required this.includedServices,
|
||||
}) : super.fromProto(
|
||||
BmBluetoothService(
|
||||
remoteId: DeviceIdentifier(remoteId.str),
|
||||
serviceUuid: serviceUuid,
|
||||
characteristics: [for (final c in characteristics) c.toProto()],
|
||||
primaryServiceUuid: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,353 +0,0 @@
|
||||
part of 'windows.dart';
|
||||
|
||||
class FlutterBluePlusWindows {
|
||||
static bool _initialized = false;
|
||||
|
||||
static BluetoothAdapterState _state = BluetoothAdapterState.unknown;
|
||||
|
||||
// stream used for the isScanning public api
|
||||
static final _isScanning = _StreamController(initialValue: false);
|
||||
|
||||
// we always keep track of these device variables
|
||||
static final _platformNames = <DeviceIdentifier, String>{};
|
||||
static final _advNames = <DeviceIdentifier, String>{};
|
||||
static final _rssiMap = <DeviceIdentifier, int?>{};
|
||||
static final _knownServices = <DeviceIdentifier, List<BluetoothServiceWindows>>{};
|
||||
static final Map<DeviceIdentifier, Map<String, List<int>>> _lastChrs = {};
|
||||
static final Map<DeviceIdentifier, Map<String, bool>> _isNotifying = {};
|
||||
static final Map<DeviceIdentifier, Map<String, List<BluetoothCharacteristic>>> _characteristicCache = {};
|
||||
static final Map<DeviceIdentifier, List<StreamSubscription>> _deviceSubscriptions = {};
|
||||
static final Map<DeviceIdentifier, List<StreamSubscription>> _delayedSubscriptions = {};
|
||||
static final List<StreamSubscription> _scanSubscriptions = [];
|
||||
|
||||
// stream used for the scanResults public api
|
||||
static final _scanResultsList = _StreamController(initialValue: <ScanResult>[]);
|
||||
|
||||
// the subscription to the scan results stream
|
||||
static StreamSubscription<BleDevice?>? _scanSubscription;
|
||||
|
||||
// timeout for scanning that can be cancelled by stopScan
|
||||
static Timer? _scanTimeout;
|
||||
|
||||
static List<BluetoothDeviceWindows> get _devices => [..._deviceSet];
|
||||
|
||||
static final _deviceSet = <BluetoothDeviceWindows>{};
|
||||
static final _removedDeviceTracer = <BluetoothDeviceWindows, StreamSubscription>{};
|
||||
|
||||
// static final _unhandledDeviceSet = <BluetoothDeviceWindows>{};
|
||||
|
||||
/// Flutter blue plus windows
|
||||
static final _charReadWriteStreamController = StreamController<(String, List<int>)>();
|
||||
static final _charReadStreamController = StreamController<(String, List<int>)>();
|
||||
|
||||
static final _charReadWriteStream = _charReadWriteStreamController.stream.asBroadcastStream();
|
||||
static final _charReadStream = _charReadStreamController.stream.asBroadcastStream();
|
||||
|
||||
/// Flutter blue plus windows
|
||||
static final _connectionStream = _StreamController(initialValue: <String, bool>{});
|
||||
|
||||
static Future<void> _initialize() async {
|
||||
if (_initialized) return;
|
||||
await WinBle.initialize(
|
||||
serverPath: await WinServer.path(),
|
||||
enableLog: false,
|
||||
);
|
||||
|
||||
WinBle.connectionStream.listen(
|
||||
(event) {
|
||||
log('$event - event');
|
||||
if (event['device'] == null) return;
|
||||
if (event['connected'] == null) return;
|
||||
|
||||
final map = _connectionStream.latestValue;
|
||||
map[event['device']] = event['connected'];
|
||||
|
||||
log('$map - map');
|
||||
_connectionStream.add(map);
|
||||
|
||||
if (!event['connected']) {
|
||||
final removingDevices = [
|
||||
..._deviceSet.where(
|
||||
(device) => device._address == event['device'],
|
||||
),
|
||||
];
|
||||
for (final device in removingDevices) {
|
||||
_deviceSet.remove(device);
|
||||
if (!_removedDeviceTracer.keys.contains(device)) {
|
||||
_removedDeviceTracer[device] = Stream.periodic(const Duration(seconds: 10), (_) => device).listen(
|
||||
(event) {
|
||||
if(event.isConnected) {
|
||||
_removedDeviceTracer[device]?.cancel();
|
||||
_removedDeviceTracer.remove(device);
|
||||
return;
|
||||
}
|
||||
event.connect();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
_deviceSubscriptions[device.remoteId]?.forEach((s) => s.cancel());
|
||||
_deviceSubscriptions.remove(device.remoteId);
|
||||
// use delayed to update the stream before we cancel it
|
||||
Future.delayed(Duration.zero).then((_) {
|
||||
_delayedSubscriptions[device.remoteId]?.forEach((s) => s.cancel());
|
||||
_delayedSubscriptions.remove(device.remoteId);
|
||||
});
|
||||
|
||||
_lastChrs[device.remoteId]?.clear();
|
||||
_isNotifying[device.remoteId]?.clear();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
static Future<bool> get isSupported async {
|
||||
return true;
|
||||
}
|
||||
|
||||
static Future<String> get adapterName async {
|
||||
return 'Windows';
|
||||
}
|
||||
|
||||
static Stream<bool> get isScanning => _isScanning.stream;
|
||||
|
||||
static bool get isScanningNow => _isScanning.latestValue;
|
||||
|
||||
static Future<void> turnOn({int timeout = 10}) async {
|
||||
await _initialize();
|
||||
await WinBle.updateBluetoothState(true);
|
||||
}
|
||||
|
||||
// TODO: compare with original lib
|
||||
static Stream<List<ScanResult>> get scanResults => _scanResultsList.stream;
|
||||
|
||||
static Stream<BluetoothAdapterState> get adapterState async* {
|
||||
await _initialize();
|
||||
yield _state;
|
||||
yield* WinBle.bleState.asBroadcastStream().map(
|
||||
(s) {
|
||||
_state = s.toAdapterState();
|
||||
return _state;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Start a scan, and return a stream of results
|
||||
/// Note: scan filters use an "or" behavior. i.e. if you set `withServices` & `withNames` we
|
||||
/// return all the advertisments that match any of the specified services *or* any of the specified names.
|
||||
/// - [withServices] filter by advertised services
|
||||
/// - [withRemoteIds] filter for known remoteIds (iOS: 128-bit guid, android: 48-bit mac address)
|
||||
/// - [withNames] filter by advertised names (exact match)
|
||||
/// - [withKeywords] filter by advertised names (matches any substring)
|
||||
/// - [withMsd] filter by manfacture specific data
|
||||
/// - [withServiceData] filter by service data
|
||||
/// - [timeout] calls stopScan after a specified duration
|
||||
/// - [removeIfGone] if true, remove devices after they've stopped advertising for X duration
|
||||
/// - [continuousUpdates] If `true`, we continually update 'lastSeen' & 'rssi' by processing
|
||||
/// duplicate advertisements. This takes more power. You typically should not use this option.
|
||||
/// - [continuousDivisor] Useful to help performance. If divisor is 3, then two-thirds of advertisements are
|
||||
/// ignored, and one-third are processed. This reduces main-thread usage caused by the platform channel.
|
||||
/// The scan counting is per-device so you always get the 1st advertisement from each device.
|
||||
/// If divisor is 1, all advertisements are returned. This argument only matters for `continuousUpdates` mode.
|
||||
/// - [oneByOne] if `true`, we will stream every advertistment one by one, possibly including duplicates.
|
||||
/// If `false`, we deduplicate the advertisements, and return a list of devices.
|
||||
/// - [androidLegacy] Android only. If `true`, scan on 1M phy only.
|
||||
/// If `false`, scan on all supported phys. How the radio cycles through all the supported phys is purely
|
||||
/// dependent on the your Bluetooth stack implementation.
|
||||
/// - [androidScanMode] choose the android scan mode to use when scanning
|
||||
/// - [androidUsesFineLocation] request `ACCESS_FINE_LOCATION` permission at runtime
|
||||
static Future<void> startScan({
|
||||
List<Guid> withServices = const [],
|
||||
List<String> withRemoteIds = const [],
|
||||
List<String> withNames = const [],
|
||||
//TODO: implementation missing
|
||||
List<String> withKeywords = const [],
|
||||
//TODO: implementation missing
|
||||
List<MsdFilter> withMsd = const [],
|
||||
List<ServiceDataFilter> withServiceData = const [],
|
||||
Duration? timeout,
|
||||
Duration? removeIfGone,
|
||||
bool continuousUpdates = false,
|
||||
int continuousDivisor = 1,
|
||||
bool oneByOne = false,
|
||||
bool androidLegacy = false,
|
||||
AndroidScanMode androidScanMode = AndroidScanMode.lowLatency,
|
||||
bool androidUsesFineLocation = false,
|
||||
}) async {
|
||||
await _initialize();
|
||||
|
||||
// stop existing scan
|
||||
if (_isScanning.latestValue == true) {
|
||||
await stopScan();
|
||||
}
|
||||
|
||||
// push to stream
|
||||
_isScanning.add(true);
|
||||
|
||||
// Start timer *after* stream is being listened to, to make sure the
|
||||
// timeout does not fire before _buffer is set
|
||||
if (timeout != null) {
|
||||
_scanTimeout = Timer(timeout, stopScan);
|
||||
}
|
||||
|
||||
/// remove connection by OS.
|
||||
/// The reason why we add this logic is
|
||||
/// to avoid uncontrollable devices and to make consistency.
|
||||
|
||||
/// add WinBle scanning
|
||||
WinBle.startScanning();
|
||||
|
||||
// check every 250ms for gone devices?
|
||||
late Stream<BleDevice?> outputStream;
|
||||
if (removeIfGone != null) {
|
||||
outputStream = _mergeStreams([WinBle.scanStream, Stream.periodic(Duration(milliseconds: 250))]);
|
||||
} else {
|
||||
outputStream = WinBle.scanStream;
|
||||
}
|
||||
|
||||
final output = <ScanResult>[];
|
||||
|
||||
// listen & push to `scanResults` stream
|
||||
_scanSubscription = outputStream.listen(
|
||||
(BleDevice? winBleDevice) {
|
||||
// print(winBleDevice?.serviceUuids);
|
||||
if (winBleDevice == null) {
|
||||
// if null, this is just a periodic update for removing old results
|
||||
output.removeWhere((elm) => DateTime.now().difference(elm.timeStamp) > removeIfGone!);
|
||||
|
||||
// push to stream
|
||||
_scanResultsList.add(List.from(output));
|
||||
} else {
|
||||
final remoteId = DeviceIdentifier(winBleDevice.address.toUpperCase());
|
||||
final scanResult = output.where((sr) => sr.device.remoteId == remoteId).firstOrNull;
|
||||
final deviceName = winBleDevice.name.isNotEmpty ? winBleDevice.name : scanResult?.device.platformName ?? '';
|
||||
final serviceUuids = winBleDevice.serviceUuids.isNotEmpty
|
||||
? [...winBleDevice.serviceUuids.map((e) => Guid((e as String).replaceAll(RegExp(r'[{}]'), '')))]
|
||||
: scanResult?.advertisementData.serviceUuids ?? [];
|
||||
|
||||
final manufacturerData = winBleDevice.manufacturerData.isNotEmpty
|
||||
? {
|
||||
if (winBleDevice.manufacturerData.length >= 2)
|
||||
winBleDevice.manufacturerData[0] + (winBleDevice.manufacturerData[1] << 8):
|
||||
winBleDevice.manufacturerData.sublist(2),
|
||||
}
|
||||
: scanResult?.advertisementData.manufacturerData ?? {};
|
||||
|
||||
final rssi = int.tryParse(winBleDevice.rssi) ?? -100;
|
||||
|
||||
FlutterBluePlusWindows._platformNames[remoteId] = deviceName;
|
||||
FlutterBluePlusWindows._advNames[remoteId] = deviceName;
|
||||
FlutterBluePlusWindows._rssiMap[remoteId] = rssi;
|
||||
|
||||
final device = BluetoothDeviceWindows(remoteId: remoteId);
|
||||
|
||||
String hex(int value) => value.toRadixString(16).padLeft(2, '0');
|
||||
String hexToId(Iterable<int> values) => values.map((e) => hex(e)).join();
|
||||
|
||||
final sr = ScanResult(
|
||||
device: device,
|
||||
advertisementData: AdvertisementData(
|
||||
advName: deviceName,
|
||||
txPowerLevel: winBleDevice.adStructures?.where((e) => e.type == 10).singleOrNull?.data.firstOrNull,
|
||||
//TODO: Should verify
|
||||
connectable: !winBleDevice.advType.contains('Non'),
|
||||
manufacturerData: manufacturerData,
|
||||
serviceData: {
|
||||
for (final advStructures in winBleDevice.adStructures ?? <AdStructure>[])
|
||||
if (advStructures.type == 0x16 && advStructures.data.length >= 2)
|
||||
Guid(hexToId(advStructures.data.sublist(0, 2).reversed)): advStructures.data.sublist(2),
|
||||
for (final advStructures in winBleDevice.adStructures ?? <AdStructure>[])
|
||||
if (advStructures.type == 0x20 && advStructures.data.length >= 4)
|
||||
Guid(hexToId(advStructures.data.sublist(0, 4).reversed)): advStructures.data.sublist(4),
|
||||
for (final advStructures in winBleDevice.adStructures ?? <AdStructure>[])
|
||||
if (advStructures.type == 0x21 && advStructures.data.length >= 16)
|
||||
Guid(hexToId(advStructures.data.sublist(0, 16).reversed)): advStructures.data.sublist(16),
|
||||
},
|
||||
serviceUuids: serviceUuids,
|
||||
appearance: null,
|
||||
),
|
||||
rssi: rssi,
|
||||
timeStamp: DateTime.now(),
|
||||
);
|
||||
|
||||
// filter with services
|
||||
final isFilteredWithServices =
|
||||
withServices.isNotEmpty && serviceUuids.where((service) => withServices.contains(service)).isEmpty;
|
||||
|
||||
// filter with remote ids
|
||||
final isFilteredWithRemoteIds = withRemoteIds.isNotEmpty && !withRemoteIds.contains(remoteId);
|
||||
|
||||
// filter with names
|
||||
final isFilteredWithNames = withNames.isNotEmpty && !withNames.contains(deviceName);
|
||||
|
||||
if (isFilteredWithServices || isFilteredWithRemoteIds || isFilteredWithNames) {
|
||||
_scanResultsList.add(List.from(output));
|
||||
return;
|
||||
}
|
||||
|
||||
// add result to output
|
||||
if (oneByOne) {
|
||||
output
|
||||
..clear()
|
||||
..add(sr);
|
||||
} else {
|
||||
output.addOrUpdate(sr);
|
||||
}
|
||||
|
||||
// push to stream
|
||||
_scanResultsList.add(List.from(output));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static List<FBP.BluetoothDevice> get connectedDevices {
|
||||
return _devices;
|
||||
}
|
||||
|
||||
static Future<List<BluetoothDeviceWindows>> get bondedDevices async {
|
||||
return _devices;
|
||||
}
|
||||
|
||||
/// Stops a scan for Bluetooth Low Energy devices
|
||||
static Future<void> stopScan() async {
|
||||
await _initialize();
|
||||
WinBle.stopScanning();
|
||||
_scanSubscription?.cancel();
|
||||
_scanTimeout?.cancel();
|
||||
_isScanning.add(false);
|
||||
|
||||
for (var subscription in _scanSubscriptions) {
|
||||
subscription.cancel();
|
||||
}
|
||||
|
||||
_scanResultsList.latestValue = [];
|
||||
}
|
||||
|
||||
/// Register a subscription to be canceled when scanning is complete.
|
||||
/// This function simplifies cleanup, so you can prevent creating duplicate stream subscriptions.
|
||||
/// - this is an optional convenience function
|
||||
/// - prevents accidentally creating duplicate subscriptions before each scan
|
||||
static void cancelWhenScanComplete(StreamSubscription subscription) {
|
||||
_scanSubscriptions.add(subscription);
|
||||
}
|
||||
|
||||
/// Sets the internal FlutterBlue log level
|
||||
static Future<void> setLogLevel(LogLevel level, {color = true}) async {
|
||||
// Nothing to implement
|
||||
return;
|
||||
}
|
||||
|
||||
static Future<void> turnOff({int timeout = 10}) async {
|
||||
await _initialize();
|
||||
await WinBle.updateBluetoothState(false);
|
||||
}
|
||||
|
||||
// TODO: need to test
|
||||
static Future<bool> get isOn async {
|
||||
await _initialize();
|
||||
return await WinBle.bleState.asBroadcastStream().first == BleState.On;
|
||||
}
|
||||
}
|
||||
@@ -1,433 +0,0 @@
|
||||
part of 'windows.dart';
|
||||
|
||||
String _hexEncode(List<int> numbers) {
|
||||
return numbers
|
||||
.map((n) => (n & 0xFF).toRadixString(16).padLeft(2, '0'))
|
||||
.join();
|
||||
}
|
||||
|
||||
List<int> _hexDecode(String hex) {
|
||||
List<int> numbers = [];
|
||||
for (int i = 0; i < hex.length; i += 2) {
|
||||
String hexPart = hex.substring(i, i + 2);
|
||||
int num = int.parse(hexPart, radix: 16);
|
||||
numbers.add(num);
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
int _compareAsciiLowerCase(String a, String b) {
|
||||
const int upperCaseA = 0x41;
|
||||
const int upperCaseZ = 0x5a;
|
||||
const int asciiCaseBit = 0x20;
|
||||
var defaultResult = 0;
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (i >= b.length) return 1;
|
||||
var aChar = a.codeUnitAt(i);
|
||||
var bChar = b.codeUnitAt(i);
|
||||
if (aChar == bChar) continue;
|
||||
var aLowerCase = aChar;
|
||||
var bLowerCase = bChar;
|
||||
// Upper case if ASCII letters.
|
||||
if (upperCaseA <= bChar && bChar <= upperCaseZ) {
|
||||
bLowerCase += asciiCaseBit;
|
||||
}
|
||||
if (upperCaseA <= aChar && aChar <= upperCaseZ) {
|
||||
aLowerCase += asciiCaseBit;
|
||||
}
|
||||
if (aLowerCase != bLowerCase) return (aLowerCase - bLowerCase).sign;
|
||||
if (defaultResult == 0) defaultResult = aChar - bChar;
|
||||
}
|
||||
if (b.length > a.length) return -1;
|
||||
return defaultResult.sign;
|
||||
}
|
||||
|
||||
// This is a reimplementation of BehaviorSubject from RxDart library.
|
||||
// It is essentially a stream but:
|
||||
// 1. we cache the latestValue of the stream
|
||||
// 2. the "latestValue" is re-emitted whenever the stream is listened to
|
||||
class _StreamController<T> {
|
||||
T latestValue;
|
||||
|
||||
final StreamController<T> _controller = StreamController<T>.broadcast();
|
||||
|
||||
_StreamController({required T initialValue})
|
||||
: this.latestValue = initialValue;
|
||||
|
||||
Stream<T> get stream => _controller.stream;
|
||||
|
||||
T get value => latestValue;
|
||||
|
||||
void add(T newValue) {
|
||||
latestValue = newValue;
|
||||
_controller.add(newValue);
|
||||
}
|
||||
|
||||
void listen(Function(T) onData,
|
||||
{Function? onError, void Function()? onDone, bool? cancelOnError}) {
|
||||
onData(latestValue);
|
||||
_controller.stream.listen(onData,
|
||||
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
|
||||
}
|
||||
|
||||
Future<void> close() {
|
||||
return _controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
// imediately starts listening to a broadcast stream and
|
||||
// buffering it in a new single-subscription stream
|
||||
class _BufferStream<T> {
|
||||
final Stream<T> _inputStream;
|
||||
late final StreamSubscription? _subscription;
|
||||
late final StreamController<T> _controller;
|
||||
late bool hasReceivedValue = false;
|
||||
|
||||
_BufferStream.listen(this._inputStream) {
|
||||
_controller = StreamController<T>(
|
||||
onCancel: () {
|
||||
_subscription?.cancel();
|
||||
},
|
||||
onPause: () {
|
||||
_subscription?.pause();
|
||||
},
|
||||
onResume: () {
|
||||
_subscription?.resume();
|
||||
},
|
||||
onListen: () {}, // inputStream is already listened to
|
||||
);
|
||||
|
||||
// immediately start listening to the inputStream
|
||||
_subscription = _inputStream.listen(
|
||||
(data) {
|
||||
hasReceivedValue = true;
|
||||
_controller.add(data);
|
||||
},
|
||||
onError: (e) {
|
||||
_controller.addError(e);
|
||||
},
|
||||
onDone: () {
|
||||
_controller.close();
|
||||
},
|
||||
cancelOnError: false,
|
||||
);
|
||||
}
|
||||
|
||||
void close() {
|
||||
_subscription?.cancel();
|
||||
_controller.close();
|
||||
}
|
||||
|
||||
Stream<T> get stream async* {
|
||||
yield* _controller.stream;
|
||||
}
|
||||
}
|
||||
|
||||
// helper for 'doOnDone' method for streams.
|
||||
class _OnDoneTransformer<T> extends StreamTransformerBase<T, T> {
|
||||
final Function onDone;
|
||||
|
||||
_OnDoneTransformer({required this.onDone});
|
||||
|
||||
@override
|
||||
Stream<T> bind(Stream<T> stream) {
|
||||
if (stream.isBroadcast) {
|
||||
return _bindBroadcast(stream);
|
||||
}
|
||||
return _bindSingleSubscription(stream);
|
||||
}
|
||||
|
||||
Stream<T> _bindSingleSubscription(Stream<T> stream) {
|
||||
StreamController<T>? controller;
|
||||
StreamSubscription<T>? subscription;
|
||||
|
||||
controller = StreamController<T>(
|
||||
onListen: () {
|
||||
subscription = stream.listen(
|
||||
controller?.add,
|
||||
onError: controller?.addError,
|
||||
onDone: () {
|
||||
onDone();
|
||||
controller?.close();
|
||||
},
|
||||
);
|
||||
},
|
||||
onPause: ([Future<dynamic>? resumeSignal]) {
|
||||
subscription?.pause(resumeSignal);
|
||||
},
|
||||
onResume: () {
|
||||
subscription?.resume();
|
||||
},
|
||||
onCancel: () {
|
||||
return subscription?.cancel();
|
||||
},
|
||||
sync: true,
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Stream<T> _bindBroadcast(Stream<T> stream) {
|
||||
StreamController<T>? controller;
|
||||
StreamSubscription<T>? subscription;
|
||||
|
||||
controller = StreamController<T>.broadcast(
|
||||
onListen: () {
|
||||
subscription = stream
|
||||
.listen(controller?.add, onError: controller?.addError, onDone: () {
|
||||
onDone();
|
||||
controller?.close();
|
||||
});
|
||||
},
|
||||
onCancel: () {
|
||||
subscription?.cancel();
|
||||
},
|
||||
sync: true,
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
}
|
||||
|
||||
// helper for 'doOnCancel' method for streams.
|
||||
class _OnCancelTransformer<T> extends StreamTransformerBase<T, T> {
|
||||
final Function onCancel;
|
||||
|
||||
_OnCancelTransformer({required this.onCancel});
|
||||
|
||||
@override
|
||||
Stream<T> bind(Stream<T> stream) {
|
||||
if (stream.isBroadcast) {
|
||||
return _bindBroadcast(stream);
|
||||
}
|
||||
|
||||
return _bindSingleSubscription(stream);
|
||||
}
|
||||
|
||||
Stream<T> _bindSingleSubscription(Stream<T> stream) {
|
||||
StreamController<T>? controller;
|
||||
StreamSubscription<T>? subscription;
|
||||
|
||||
controller = StreamController<T>(
|
||||
onListen: () {
|
||||
subscription = stream.listen(
|
||||
controller?.add,
|
||||
onError: (Object error) {
|
||||
controller?.addError(error);
|
||||
controller?.close();
|
||||
},
|
||||
onDone: controller?.close,
|
||||
);
|
||||
},
|
||||
onPause: ([Future<dynamic>? resumeSignal]) {
|
||||
subscription?.pause(resumeSignal);
|
||||
},
|
||||
onResume: () {
|
||||
subscription?.resume();
|
||||
},
|
||||
onCancel: () {
|
||||
onCancel();
|
||||
return subscription?.cancel();
|
||||
},
|
||||
sync: true,
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Stream<T> _bindBroadcast(Stream<T> stream) {
|
||||
StreamController<T>? controller;
|
||||
StreamSubscription<T>? subscription;
|
||||
|
||||
controller = StreamController<T>.broadcast(
|
||||
onListen: () {
|
||||
subscription = stream.listen(
|
||||
controller?.add,
|
||||
onError: (Object error) {
|
||||
controller?.addError(error);
|
||||
controller?.close();
|
||||
},
|
||||
onDone: controller?.close,
|
||||
);
|
||||
},
|
||||
onCancel: () {
|
||||
onCancel();
|
||||
subscription?.cancel();
|
||||
},
|
||||
sync: true,
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper for 'newStreamWithInitialValue' method for streams.
|
||||
class _NewStreamWithInitialValueTransformer<T>
|
||||
extends StreamTransformerBase<T, T> {
|
||||
final T initialValue;
|
||||
|
||||
_NewStreamWithInitialValueTransformer(this.initialValue);
|
||||
|
||||
@override
|
||||
Stream<T> bind(Stream<T> stream) {
|
||||
return _bindSingleSubscription(stream);
|
||||
}
|
||||
|
||||
Stream<T> _bindSingleSubscription(Stream<T> stream) {
|
||||
StreamController<T>? controller;
|
||||
StreamSubscription<T>? subscription;
|
||||
|
||||
controller = StreamController<T>(
|
||||
onListen: () {
|
||||
// Emit the initial value
|
||||
controller?.add(initialValue);
|
||||
|
||||
subscription = stream.listen(
|
||||
controller?.add,
|
||||
onError: (Object error) {
|
||||
controller?.addError(error);
|
||||
controller?.close();
|
||||
},
|
||||
onDone: controller?.close,
|
||||
);
|
||||
},
|
||||
onPause: ([Future<dynamic>? resumeSignal]) {
|
||||
subscription?.pause(resumeSignal);
|
||||
},
|
||||
onResume: () {
|
||||
subscription?.resume();
|
||||
},
|
||||
onCancel: () {
|
||||
return subscription?.cancel();
|
||||
},
|
||||
sync: true,
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
}
|
||||
|
||||
extension _StreamDoOnDone<T> on Stream<T> {
|
||||
// ignore: unused_element
|
||||
Stream<T> doOnDone(void Function() onDone) {
|
||||
return transform(_OnDoneTransformer(onDone: onDone));
|
||||
}
|
||||
}
|
||||
|
||||
extension _StreamDoOnCancel<T> on Stream<T> {
|
||||
// ignore: unused_element
|
||||
Stream<T> doOnCancel(void Function() onCancel) {
|
||||
return transform(_OnCancelTransformer(onCancel: onCancel));
|
||||
}
|
||||
}
|
||||
|
||||
extension _StreamNewStreamWithInitialValue<T> on Stream<T> {
|
||||
Stream<T> newStreamWithInitialValue(T initialValue) {
|
||||
return transform(_NewStreamWithInitialValueTransformer(initialValue));
|
||||
}
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
Stream<T> _mergeStreams<T>(List<Stream<T>> streams) {
|
||||
StreamController<T> controller = StreamController<T>();
|
||||
List<StreamSubscription<T>> subscriptions = [];
|
||||
|
||||
void handleData(T data) {
|
||||
if (!controller.isClosed) {
|
||||
controller.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
void handleError(Object error, StackTrace stackTrace) {
|
||||
if (!controller.isClosed) {
|
||||
controller.addError(error, stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
void handleDone() {
|
||||
if (subscriptions.every((s) => s.isPaused)) {
|
||||
controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeToStream(Stream<T> stream) {
|
||||
final s =
|
||||
stream.listen(handleData, onError: handleError, onDone: handleDone);
|
||||
subscriptions.add(s);
|
||||
}
|
||||
|
||||
streams.forEach(subscribeToStream);
|
||||
|
||||
controller.onCancel = () async {
|
||||
await Future.wait(subscriptions.map((s) => s.cancel()));
|
||||
};
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
// dart is single threaded, but still has task switching.
|
||||
// this mutex lets a single task through at a time.
|
||||
class _Mutex {
|
||||
final StreamController _controller = StreamController.broadcast();
|
||||
int current = 0;
|
||||
int issued = 0;
|
||||
|
||||
Future<void> take() async {
|
||||
int mine = issued;
|
||||
issued++;
|
||||
// tasks are executed in the same order they call take()
|
||||
while (mine != current) {
|
||||
await _controller.stream.first; // wait
|
||||
}
|
||||
}
|
||||
|
||||
void give() {
|
||||
current++;
|
||||
_controller.add(null); // release waiting tasks
|
||||
}
|
||||
}
|
||||
|
||||
// Create mutexes in a parrallel-safe way,
|
||||
class _MutexFactory {
|
||||
static final _Mutex _global = _Mutex();
|
||||
static final Map<String, _Mutex> _all = {};
|
||||
|
||||
static Future<_Mutex> getMutexForKey(String key) async {
|
||||
_Mutex? value;
|
||||
await _global.take();
|
||||
{
|
||||
_all[key] ??= _Mutex();
|
||||
value = _all[key];
|
||||
}
|
||||
_global.give();
|
||||
return value!;
|
||||
}
|
||||
}
|
||||
|
||||
String _black(String s) {
|
||||
// Use ANSI escape codes
|
||||
return '\x1B[1;30m$s\x1B[0m';
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
String _green(String s) {
|
||||
// Use ANSI escape codes
|
||||
return '\x1B[1;32m$s\x1B[0m';
|
||||
}
|
||||
|
||||
String _magenta(String s) {
|
||||
// Use ANSI escape codes
|
||||
return '\x1B[1;35m$s\x1B[0m';
|
||||
}
|
||||
|
||||
String _brown(String s) {
|
||||
// Use ANSI escape codes
|
||||
return '\x1B[1;33m$s\x1B[0m';
|
||||
}
|
||||
|
||||
extension Boolean2ConnectionState on bool {
|
||||
BluetoothConnectionState get isConnected {
|
||||
if (this) return BluetoothConnectionState.connected;
|
||||
return BluetoothConnectionState.disconnected;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart' as FBP;
|
||||
import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_interface.dart';
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
part 'bluetooth_characteristic_windows.dart';
|
||||
part 'bluetooth_device_windows.dart';
|
||||
part 'bluetooth_service_windows.dart';
|
||||
part 'flutter_blue_plus_windows.dart';
|
||||
part 'util.dart';
|
||||
@@ -1,141 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart' as FBP;
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
|
||||
class FlutterBluePlus {
|
||||
static Future<void> startScan({
|
||||
List<Guid> withServices = const [],
|
||||
List<String> withRemoteIds = const [],
|
||||
List<String> withNames = const [],
|
||||
List<String> withKeywords = const [],
|
||||
List<MsdFilter> withMsd = const [],
|
||||
List<ServiceDataFilter> withServiceData = const [],
|
||||
Duration? timeout,
|
||||
Duration? removeIfGone,
|
||||
bool continuousUpdates = false,
|
||||
int continuousDivisor = 1,
|
||||
bool oneByOne = false,
|
||||
bool androidLegacy = false,
|
||||
AndroidScanMode androidScanMode = AndroidScanMode.lowLatency,
|
||||
bool androidUsesFineLocation = false,
|
||||
List<Guid> webOptionalServices = const [],
|
||||
}) async {
|
||||
if (!kIsWeb && Platform.isWindows) {
|
||||
return await FlutterBluePlusWindows.startScan(
|
||||
withServices: withServices,
|
||||
withRemoteIds: withRemoteIds,
|
||||
withNames: withNames,
|
||||
withKeywords: withKeywords,
|
||||
withMsd: withMsd,
|
||||
withServiceData: withServiceData,
|
||||
timeout: timeout,
|
||||
removeIfGone: removeIfGone,
|
||||
continuousUpdates: continuousUpdates,
|
||||
continuousDivisor: continuousDivisor,
|
||||
oneByOne: oneByOne,
|
||||
androidLegacy: androidLegacy,
|
||||
androidScanMode: androidScanMode,
|
||||
androidUsesFineLocation: androidUsesFineLocation,
|
||||
);
|
||||
}
|
||||
|
||||
return await FBP.FlutterBluePlus.startScan(
|
||||
withServices: withServices,
|
||||
withRemoteIds: withRemoteIds,
|
||||
withNames: withNames,
|
||||
withKeywords: withKeywords,
|
||||
withMsd: withMsd,
|
||||
withServiceData: withServiceData,
|
||||
timeout: timeout,
|
||||
removeIfGone: removeIfGone,
|
||||
continuousUpdates: continuousUpdates,
|
||||
continuousDivisor: continuousDivisor,
|
||||
oneByOne: oneByOne,
|
||||
androidLegacy: androidLegacy,
|
||||
androidScanMode: androidScanMode,
|
||||
androidUsesFineLocation: androidUsesFineLocation,
|
||||
webOptionalServices: webOptionalServices,
|
||||
);
|
||||
}
|
||||
|
||||
static Stream<BluetoothAdapterState> get adapterState {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.adapterState;
|
||||
return FBP.FlutterBluePlus.adapterState;
|
||||
}
|
||||
|
||||
static Stream<List<ScanResult>> get scanResults {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.scanResults;
|
||||
return FBP.FlutterBluePlus.scanResults;
|
||||
}
|
||||
|
||||
static bool get isScanningNow {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.isScanningNow;
|
||||
return FBP.FlutterBluePlus.isScanningNow;
|
||||
}
|
||||
|
||||
static Stream<bool> get isScanning {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.isScanning;
|
||||
return FBP.FlutterBluePlus.isScanning;
|
||||
}
|
||||
|
||||
static Future<void> stopScan() async {
|
||||
if (!kIsWeb && Platform.isWindows) return await FlutterBluePlusWindows.stopScan();
|
||||
return await FBP.FlutterBluePlus.stopScan();
|
||||
}
|
||||
|
||||
static Future<void> setLogLevel(LogLevel level, {color = true}) async {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.setLogLevel(level, color: color);
|
||||
return FBP.FlutterBluePlus.setLogLevel(level, color: color);
|
||||
}
|
||||
|
||||
/// TODO: need to verify
|
||||
static LogLevel get logLevel => FBP.FlutterBluePlus.logLevel;
|
||||
|
||||
static Future<void> setOptions({bool restoreState = false, bool showPowerAlert = true}) async {
|
||||
if (!kIsWeb && Platform.isWindows) return;
|
||||
FBP.FlutterBluePlus.setOptions(restoreState: restoreState, showPowerAlert: showPowerAlert);
|
||||
}
|
||||
|
||||
static Future<bool> get isSupported async {
|
||||
if (!kIsWeb && Platform.isWindows) return await FlutterBluePlusWindows.isSupported;
|
||||
return await FBP.FlutterBluePlus.isSupported;
|
||||
}
|
||||
|
||||
static Future<String> get adapterName async {
|
||||
if (!kIsWeb && Platform.isWindows) return await FlutterBluePlusWindows.adapterName;
|
||||
return await FBP.FlutterBluePlus.adapterName;
|
||||
}
|
||||
|
||||
static Future<void> turnOn({int timeout = 60}) async {
|
||||
if (!kIsWeb && Platform.isWindows) return await FlutterBluePlusWindows.turnOn(timeout: timeout);
|
||||
return await FBP.FlutterBluePlus.turnOn(timeout: timeout);
|
||||
}
|
||||
|
||||
static List<FBP.BluetoothDevice> get connectedDevices {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
|
||||
return FBP.FlutterBluePlus.connectedDevices;
|
||||
}
|
||||
|
||||
static Future<List<FBP.BluetoothDevice>> systemDevices(List<Guid> withServices) async {
|
||||
//TODO: connected devices => system devices
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
|
||||
return await FBP.FlutterBluePlus.systemDevices(withServices);
|
||||
}
|
||||
|
||||
static Future<PhySupport> getPhySupport() {
|
||||
return FBP.FlutterBluePlus.getPhySupport();
|
||||
}
|
||||
|
||||
static Future<List<FBP.BluetoothDevice>> get bondedDevices async {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
|
||||
return await FBP.FlutterBluePlus.bondedDevices;
|
||||
}
|
||||
|
||||
static void cancelWhenScanComplete(StreamSubscription subscription) {
|
||||
if (!kIsWeb && Platform.isWindows) return FlutterBluePlusWindows.cancelWhenScanComplete(subscription);
|
||||
return FBP.FlutterBluePlus.cancelWhenScanComplete(subscription);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export 'flutter_blue_plus_wrapper.dart';
|
||||
@@ -1,13 +0,0 @@
|
||||
name: flutter_blue_plus_windows
|
||||
description: Flutter blue plus for Windows
|
||||
version: 1.26.1
|
||||
repository: https://github.com/chan150/flutter_blue_plus_windows
|
||||
#publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter_blue_plus: ">=1.32.4"
|
||||
win_ble: ">=1.1.1"
|
||||
stream_with_value: ">=0.5.0"
|
||||
@@ -22,6 +22,7 @@ class SwiftPlayApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'SwiftControl',
|
||||
theme: AppTheme.light,
|
||||
darkTheme: AppTheme.dark,
|
||||
|
||||
@@ -3,9 +3,10 @@ import 'dart:async';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/devices/ble_device.dart';
|
||||
import 'package:swift_control/utils/devices/base_device.dart';
|
||||
import 'package:swift_control/widgets/logviewer.dart';
|
||||
|
||||
import '../utils/messages/notification.dart';
|
||||
import '../widgets/menu.dart';
|
||||
|
||||
class DevicePage extends StatefulWidget {
|
||||
const DevicePage({super.key});
|
||||
@@ -15,24 +16,12 @@ class DevicePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DevicePageState extends State<DevicePage> {
|
||||
List<String> _actions = [];
|
||||
|
||||
late StreamSubscription<BleDevice> _connectionStateSubscription;
|
||||
|
||||
late StreamSubscription<BaseNotification> _actionSubscription;
|
||||
late StreamSubscription<BaseDevice> _connectionStateSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_actionSubscription = connection.actionStream.listen((data) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_actions.add('${DateTime.now().toString().split(" ").last}: $data');
|
||||
_actions = _actions.takeLast(30).toList();
|
||||
});
|
||||
}
|
||||
});
|
||||
_connectionStateSubscription = connection.connectionStream.listen((state) async {
|
||||
setState(() {});
|
||||
});
|
||||
@@ -41,7 +30,6 @@ class _DevicePageState extends State<DevicePage> {
|
||||
@override
|
||||
void dispose() {
|
||||
_connectionStateSubscription.cancel();
|
||||
_actionSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -58,15 +46,7 @@ class _DevicePageState extends State<DevicePage> {
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('SwiftControl'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_actions.clear();
|
||||
setState(() {});
|
||||
},
|
||||
icon: Icon(Icons.clear),
|
||||
),
|
||||
],
|
||||
actions: [MenuButton()],
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
),
|
||||
body: Padding(
|
||||
@@ -76,23 +56,11 @@ class _DevicePageState extends State<DevicePage> {
|
||||
children: [
|
||||
Text(
|
||||
'Devices:\n${connection.devices.joinToString(separator: '\n', transform: (it) {
|
||||
return "${it.device.platformName}: ${it.device.isConnected ? 'Connected' : 'Not connected'}";
|
||||
return "${it.device.name}: ${it.isConnected ? 'Connected' : 'Not connected'}";
|
||||
})}',
|
||||
),
|
||||
Divider(color: Theme.of(context).colorScheme.primary, height: 30),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children:
|
||||
_actions
|
||||
.map(
|
||||
(action) => Text(
|
||||
action,
|
||||
style: TextStyle(fontSize: 12, fontFeatures: [FontFeature.tabularFigures()]),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
Expanded(child: LogViewer()),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/widgets/menu.dart';
|
||||
|
||||
import 'device.dart';
|
||||
|
||||
@@ -60,7 +61,11 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('SwiftControl'), backgroundColor: Theme.of(context).colorScheme.inversePrimary),
|
||||
appBar: AppBar(
|
||||
title: Text('SwiftControl'),
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
actions: [MenuButton()],
|
||||
),
|
||||
body:
|
||||
_requirements.isEmpty
|
||||
? Center(child: CircularProgressIndicator())
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/ble.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
|
||||
import '../widgets/logviewer.dart';
|
||||
|
||||
class ScanWidget extends StatefulWidget {
|
||||
const ScanWidget({super.key});
|
||||
|
||||
@@ -15,73 +13,28 @@ class ScanWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ScanWidgetState extends State<ScanWidget> {
|
||||
bool _isScanning = false;
|
||||
late StreamSubscription<bool> _isScanningSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
connection.startScanning();
|
||||
connection.initialize();
|
||||
|
||||
_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
|
||||
/*_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
|
||||
_isScanning = state;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
// after the first frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
onScanPressed();
|
||||
// must be called from a button
|
||||
if (!kIsWeb) {
|
||||
connection.performScanning();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_isScanningSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future onScanPressed() async {
|
||||
try {
|
||||
await FlutterBluePlus.startScan(
|
||||
timeout: const Duration(seconds: 30),
|
||||
withServices: [BleUuid.ZWIFT_CUSTOM_SERVICE_UUID, BleUuid.ZWIFT_RIDE_CUSTOM_SERVICE_UUID],
|
||||
webOptionalServices: kIsWeb ? [BleUuid.ZWIFT_CUSTOM_SERVICE_UUID] : [],
|
||||
);
|
||||
} catch (e, backtrace) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Error: $e'), duration: const Duration(seconds: 5)));
|
||||
print(e);
|
||||
print("backtrace: $backtrace");
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Future onStopPressed() async {
|
||||
try {
|
||||
FlutterBluePlus.stopScan();
|
||||
} catch (e, backtrace) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('Error: $e'), duration: const Duration(seconds: 5)));
|
||||
print(e);
|
||||
print("backtrace: $backtrace");
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildScanButton(BuildContext context) {
|
||||
if (FlutterBluePlus.isScanningNow) {
|
||||
return ElevatedButton(onPressed: onStopPressed, child: const Icon(Icons.stop));
|
||||
} else {
|
||||
return ElevatedButton(onPressed: onScanPressed, child: const Text("SCAN"));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -89,7 +42,32 @@ class _ScanWidgetState extends State<ScanWidget> {
|
||||
child: ListView(
|
||||
padding: EdgeInsets.all(16),
|
||||
shrinkWrap: true,
|
||||
children: [if (_isScanning) SmallProgressIndicator() else buildScanButton(context)],
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: connection.isScanning,
|
||||
builder: (context, isScanning, widget) {
|
||||
if (isScanning) {
|
||||
return Column(
|
||||
spacing: 12,
|
||||
children: [
|
||||
Text(
|
||||
'Scanning for devices... Make sure they are powered on and in range and not connected to another device.',
|
||||
),
|
||||
SmallProgressIndicator(),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
connection.performScanning();
|
||||
},
|
||||
child: const Text("SCAN"),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (kDebugMode) LogViewer(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,4 +47,9 @@ class AndroidActions extends BaseActions {
|
||||
accessibilityHandler.performTouch(point.dx, point.dy);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void controlMedia(MediaAction action) {
|
||||
accessibilityHandler.controlMedia(action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:accessibility/accessibility.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../keymap/keymap.dart';
|
||||
@@ -12,6 +13,10 @@ abstract class BaseActions {
|
||||
void init(Keymap? keymap) {}
|
||||
void increaseGear();
|
||||
void decreaseGear();
|
||||
|
||||
void controlMedia(MediaAction action) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
class StubActions extends BaseActions {
|
||||
@@ -52,4 +57,8 @@ class ActionHandler {
|
||||
void decreaseGear() {
|
||||
actions.decreaseGear();
|
||||
}
|
||||
|
||||
void controlMedia(MediaAction action) {
|
||||
actions.controlMedia(action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
|
||||
class BleUuid {
|
||||
static final ZWIFT_CUSTOM_SERVICE_UUID = Guid("00000001-19CA-4651-86E5-FA29DCDD09D1");
|
||||
static final ZWIFT_RIDE_CUSTOM_SERVICE_UUID = Guid("0000fc82-0000-1000-8000-00805f9b34fb");
|
||||
static final ZWIFT_ASYNC_CHARACTERISTIC_UUID = Guid("00000002-19CA-4651-86E5-FA29DCDD09D1");
|
||||
static final ZWIFT_SYNC_RX_CHARACTERISTIC_UUID = Guid("00000003-19CA-4651-86E5-FA29DCDD09D1");
|
||||
static final ZWIFT_SYNC_TX_CHARACTERISTIC_UUID = Guid("00000004-19CA-4651-86E5-FA29DCDD09D1");
|
||||
static final ZWIFT_CUSTOM_SERVICE_UUID = "00000001-19CA-4651-86E5-FA29DCDD09D1".toLowerCase();
|
||||
static final ZWIFT_RIDE_CUSTOM_SERVICE_UUID = "0000fc82-0000-1000-8000-00805f9b34fb".toLowerCase();
|
||||
static final ZWIFT_ASYNC_CHARACTERISTIC_UUID = "00000002-19CA-4651-86E5-FA29DCDD09D1".toLowerCase();
|
||||
static final ZWIFT_SYNC_RX_CHARACTERISTIC_UUID = "00000003-19CA-4651-86E5-FA29DCDD09D1".toLowerCase();
|
||||
static final ZWIFT_SYNC_TX_CHARACTERISTIC_UUID = "00000004-19CA-4651-86E5-FA29DCDD09D1".toLowerCase();
|
||||
}
|
||||
|
||||
class Constants {
|
||||
@@ -17,6 +15,10 @@ class Constants {
|
||||
static const RC1_LEFT_SIDE = 0x03;
|
||||
static const RC1_RIGHT_SIDE = 0x02;
|
||||
|
||||
// Zwift Ride
|
||||
static const RIDE_RIGHT_SIDE = 0x07;
|
||||
static const RIDE_LEFT_SIDE = 0x08;
|
||||
|
||||
// Zwift Click = BC1
|
||||
static const BC1 = 0x09;
|
||||
|
||||
@@ -35,7 +37,7 @@ class Constants {
|
||||
// not figured out the protobuf type this really is, the content is just two varints.
|
||||
static const int CLICK_NOTIFICATION_MESSAGE_TYPE = 55;
|
||||
static const int PLAY_NOTIFICATION_MESSAGE_TYPE = 7;
|
||||
static const int RIDE_NOTIFICATION_MESSAGE_TYPE = 35;
|
||||
static const int RIDE_NOTIFICATION_MESSAGE_TYPE = 35; // 0x23
|
||||
|
||||
// see this if connected to Core then Zwift connects to it. just one byte
|
||||
static const DISCONNECT_MESSAGE_TYPE = 0xFE;
|
||||
|
||||
@@ -3,47 +3,76 @@ import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/devices/ble_device.dart';
|
||||
import 'package:swift_control/utils/devices/base_device.dart';
|
||||
import 'package:swift_control/utils/requirements/android.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import 'ble.dart';
|
||||
import 'messages/notification.dart';
|
||||
|
||||
class Connection {
|
||||
final devices = <BleDevice>[];
|
||||
final devices = <BaseDevice>[];
|
||||
var androidNotificationsSetup = false;
|
||||
|
||||
final Map<BleDevice, StreamSubscription<BaseNotification>> _streamSubscriptions = {};
|
||||
final Map<BaseDevice, StreamSubscription<BaseNotification>> _streamSubscriptions = {};
|
||||
final StreamController<BaseNotification> _actionStreams = StreamController<BaseNotification>.broadcast();
|
||||
Stream<BaseNotification> get actionStream => _actionStreams.stream;
|
||||
|
||||
final Map<BleDevice, StreamSubscription<BluetoothConnectionState>> _connectionSubscriptions = {};
|
||||
final StreamController<BleDevice> _connectionStreams = StreamController<BleDevice>.broadcast();
|
||||
Stream<BleDevice> get connectionStream => _connectionStreams.stream;
|
||||
final Map<BaseDevice, StreamSubscription<BleConnectionUpdate>> _connectionSubscriptions = {};
|
||||
final StreamController<BaseDevice> _connectionStreams = StreamController<BaseDevice>.broadcast();
|
||||
Stream<BaseDevice> get connectionStream => _connectionStreams.stream;
|
||||
|
||||
var _lastScanResult = <BleDevice>[];
|
||||
final ValueNotifier<bool> hasDevices = ValueNotifier(false);
|
||||
late StreamSubscription<List<ScanResult>> _scanResultsSubscription;
|
||||
final ValueNotifier<bool> isScanning = ValueNotifier(false);
|
||||
|
||||
void startScanning() {
|
||||
_scanResultsSubscription = FlutterBluePlus.scanResults.listen(
|
||||
(results) {
|
||||
final scanResults = results.mapNotNull(BleDevice.fromScanResult).toList();
|
||||
_addDevices(scanResults);
|
||||
},
|
||||
onError: (e) {
|
||||
_actionStreams.add(LogNotification(e.toString()));
|
||||
},
|
||||
);
|
||||
void initialize() {
|
||||
UniversalBle.onScanResult = (result) {
|
||||
if (_lastScanResult.none((e) => e.deviceId == result.deviceId)) {
|
||||
_lastScanResult.add(result);
|
||||
_actionStreams.add(LogNotification('Found new devices: ${result.name}'));
|
||||
final scanResult = BaseDevice.fromScanResult(result);
|
||||
if (scanResult != null) {
|
||||
_addDevices([scanResult]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UniversalBle.onValueChange = (deviceId, characteristicUuid, value) {
|
||||
final device = devices.firstOrNullWhere((e) => e.device.deviceId == deviceId);
|
||||
if (device == null) {
|
||||
_actionStreams.add(LogNotification('Device not found: $deviceId'));
|
||||
return;
|
||||
} else {
|
||||
device.processCharacteristic(characteristicUuid, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void _addDevices(List<BleDevice> dev) {
|
||||
Future<void> performScanning() async {
|
||||
isScanning.value = true;
|
||||
|
||||
await UniversalBle.startScan(
|
||||
scanFilter: ScanFilter(withServices: [BleUuid.ZWIFT_CUSTOM_SERVICE_UUID, BleUuid.ZWIFT_RIDE_CUSTOM_SERVICE_UUID]),
|
||||
platformConfig: PlatformConfig(web: WebOptions(optionalServices: [BleUuid.ZWIFT_CUSTOM_SERVICE_UUID])),
|
||||
);
|
||||
Future.delayed(Duration(seconds: 30)).then((_) {
|
||||
if (isScanning.value) {
|
||||
UniversalBle.stopScan();
|
||||
isScanning.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _addDevices(List<BaseDevice> dev) {
|
||||
final newDevices = dev.where((device) => !devices.contains(device)).toList();
|
||||
devices.addAll(newDevices);
|
||||
|
||||
for (final device in newDevices) {
|
||||
_connect(device).then((_) {});
|
||||
}
|
||||
|
||||
hasDevices.value = devices.isNotEmpty;
|
||||
if (devices.isNotEmpty && !androidNotificationsSetup && !kIsWeb && Platform.isAndroid) {
|
||||
androidNotificationsSetup = true;
|
||||
@@ -54,37 +83,43 @@ class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _connect(BleDevice bleDevice) async {
|
||||
Future<void> _connect(BaseDevice bleDevice) async {
|
||||
try {
|
||||
await bleDevice.connect();
|
||||
|
||||
final actionSubscription = bleDevice.actionStream.listen((data) {
|
||||
_actionStreams.add(data);
|
||||
});
|
||||
_streamSubscriptions[bleDevice] = actionSubscription;
|
||||
|
||||
final connectionStateSubscription = bleDevice.device.connectionState.listen((state) async {
|
||||
final connectionStateSubscription = UniversalBle.connectionStream(bleDevice.device.deviceId).listen((
|
||||
state,
|
||||
) async {
|
||||
bleDevice.isConnected = state.isConnected;
|
||||
_connectionStreams.add(bleDevice);
|
||||
});
|
||||
_connectionSubscriptions[bleDevice] = connectionStateSubscription;
|
||||
|
||||
await bleDevice.connect();
|
||||
|
||||
_streamSubscriptions[bleDevice] = actionSubscription;
|
||||
} catch (e, backtrace) {
|
||||
if (e is FlutterBluePlusException && e.code == FbpErrorCode.connectionCanceled.index) {
|
||||
// ignore connections canceled by the user
|
||||
} else {
|
||||
_actionStreams.add(LogNotification(e.toString()));
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
print("backtrace: $backtrace");
|
||||
}
|
||||
_actionStreams.add(LogNotification(e.toString()));
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
print("backtrace: $backtrace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
FlutterBluePlus.stopScan();
|
||||
UniversalBle.stopScan();
|
||||
isScanning.value = false;
|
||||
for (var device in devices) {
|
||||
device.device.disconnect();
|
||||
_streamSubscriptions[device]?.cancel();
|
||||
_streamSubscriptions.remove(device);
|
||||
_connectionSubscriptions[device]?.cancel();
|
||||
_connectionSubscriptions.remove(device);
|
||||
UniversalBle.disconnect(device.device.deviceId);
|
||||
}
|
||||
_lastScanResult.clear();
|
||||
hasDevices.value = false;
|
||||
devices.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,42 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:swift_control/utils/ble.dart';
|
||||
import 'package:swift_control/utils/crypto/local_key_provider.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_click.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_play.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_ride.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../crypto/zap_crypto.dart';
|
||||
import '../messages/notification.dart';
|
||||
|
||||
abstract class BleDevice {
|
||||
final ScanResult scanResult;
|
||||
abstract class BaseDevice {
|
||||
final BleDevice scanResult;
|
||||
final zapEncryption = ZapCrypto(LocalKeyProvider());
|
||||
|
||||
bool isConnected = false;
|
||||
|
||||
bool supportsEncryption = true;
|
||||
|
||||
BleDevice(this.scanResult);
|
||||
BaseDevice(this.scanResult);
|
||||
|
||||
static BleDevice? fromScanResult(ScanResult scanResult) {
|
||||
if (scanResult.device.platformName == 'Zwift Ride') {
|
||||
static BaseDevice? fromScanResult(BleDevice scanResult) {
|
||||
if (scanResult.name == 'Zwift Ride') {
|
||||
return ZwiftRide(scanResult);
|
||||
}
|
||||
if (kIsWeb) {
|
||||
// manufacturer data is not available on web
|
||||
if (scanResult.device.platformName == 'Zwift Play') {
|
||||
if (scanResult.name == 'Zwift Play') {
|
||||
return ZwiftPlay(scanResult);
|
||||
} else if (scanResult.device.platformName == 'Zwift Click') {
|
||||
} else if (scanResult.name == 'Zwift Click') {
|
||||
return ZwiftClick(scanResult);
|
||||
}
|
||||
}
|
||||
final manufacturerData = scanResult.advertisementData.manufacturerData;
|
||||
final data = manufacturerData[Constants.ZWIFT_MANUFACTURER_ID];
|
||||
final manufacturerData = scanResult.manufacturerDataList;
|
||||
final data = manufacturerData.firstOrNullWhere((e) => e.companyId == Constants.ZWIFT_MANUFACTURER_ID)?.payload;
|
||||
if (data == null || data.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
@@ -49,7 +52,7 @@ abstract class BleDevice {
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BleDevice && runtimeType == other.runtimeType && scanResult == other.scanResult;
|
||||
other is BaseDevice && runtimeType == other.runtimeType && scanResult == other.scanResult;
|
||||
|
||||
@override
|
||||
int get hashCode => scanResult.hashCode;
|
||||
@@ -59,35 +62,22 @@ abstract class BleDevice {
|
||||
return runtimeType.toString();
|
||||
}
|
||||
|
||||
BluetoothDevice get device => scanResult.device;
|
||||
BleDevice get device => scanResult;
|
||||
final StreamController<BaseNotification> actionStreamInternal = StreamController<BaseNotification>.broadcast();
|
||||
Stream<BaseNotification> get actionStream => actionStreamInternal.stream;
|
||||
|
||||
Future<void> connect() async {
|
||||
await device.connect(autoConnect: false).timeout(const Duration(seconds: 3));
|
||||
|
||||
var filteredStateStream = device.connectionState.where((s) => s == BluetoothConnectionState.connected);
|
||||
|
||||
// Start listening now, before invokeMethod, to ensure we don't miss the response
|
||||
Future<BluetoothConnectionState> futureState = filteredStateStream.first;
|
||||
|
||||
// wait for connection
|
||||
await futureState.timeout(
|
||||
const Duration(seconds: 10),
|
||||
onTimeout: () {
|
||||
throw TimeoutException('Failed to connect in time.');
|
||||
},
|
||||
);
|
||||
await UniversalBle.connect(device.deviceId, connectionTimeout: const Duration(seconds: 3));
|
||||
|
||||
if (!kIsWeb && Platform.isAndroid) {
|
||||
await device.requestMtu(256);
|
||||
//await UniversalBle.requestMtu(device.deviceId, 256);
|
||||
}
|
||||
final services = await device.discoverServices();
|
||||
|
||||
if (device.isConnected) {
|
||||
await handleServices(services);
|
||||
}
|
||||
final services = await UniversalBle.discoverServices(device.deviceId);
|
||||
await handleServices(services);
|
||||
}
|
||||
|
||||
Future<void> handleServices(List<BluetoothService> services);
|
||||
Future<void> handleServices(List<BleService> services);
|
||||
|
||||
void processCharacteristic(String tag, Uint8List bytes);
|
||||
}
|
||||
@@ -1,24 +1,22 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/devices/ble_device.dart';
|
||||
import 'package:swift_control/utils/devices/base_device.dart';
|
||||
import 'package:swift_control/utils/messages/notification.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../ble.dart';
|
||||
import '../crypto/encryption_utils.dart';
|
||||
import '../messages/click_notification.dart';
|
||||
|
||||
class ZwiftClick extends BleDevice {
|
||||
class ZwiftClick extends BaseDevice {
|
||||
ZwiftClick(super.scanResult);
|
||||
|
||||
List<int> get startCommand => Constants.RIDE_ON + Constants.RESPONSE_START_CLICK;
|
||||
Guid get customServiceId => BleUuid.ZWIFT_CUSTOM_SERVICE_UUID;
|
||||
String get customServiceId => BleUuid.ZWIFT_CUSTOM_SERVICE_UUID;
|
||||
|
||||
@override
|
||||
Future<void> handleServices(List<BluetoothService> services) async {
|
||||
Future<void> handleServices(List<BleService> services) async {
|
||||
final customService = services.firstOrNullWhere((service) => service.uuid == customServiceId);
|
||||
|
||||
if (customService == null) {
|
||||
@@ -39,41 +37,51 @@ class ZwiftClick extends BleDevice {
|
||||
throw Exception('Characteristics not found');
|
||||
}
|
||||
|
||||
if (!asyncCharacteristic.isNotifying) {
|
||||
await asyncCharacteristic.setNotifyValue(true);
|
||||
}
|
||||
final asyncSubscription = asyncCharacteristic.lastValueStream.listen((onData) {
|
||||
_processCharacteristic('async', Uint8List.fromList(onData));
|
||||
});
|
||||
device.cancelWhenDisconnected(asyncSubscription);
|
||||
|
||||
if (!syncTxCharacteristic.isNotifying) {
|
||||
await syncTxCharacteristic.setNotifyValue(true, forceIndications: !kIsWeb && Platform.isAndroid);
|
||||
}
|
||||
final syncSubscription = syncTxCharacteristic.lastValueStream.listen((onData) {
|
||||
_processCharacteristic('sync', Uint8List.fromList(onData));
|
||||
});
|
||||
device.cancelWhenDisconnected(syncSubscription);
|
||||
await UniversalBle.setNotifiable(
|
||||
device.deviceId,
|
||||
customService.uuid,
|
||||
asyncCharacteristic.uuid,
|
||||
BleInputProperty.notification,
|
||||
);
|
||||
await UniversalBle.setNotifiable(
|
||||
device.deviceId,
|
||||
customService.uuid,
|
||||
syncTxCharacteristic.uuid,
|
||||
BleInputProperty.indication,
|
||||
);
|
||||
|
||||
await _setupHandshake(syncRxCharacteristic);
|
||||
}
|
||||
|
||||
Future<void> _setupHandshake(BluetoothCharacteristic syncRxCharacteristic) async {
|
||||
Future<void> _setupHandshake(BleCharacteristic syncRxCharacteristic) async {
|
||||
if (supportsEncryption) {
|
||||
await syncRxCharacteristic.write([
|
||||
...Constants.RIDE_ON,
|
||||
...Constants.REQUEST_START,
|
||||
...zapEncryption.localKeyProvider.getPublicKeyBytes(),
|
||||
], withoutResponse: true);
|
||||
await UniversalBle.writeValue(
|
||||
device.deviceId,
|
||||
customServiceId,
|
||||
syncRxCharacteristic.uuid,
|
||||
Uint8List.fromList([
|
||||
...Constants.RIDE_ON,
|
||||
...Constants.REQUEST_START,
|
||||
...zapEncryption.localKeyProvider.getPublicKeyBytes(),
|
||||
]),
|
||||
BleOutputProperty.withoutResponse,
|
||||
);
|
||||
} else {
|
||||
await syncRxCharacteristic.write(Constants.RIDE_ON, withoutResponse: true);
|
||||
await UniversalBle.writeValue(
|
||||
device.deviceId,
|
||||
customServiceId,
|
||||
syncRxCharacteristic.uuid,
|
||||
Constants.RIDE_ON,
|
||||
BleOutputProperty.withoutResponse,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _processCharacteristic(String tag, Uint8List bytes) {
|
||||
@override
|
||||
void processCharacteristic(String characteristic, Uint8List bytes) {
|
||||
if (kDebugMode && false) {
|
||||
print('Received $tag: ${bytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(' ')}');
|
||||
print('Received $tag: ${String.fromCharCodes(bytes)}');
|
||||
print('Received $characteristic: ${bytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(' ')}');
|
||||
print('Received $characteristic: ${String.fromCharCodes(bytes)}');
|
||||
}
|
||||
|
||||
if (bytes.isEmpty) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:accessibility/accessibility.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_click.dart';
|
||||
import 'package:swift_control/utils/messages/controller_notification.dart';
|
||||
import 'package:swift_control/utils/messages/play_notification.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../ble.dart';
|
||||
@@ -8,14 +9,14 @@ import '../ble.dart';
|
||||
class ZwiftPlay extends ZwiftClick {
|
||||
ZwiftPlay(super.scanResult);
|
||||
|
||||
ControllerNotification? _lastControllerNotification;
|
||||
PlayNotification? _lastControllerNotification;
|
||||
|
||||
@override
|
||||
List<int> get startCommand => Constants.RIDE_ON + Constants.RESPONSE_START_PLAY;
|
||||
|
||||
@override
|
||||
void processClickNotification(Uint8List message) {
|
||||
final ControllerNotification clickNotification = ControllerNotification(message);
|
||||
final PlayNotification clickNotification = PlayNotification(message);
|
||||
if (_lastControllerNotification == null || _lastControllerNotification != clickNotification) {
|
||||
_lastControllerNotification = clickNotification;
|
||||
actionStreamInternal.add(clickNotification);
|
||||
@@ -25,6 +26,17 @@ class ZwiftPlay extends ZwiftClick {
|
||||
} else if (!clickNotification.rightPad && clickNotification.analogLR.abs() == 100) {
|
||||
actionHandler.decreaseGear();
|
||||
}
|
||||
if (clickNotification.rightPad) {
|
||||
if (clickNotification.buttonA) {
|
||||
actionHandler.controlMedia(MediaAction.next);
|
||||
} else if (clickNotification.buttonY) {
|
||||
actionHandler.controlMedia(MediaAction.volumeUp);
|
||||
} else if (clickNotification.buttonB) {
|
||||
actionHandler.controlMedia(MediaAction.volumeDown);
|
||||
} else if (clickNotification.buttonZ) {
|
||||
actionHandler.controlMedia(MediaAction.playPause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,44 @@
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_play.dart';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:accessibility/accessibility.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/devices/zwift_click.dart';
|
||||
import 'package:swift_control/utils/messages/ride_notification.dart';
|
||||
|
||||
import '../ble.dart';
|
||||
|
||||
class ZwiftRide extends ZwiftPlay {
|
||||
class ZwiftRide extends ZwiftClick {
|
||||
ZwiftRide(super.scanResult);
|
||||
|
||||
@override
|
||||
Guid get customServiceId => BleUuid.ZWIFT_RIDE_CUSTOM_SERVICE_UUID;
|
||||
String get customServiceId => BleUuid.ZWIFT_RIDE_CUSTOM_SERVICE_UUID;
|
||||
|
||||
@override
|
||||
bool get supportsEncryption => false;
|
||||
|
||||
RideNotification? _lastControllerNotification;
|
||||
|
||||
@override
|
||||
void processClickNotification(Uint8List message) {
|
||||
final RideNotification clickNotification = RideNotification(message);
|
||||
if (_lastControllerNotification == null || _lastControllerNotification != clickNotification) {
|
||||
_lastControllerNotification = clickNotification;
|
||||
actionStreamInternal.add(clickNotification);
|
||||
|
||||
if (clickNotification.analogLR.abs() == 100) {
|
||||
actionHandler.increaseGear();
|
||||
} else if (clickNotification.analogUD.abs() == 100) {
|
||||
actionHandler.decreaseGear();
|
||||
}
|
||||
if (clickNotification.buttonA) {
|
||||
actionHandler.controlMedia(MediaAction.next);
|
||||
} else if (clickNotification.buttonY) {
|
||||
actionHandler.controlMedia(MediaAction.volumeUp);
|
||||
} else if (clickNotification.buttonB) {
|
||||
actionHandler.controlMedia(MediaAction.volumeDown);
|
||||
} else if (clickNotification.buttonZ) {
|
||||
actionHandler.controlMedia(MediaAction.playPause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import 'package:swift_control/utils/messages/notification.dart';
|
||||
|
||||
import '../../protocol/zwift.pb.dart';
|
||||
|
||||
class ControllerNotification extends BaseNotification {
|
||||
class PlayNotification extends BaseNotification {
|
||||
static const int BTN_PRESSED = 0;
|
||||
|
||||
late bool rightPad, buttonY, buttonZ, buttonA, buttonB, buttonOn, buttonShift;
|
||||
late int analogLR, analogUD;
|
||||
|
||||
ControllerNotification(Uint8List message) {
|
||||
PlayNotification(Uint8List message) {
|
||||
final status = PlayKeyPadStatus.fromBuffer(message);
|
||||
|
||||
rightPad = status.rightPad.value == BTN_PRESSED;
|
||||
@@ -41,7 +41,7 @@ class ControllerNotification extends BaseNotification {
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ControllerNotification &&
|
||||
other is PlayNotification &&
|
||||
runtimeType == other.runtimeType &&
|
||||
rightPad == other.rightPad &&
|
||||
buttonY == other.buttonY &&
|
||||
140
lib/utils/messages/ride_notification.dart
Normal file
140
lib/utils/messages/ride_notification.dart
Normal file
@@ -0,0 +1,140 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:swift_control/utils/messages/notification.dart';
|
||||
|
||||
import '../../protocol/zwift.pb.dart';
|
||||
|
||||
enum _RideButtonMask {
|
||||
LEFT_BTN(0x00001),
|
||||
UP_BTN(0x00002),
|
||||
RIGHT_BTN(0x00004),
|
||||
DOWN_BTN(0x00008),
|
||||
A_BTN(0x00010),
|
||||
B_BTN(0x00020),
|
||||
Y_BTN(0x00040),
|
||||
|
||||
Z_BTN(0x00100),
|
||||
SHFT_UP_L_BTN(0x00200),
|
||||
SHFT_DN_L_BTN(0x00400),
|
||||
POWERUP_L_BTN(0x00800),
|
||||
ONOFF_L_BTN(0x01000),
|
||||
SHFT_UP_R_BTN(0x02000),
|
||||
SHFT_DN_R_BTN(0x04000),
|
||||
|
||||
POWERUP_R_BTN(0x10000),
|
||||
ONOFF_R_BTN(0x20000);
|
||||
|
||||
final int mask;
|
||||
|
||||
const _RideButtonMask(this.mask);
|
||||
}
|
||||
|
||||
class RideNotification extends BaseNotification {
|
||||
static const int BTN_PRESSED = 0;
|
||||
|
||||
late bool buttonLeft, buttonRight, buttonUp, buttonDown;
|
||||
late bool buttonA, buttonB, buttonY, buttonZ;
|
||||
late bool buttonShiftUpLeft, buttonShiftDownLeft;
|
||||
late bool buttonShiftUpRight, buttonShiftDownRight;
|
||||
late bool buttonPowerUpLeft, buttonPowerDownLeft;
|
||||
late bool buttonOnOffLeft, buttonOnOffRight;
|
||||
|
||||
late int analogLR, analogUD;
|
||||
|
||||
RideNotification(Uint8List message) {
|
||||
final status = RideKeyPadStatus.fromBuffer(message);
|
||||
|
||||
buttonLeft = status.buttonMap & _RideButtonMask.LEFT_BTN.mask == BTN_PRESSED;
|
||||
buttonRight = status.buttonMap & _RideButtonMask.RIGHT_BTN.mask == BTN_PRESSED;
|
||||
buttonUp = status.buttonMap & _RideButtonMask.UP_BTN.mask == BTN_PRESSED;
|
||||
buttonDown = status.buttonMap & _RideButtonMask.DOWN_BTN.mask == BTN_PRESSED;
|
||||
buttonA = status.buttonMap & _RideButtonMask.A_BTN.mask == BTN_PRESSED;
|
||||
buttonB = status.buttonMap & _RideButtonMask.B_BTN.mask == BTN_PRESSED;
|
||||
buttonY = status.buttonMap & _RideButtonMask.Y_BTN.mask == BTN_PRESSED;
|
||||
buttonZ = status.buttonMap & _RideButtonMask.Z_BTN.mask == BTN_PRESSED;
|
||||
buttonShiftUpLeft = status.buttonMap & _RideButtonMask.SHFT_UP_L_BTN.mask == BTN_PRESSED;
|
||||
buttonShiftDownLeft = status.buttonMap & _RideButtonMask.SHFT_DN_L_BTN.mask == BTN_PRESSED;
|
||||
buttonShiftUpRight = status.buttonMap & _RideButtonMask.SHFT_UP_R_BTN.mask == BTN_PRESSED;
|
||||
buttonShiftDownRight = status.buttonMap & _RideButtonMask.SHFT_DN_R_BTN.mask == BTN_PRESSED;
|
||||
buttonPowerUpLeft = status.buttonMap & _RideButtonMask.POWERUP_L_BTN.mask == BTN_PRESSED;
|
||||
buttonPowerDownLeft = status.buttonMap & _RideButtonMask.POWERUP_R_BTN.mask == BTN_PRESSED;
|
||||
buttonOnOffLeft = status.buttonMap & _RideButtonMask.ONOFF_L_BTN.mask == BTN_PRESSED;
|
||||
buttonOnOffRight = status.buttonMap & _RideButtonMask.ONOFF_R_BTN.mask == BTN_PRESSED;
|
||||
|
||||
for (final analogue in status.analogButtons.groupStatus) {
|
||||
if (analogue.location == RideAnalogLocation.LEFT) {
|
||||
analogLR = analogue.analogValue;
|
||||
} else if (analogue.location == RideAnalogLocation.DOWN) {
|
||||
analogUD = analogue.analogValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final allTrueParameters = [
|
||||
if (buttonLeft) 'buttonLeft',
|
||||
if (buttonRight) 'buttonRight',
|
||||
if (buttonUp) 'buttonUp',
|
||||
if (buttonDown) 'buttonDown',
|
||||
if (buttonA) 'buttonA',
|
||||
if (buttonB) 'buttonB',
|
||||
if (buttonY) 'buttonY',
|
||||
if (buttonZ) 'buttonZ',
|
||||
if (buttonShiftUpLeft) 'buttonShiftUpLeft',
|
||||
if (buttonShiftDownLeft) 'buttonShiftDownLeft',
|
||||
if (buttonShiftUpRight) 'buttonShiftUpRight',
|
||||
if (buttonShiftDownRight) 'buttonShiftDownRight',
|
||||
if (buttonPowerUpLeft) 'buttonPowerUpLeft',
|
||||
if (buttonPowerDownLeft) 'buttonPowerDownLeft',
|
||||
if (buttonOnOffLeft) 'buttonOnOffLeft',
|
||||
if (buttonOnOffRight) 'buttonOnOffRight',
|
||||
];
|
||||
return '{$allTrueParameters, analogLR: $analogLR, analogUD: $analogUD}';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is RideNotification &&
|
||||
runtimeType == other.runtimeType &&
|
||||
buttonLeft == other.buttonLeft &&
|
||||
buttonRight == other.buttonRight &&
|
||||
buttonUp == other.buttonUp &&
|
||||
buttonDown == other.buttonDown &&
|
||||
buttonA == other.buttonA &&
|
||||
buttonB == other.buttonB &&
|
||||
buttonY == other.buttonY &&
|
||||
buttonZ == other.buttonZ &&
|
||||
buttonShiftUpLeft == other.buttonShiftUpLeft &&
|
||||
buttonShiftDownLeft == other.buttonShiftDownLeft &&
|
||||
buttonShiftUpRight == other.buttonShiftUpRight &&
|
||||
buttonShiftDownRight == other.buttonShiftDownRight &&
|
||||
buttonPowerUpLeft == other.buttonPowerUpLeft &&
|
||||
buttonPowerDownLeft == other.buttonPowerDownLeft &&
|
||||
buttonOnOffLeft == other.buttonOnOffLeft &&
|
||||
buttonOnOffRight == other.buttonOnOffRight &&
|
||||
analogLR == other.analogLR &&
|
||||
analogUD == other.analogUD;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
buttonLeft.hashCode ^
|
||||
buttonRight.hashCode ^
|
||||
buttonUp.hashCode ^
|
||||
buttonDown.hashCode ^
|
||||
buttonA.hashCode ^
|
||||
buttonB.hashCode ^
|
||||
buttonY.hashCode ^
|
||||
buttonZ.hashCode ^
|
||||
buttonShiftUpLeft.hashCode ^
|
||||
buttonShiftDownLeft.hashCode ^
|
||||
buttonShiftUpRight.hashCode ^
|
||||
buttonShiftDownRight.hashCode ^
|
||||
buttonPowerUpLeft.hashCode ^
|
||||
buttonPowerDownLeft.hashCode ^
|
||||
buttonOnOffLeft.hashCode ^
|
||||
buttonOnOffRight.hashCode ^
|
||||
analogLR.hashCode ^
|
||||
analogUD.hashCode;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:keypress_simulator/keypress_simulator.dart';
|
||||
import 'package:swift_control/pages/scan.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../keymap/keymap.dart';
|
||||
@@ -56,12 +56,13 @@ class BluetoothTurnedOn extends PlatformRequirement {
|
||||
|
||||
@override
|
||||
Future<void> call() async {
|
||||
return FlutterBluePlus.turnOn();
|
||||
await UniversalBle.enableBluetooth();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {
|
||||
status = FlutterBluePlus.adapterStateNow != BluetoothAdapterState.off;
|
||||
final currentState = await UniversalBle.getBluetoothAvailabilityState();
|
||||
status = currentState == AvailabilityState.poweredOn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
68
lib/widgets/logviewer.dart
Normal file
68
lib/widgets/logviewer.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../main.dart';
|
||||
import '../utils/messages/notification.dart';
|
||||
|
||||
class LogViewer extends StatefulWidget {
|
||||
const LogViewer({super.key});
|
||||
|
||||
@override
|
||||
State<LogViewer> createState() => _LogviewerState();
|
||||
}
|
||||
|
||||
class _LogviewerState extends State<LogViewer> {
|
||||
List<String> _actions = [];
|
||||
|
||||
late StreamSubscription<BaseNotification> _actionSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_actionSubscription = connection.actionStream.listen((data) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_actions.add('${DateTime.now().toString().split(" ").last}: $data');
|
||||
_actions = _actions.takeLast(30).toList();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_actionSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
children:
|
||||
_actions
|
||||
.map(
|
||||
(action) =>
|
||||
Text(action, style: TextStyle(fontSize: 12, fontFeatures: [FontFeature.tabularFigures()])),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
_actions.clear();
|
||||
setState(() {});
|
||||
},
|
||||
icon: Icon(Icons.clear),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
33
lib/widgets/menu.dart
Normal file
33
lib/widgets/menu.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class MenuButton extends StatelessWidget {
|
||||
const MenuButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopupMenuButton(
|
||||
itemBuilder:
|
||||
(c) => [
|
||||
PopupMenuItem(
|
||||
child: Text('Feedback'),
|
||||
onTap: () {
|
||||
launchUrlString('https://github.com/jonasbark/swiftcontrol/issues');
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Donate 🫶'),
|
||||
onTap: () {
|
||||
launchUrlString('https://paypal.me/boni');
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('License'),
|
||||
onTap: () {
|
||||
showLicensePage(context: context);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
url_launcher_linux
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import flutter_blue_plus_darwin
|
||||
import flutter_local_notifications
|
||||
import keypress_simulator_macos
|
||||
import path_provider_foundation
|
||||
import universal_ble
|
||||
import url_launcher_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterBluePlusPlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlusPlugin"))
|
||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||
KeypressSimulatorMacosPlugin.register(with: registry.registrar(forPlugin: "KeypressSimulatorMacosPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
UniversalBlePlugin.register(with: registry.registrar(forPlugin: "UniversalBlePlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
}
|
||||
|
||||
@@ -1,41 +1,40 @@
|
||||
PODS:
|
||||
- flutter_blue_plus_darwin (0.0.2):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- flutter_local_notifications (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- keypress_simulator_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- path_provider_foundation (0.0.1):
|
||||
- universal_ble (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- url_launcher_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
|
||||
DEPENDENCIES:
|
||||
- flutter_blue_plus_darwin (from `Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus_darwin/darwin`)
|
||||
- flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- keypress_simulator_macos (from `Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos`)
|
||||
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- universal_ble (from `Flutter/ephemeral/.symlinks/plugins/universal_ble/darwin`)
|
||||
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
flutter_blue_plus_darwin:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_blue_plus_darwin/darwin
|
||||
flutter_local_notifications:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
keypress_simulator_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos
|
||||
path_provider_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
|
||||
universal_ble:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/universal_ble/darwin
|
||||
url_launcher_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
flutter_blue_plus_darwin: 3ea4ec9133b377febcc8a70b28cd2d2dc9242bd9
|
||||
flutter_local_notifications: 4ccab5b7a22835214a6672e3f9c5e8ae207dab36
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
keypress_simulator_macos: f8556f9101f9f2f175652e0bceddf0fe82a4c6b2
|
||||
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
|
||||
universal_ble: cf52a7b3fd2e7c14d6d7262e9fdadb72ab6b88a6
|
||||
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
|
||||
|
||||
PODFILE CHECKSUM: 7eb978b976557c8c1cd717d8185ec483fd090a82
|
||||
|
||||
|
||||
@@ -269,7 +269,6 @@
|
||||
33CC10EC2044A3C60003C045 = {
|
||||
CreatedOnToolsVersion = 9.2;
|
||||
LastSwiftMigration = 1100;
|
||||
ProvisioningStyle = Automatic;
|
||||
SystemCapabilities = {
|
||||
com.apple.Sandbox = {
|
||||
enabled = 1;
|
||||
@@ -571,15 +570,19 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
"DEVELOPMENT_TEAM[sdk=macosx*]" = 65H3XQQ399;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.jonasbark.swiftControl;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
@@ -705,15 +708,19 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
"DEVELOPMENT_TEAM[sdk=macosx*]" = 65H3XQQ399;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.jonasbark.swiftControl;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -727,15 +734,19 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements;
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
"DEVELOPMENT_TEAM[sdk=macosx*]" = 65H3XQQ399;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.jonasbark.swiftControl;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>We need BT access because it's a BT App.</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>$(PRODUCT_COPYRIGHT)</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>We need BT access because it's a BT App.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
224
pubspec.lock
224
pubspec.lock
@@ -165,62 +165,6 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_blue_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_blue_plus
|
||||
sha256: "2d926dbef0fd6c58d4be8fca9eaaf1ba747c0ccb8373ddd5386665317e26eb61"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.35.3"
|
||||
flutter_blue_plus_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_blue_plus_android
|
||||
sha256: c1d83f84b514e46345a8a58599c428f20b11e78379521e0d3b0611c7b7cbf2c1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
flutter_blue_plus_darwin:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_blue_plus_darwin
|
||||
sha256: "8d0a0f11f83b13dda173396b7e4028b4e8656bc8dbbc82c26a7e49aafc62644b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
flutter_blue_plus_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_blue_plus_linux
|
||||
sha256: "1d367ed378b2bd6c3b9685fda7044e1d2f169884802b7dec7badb31a99a72660"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
flutter_blue_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_blue_plus_platform_interface
|
||||
sha256: "114f8e85a03a28a48d707a4df6cc9218e1f2005cf260c5e815e5585a00da5778"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
flutter_blue_plus_web:
|
||||
dependency: "direct overridden"
|
||||
description:
|
||||
path: "packages/flutter_blue_plus_web"
|
||||
ref: HEAD
|
||||
resolved-ref: "5fc128ed6ff6b1bc038ec9f91a6d9789c2cebc53"
|
||||
url: "https://github.com/chipweinberger/flutter_blue_plus.git"
|
||||
source: git
|
||||
version: "3.0.0"
|
||||
flutter_blue_plus_windows:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: flutter_blue_plus_windows
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.26.1"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -274,6 +218,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_bluetooth:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_web_bluetooth
|
||||
sha256: "1363831def5eed1e1064d1eca04e8ccb35446e8f758579c3c519e156b77926da"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -375,6 +327,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.1.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -407,54 +367,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider
|
||||
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.5"
|
||||
path_provider_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_android
|
||||
sha256: "0ca7359dad67fd7063cb2892ab0c0737b2daafd807cf1acecd62374c8fae6c12"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.16"
|
||||
path_provider_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_foundation
|
||||
sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_platform_interface
|
||||
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_windows
|
||||
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -463,14 +375,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: platform
|
||||
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.6"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -503,14 +407,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
rxdart:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: rxdart
|
||||
sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.28.0"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -540,14 +436,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
stream_with_value:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_with_value
|
||||
sha256: "483d79bf604fdea5274e31207956b2f624f5f03a506cacf081b65cdfcfa647a6"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -604,6 +492,78 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
universal_ble:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: universal_ble
|
||||
sha256: "35d210e93a5938c6a6d1fd3c710cf4ac90b1bdd1b11c8eb2beeb32600672e6e6"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.17.0"
|
||||
url_launcher:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.1"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: "1d0eae19bd7606ef60fe69ef3b312a437a16549476c42321d5dc1506c9ca3bf4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.15"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.2"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.1"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.2"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "3ba963161bd0fe395917ba881d320b9c4f6dd3c4a233da62ab18a5025c85f1e9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.4"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -628,14 +588,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
win_ble:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win_ble
|
||||
sha256: "2a867e13c4b355b101fc2c6e2ac85eeebf965db34eca46856f8b478e93b41e96"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
13
pubspec.yaml
13
pubspec.yaml
@@ -1,7 +1,7 @@
|
||||
name: swift_control
|
||||
description: "SwiftControl - Control your virtual riding"
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
version: 1.0.0+1
|
||||
version: 1.0.0+4
|
||||
|
||||
environment:
|
||||
sdk: ^3.7.0
|
||||
@@ -10,24 +10,17 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
url_launcher: ^6.3.1
|
||||
flutter_local_notifications: ^19.0.0
|
||||
flutter_blue_plus: ^1.35.3
|
||||
universal_ble: any
|
||||
protobuf: ^3.1.0
|
||||
dartx: any
|
||||
pointycastle: any
|
||||
keypress_simulator: ^0.2.0
|
||||
flex_color_scheme: ^8.2.0
|
||||
flutter_blue_plus_windows:
|
||||
path: flutter_blue_plus_windows
|
||||
accessibility:
|
||||
path: accessibility
|
||||
|
||||
dependency_overrides:
|
||||
flutter_blue_plus_web:
|
||||
git:
|
||||
url: https://github.com/chipweinberger/flutter_blue_plus.git
|
||||
path: packages/flutter_blue_plus_web
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
If you are serving your web app in a path other than the root, change the
|
||||
href value below to reflect the base path you are serving from.
|
||||
|
||||
The path provided below has to start and end with a slash "/" in order for
|
||||
it to work correctly.
|
||||
|
||||
For more details:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
@@ -29,7 +16,7 @@
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>swift_play</title>
|
||||
<title>SwiftControl</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
294
web/zwift_ride.html
Normal file
294
web/zwift_ride.html
Normal file
@@ -0,0 +1,294 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Zwift Ride Scanner (Protocol Buffers)</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- thanks to https://www.makinolo.com/blog/2024/07/26/zwift-ride-protocol/ and https://www.makinolo.com/blog/2023/10/08/connecting-to-zwift-play-controllers/ -->
|
||||
<h1>Zwift Ride Scanner</h1>
|
||||
<button onclick="scanForDevices()">Scan for Devices</button>
|
||||
<div id="status">Status: Disconnected</div>
|
||||
<pre id="log" style="white-space: pre-wrap"></pre>
|
||||
|
||||
<script>
|
||||
const statusDiv = document.getElementById("status");
|
||||
const logDiv = document.getElementById("log");
|
||||
let controlCharacteristic = null;
|
||||
|
||||
const BUTTON_MASKS = {
|
||||
LEFT_BTN: 0x1,
|
||||
UP_BTN: 0x2,
|
||||
RIGHT_BTN: 0x4,
|
||||
DOWN_BTN: 0x8,
|
||||
A_BTN: 0x10,
|
||||
B_BTN: 0x20,
|
||||
Y_BTN: 0x40,
|
||||
Z_BTN: 0x100,
|
||||
SHFT_UP_L_BTN: 0x200,
|
||||
SHFT_DN_L_BTN: 0x400,
|
||||
POWERUP_L_BTN: 0x800,
|
||||
ONOFF_L_BTN: 0x1000,
|
||||
SHFT_UP_R_BTN: 0x2000,
|
||||
SHFT_DN_R_BTN: 0x4000,
|
||||
POWERUP_R_BTN: 0x10000,
|
||||
ONOFF_R_BTN: 0x20000,
|
||||
};
|
||||
|
||||
function log(message) {
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
logDiv.textContent += `[${timestamp}] ${message}\n`;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
function parseKeyPress(buffer) {
|
||||
let location = null;
|
||||
let analogValue = null;
|
||||
|
||||
let offset = 0;
|
||||
while (offset < buffer.length) {
|
||||
const tag = buffer[offset];
|
||||
const fieldNum = tag >> 3;
|
||||
const wireType = tag & 0x7;
|
||||
offset++;
|
||||
|
||||
switch (fieldNum) {
|
||||
case 1: // Location
|
||||
if (wireType === 0) {
|
||||
let value = 0;
|
||||
let shift = 0;
|
||||
while (true) {
|
||||
const byte = buffer[offset++];
|
||||
value |= (byte & 0x7f) << shift;
|
||||
if ((byte & 0x80) === 0) break;
|
||||
shift += 7;
|
||||
}
|
||||
location = value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // AnalogValue
|
||||
if (wireType === 0) {
|
||||
let value = 0;
|
||||
let shift = 0;
|
||||
while (true) {
|
||||
const byte = buffer[offset++];
|
||||
value |= (byte & 0x7f) << shift;
|
||||
if ((byte & 0x80) === 0) break;
|
||||
shift += 7;
|
||||
}
|
||||
// ZigZag decode for sint32
|
||||
analogValue = (value >>> 1) ^ -(value & 1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Skip unknown fields
|
||||
if (wireType === 0) {
|
||||
while (buffer[offset++] & 0x80);
|
||||
} else if (wireType === 2) {
|
||||
const length = buffer[offset++];
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { location: location, value: analogValue };
|
||||
}
|
||||
|
||||
function parseKeyGroup(buffer) {
|
||||
let groupStatus = {};
|
||||
|
||||
let offset = 0;
|
||||
while (offset < buffer.length) {
|
||||
const tag = buffer[offset];
|
||||
const fieldNum = tag >> 3;
|
||||
const wireType = tag & 0x7;
|
||||
offset++;
|
||||
|
||||
if (fieldNum === 3 && wireType === 2) {
|
||||
const length = buffer[offset++];
|
||||
const messageBuffer = buffer.slice(
|
||||
offset,
|
||||
offset + length,
|
||||
);
|
||||
let res = parseKeyPress(messageBuffer);
|
||||
groupStatus[res.location] = res.value;
|
||||
offset += length;
|
||||
} else {
|
||||
// Skip unknown fields
|
||||
if (wireType === 0) {
|
||||
while (buffer[offset++] & 0x80);
|
||||
} else if (wireType === 2) {
|
||||
const length = buffer[offset++];
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return groupStatus;
|
||||
}
|
||||
|
||||
function parseButtonState(buttonMap) {
|
||||
const pressedButtons = [];
|
||||
for (const [button, mask] of Object.entries(BUTTON_MASKS)) {
|
||||
if ((buttonMap & mask) === 0) {
|
||||
pressedButtons.push(button);
|
||||
}
|
||||
}
|
||||
return pressedButtons;
|
||||
}
|
||||
|
||||
function parseAnalogMessage(data) {
|
||||
// Each analog group starts with 0x1a
|
||||
if (data[0] !== 0x1a) return null;
|
||||
|
||||
let res = parseKeyGroup(data);
|
||||
return {
|
||||
left: "0" in res ? res["0"] : 0,
|
||||
right: "1" in res ? res["1"] : 0,
|
||||
};
|
||||
}
|
||||
|
||||
function handleMessage(value) {
|
||||
const data = new Uint8Array(value.buffer);
|
||||
const msgType = data[0];
|
||||
|
||||
switch (msgType) {
|
||||
case 0x23: {
|
||||
// Button status
|
||||
const buttonMap =
|
||||
data[2] |
|
||||
(data[3] << 8) |
|
||||
(data[4] << 16) |
|
||||
(data[5] << 24);
|
||||
const pressedButtons = parseButtonState(buttonMap);
|
||||
|
||||
if (pressedButtons.length > 0) {
|
||||
log(
|
||||
`Buttons pressed! ${pressedButtons.join(", ")}`,
|
||||
);
|
||||
}
|
||||
// Find analog values section (after button map)
|
||||
let startIndex = 7; // Skip message type, field number, and button map
|
||||
while (startIndex < data.length) {
|
||||
const analogData = parseAnalogMessage(
|
||||
data.slice(startIndex),
|
||||
);
|
||||
if (!analogData) break;
|
||||
|
||||
log(
|
||||
`Analog left:${analogData.left} right:${analogData.right}`,
|
||||
);
|
||||
startIndex = analogData.nextIndex;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x2a: // Initial status
|
||||
log("Initial status received");
|
||||
break;
|
||||
|
||||
case 0x15: // Idle
|
||||
break;
|
||||
|
||||
case 0x19: // Status update
|
||||
break;
|
||||
|
||||
default:
|
||||
log(
|
||||
`Unknown message: ${Array.from(data)
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join(" ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function scanForDevices() {
|
||||
if (!navigator.bluetooth) {
|
||||
statusDiv.textContent =
|
||||
"Status: Web Bluetooth API is not supported";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
statusDiv.textContent = "Status: Scanning...";
|
||||
logDiv.textContent = "";
|
||||
|
||||
const device = await navigator.bluetooth.requestDevice({
|
||||
filters: [
|
||||
{
|
||||
name: "Zwift Ride",
|
||||
},
|
||||
],
|
||||
optionalServices: [
|
||||
"0000180f-0000-1000-8000-00805f9b34fb", // Battery Service
|
||||
"0000180a-0000-1000-8000-00805f9b34fb", // Device Information
|
||||
"0000fc82-0000-1000-8000-00805f9b34fb", // Custom Service
|
||||
],
|
||||
});
|
||||
|
||||
log(`Device name: ${device.name}`);
|
||||
log(`Device ID: ${device.id}`);
|
||||
|
||||
statusDiv.textContent = "Status: Connecting...";
|
||||
const server = await device.gatt.connect();
|
||||
log("Connected to GATT server");
|
||||
|
||||
const service = await server.getPrimaryService(
|
||||
"0000fc82-0000-1000-8000-00805f9b34fb",
|
||||
);
|
||||
log("Found custom service");
|
||||
|
||||
const measurementChar = await service.getCharacteristic(
|
||||
"00000002-19ca-4651-86e5-fa29dcdd09d1",
|
||||
);
|
||||
controlCharacteristic = await service.getCharacteristic(
|
||||
"00000003-19ca-4651-86e5-fa29dcdd09d1",
|
||||
);
|
||||
const responseChar = await service.getCharacteristic(
|
||||
"00000004-19ca-4651-86e5-fa29dcdd09d1",
|
||||
);
|
||||
|
||||
log("Got service characteristics");
|
||||
|
||||
// Initial handshake
|
||||
const handshake = new TextEncoder().encode("RideOn");
|
||||
await controlCharacteristic.writeValue(handshake);
|
||||
log("Sent RideOn handshake");
|
||||
|
||||
// Set up notifications
|
||||
await measurementChar.startNotifications();
|
||||
measurementChar.addEventListener(
|
||||
"characteristicvaluechanged",
|
||||
(event) => {
|
||||
handleMessage(event.target.value);
|
||||
},
|
||||
);
|
||||
|
||||
await responseChar.startNotifications();
|
||||
responseChar.addEventListener(
|
||||
"characteristicvaluechanged",
|
||||
(event) => {
|
||||
const value = new TextDecoder().decode(
|
||||
event.target.value,
|
||||
);
|
||||
log(`Response: ${value}`);
|
||||
},
|
||||
);
|
||||
|
||||
device.addEventListener("gattserverdisconnected", () => {
|
||||
statusDiv.textContent = "Status: Device disconnected";
|
||||
log("Device disconnected");
|
||||
});
|
||||
|
||||
statusDiv.textContent =
|
||||
"Status: Connected and watching for input";
|
||||
} catch (error) {
|
||||
statusDiv.textContent = `Status: Error - ${error}`;
|
||||
log(`Error: ${error.message}`);
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,10 @@
|
||||
# Project-level configuration.
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(swift_play LANGUAGES CXX)
|
||||
project(swift_control LANGUAGES CXX)
|
||||
|
||||
# The name of the executable created for the application. Change this to change
|
||||
# the on-disk name of your application.
|
||||
set(BINARY_NAME "swift_play")
|
||||
set(BINARY_NAME "swift_control")
|
||||
|
||||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||||
# versions of CMake.
|
||||
|
||||
@@ -7,8 +7,14 @@
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <keypress_simulator_windows/keypress_simulator_windows_plugin_c_api.h>
|
||||
#include <universal_ble/universal_ble_plugin_c_api.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
KeypressSimulatorWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("KeypressSimulatorWindowsPluginCApi"));
|
||||
UniversalBlePluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UniversalBlePluginCApi"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
keypress_simulator_windows
|
||||
universal_ble
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
||||
@@ -90,12 +90,12 @@ BEGIN
|
||||
BLOCK "040904e4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "de.jonasbark" "\0"
|
||||
VALUE "FileDescription", "swift_play" "\0"
|
||||
VALUE "FileDescription", "swift_control" "\0"
|
||||
VALUE "FileVersion", VERSION_AS_STRING "\0"
|
||||
VALUE "InternalName", "swift_play" "\0"
|
||||
VALUE "InternalName", "swift_control" "\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2025 de.jonasbark. All rights reserved." "\0"
|
||||
VALUE "OriginalFilename", "swift_play.exe" "\0"
|
||||
VALUE "ProductName", "swift_play" "\0"
|
||||
VALUE "OriginalFilename", "swift_control.exe" "\0"
|
||||
VALUE "ProductName", "swift_control" "\0"
|
||||
VALUE "ProductVersion", VERSION_AS_STRING "\0"
|
||||
END
|
||||
END
|
||||
|
||||
@@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||
FlutterWindow window(project);
|
||||
Win32Window::Point origin(10, 10);
|
||||
Win32Window::Size size(1280, 720);
|
||||
if (!window.Create(L"swift_play", origin, size)) {
|
||||
if (!window.Create(L"swift_control", origin, size)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
window.SetQuitOnClose(true);
|
||||
|
||||
Reference in New Issue
Block a user