mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
Compare commits
152 Commits
v3.1.0+28-
...
v3.3.2+36
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
284d2ca70f | ||
|
|
57961aec5d | ||
|
|
1675d7f2d0 | ||
|
|
baec8d24c3 | ||
|
|
a968723277 | ||
|
|
8668957738 | ||
|
|
ac550fad5b | ||
|
|
c511ac32b6 | ||
|
|
ee48ce0f4e | ||
|
|
8a3d64491b | ||
|
|
b72cc803f0 | ||
|
|
ea17b2e142 | ||
|
|
da62fc4dc6 | ||
|
|
239630f681 | ||
|
|
d95d0cf8cf | ||
|
|
2b25ba942c | ||
|
|
c65369a746 | ||
|
|
fa7d5e7853 | ||
|
|
8ac47cbd4d | ||
|
|
eb85844503 | ||
|
|
010d0ed331 | ||
|
|
1f8f7765a3 | ||
|
|
68f416dda3 | ||
|
|
49e45faec0 | ||
|
|
c81516350a | ||
|
|
890f393fd6 | ||
|
|
e46969c5c4 | ||
|
|
1ec9b55645 | ||
|
|
b0caf7c13b | ||
|
|
302fc15dd7 | ||
|
|
6a2cf1a1c9 | ||
|
|
8ea73bc54a | ||
|
|
7cbab3925f | ||
|
|
246a1bd2be | ||
|
|
f7e2a89ed6 | ||
|
|
f94252edb9 | ||
|
|
b7b6b9803f | ||
|
|
807d868b74 | ||
|
|
c3e8c4666c | ||
|
|
926651ebb3 | ||
|
|
a7d5624582 | ||
|
|
03209740ec | ||
|
|
af6ae3433e | ||
|
|
41f4dd1d57 | ||
|
|
d5c1b67675 | ||
|
|
0b18d74ac9 | ||
|
|
fb3fe5f8c0 | ||
|
|
796c973fd4 | ||
|
|
7c6335c4d1 | ||
|
|
af2267c486 | ||
|
|
56d9e62610 | ||
|
|
7e18a169d4 | ||
|
|
74280eda34 | ||
|
|
e1309d4d95 | ||
|
|
14aa6f7454 | ||
|
|
1368d7d24e | ||
|
|
8c09b170c3 | ||
|
|
080409b984 | ||
|
|
f0ec276547 | ||
|
|
23aafcd7bc | ||
|
|
3718a126ac | ||
|
|
846dd07bf4 | ||
|
|
ba60062a24 | ||
|
|
ed4f928fde | ||
|
|
2a09d550e5 | ||
|
|
bb1ae4e616 | ||
|
|
828aa70a56 | ||
|
|
4021f3131d | ||
|
|
80ef81ca64 | ||
|
|
fec13d012b | ||
|
|
e8ca3fc287 | ||
|
|
d5260d801c | ||
|
|
916b1ec1fc | ||
|
|
7380bb5001 | ||
|
|
2e95fb556a | ||
|
|
90591cbfa2 | ||
|
|
929409db71 | ||
|
|
4263375fb2 | ||
|
|
bb5d149ba4 | ||
|
|
1a322dc0d3 | ||
|
|
d10da94f20 | ||
|
|
7eb28881cb | ||
|
|
823e04d189 | ||
|
|
ca5d4aeadb | ||
|
|
a4d937c4f3 | ||
|
|
fa4add6797 | ||
|
|
ec2ed4e6c5 | ||
|
|
6bd41d9a54 | ||
|
|
1ff2a205bc | ||
|
|
dd73c3249b | ||
|
|
75eef49317 | ||
|
|
e8858e0c7d | ||
|
|
df9142a6bf | ||
|
|
36f312403b | ||
|
|
d8983889ae | ||
|
|
bfaf2f2d29 | ||
|
|
2ba9c284ba | ||
|
|
ef2b4af28a | ||
|
|
ba042cd07d | ||
|
|
f8cb4cff4f | ||
|
|
92010b787b | ||
|
|
e142a8c587 | ||
|
|
759dcaa8b8 | ||
|
|
05939dcf1e | ||
|
|
34494819f5 | ||
|
|
a9491b7fa5 | ||
|
|
311a676aea | ||
|
|
2eab9c581c | ||
|
|
1284499c25 | ||
|
|
a74471b9f8 | ||
|
|
81f61a5b87 | ||
|
|
7b2446b6e0 | ||
|
|
60898f7536 | ||
|
|
b2fa7870b6 | ||
|
|
6ef2ff711a | ||
|
|
9f58dca10e | ||
|
|
35e499720b | ||
|
|
7820a80241 | ||
|
|
ffc6409488 | ||
|
|
8eaa411a80 | ||
|
|
f08714f25a | ||
|
|
1f3352ff80 | ||
|
|
2601844970 | ||
|
|
e4bbb8b279 | ||
|
|
a13e2aa494 | ||
|
|
b8383a2280 | ||
|
|
2cb5ef03ce | ||
|
|
5203c3a576 | ||
|
|
36dfb2dc0b | ||
|
|
3f6434b5a3 | ||
|
|
d9595a3485 | ||
|
|
b3352d0c1c | ||
|
|
7e15df1f15 | ||
|
|
b7e086c326 | ||
|
|
659e7b0585 | ||
|
|
501ab48da5 | ||
|
|
3b9ceea64b | ||
|
|
f3c7bbbcbf | ||
|
|
9b21a2775e | ||
|
|
b669d4c5ea | ||
|
|
a744242c70 | ||
|
|
7f963f71f8 | ||
|
|
9f0ab53e1f | ||
|
|
5fc16e9fb7 | ||
|
|
4329afba1c | ||
|
|
01f87beef5 | ||
|
|
45fecfb4f6 | ||
|
|
9b020e09ae | ||
|
|
3b1c05aba4 | ||
|
|
90a111944a | ||
|
|
ceb029afb0 | ||
|
|
dc769ce6a0 |
64
.github/workflows/build.yml
vendored
64
.github/workflows/build.yml
vendored
@@ -31,7 +31,7 @@ on:
|
||||
build_web:
|
||||
description: 'Build for Web'
|
||||
required: false
|
||||
default: true
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
@@ -97,6 +97,7 @@ jobs:
|
||||
cp $PP_PATH_MACOS ~/Library/MobileDevice/Provisioning\ Profiles
|
||||
|
||||
- name: 🐦 Setup Shorebird
|
||||
if: inputs.build_mac || inputs.build_android || inputs.build_ios || inputs.build_web
|
||||
uses: shorebirdtech/setup-shorebird@v1
|
||||
with:
|
||||
cache: true
|
||||
@@ -239,25 +240,6 @@ jobs:
|
||||
version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
|
||||
echo "VERSION=$version" >> $GITHUB_ENV
|
||||
|
||||
#11 Check if Tag Exists
|
||||
- name: Check if Tag Exists
|
||||
if: inputs.build_github
|
||||
id: check_tag
|
||||
run: |
|
||||
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
|
||||
echo "TAG_EXISTS=true" >> $GITHUB_ENV
|
||||
else
|
||||
echo "TAG_EXISTS=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
#12 Modify Tag if it Exists
|
||||
- name: Modify Tag
|
||||
if: env.TAG_EXISTS && inputs.build_github
|
||||
id: modify_tag
|
||||
run: |
|
||||
new_version="${{ env.VERSION }}-build-${{ github.run_number }}"
|
||||
echo "VERSION=$new_version" >> $GITHUB_ENV
|
||||
|
||||
#13 Create Release
|
||||
- name: Create Release
|
||||
if: inputs.build_github
|
||||
@@ -272,7 +254,7 @@ jobs:
|
||||
|
||||
windows:
|
||||
needs: build
|
||||
if: inputs.build_windows && inputs.build_github
|
||||
if: inputs.build_windows
|
||||
name: Build & Release on Windows
|
||||
runs-on: windows-latest
|
||||
|
||||
@@ -281,13 +263,6 @@ jobs:
|
||||
- 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'
|
||||
|
||||
- name: 🐦 Setup Shorebird
|
||||
uses: shorebirdtech/setup-shorebird@v1
|
||||
with:
|
||||
@@ -323,7 +298,31 @@ jobs:
|
||||
}
|
||||
Compress-Archive -Path "build/windows/x64/runner/Release/*" -DestinationPath "build/windows/x64/runner/Release/SwiftControl.windows.zip"
|
||||
|
||||
#9 Upload Artifacts
|
||||
- uses: microsoft/setup-msstore-cli@v1
|
||||
if: false
|
||||
|
||||
- name: Configure the Microsoft Store CLI
|
||||
if: false
|
||||
run: msstore reconfigure --tenantId $ --clientId $ --clientSecret $ --sellerId $
|
||||
|
||||
- name: Set Up Flutter
|
||||
uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: 'stable'
|
||||
flutter-version: ${{ env.FLUTTER_VERSION }}
|
||||
|
||||
- name: Create MSIX package
|
||||
run: dart run msix:create
|
||||
|
||||
- name: Publish MSIX to the Microsoft Store
|
||||
if: false
|
||||
run: msstore publish -v "build/windows/x64/runner/Release/"
|
||||
|
||||
- name: Rename swift_control.msix to SwiftControl.windows.msix
|
||||
shell: pwsh
|
||||
run: |
|
||||
Rename-Item -Path "build/windows/x64/runner/Release/swift_control.msix" -NewName "SwiftControl.windows.msix"
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -331,8 +330,8 @@ jobs:
|
||||
name: Releases
|
||||
path: |
|
||||
build/windows/x64/runner/Release/SwiftControl.windows.zip
|
||||
build/windows/x64/runner/Release/SwiftControl.windows.msix
|
||||
|
||||
#10 Extract Version
|
||||
- name: Extract version from pubspec.yaml (Windows)
|
||||
shell: pwsh
|
||||
run: |
|
||||
@@ -341,13 +340,12 @@ jobs:
|
||||
}
|
||||
echo "VERSION=$version" >> $env:GITHUB_ENV
|
||||
|
||||
# add artifact to release
|
||||
|
||||
- name: Create Release
|
||||
- name: Update Release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
allowUpdates: true
|
||||
artifacts: "build/windows/x64/runner/Release/SwiftControl.windows.zip"
|
||||
artifacts: "build/windows/x64/runner/Release/SwiftControl.windows.zip,build/windows/x64/runner/Release/SwiftControl.windows.msix"
|
||||
bodyFile: scripts/RELEASE_NOTES.md
|
||||
prerelease: true
|
||||
tag: v${{ env.VERSION }}
|
||||
|
||||
16
.github/workflows/patch.yml
vendored
16
.github/workflows/patch.yml
vendored
@@ -23,7 +23,6 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: 🐦 Setup Shorebird
|
||||
if: false
|
||||
uses: shorebirdtech/setup-shorebird@v1
|
||||
with:
|
||||
cache: true
|
||||
@@ -71,34 +70,31 @@ jobs:
|
||||
cp $PP_PATH_MACOS ~/Library/MobileDevice/Provisioning\ Profiles
|
||||
|
||||
- name: Decode Keystore
|
||||
if: false
|
||||
run: |
|
||||
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > android/android.keystore;
|
||||
echo "${{ secrets.KEYSTORE_PROPERTIES }}" > android/keystore.properties;
|
||||
|
||||
- name: 🚀 Shorebird Patch macOS
|
||||
if: false
|
||||
if: false # patch doesn't work: https://github.com/jonasbark/swiftcontrol/issues/143
|
||||
uses: shorebirdtech/shorebird-patch@v1
|
||||
with:
|
||||
platform: macos
|
||||
release-version: latest
|
||||
args: '--allow-asset-diffs'
|
||||
args: '--allow-asset-diffs --allow-native-diffs'
|
||||
|
||||
- name: 🚀 Shorebird Patch Android
|
||||
if: false
|
||||
uses: shorebirdtech/shorebird-patch@v1
|
||||
with:
|
||||
platform: android
|
||||
release-version: latest
|
||||
args: '--allow-asset-diffs'
|
||||
args: '--allow-asset-diffs --allow-native-diffs'
|
||||
|
||||
- name: 🚀 Shorebird Patch iOS
|
||||
if: false
|
||||
uses: shorebirdtech/shorebird-patch@v1
|
||||
with:
|
||||
platform: ios
|
||||
release-version: latest
|
||||
args: '--allow-asset-diffs'
|
||||
args: '--allow-asset-diffs --allow-native-diffs'
|
||||
|
||||
- name: Set Up Flutter
|
||||
uses: subosito/flutter-action@v2
|
||||
@@ -136,12 +132,12 @@ jobs:
|
||||
allowUpdates: true
|
||||
artifacts: "build/macos/Build/Products/Release/SwiftControl.macos.zip"
|
||||
bodyFile: scripts/RELEASE_NOTES.md
|
||||
prerelease: true
|
||||
tag: v${{ env.VERSION }}
|
||||
token: ${{ secrets.TOKEN }}
|
||||
|
||||
windows:
|
||||
name: Patch Windows
|
||||
if: false
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
@@ -166,4 +162,4 @@ jobs:
|
||||
with:
|
||||
platform: windows
|
||||
release-version: latest
|
||||
args: '--allow-asset-diffs'
|
||||
args: '--allow-asset-diffs --allow-native-diffs'
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,6 +10,7 @@
|
||||
.history
|
||||
.svn/
|
||||
.swiftpm/
|
||||
debug/
|
||||
migrate_working_dir/
|
||||
|
||||
android/keystore.properties
|
||||
|
||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,8 +1,42 @@
|
||||
### 3.3.1 (unreleased)
|
||||
**New Features:**
|
||||
- Support for Shimano Di2
|
||||
|
||||
**Fixes:**
|
||||
- fix detection of Elite Square Sterzo devices
|
||||
|
||||
### 3.3.0 (31-10-2025)
|
||||
|
||||
**New Features:**
|
||||
- Support for Elite Sterzo (thanks @michidk)
|
||||
- Support for Gamepads
|
||||
- Support for cheap bluetooth remotes (such as [these](https://www.amazon.com/s?k=bluetooth+remote))
|
||||
- you can now customize the Keymap right from the Customize section
|
||||
- show signal strength of connected devices (thanks @michidk)
|
||||
- Android and Windows only: simulate bluetooth controllers
|
||||
- enables gamepad and bluetooth remotes support for Zwift, Rouvy and Biketerra
|
||||
|
||||
**Fixes:**
|
||||
- fix firmware version display for Zwift Click V2 devices
|
||||
- fix touch position on some Android devices
|
||||
- Wahoo Kickr Bike Shift can now be connected
|
||||
- update default keymap for TrainingPeaks
|
||||
|
||||
### 3.2.0 (2025-10-22)
|
||||
- a brand-new way of controlling MyWhoosh:
|
||||
- device pairing no longer required as mouse emulation is no longer needed
|
||||
- SwiftControl can now stay in the background
|
||||
- more devices can be controlled
|
||||
- do more, such as define Emotes, Camera angles and steering
|
||||
|
||||
### 3.1.0 (2025-10-17)
|
||||
- new app icon
|
||||
- adjusted MyWhoosh keyboard navigation mapping (thanks @bin101)
|
||||
- support for Wahook Kickr Bike Shift (thanks @MattW2)
|
||||
- initial support for Elite Square Smart Frame
|
||||
- initial support for Elite Square Smart Frame
|
||||
- reconnects to your device automatically when connection is lost
|
||||
- SwiftControl now warns you if your device firmware is outdated
|
||||
- SwiftControl is now available in Microsoft Store: https://apps.microsoft.com/detail/9NP42GS03Z26
|
||||
|
||||
### 3.0.3 (2025-10-12)
|
||||
- SwiftControl now supports iOS!
|
||||
|
||||
1
INSTRUCTIONS_ANDROID.md
Normal file
1
INSTRUCTIONS_ANDROID.md
Normal file
@@ -0,0 +1 @@
|
||||
Instructions will be added soon
|
||||
10
INSTRUCTIONS_IOS.md
Normal file
10
INSTRUCTIONS_IOS.md
Normal file
@@ -0,0 +1,10 @@
|
||||
**Instructions for using the MyWhoosh Link method**
|
||||
1) launch MyWhoosh on the device of your choice
|
||||
2) launch MyWhoosh Link, check if the "Link" connection works
|
||||
3) close MyWhoosh Link, open SwiftControl, follow on screen instructions
|
||||
Step 2 is not necessary after that once step 3 works
|
||||
|
||||
And here's a video with a few explanations:
|
||||
|
||||
[](https://www.youtube.com/watch?v=p8sgQhuufeI)
|
||||
[https://www.youtube.com/watch?v=p8sgQhuufeI](https://www.youtube.com/watch?v=p8sgQhuufeI)
|
||||
1
INSTRUCTIONS_MACOS.md
Normal file
1
INSTRUCTIONS_MACOS.md
Normal file
@@ -0,0 +1 @@
|
||||
Instructions will be added soon
|
||||
1
INSTRUCTIONS_WINDOWS.md
Normal file
1
INSTRUCTIONS_WINDOWS.md
Normal file
@@ -0,0 +1 @@
|
||||
Instructions will be added soon
|
||||
60
README.md
60
README.md
@@ -4,12 +4,12 @@
|
||||
|
||||
## Description
|
||||
|
||||
With SwiftControl you can **control your favorite trainer app** using your Zwift Click, Zwift Ride or Zwift Play devices. Here's what you can do with it, depending on your configuration:
|
||||
With SwiftControl you can **control your favorite trainer app** using your Zwift Click, Zwift Ride, Zwift Play, or other similar devices. Here's what you can do with it, depending on your configuration:
|
||||
- Virtual Gear shifting
|
||||
- Steering / turning
|
||||
- Steering/turning
|
||||
- adjust workout intensity
|
||||
- control music on your device
|
||||
- more? If you can do it via keyboard, mouse or touch, you can do it with SwiftControl
|
||||
- more? If you can do it via keyboard, mouse, or touch, you can do it with SwiftControl
|
||||
|
||||
|
||||
https://github.com/user-attachments/assets/1f81b674-1628-4763-ad66-5f3ed7a3f159
|
||||
@@ -21,26 +21,40 @@ https://github.com/user-attachments/assets/1f81b674-1628-4763-ad66-5f3ed7a3f159
|
||||
Check the compatibility matrix below!
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=de.jonasbark.swiftcontrol"><img width="270" height="80" alt="GetItOnGooglePlay_Badge_Web_color_English" src="https://github.com/user-attachments/assets/a059d5a1-2efb-4f65-8117-ef6a99823b21" /></a>
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a>
|
||||
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a>
|
||||
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=mac"><img width="270" height="80" alt="Mac App Store" src="https://github.com/user-attachments/assets/b3552436-409c-43b0-ba7d-b6a72ae30ff1" /></a>
|
||||
|
||||
|
||||
Get the latest version for Windows here: https://github.com/jonasbark/swiftcontrol/releases
|
||||
<a href="https://apps.microsoft.com/detail/9NP42GS03Z26"><img width="270" alt="Microsoft Store" src="https://github.com/user-attachments/assets/7a8a3cd6-ec26-4678-a850-732eedd27c48" /></a>
|
||||
|
||||
## Supported Apps
|
||||
- MyWhoosh
|
||||
- TrainingPeaks Virtual / indieVelo
|
||||
- Biketerra.com (they do offer native integration already - check it out)
|
||||
- Rouvy (most Zwift devices are already supported by Rouvy)
|
||||
- any other! You can add custom mapping and adjust touch points or keyboard shortcuts to your liking
|
||||
- Biketerra.com
|
||||
- Rouvy
|
||||
- Zwift
|
||||
- running SwiftControl on Android or Windows is required to act as a "Controllable" in Zwift - iOS and macOS are not able to do so
|
||||
- any other!
|
||||
- You can add custom mapping and adjust touch points or keyboard shortcuts to your liking
|
||||
|
||||
## Supported Devices
|
||||
- Zwift Click
|
||||
- Zwift Click v2 (mostly, see issue #68)
|
||||
- Zwift Ride
|
||||
- Zwift Play
|
||||
- Shimano Di2
|
||||
- Configure your levers to use D-Fly channels with Shimano E-Tube app
|
||||
- Wahoo Kickr Bike Shift
|
||||
- CYCPLUS BC2 Virtual Shifter
|
||||
- Elite Sterzo Smart (for steering support)
|
||||
- Elite Square Smart Frame (beta)
|
||||
- Wahoo Kickr Bike Shift (beta)
|
||||
- Gamepads (beta)
|
||||
- Cheap Bluetooth buttons such as [these](https://www.amazon.com/s?k=bluetooth+remote) (beta)
|
||||
- works on Android
|
||||
- on iOS, macOS and Windows it would require SwiftControl to act as media player - let me know if that works for you
|
||||
|
||||
Support for other devices can be added; check the issues tab here on GitHub.
|
||||
|
||||
## Supported Platforms
|
||||
|
||||
@@ -49,31 +63,31 @@ Follow this compatibility matrix. It all depends on where you want to run your t
|
||||
| Run Trainer app (MyWhoosh, ...) on: | Possible | Link | Information |
|
||||
|-------------------------------------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Android | ✅ | <a href="https://play.google.com/store/apps/details?id=de.jonasbark.swiftcontrol"><img width="270" height="80" alt="GetItOnGooglePlay_Badge_Web_color_English" src="https://github.com/user-attachments/assets/a059d5a1-2efb-4f65-8117-ef6a99823b21" /></a> | |
|
||||
| iPad | ✅ | <a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a> | You will need to use SwiftControl as a "remote" to control the trainer app on your iPad. Typically you would use an iPhone or an Android phone for that. |
|
||||
| Windows | ✅ | [Get it here](https://github.com/jonasbark/swiftcontrol/releases) | - Windows may flag the app as virus. It likely does so because the app controls the mouse and keyboard.<br>- Bluetooth connection unstable? You may need to use an [external Bluetooth adapter](https://github.com/jonasbark/swiftcontrol/issues/14#issuecomment-3193839509).<br>- Make sure your Zwift device is not paired with Windows Bluetooth settings: [more information](https://github.com/jonasbark/swiftcontrol/issues/70). |
|
||||
| iPad | ✅ | <a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a> | You will need to use SwiftControl as a "remote" to control the trainer app on your iPad. Typically, you would use an iPhone or an Android phone for that. |
|
||||
| Windows | ✅ | <a href="https://apps.microsoft.com/detail/9NP42GS03Z26"><img width="270" alt="Microsoft Store" src="https://github.com/user-attachments/assets/7a8a3cd6-ec26-4678-a850-732eedd27c48" /></a> | - Windows may flag the app as virus. It likely does so because the app controls the mouse and keyboard.<br>- Bluetooth connection unstable? You may need to use an [external Bluetooth adapter](https://github.com/jonasbark/swiftcontrol/issues/14#issuecomment-3193839509).<br>- Make sure your Zwift device is not paired with Windows Bluetooth settings: [more information](https://github.com/jonasbark/swiftcontrol/issues/70). |
|
||||
| macOS | ✅ | <a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=mac"><img width="270" height="80" alt="Mac App Store" src="https://github.com/user-attachments/assets/b3552436-409c-43b0-ba7d-b6a72ae30ff1" /></a> | |
|
||||
| iPhone | ❌ | <a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a> | Note that you can't run SwiftControl and your trainer app on the same iPhone due to iOS limitations, but you can use it to remotely control MyWhoosh and similar on e.g. an iPad. |
|
||||
| Apple TV | ❌ | | Apple TV does not support touch inputs. Instead you can use e.g. SwiftControl with MyWhoosh Link to control your session |
|
||||
| iPhone | (✅) | <a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a> | Note that you can't run SwiftControl and your trainer app on the same iPhone due to iOS limitations, but you could use the Link method on another device to control MyWhoosh (and only MyWhoosh) on an iPhone. |
|
||||
| Apple TV | (✅*) | | *only MyWhoosh using the Link method is supported - but you cannot also use MyWhoosh Link at the same time |
|
||||
|
||||
|
||||
For testing purposes you can also run it on [Web](https://jonasbark.github.io/swiftcontrol/) but this is just a tech demo - you won't be able to control other apps.
|
||||
For testing purposes, you can also run it on [Web](https://jonasbark.github.io/swiftcontrol/), but this is just a tech demo - you won't be able to control other apps.
|
||||
|
||||
## Troubleshooting
|
||||
Check the troubleshooting guide [here](TROUBLESHOOTING.md).
|
||||
|
||||
## How does it work?
|
||||
The app connects to your Zwift devices automatically. It does not connect to your trainer itself.
|
||||
The app connects to your Controller devices (such as Zwift ones) automatically. It does not connect to your trainer itself.
|
||||
|
||||
- **Android**: SwiftControl uses the AccessibilityService API to simulate touch gestures on specific parts of your screen to trigger actions in training apps. The service monitors which training app window is currently active to ensure gestures are sent to the correct app.
|
||||
- **iOS**: use SwiftControl as "remote control" for other devices, such as an iPad. Example scenario:
|
||||
- your phone (Android/iOS) runs SwiftControl and connects to your Zwift devices
|
||||
- **iOS**: use SwiftControl as a "remote control" for other devices, such as an iPad. Example scenario:
|
||||
- your phone (Android/iOS) runs SwiftControl and connects to your Controller devices
|
||||
- your iPad or other tablet runs e.g. MyWhoosh (does not need to have SwiftControl installed)
|
||||
- after pairing SwiftControl to your iPad / tablet via Bluetooth your phone will send the button presses to your iPad / tablet
|
||||
- If you want to use MyWhoosh, you can use the Link method to directly connect to MyWhoosh
|
||||
- For other trainer apps, you need to pair SwiftControl to your iPad / tablet via Bluetooth, and your phone will send the button presses to your iPad / tablet
|
||||
- **macOS** / **Windows** a keyboard or mouse click is used to trigger the action.
|
||||
- there are predefined Keymaps for MyWhoosh, indieVelo / Training Peaks, and others
|
||||
- you can also create your own Keymaps for any other app
|
||||
- you can also use the mouse to click on a certain part of the screen, or use keyboard shortcuts
|
||||
</details>
|
||||
- There are predefined Keymaps for MyWhoosh, indieVelo / Training Peaks, and others
|
||||
- You can also create your own Keymaps for any other app
|
||||
- You can also use the mouse to click on a certain part of the screen, or use keyboard shortcuts
|
||||
|
||||
## Alternatives
|
||||
- [qdomyos-zwift](https://www.qzfitness.com/) directly controls the trainer (as opposed to controlling the trainer app). This can be useful if your trainer app does not support virtual shifting.
|
||||
|
||||
@@ -15,6 +15,13 @@ If you don't do that SwiftControl will need to reconnect every minute.
|
||||
3. Connect your Trainer, then connect the Click V2
|
||||
4. Close the Zwift app again and connect again in SwiftControl
|
||||
|
||||
## Android: Connection works, buttons work but nothing happens in MyWhoosh and similar
|
||||
- especially for Redmi and other chinese Android devices please follow the instructions on [https://dontkillmyapp.com/](https://dontkillmyapp.com/):
|
||||
- disable battery optimization for SwiftControl
|
||||
- enable auto start of SwiftControl
|
||||
- grant accessibility permission for SwiftControl
|
||||
- see [https://github.com/jonasbark/swiftcontrol/issues/38](https://github.com/jonasbark/swiftcontrol/issues/38) for more details
|
||||
|
||||
## Remote control is not working - nothing happens
|
||||
- Try to unpair it from your phone / computer Bluetooth settings, then re-pair it.
|
||||
- Try restarting the pairing process in SwiftControl
|
||||
@@ -29,3 +36,17 @@ switch the setting to None, then back to Single-Tap and it should work again
|
||||
|
||||
## SwiftControl crashes on Windows when searching for the device
|
||||
You're probably running into [this](https://github.com/jonasbark/swiftcontrol/issues/70) issue. Disconnect your controller device (e.g. Zwift Play) from Windows Bluetooth settings.
|
||||
|
||||
## Link requirement for MyWhoosh stuck at "Waiting for MyWhoosh"
|
||||
The same network restrictions apply for SwiftControl as it applies to MyWhoosh Link app. Please verify with the MyWhoosh Link app if connection is possible at all.
|
||||
Here are some instructions that can help:
|
||||
|
||||
[https://mywhoosh.com/troubleshoot/](https://mywhoosh.com/troubleshoot/)
|
||||
[https://www.facebook.com/groups/mywhoosh/posts/1323791068858873/](https://www.facebook.com/groups/mywhoosh/posts/1323791068858873/)
|
||||
|
||||
In essence:
|
||||
- your two devices (phone, tablet) need to be on the same WiFi network
|
||||
- on iOS you have to turn off "Private Wi-Fi Address" in the WiFi settings
|
||||
- Limit IP Address Tracking may need to be disabled
|
||||
- mesh networks may not work
|
||||
|
||||
|
||||
1
WINDOWS_STORE_VERSION.txt
Normal file
1
WINDOWS_STORE_VERSION.txt
Normal file
@@ -0,0 +1 @@
|
||||
3.3.0
|
||||
@@ -5,6 +5,7 @@ import android.accessibilityservice.GestureDescription
|
||||
import android.accessibilityservice.GestureDescription.StrokeDescription
|
||||
import android.graphics.Path
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
@@ -56,7 +57,12 @@ class AccessibilityService : AccessibilityService(), Listener {
|
||||
path.moveTo(x.toFloat(), y.toFloat())
|
||||
path.lineTo(x.toFloat()+1, y.toFloat())
|
||||
|
||||
val stroke = StrokeDescription(path, 0, ViewConfiguration.getTapTimeout().toLong(), isKeyDown && !isKeyUp)
|
||||
val stroke = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
StrokeDescription(path, 0, ViewConfiguration.getTapTimeout().toLong(), isKeyDown && !isKeyUp)
|
||||
} else {
|
||||
// API 24–25: no “willContinue” support
|
||||
StrokeDescription(path, 0L, ViewConfiguration.getTapTimeout().toLong())
|
||||
}
|
||||
gestureBuilder.addStroke(stroke)
|
||||
|
||||
dispatchGesture(gestureBuilder.build(), null, null)
|
||||
|
||||
@@ -1,5 +1,46 @@
|
||||
package de.jonasbark.swiftcontrol
|
||||
|
||||
import android.hardware.input.InputManager
|
||||
import android.os.Handler
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import org.flame_engine.gamepads_android.GamepadsCompatibleActivity
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
class MainActivity: FlutterActivity(), GamepadsCompatibleActivity {
|
||||
var keyListener: ((KeyEvent) -> Boolean)? = null
|
||||
var motionListener: ((MotionEvent) -> Boolean)? = null
|
||||
|
||||
override fun isGamepadsInputDevice(device: InputDevice): Boolean {
|
||||
return device.sources and InputDevice.SOURCE_GAMEPAD == InputDevice.SOURCE_GAMEPAD
|
||||
|| device.sources and InputDevice.SOURCE_JOYSTICK == InputDevice.SOURCE_JOYSTICK
|
||||
// Some bluetooth keyboards are identified as GamePad. Check if it is ALPHABETIC keyboard.
|
||||
// && device.keyboardType != InputDevice.KEYBOARD_TYPE_ALPHABETIC
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(motionEvent: MotionEvent): Boolean {
|
||||
return motionListener?.invoke(motionEvent) ?: false
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(keyEvent: KeyEvent): Boolean {
|
||||
if (keyListener?.invoke(keyEvent) == true) {
|
||||
return true
|
||||
}
|
||||
return super.dispatchKeyEvent(keyEvent)
|
||||
}
|
||||
|
||||
override fun registerInputDeviceListener(
|
||||
listener: InputManager.InputDeviceListener, handler: Handler?) {
|
||||
val inputManager = getSystemService(INPUT_SERVICE) as InputManager
|
||||
inputManager.registerInputDeviceListener(listener, null)
|
||||
}
|
||||
|
||||
override fun registerKeyEventHandler(handler: (KeyEvent) -> Boolean) {
|
||||
keyListener = handler
|
||||
}
|
||||
|
||||
override fun registerMotionEventHandler(handler: (MotionEvent) -> Boolean) {
|
||||
motionListener = handler
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,15 @@ PODS:
|
||||
- Flutter (1.0.0)
|
||||
- flutter_local_notifications (0.0.1):
|
||||
- Flutter
|
||||
- gamepads_ios (0.1.1):
|
||||
- Flutter
|
||||
- image_picker_ios (0.0.1):
|
||||
- Flutter
|
||||
- package_info_plus (0.4.5):
|
||||
- Flutter
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- permission_handler_apple (9.3.0):
|
||||
- Flutter
|
||||
- restart_app (0.0.1):
|
||||
@@ -31,8 +36,10 @@ DEPENDENCIES:
|
||||
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
|
||||
- gamepads_ios (from `.symlinks/plugins/gamepads_ios/ios`)
|
||||
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
|
||||
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
|
||||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||
- restart_app (from `.symlinks/plugins/restart_app/ios`)
|
||||
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
|
||||
@@ -49,10 +56,14 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter
|
||||
flutter_local_notifications:
|
||||
:path: ".symlinks/plugins/flutter_local_notifications/ios"
|
||||
gamepads_ios:
|
||||
:path: ".symlinks/plugins/gamepads_ios/ios"
|
||||
image_picker_ios:
|
||||
:path: ".symlinks/plugins/image_picker_ios/ios"
|
||||
package_info_plus:
|
||||
:path: ".symlinks/plugins/package_info_plus/ios"
|
||||
path_provider_foundation:
|
||||
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
||||
permission_handler_apple:
|
||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||
restart_app:
|
||||
@@ -71,8 +82,10 @@ SPEC CHECKSUMS:
|
||||
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
|
||||
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
|
||||
flutter_local_notifications: ff50f8405aaa0ccdc7dcfb9022ca192e8ad9688f
|
||||
gamepads_ios: 1d2930c7a4450a9a1b57444ebf305a6a6cbeea0b
|
||||
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
|
||||
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
|
||||
path_provider_foundation: 0b743cbb62d8e47eab856f09262bb8c1ddcfe6ba
|
||||
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
|
||||
restart_app: 806659942bf932f6ce51c5372f91ce5e81c8c14a
|
||||
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>This app connects to your trainer app on your local network.</string>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>SwiftControl uses Bluetooth to connect to accessories.</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
|
||||
@@ -67,11 +67,11 @@ public class KeypressSimulatorMacosPlugin: NSObject, FlutterPlugin {
|
||||
let point = CGPoint(x: x, y: y)
|
||||
|
||||
// Move mouse to the point
|
||||
/*let move = CGEvent(mouseEventSource: nil,
|
||||
let move = CGEvent(mouseEventSource: nil,
|
||||
mouseType: .mouseMoved,
|
||||
mouseCursorPosition: point,
|
||||
mouseButton: .left)
|
||||
move?.post(tap: .cghidEventTap)*/
|
||||
move?.post(tap: .cghidEventTap)
|
||||
|
||||
if (keyDown) {
|
||||
// Mouse down
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
class BleUuid {
|
||||
static final DEVICE_INFORMATION_SERVICE_UUID = "0000180a-0000-1000-8000-00805f9b34fb".toLowerCase();
|
||||
static final DEVICE_INFORMATION_CHARACTERISTIC_FIRMWARE_REVISION = "00002a26-0000-1000-8000-00805f9b34fb"
|
||||
.toLowerCase();
|
||||
static const DEVICE_INFORMATION_SERVICE_UUID = "0000180a-0000-1000-8000-00805f9b34fb";
|
||||
static const DEVICE_INFORMATION_CHARACTERISTIC_FIRMWARE_REVISION = "00002a26-0000-1000-8000-00805f9b34fb";
|
||||
|
||||
static final DEVICE_BATTERY_SERVICE_UUID = "0000180f-0000-1000-8000-00805f9b34fb".toLowerCase();
|
||||
static final DEVICE_INFORMATION_CHARACTERISTIC_BATTERY_LEVEL = "00002a19-0000-1000-8000-00805f9b34fb".toLowerCase();
|
||||
static const DEVICE_BATTERY_SERVICE_UUID = "0000180f-0000-1000-8000-00805f9b34fb";
|
||||
static const DEVICE_INFORMATION_CHARACTERISTIC_BATTERY_LEVEL = "00002A19-0000-1000-8000-00805F9B34FB";
|
||||
}
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:gamepads/gamepads.dart';
|
||||
import 'package:swift_control/bluetooth/devices/bluetooth_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/gamepad/gamepad_device.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/android.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
import 'package:swift_control/utils/requirements/android.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../utils/keymap/apps/my_whoosh.dart';
|
||||
import 'devices/base_device.dart';
|
||||
import 'devices/link/link_device.dart';
|
||||
import 'devices/zwift/constants.dart';
|
||||
import 'messages/notification.dart';
|
||||
|
||||
class Connection {
|
||||
final devices = <BaseDevice>[];
|
||||
|
||||
List<BluetoothDevice> get bluetoothDevices => devices.whereType<BluetoothDevice>().toList();
|
||||
List<GamepadDevice> get gamepadDevices => devices.whereType<GamepadDevice>().toList();
|
||||
List<BaseDevice> get controllerDevices => [...bluetoothDevices, ...gamepadDevices];
|
||||
List<BaseDevice> get remoteDevices => devices.whereNot((d) => d is BluetoothDevice || d is GamepadDevice).toList();
|
||||
|
||||
var _androidNotificationsSetup = false;
|
||||
|
||||
final _connectionQueue = <BaseDevice>[];
|
||||
@@ -32,11 +45,35 @@ class Connection {
|
||||
final ValueNotifier<bool> hasDevices = ValueNotifier(false);
|
||||
final ValueNotifier<bool> isScanning = ValueNotifier(false);
|
||||
|
||||
Timer? _gamePadSearchTimer;
|
||||
|
||||
void initialize() {
|
||||
UniversalBle.onAvailabilityChange = (available) {
|
||||
_actionStreams.add(BluetoothAvailabilityNotification(available == AvailabilityState.poweredOn));
|
||||
if (available == AvailabilityState.poweredOn && !kIsWeb) {
|
||||
performScanning();
|
||||
} else if (available == AvailabilityState.poweredOff) {
|
||||
reset();
|
||||
}
|
||||
};
|
||||
UniversalBle.onScanResult = (result) {
|
||||
if (_lastScanResult.none((e) => e.deviceId == result.deviceId)) {
|
||||
// Update RSSI for already connected devices
|
||||
final existingDevice = bluetoothDevices.firstOrNullWhere(
|
||||
(e) => e.device.deviceId == result.deviceId,
|
||||
);
|
||||
if (existingDevice != null && existingDevice.rssi != result.rssi) {
|
||||
existingDevice.rssi = result.rssi;
|
||||
_connectionStreams.add(existingDevice); // Notify UI of update
|
||||
}
|
||||
|
||||
if (_lastScanResult.none((e) => e.deviceId == result.deviceId && e.services.contentEquals(result.services))) {
|
||||
_lastScanResult.add(result);
|
||||
final scanResult = BaseDevice.fromScanResult(result);
|
||||
|
||||
if (kDebugMode) {
|
||||
print('Scan result: ${result.name} - ${result.deviceId}');
|
||||
}
|
||||
|
||||
final scanResult = BluetoothDevice.fromScanResult(result);
|
||||
|
||||
if (scanResult != null) {
|
||||
_actionStreams.add(LogNotification('Found new device: ${scanResult.runtimeType}'));
|
||||
@@ -46,13 +83,15 @@ class Connection {
|
||||
final data = manufacturerData
|
||||
.firstOrNullWhere((e) => e.companyId == ZwiftConstants.ZWIFT_MANUFACTURER_ID)
|
||||
?.payload;
|
||||
_actionStreams.add(LogNotification('Found unknown device with identifier: ${data?.firstOrNull}'));
|
||||
if (data != null && kDebugMode) {
|
||||
_actionStreams.add(LogNotification('Found unknown device with identifier: ${data.firstOrNull}'));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
UniversalBle.onValueChange = (deviceId, characteristicUuid, value) {
|
||||
final device = devices.firstOrNullWhere((e) => e.device.deviceId == deviceId);
|
||||
final device = bluetoothDevices.firstOrNullWhere((e) => e.device.deviceId == deviceId);
|
||||
if (device == null) {
|
||||
_actionStreams.add(LogNotification('Device not found: $deviceId'));
|
||||
UniversalBle.disconnect(deviceId);
|
||||
@@ -61,18 +100,29 @@ class Connection {
|
||||
device.processCharacteristic(characteristicUuid, value);
|
||||
}
|
||||
};
|
||||
|
||||
UniversalBle.onConnectionChange = (String deviceId, bool isConnected, String? error) {
|
||||
final device = bluetoothDevices.firstOrNullWhere((e) => e.device.deviceId == deviceId);
|
||||
if (device != null && !isConnected) {
|
||||
// allow reconnection
|
||||
_lastScanResult.removeWhere((d) => d.deviceId == deviceId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> performScanning() async {
|
||||
if (isScanning.value) {
|
||||
return;
|
||||
}
|
||||
isScanning.value = true;
|
||||
_actionStreams.add(LogNotification('Scanning for devices...'));
|
||||
|
||||
// does not work on web, may not work on Windows
|
||||
if (!kIsWeb && !Platform.isWindows) {
|
||||
UniversalBle.getSystemDevices(
|
||||
withServices: BaseDevice.servicesToScan,
|
||||
withServices: BluetoothDevice.servicesToScan,
|
||||
).then((devices) async {
|
||||
final baseDevices = devices.mapNotNull(BaseDevice.fromScanResult).toList();
|
||||
final baseDevices = devices.mapNotNull(BluetoothDevice.fromScanResult).toList();
|
||||
if (baseDevices.isNotEmpty) {
|
||||
_addDevices(baseDevices);
|
||||
}
|
||||
@@ -80,22 +130,68 @@ class Connection {
|
||||
}
|
||||
|
||||
await UniversalBle.startScan(
|
||||
scanFilter: ScanFilter(withServices: BaseDevice.servicesToScan),
|
||||
platformConfig: PlatformConfig(web: WebOptions(optionalServices: BaseDevice.servicesToScan)),
|
||||
// allow all to enable Wahoo Kickr Bike Shift detection
|
||||
//scanFilter: kIsWeb ? ScanFilter(withServices: BluetoothDevice.servicesToScan) : null,
|
||||
platformConfig: PlatformConfig(web: WebOptions(optionalServices: BluetoothDevice.servicesToScan)),
|
||||
);
|
||||
|
||||
if (!kIsWeb) {
|
||||
_gamePadSearchTimer = Timer.periodic(Duration(seconds: 3), (_) {
|
||||
Gamepads.list().then((list) {
|
||||
final pads = list.map((pad) => GamepadDevice(pad.name, id: pad.id)).toList();
|
||||
_addDevices(pads);
|
||||
|
||||
final removedDevices = gamepadDevices.where((device) => list.none((pad) => pad.id == device.id)).toList();
|
||||
for (var device in removedDevices) {
|
||||
devices.remove(device);
|
||||
_streamSubscriptions[device]?.cancel();
|
||||
_streamSubscriptions.remove(device);
|
||||
_connectionSubscriptions[device]?.cancel();
|
||||
_connectionSubscriptions.remove(device);
|
||||
signalChange(device);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Gamepads.list().then((list) {
|
||||
final pads = list.map((pad) => GamepadDevice(pad.name, id: pad.id)).toList();
|
||||
_addDevices(pads);
|
||||
});
|
||||
}
|
||||
|
||||
if (settings.getMyWhooshLinkEnabled() && settings.getTrainerApp() is MyWhoosh && !whooshLink.isStarted.value) {
|
||||
startMyWhooshServer();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> startMyWhooshServer() {
|
||||
return whooshLink.startServer(
|
||||
onConnected: (socket) {
|
||||
final existing = remoteDevices.firstOrNullWhere(
|
||||
(e) => e is LinkDevice && e.identifier == socket.remoteAddress.address,
|
||||
);
|
||||
if (existing != null) {
|
||||
existing.isConnected = true;
|
||||
signalChange(existing);
|
||||
}
|
||||
},
|
||||
onDisconnected: (socket) {
|
||||
final device = devices.firstOrNullWhere(
|
||||
(device) => device is LinkDevice && device.identifier == socket.remoteAddress.address,
|
||||
);
|
||||
if (device != null) {
|
||||
devices.remove(device);
|
||||
signalChange(device);
|
||||
}
|
||||
},
|
||||
);
|
||||
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);
|
||||
|
||||
_connectionQueue.addAll(newDevices);
|
||||
|
||||
_handleConnectionQueue();
|
||||
|
||||
hasDevices.value = devices.isNotEmpty;
|
||||
@@ -112,18 +208,20 @@ class Connection {
|
||||
if (_connectionQueue.isNotEmpty && !_handlingConnectionQueue) {
|
||||
_handlingConnectionQueue = true;
|
||||
final device = _connectionQueue.removeAt(0);
|
||||
_actionStreams.add(LogNotification('Connecting to: ${device.device.name ?? device.runtimeType}'));
|
||||
_actionStreams.add(LogNotification('Connecting to: ${device.name}'));
|
||||
_connect(device)
|
||||
.then((_) {
|
||||
_handlingConnectionQueue = false;
|
||||
_actionStreams.add(LogNotification('Connection finished: ${device.device.name ?? device.runtimeType}'));
|
||||
_actionStreams.add(LogNotification('Connection finished: ${device.name}'));
|
||||
if (_connectionQueue.isNotEmpty) {
|
||||
_handleConnectionQueue();
|
||||
}
|
||||
})
|
||||
.catchError((e) {
|
||||
_handlingConnectionQueue = false;
|
||||
_actionStreams.add(LogNotification('Connection failed: ${device.device.name ?? device.runtimeType} - $e'));
|
||||
_actionStreams.add(
|
||||
LogNotification('Connection failed: ${device.name} - $e'),
|
||||
);
|
||||
if (_connectionQueue.isNotEmpty) {
|
||||
_handleConnectionQueue();
|
||||
}
|
||||
@@ -131,32 +229,43 @@ class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _connect(BaseDevice bleDevice) async {
|
||||
Future<void> _connect(BaseDevice device) async {
|
||||
try {
|
||||
final actionSubscription = bleDevice.actionStream.listen((data) {
|
||||
final actionSubscription = device.actionStream.listen((data) {
|
||||
_actionStreams.add(data);
|
||||
});
|
||||
final connectionStateSubscription = UniversalBle.connectionStream(bleDevice.device.deviceId).listen((state) {
|
||||
bleDevice.isConnected = state;
|
||||
_connectionStreams.add(bleDevice);
|
||||
if (!bleDevice.isConnected) {
|
||||
devices.remove(bleDevice);
|
||||
_streamSubscriptions[bleDevice]?.cancel();
|
||||
_streamSubscriptions.remove(bleDevice);
|
||||
_connectionSubscriptions[bleDevice]?.cancel();
|
||||
_connectionSubscriptions.remove(bleDevice);
|
||||
_lastScanResult.clear();
|
||||
// try reconnect
|
||||
if (!isScanning.value) {
|
||||
if (device is BluetoothDevice) {
|
||||
final connectionStateSubscription = UniversalBle.connectionStream(device.device.deviceId).listen((state) {
|
||||
device.isConnected = state;
|
||||
_connectionStreams.add(device);
|
||||
if (!device.isConnected) {
|
||||
disconnect(device, forget: true);
|
||||
// try reconnect
|
||||
performScanning();
|
||||
}
|
||||
}
|
||||
});
|
||||
_connectionSubscriptions[bleDevice] = connectionStateSubscription;
|
||||
});
|
||||
_connectionSubscriptions[device] = connectionStateSubscription;
|
||||
}
|
||||
|
||||
await bleDevice.connect();
|
||||
await device.connect();
|
||||
signalChange(device);
|
||||
|
||||
_streamSubscriptions[bleDevice] = actionSubscription;
|
||||
final newButtons = device.availableButtons.filter(
|
||||
(button) => actionHandler.supportedApp?.keymap.getKeyPair(button) == null,
|
||||
);
|
||||
for (final button in newButtons) {
|
||||
actionHandler.supportedApp?.keymap.addKeyPair(
|
||||
KeyPair(
|
||||
touchPosition: Offset.zero,
|
||||
buttons: [button],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
isLongPress: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_streamSubscriptions[device] = actionSubscription;
|
||||
} catch (e, backtrace) {
|
||||
_actionStreams.add(LogNotification("$e\n$backtrace"));
|
||||
if (kDebugMode) {
|
||||
@@ -167,21 +276,26 @@ class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
Future<void> reset() async {
|
||||
_actionStreams.add(LogNotification('Disconnecting all devices'));
|
||||
if (actionHandler is AndroidActions) {
|
||||
AndroidFlutterLocalNotificationsPlugin().stopForegroundService();
|
||||
_androidNotificationsSetup = false;
|
||||
}
|
||||
UniversalBle.stopScan();
|
||||
final isBtEnabled = (await UniversalBle.getBluetoothAvailabilityState()) == AvailabilityState.poweredOn;
|
||||
if (isBtEnabled) {
|
||||
UniversalBle.stopScan();
|
||||
}
|
||||
isScanning.value = false;
|
||||
for (var device in devices) {
|
||||
for (var device in bluetoothDevices) {
|
||||
_streamSubscriptions[device]?.cancel();
|
||||
_streamSubscriptions.remove(device);
|
||||
_connectionSubscriptions[device]?.cancel();
|
||||
_connectionSubscriptions.remove(device);
|
||||
UniversalBle.disconnect(device.device.deviceId);
|
||||
signalChange(device);
|
||||
}
|
||||
_gamePadSearchTimer?.cancel();
|
||||
_lastScanResult.clear();
|
||||
hasDevices.value = false;
|
||||
devices.clear();
|
||||
@@ -194,4 +308,22 @@ class Connection {
|
||||
void signalChange(BaseDevice baseDevice) {
|
||||
_connectionStreams.add(baseDevice);
|
||||
}
|
||||
|
||||
Future<void> disconnect(BaseDevice device, {required bool forget}) async {
|
||||
if (device.isConnected) {
|
||||
await device.disconnect();
|
||||
}
|
||||
if (device is! LinkDevice) {
|
||||
// keep it in the list to allow reconnect
|
||||
devices.remove(device);
|
||||
}
|
||||
if (!forget && device is BluetoothDevice) {
|
||||
_lastScanResult.removeWhere((b) => b.deviceId == device.device.deviceId);
|
||||
_streamSubscriptions[device]?.cancel();
|
||||
_streamSubscriptions.remove(device);
|
||||
_connectionSubscriptions[device]?.cancel();
|
||||
_connectionSubscriptions.remove(device);
|
||||
}
|
||||
signalChange(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,145 +1,45 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:swift_control/bluetooth/devices/wahoo/wahoo_kickr_bike_shift.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_click.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_clickv2.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_play.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_ride.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/desktop.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
|
||||
import '../../utils/keymap/buttons.dart';
|
||||
import '../messages/notification.dart';
|
||||
import 'elite/elite_square.dart';
|
||||
|
||||
abstract class BaseDevice {
|
||||
final BleDevice scanResult;
|
||||
final String name;
|
||||
final bool isBeta;
|
||||
final List<ControllerButton> availableButtons;
|
||||
|
||||
BaseDevice(this.scanResult, {required this.availableButtons, this.isBeta = false});
|
||||
BaseDevice(this.name, {required this.availableButtons, this.isBeta = false});
|
||||
|
||||
bool isConnected = false;
|
||||
int? batteryLevel;
|
||||
String? firmwareVersion;
|
||||
|
||||
Timer? _longPressTimer;
|
||||
Set<ControllerButton> _previouslyPressedButtons = <ControllerButton>{};
|
||||
|
||||
static List<String> servicesToScan = [
|
||||
ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID,
|
||||
ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID,
|
||||
SquareConstants.SERVICE_UUID,
|
||||
WahooKickrBikeShiftConstants.SERVICE_UUID,
|
||||
];
|
||||
|
||||
static BaseDevice? fromScanResult(BleDevice scanResult) {
|
||||
// Use the name first as the "System Devices" and Web (android sometimes Windows) don't have manufacturer data
|
||||
BaseDevice? device;
|
||||
if (kIsWeb) {
|
||||
device = switch (scanResult.name) {
|
||||
'Zwift Ride' => ZwiftRide(scanResult),
|
||||
'Zwift Play' => ZwiftPlay(scanResult),
|
||||
'Zwift Click' => ZwiftClickV2(scanResult),
|
||||
'SQUARE' => EliteSquare(scanResult),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (scanResult.name != null && scanResult.name!.toUpperCase().startsWith('KICKR BIKE SHIFT')) {
|
||||
device = WahooKickrBikeShift(scanResult);
|
||||
}
|
||||
} else {
|
||||
device = switch (scanResult.name) {
|
||||
//'Zwift Ride' => ZwiftRide(scanResult), special case for Zwift Ride: we must only connect to the left controller
|
||||
// https://www.makinolo.com/blog/2024/07/26/zwift-ride-protocol/
|
||||
'Zwift Play' => ZwiftPlay(scanResult),
|
||||
//'Zwift Click' => ZwiftClick(scanResult), special case for Zwift Click v2: we must only connect to the left controller
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
if (device != null) {
|
||||
return device;
|
||||
} else if (scanResult.services.containsAny([
|
||||
ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID,
|
||||
ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID,
|
||||
])) {
|
||||
// otherwise use the manufacturer data to identify the device
|
||||
final manufacturerData = scanResult.manufacturerDataList;
|
||||
final data = manufacturerData
|
||||
.firstOrNullWhere((e) => e.companyId == ZwiftConstants.ZWIFT_MANUFACTURER_ID)
|
||||
?.payload;
|
||||
|
||||
if (data == null || data.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final type = ZwiftDeviceType.fromManufacturerData(data.first);
|
||||
return switch (type) {
|
||||
ZwiftDeviceType.click => ZwiftClick(scanResult),
|
||||
ZwiftDeviceType.playRight => ZwiftPlay(scanResult),
|
||||
ZwiftDeviceType.playLeft => ZwiftPlay(scanResult),
|
||||
ZwiftDeviceType.rideLeft => ZwiftRide(scanResult),
|
||||
//DeviceType.rideRight => ZwiftRide(scanResult), // see comment above
|
||||
ZwiftDeviceType.clickV2Left => ZwiftClickV2(scanResult),
|
||||
//DeviceType.clickV2Right => ZwiftClickV2(scanResult), // see comment above
|
||||
_ => null,
|
||||
};
|
||||
} else if (scanResult.services.contains(SquareConstants.SERVICE_UUID)) {
|
||||
return EliteSquare(scanResult);
|
||||
} else if (scanResult.services.contains(WahooKickrBikeShiftConstants.SERVICE_UUID)) {
|
||||
if (scanResult.name != null && !scanResult.name!.toUpperCase().contains('KICKR BIKE SHIFT')) {
|
||||
return WahooKickrBikeShift(scanResult);
|
||||
} else if (kIsWeb && scanResult.name == null) {
|
||||
// some devices don't broadcast the name, so we must rely on the service UUID
|
||||
return WahooKickrBikeShift(scanResult);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BaseDevice && runtimeType == other.runtimeType && scanResult == other.scanResult;
|
||||
identical(this, other) || other is BaseDevice && runtimeType == other.runtimeType && name == other.name;
|
||||
|
||||
@override
|
||||
int get hashCode => scanResult.hashCode;
|
||||
int get hashCode => name.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return runtimeType.toString();
|
||||
}
|
||||
|
||||
BleDevice get device => scanResult;
|
||||
final StreamController<BaseNotification> actionStreamInternal = StreamController<BaseNotification>.broadcast();
|
||||
|
||||
Stream<BaseNotification> get actionStream => actionStreamInternal.stream;
|
||||
|
||||
Future<void> connect() async {
|
||||
actionStream.listen((message) {
|
||||
print("Received message: $message");
|
||||
});
|
||||
|
||||
await UniversalBle.connect(device.deviceId);
|
||||
|
||||
if (!kIsWeb) {
|
||||
await UniversalBle.requestMtu(device.deviceId, 517);
|
||||
}
|
||||
|
||||
final services = await UniversalBle.discoverServices(device.deviceId);
|
||||
await handleServices(services);
|
||||
}
|
||||
|
||||
Future<void> handleServices(List<BleService> services);
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes);
|
||||
Future<void> connect();
|
||||
|
||||
Future<void> handleButtonsClicked(List<ControllerButton>? buttonsClicked) async {
|
||||
if (buttonsClicked == null) {
|
||||
@@ -174,8 +74,8 @@ abstract class BaseDevice {
|
||||
actionHandler.supportedApp?.keymap.getKeyPair(buttonsClicked.single)?.isLongPress == true;
|
||||
|
||||
if (!isLongPress &&
|
||||
!(buttonsClicked.singleOrNull == ControllerButton.onOffLeft ||
|
||||
buttonsClicked.singleOrNull == ControllerButton.onOffRight)) {
|
||||
!(buttonsClicked.singleOrNull == ZwiftButtons.onOffLeft ||
|
||||
buttonsClicked.singleOrNull == ZwiftButtons.onOffRight)) {
|
||||
// we don't want to trigger the long press timer for the on/off buttons, also not when it's a long press key
|
||||
_longPressTimer?.cancel();
|
||||
_longPressTimer = Timer.periodic(const Duration(milliseconds: 350), (timer) async {
|
||||
@@ -225,7 +125,31 @@ abstract class BaseDevice {
|
||||
await (actionHandler as DesktopActions).releaseAllHeldKeys(_previouslyPressedButtons.toList());
|
||||
}
|
||||
_previouslyPressedButtons.clear();
|
||||
await UniversalBle.disconnect(device.deviceId);
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
Widget showInformation(BuildContext context);
|
||||
|
||||
ControllerButton? getOrAddButton(String name, ControllerButton Function() button) {
|
||||
if (actionHandler.supportedApp is CustomApp) {
|
||||
final allButtons = actionHandler.supportedApp!.keymap.keyPairs.expand((kp) => kp.buttons).toSet().toList();
|
||||
if (allButtons.none((b) => b.name == name)) {
|
||||
final newButton = button();
|
||||
availableButtons.add(newButton);
|
||||
actionHandler.supportedApp!.keymap.addKeyPair(
|
||||
KeyPair(
|
||||
touchPosition: Offset.zero,
|
||||
buttons: [newButton],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
isLongPress: false,
|
||||
),
|
||||
);
|
||||
return newButton;
|
||||
} else {
|
||||
return allButtons.firstWhere((b) => b.name == name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
251
lib/bluetooth/devices/bluetooth_device.dart
Normal file
251
lib/bluetooth/devices/bluetooth_device.dart
Normal file
@@ -0,0 +1,251 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/ble.dart';
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/shimano/shimano_di2.dart';
|
||||
import 'package:swift_control/bluetooth/devices/wahoo/wahoo_kickr_bike_shift.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_click.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_clickv2.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_play.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_ride.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/device.dart';
|
||||
import 'package:swift_control/widgets/beta_pill.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import 'cycplus/cycplus_bc2.dart';
|
||||
import 'elite/elite_square.dart';
|
||||
import 'elite/elite_sterzo.dart';
|
||||
|
||||
abstract class BluetoothDevice extends BaseDevice {
|
||||
final BleDevice scanResult;
|
||||
|
||||
BluetoothDevice(this.scanResult, {required super.availableButtons, super.isBeta = false})
|
||||
: super(scanResult.name ?? 'Unknown Device') {
|
||||
rssi = scanResult.rssi;
|
||||
}
|
||||
|
||||
int? batteryLevel;
|
||||
String? firmwareVersion;
|
||||
int? rssi;
|
||||
|
||||
static List<String> servicesToScan = [
|
||||
ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID,
|
||||
ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID,
|
||||
SquareConstants.SERVICE_UUID,
|
||||
WahooKickrBikeShiftConstants.SERVICE_UUID,
|
||||
SterzoConstants.SERVICE_UUID,
|
||||
CycplusBc2Constants.SERVICE_UUID,
|
||||
ShimanoDi2Constants.SERVICE_UUID,
|
||||
];
|
||||
|
||||
static BluetoothDevice? fromScanResult(BleDevice scanResult) {
|
||||
// Use the name first as the "System Devices" and Web (android sometimes Windows) don't have manufacturer data
|
||||
BluetoothDevice? device;
|
||||
if (kIsWeb) {
|
||||
device = switch (scanResult.name) {
|
||||
'Zwift Ride' => ZwiftRide(scanResult),
|
||||
'Zwift Play' => ZwiftPlay(scanResult),
|
||||
'Zwift Click' => ZwiftClickV2(scanResult),
|
||||
'SQUARE' => EliteSquare(scanResult),
|
||||
null => null,
|
||||
_ when scanResult.name!.toUpperCase().startsWith('STERZO') => EliteSterzo(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().startsWith('KICKR BIKE SHIFT') => WahooKickrBikeShift(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().startsWith('CYCPLUS') || scanResult.name!.toUpperCase().contains('BC2') =>
|
||||
CycplusBc2(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().startsWith('RDR') => ShimanoDi2(scanResult),
|
||||
_ => null,
|
||||
};
|
||||
} else {
|
||||
device = switch (scanResult.name) {
|
||||
null => null,
|
||||
//'Zwift Ride' => ZwiftRide(scanResult), special case for Zwift Ride: we must only connect to the left controller
|
||||
// https://www.makinolo.com/blog/2024/07/26/zwift-ride-protocol/
|
||||
'Zwift Play' => ZwiftPlay(scanResult),
|
||||
//'Zwift Click' => ZwiftClick(scanResult), special case for Zwift Click v2: we must only connect to the left controller
|
||||
_ when scanResult.name!.toUpperCase().startsWith('SQUARE') => EliteSquare(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().startsWith('STERZO') => EliteSterzo(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().contains('KICKR BIKE SHIFT') => WahooKickrBikeShift(scanResult),
|
||||
_ when scanResult.name!.toUpperCase().startsWith('CYCPLUS') || scanResult.name!.toUpperCase().contains('BC2') =>
|
||||
CycplusBc2(scanResult),
|
||||
_ when scanResult.services.contains(CycplusBc2Constants.SERVICE_UUID.toLowerCase()) => CycplusBc2(scanResult),
|
||||
_ when scanResult.services.contains(ShimanoDi2Constants.SERVICE_UUID.toLowerCase()) => ShimanoDi2(scanResult),
|
||||
// otherwise the service UUIDs will be used
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
if (device != null) {
|
||||
return device;
|
||||
} else if (scanResult.services.containsAny([
|
||||
ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID.toLowerCase(),
|
||||
ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID.toLowerCase(),
|
||||
])) {
|
||||
// otherwise use the manufacturer data to identify the device
|
||||
final manufacturerData = scanResult.manufacturerDataList;
|
||||
final data = manufacturerData
|
||||
.firstOrNullWhere((e) => e.companyId == ZwiftConstants.ZWIFT_MANUFACTURER_ID)
|
||||
?.payload;
|
||||
|
||||
if (data == null || data.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final type = ZwiftDeviceType.fromManufacturerData(data.first);
|
||||
return switch (type) {
|
||||
ZwiftDeviceType.click => ZwiftClick(scanResult),
|
||||
ZwiftDeviceType.playRight => ZwiftPlay(scanResult),
|
||||
ZwiftDeviceType.playLeft => ZwiftPlay(scanResult),
|
||||
ZwiftDeviceType.rideLeft => ZwiftRide(scanResult),
|
||||
//DeviceType.rideRight => ZwiftRide(scanResult), // see comment above
|
||||
ZwiftDeviceType.clickV2Left => ZwiftClickV2(scanResult),
|
||||
//DeviceType.clickV2Right => ZwiftClickV2(scanResult), // see comment above
|
||||
_ => null,
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is BluetoothDevice && runtimeType == other.runtimeType && scanResult == other.scanResult;
|
||||
|
||||
@override
|
||||
int get hashCode => scanResult.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return runtimeType.toString();
|
||||
}
|
||||
|
||||
BleDevice get device => scanResult;
|
||||
|
||||
@override
|
||||
Future<void> connect() async {
|
||||
actionStream.listen((message) {
|
||||
print("Received message: $message");
|
||||
});
|
||||
|
||||
await UniversalBle.connect(device.deviceId);
|
||||
|
||||
if (!kIsWeb) {
|
||||
await UniversalBle.requestMtu(device.deviceId, 517);
|
||||
}
|
||||
|
||||
final services = await UniversalBle.discoverServices(device.deviceId);
|
||||
final deviceInformationService = services.firstOrNullWhere(
|
||||
(service) => service.uuid == BleUuid.DEVICE_INFORMATION_SERVICE_UUID.toLowerCase(),
|
||||
);
|
||||
final firmwareCharacteristic = deviceInformationService?.characteristics.firstOrNullWhere(
|
||||
(c) => c.uuid == BleUuid.DEVICE_INFORMATION_CHARACTERISTIC_FIRMWARE_REVISION.toLowerCase(),
|
||||
);
|
||||
if (firmwareCharacteristic != null) {
|
||||
final firmwareData = await UniversalBle.read(
|
||||
device.deviceId,
|
||||
deviceInformationService!.uuid,
|
||||
firmwareCharacteristic.uuid,
|
||||
);
|
||||
firmwareVersion = String.fromCharCodes(firmwareData);
|
||||
connection.signalChange(this);
|
||||
}
|
||||
|
||||
final batteryService = services.firstOrNullWhere(
|
||||
(service) => service.uuid == BleUuid.DEVICE_BATTERY_SERVICE_UUID.toLowerCase(),
|
||||
);
|
||||
|
||||
final batteryCharacteristic = batteryService?.characteristics.firstOrNullWhere(
|
||||
(c) => c.uuid == BleUuid.DEVICE_INFORMATION_CHARACTERISTIC_BATTERY_LEVEL.toLowerCase(),
|
||||
);
|
||||
if (batteryCharacteristic != null) {
|
||||
final batteryData = await UniversalBle.read(
|
||||
device.deviceId,
|
||||
batteryService!.uuid,
|
||||
batteryCharacteristic.uuid,
|
||||
);
|
||||
if (batteryData.isNotEmpty) {
|
||||
batteryLevel = batteryData.first;
|
||||
connection.signalChange(this);
|
||||
}
|
||||
}
|
||||
|
||||
await handleServices(services);
|
||||
}
|
||||
|
||||
Future<void> handleServices(List<BleService> services);
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes);
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
await UniversalBle.disconnect(device.deviceId);
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget showInformation(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Text(
|
||||
device.name?.screenshot ?? device.runtimeType.toString(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (isBeta) BetaPill(),
|
||||
if (batteryLevel != null) ...[
|
||||
Icon(switch (batteryLevel!) {
|
||||
>= 80 => Icons.battery_full,
|
||||
>= 60 => Icons.battery_6_bar,
|
||||
>= 50 => Icons.battery_5_bar,
|
||||
>= 25 => Icons.battery_4_bar,
|
||||
>= 10 => Icons.battery_2_bar,
|
||||
_ => Icons.battery_alert,
|
||||
}),
|
||||
Text('$batteryLevel%'),
|
||||
],
|
||||
if (firmwareVersion != null) Text(' - v$firmwareVersion'),
|
||||
if (firmwareVersion != null &&
|
||||
this is ZwiftDevice &&
|
||||
firmwareVersion != (this as ZwiftDevice).latestFirmwareVersion) ...[
|
||||
SizedBox(width: 8),
|
||||
Icon(Icons.warning, color: Theme.of(context).colorScheme.error),
|
||||
Text(
|
||||
' (latest: ${(this as ZwiftDevice).latestFirmwareVersion})',
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
],
|
||||
if (rssi != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Tooltip(
|
||||
message: 'Signal Strength: $rssi dBm',
|
||||
child: Icon(
|
||||
switch (rssi!) {
|
||||
>= -50 => Icons.signal_cellular_4_bar,
|
||||
>= -60 => Icons.signal_cellular_alt_2_bar,
|
||||
>= -70 => Icons.signal_cellular_alt_1_bar,
|
||||
_ => Icons.signal_cellular_alt,
|
||||
},
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: SizedBox()),
|
||||
PopupMenuButton(
|
||||
itemBuilder: (c) => [
|
||||
PopupMenuItem(
|
||||
child: Text('Disconnect and Forget'),
|
||||
onTap: () {
|
||||
connection.disconnect(this, forget: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
97
lib/bluetooth/devices/cycplus/cycplus_bc2.dart
Normal file
97
lib/bluetooth/devices/cycplus/cycplus_bc2.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/messages/notification.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../bluetooth_device.dart';
|
||||
|
||||
class CycplusBc2 extends BluetoothDevice {
|
||||
CycplusBc2(super.scanResult)
|
||||
: super(
|
||||
availableButtons: CycplusBc2Buttons.values,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> handleServices(List<BleService> services) async {
|
||||
final service = services.firstWhere(
|
||||
(e) => e.uuid.toLowerCase() == CycplusBc2Constants.SERVICE_UUID.toLowerCase(),
|
||||
orElse: () => throw Exception('Service not found: ${CycplusBc2Constants.SERVICE_UUID}'),
|
||||
);
|
||||
final characteristic = service.characteristics.firstWhere(
|
||||
(e) => e.uuid.toLowerCase() == CycplusBc2Constants.TX_CHARACTERISTIC_UUID.toLowerCase(),
|
||||
orElse: () => throw Exception('Characteristic not found: ${CycplusBc2Constants.TX_CHARACTERISTIC_UUID}'),
|
||||
);
|
||||
|
||||
await UniversalBle.subscribeNotifications(device.deviceId, service.uuid, characteristic.uuid);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes) {
|
||||
if (characteristic.toLowerCase() == CycplusBc2Constants.TX_CHARACTERISTIC_UUID.toLowerCase()) {
|
||||
// Process CYCPLUS BC2 data
|
||||
// The BC2 typically sends button press data as simple byte values
|
||||
// Common patterns for virtual shifters:
|
||||
// - 0x01 or similar for shift up
|
||||
// - 0x02 or similar for shift down
|
||||
// - 0x00 for button release
|
||||
|
||||
if (bytes.isNotEmpty) {
|
||||
final buttonCode = bytes[0];
|
||||
|
||||
switch (buttonCode) {
|
||||
case 0x01:
|
||||
// Shift up button pressed
|
||||
handleButtonsClicked([CycplusBc2Buttons.shiftUp]);
|
||||
break;
|
||||
case 0x02:
|
||||
// Shift down button pressed
|
||||
handleButtonsClicked([CycplusBc2Buttons.shiftDown]);
|
||||
break;
|
||||
case 0x00:
|
||||
// Button released
|
||||
handleButtonsClicked([]);
|
||||
break;
|
||||
default:
|
||||
// Unknown button code - log for debugging
|
||||
actionStreamInternal.add(
|
||||
LogNotification('CYCPLUS BC2: Unknown button code: 0x${buttonCode.toRadixString(16)}'),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
}
|
||||
|
||||
class CycplusBc2Constants {
|
||||
// Nordic UART Service (NUS) - commonly used by CYCPLUS BC2
|
||||
static const String SERVICE_UUID = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
|
||||
// TX Characteristic - device sends data to app
|
||||
static const String TX_CHARACTERISTIC_UUID = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
|
||||
// RX Characteristic - app sends data to device (not used for button reading)
|
||||
static const String RX_CHARACTERISTIC_UUID = "6e400002-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
}
|
||||
|
||||
class CycplusBc2Buttons {
|
||||
static const ControllerButton shiftUp = ControllerButton(
|
||||
'shiftUp',
|
||||
action: InGameAction.shiftUp,
|
||||
icon: Icons.add,
|
||||
);
|
||||
|
||||
static const ControllerButton shiftDown = ControllerButton(
|
||||
'shiftDown',
|
||||
action: InGameAction.shiftDown,
|
||||
icon: Icons.remove,
|
||||
);
|
||||
|
||||
static const List<ControllerButton> values = [
|
||||
shiftUp,
|
||||
shiftDown,
|
||||
];
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../../messages/notification.dart';
|
||||
import '../bluetooth_device.dart';
|
||||
|
||||
class EliteSquare extends BaseDevice {
|
||||
class EliteSquare extends BluetoothDevice {
|
||||
EliteSquare(super.scanResult)
|
||||
: super(
|
||||
availableButtons: SquareConstants.BUTTON_MAPPING.values.toList(),
|
||||
availableButtons: EliteSquareButtons.values.toList(),
|
||||
isBeta: true,
|
||||
);
|
||||
|
||||
@@ -83,25 +83,74 @@ class SquareConstants {
|
||||
|
||||
// Button mapping https://images.bike24.com/i/mb/c7/36/d9/elite-square-smart-frame-indoor-bike-3-1724305.jpg
|
||||
static const Map<String, ControllerButton> BUTTON_MAPPING = {
|
||||
"00000200": ControllerButton.navigationUp, //"Up",
|
||||
"00000100": ControllerButton.navigationLeft, //"Left",
|
||||
"00000800": ControllerButton.navigationDown, // "Down",
|
||||
"00000400": ControllerButton.navigationRight, //"Right",
|
||||
"00002000": ControllerButton.powerUpLeft, //"X",
|
||||
"00001000": ControllerButton.sideButtonLeft, // "Square",
|
||||
"00008000": ControllerButton.campagnoloLeft, // "Left Campagnolo",
|
||||
"00004000": ControllerButton.onOffLeft, //"Left brake",
|
||||
"00000002": ControllerButton.shiftDownLeft, //"Left shift 1",
|
||||
"00000001": ControllerButton.paddleLeft, // "Left shift 2",
|
||||
"02000000": ControllerButton.y, // "Y",
|
||||
"01000000": ControllerButton.a, //"A",
|
||||
"08000000": ControllerButton.b, // "B",
|
||||
"04000000": ControllerButton.z, // "Z",
|
||||
"20000000": ControllerButton.powerUpRight, // "Circle",
|
||||
"10000000": ControllerButton.sideButtonRight, //"Triangle",
|
||||
"80000000": ControllerButton.campagnoloRight, // "Right Campagnolo",
|
||||
"40000000": ControllerButton.onOffRight, //"Right brake",
|
||||
"00020000": ControllerButton.sideButtonRight, //"Right shift 1",
|
||||
"00010000": ControllerButton.paddleRight, //"Right shift 2",
|
||||
"00000200": EliteSquareButtons.up, //"Up",
|
||||
"00000100": EliteSquareButtons.left, //"Left",
|
||||
"00000800": EliteSquareButtons.down, // "Down",
|
||||
"00000400": EliteSquareButtons.right, //"Right",
|
||||
"00002000": EliteSquareButtons.x, //"X",
|
||||
"00001000": EliteSquareButtons.square, // "Square",
|
||||
"00008000": EliteSquareButtons.campagnoloLeft, // "Left Campagnolo",
|
||||
"00004000": EliteSquareButtons.leftBrake, //"Left brake",
|
||||
"00000002": EliteSquareButtons.leftShift1, //"Left shift 1",
|
||||
"00000001": EliteSquareButtons.leftShift2, // "Left shift 2",
|
||||
"02000000": EliteSquareButtons.y, // "Y",
|
||||
"01000000": EliteSquareButtons.a, //"A",
|
||||
"08000000": EliteSquareButtons.b, // "B",
|
||||
"04000000": EliteSquareButtons.z, // "Z",
|
||||
"20000000": EliteSquareButtons.circle, // "Circle",
|
||||
"10000000": EliteSquareButtons.triangle, //"Triangle",
|
||||
"80000000": EliteSquareButtons.campagnoloRight, // "Right Campagnolo",
|
||||
"40000000": EliteSquareButtons.rightBrake, //"Right brake",
|
||||
"00020000": EliteSquareButtons.rightShift1, //"Right shift 1",
|
||||
"00010000": EliteSquareButtons.rightShift2, //"Right shift 2",
|
||||
};
|
||||
}
|
||||
|
||||
class EliteSquareButtons {
|
||||
static const ControllerButton up = ControllerButton('eliteSquareUp', action: null);
|
||||
static const ControllerButton left = ControllerButton('eliteSquareLeft', action: InGameAction.navigateLeft);
|
||||
static const ControllerButton down = ControllerButton('eliteSquareDown', action: null);
|
||||
static const ControllerButton right = ControllerButton('eliteSquareRight', action: InGameAction.navigateRight);
|
||||
static const ControllerButton x = ControllerButton('eliteSquareX', action: null);
|
||||
static const ControllerButton square = ControllerButton('eliteSquareSquare', action: null);
|
||||
static const ControllerButton campagnoloLeft = ControllerButton('eliteSquareCampagnoloLeft', action: null);
|
||||
static const ControllerButton leftBrake = ControllerButton('eliteSquareLeftBrake', action: null);
|
||||
static const ControllerButton leftShift1 = ControllerButton('eliteSquareLeftShift1', action: InGameAction.shiftUp);
|
||||
static const ControllerButton leftShift2 = ControllerButton('eliteSquareLeftShift2', action: InGameAction.shiftDown);
|
||||
static const ControllerButton y = ControllerButton('y', action: null);
|
||||
static const ControllerButton a = ControllerButton('a', action: null);
|
||||
static const ControllerButton b = ControllerButton('b', action: null);
|
||||
static const ControllerButton z = ControllerButton('z', action: null);
|
||||
static const ControllerButton circle = ControllerButton('eliteSquareCircle', action: null);
|
||||
static const ControllerButton triangle = ControllerButton('eliteSquareTriangle', action: null);
|
||||
static const ControllerButton campagnoloRight = ControllerButton('eliteSquareCampagnoloRight', action: null);
|
||||
static const ControllerButton rightBrake = ControllerButton('eliteSquareRightBrake', action: null);
|
||||
static const ControllerButton rightShift1 = ControllerButton('eliteSquareRightShift1', action: InGameAction.shiftUp);
|
||||
static const ControllerButton rightShift2 = ControllerButton(
|
||||
'eliteSquareRightShift2',
|
||||
action: InGameAction.shiftDown,
|
||||
);
|
||||
|
||||
static const List<ControllerButton> values = [
|
||||
up,
|
||||
left,
|
||||
down,
|
||||
right,
|
||||
x,
|
||||
square,
|
||||
campagnoloLeft,
|
||||
leftBrake,
|
||||
leftShift1,
|
||||
leftShift2,
|
||||
y,
|
||||
a,
|
||||
b,
|
||||
z,
|
||||
circle,
|
||||
triangle,
|
||||
campagnoloRight,
|
||||
rightBrake,
|
||||
rightShift1,
|
||||
rightShift2,
|
||||
];
|
||||
}
|
||||
|
||||
390
lib/bluetooth/devices/elite/elite_sterzo.dart
Normal file
390
lib/bluetooth/devices/elite/elite_sterzo.dart
Normal file
@@ -0,0 +1,390 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:swift_control/bluetooth/devices/bluetooth_device.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../../messages/notification.dart';
|
||||
|
||||
class EliteSterzo extends BluetoothDevice {
|
||||
EliteSterzo(super.scanResult) : super(availableButtons: SterzoButtons.values);
|
||||
|
||||
double _lastAngle = 0.0;
|
||||
int? _latestChallenge;
|
||||
String? _serviceUuid;
|
||||
static Uint8List? _challengeCodesData;
|
||||
static bool _isLoadingChallenges = false;
|
||||
|
||||
// Calibration state
|
||||
final List<double> _calibrationSamples = [];
|
||||
double _calibrationOffset = 0.0;
|
||||
bool _isCalibrated = false;
|
||||
|
||||
// Last rounded angle for logging optimization
|
||||
int? _lastRoundedAngle;
|
||||
|
||||
// Debounce timer for PWM-like keypress behavior
|
||||
Timer? _keypressTimer;
|
||||
bool _isProcessingKeypresses = false;
|
||||
|
||||
@override
|
||||
Future<void> handleServices(List<BleService> services) async {
|
||||
final service = services.firstOrNullWhere(
|
||||
(e) => e.uuid.toLowerCase().startsWith('347b0'),
|
||||
);
|
||||
if (service == null) {
|
||||
throw Exception('Elite Sterzo service not found');
|
||||
}
|
||||
|
||||
_serviceUuid = service.uuid;
|
||||
|
||||
// Find characteristics
|
||||
final challengeChar = service.characteristics.firstOrNullWhere(
|
||||
(e) => e.uuid == SterzoConstants.CHALLENGE_CODE_CHARACTERISTIC_UUID,
|
||||
);
|
||||
final measurementChar = service.characteristics.firstOrNullWhere(
|
||||
(e) => e.uuid == SterzoConstants.MEASUREMENT_CHARACTERISTIC_UUID,
|
||||
);
|
||||
final controlChar = service.characteristics.firstOrNullWhere(
|
||||
(e) => e.uuid == SterzoConstants.CONTROL_POINT_CHARACTERISTIC_UUID,
|
||||
);
|
||||
|
||||
if (challengeChar == null || measurementChar == null || controlChar == null) {
|
||||
throw Exception('Required Sterzo characteristics not found');
|
||||
}
|
||||
|
||||
// Subscribe to challenge code indications
|
||||
await UniversalBle.subscribeIndications(
|
||||
device.deviceId,
|
||||
service.uuid,
|
||||
challengeChar.uuid,
|
||||
);
|
||||
|
||||
// Subscribe to measurement notifications
|
||||
await UniversalBle.subscribeNotifications(
|
||||
device.deviceId,
|
||||
service.uuid,
|
||||
measurementChar.uuid,
|
||||
);
|
||||
|
||||
// Request to start challenge
|
||||
await UniversalBle.write(
|
||||
device.deviceId,
|
||||
service.uuid,
|
||||
controlChar.uuid,
|
||||
Uint8List.fromList([0x03, 0x10]),
|
||||
withoutResponse: false,
|
||||
);
|
||||
|
||||
actionStreamInternal.add(LogNotification('Elite Sterzo: Initialization started'));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes) async {
|
||||
if (characteristic == SterzoConstants.CHALLENGE_CODE_CHARACTERISTIC_UUID) {
|
||||
_handleChallengeCode(bytes);
|
||||
} else if (characteristic == SterzoConstants.MEASUREMENT_CHARACTERISTIC_UUID) {
|
||||
_handleSteeringMeasurement(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleChallengeCode(Uint8List bytes) async {
|
||||
if (bytes.length >= 4) {
|
||||
// Challenge is in bytes 2-3 (big-endian)
|
||||
final challenge = (bytes[2] << 8) | bytes[3];
|
||||
_latestChallenge = challenge;
|
||||
|
||||
actionStreamInternal.add(LogNotification('Elite Sterzo: Received challenge code: $challenge'));
|
||||
|
||||
// Respond to challenge
|
||||
await _activateSteeringMeasurements();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _activateSteeringMeasurements() async {
|
||||
if (_latestChallenge == null || _serviceUuid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure challenge codes are loaded
|
||||
await _ensureChallengeCodesLoaded();
|
||||
|
||||
// Get response codes for the challenge
|
||||
final challengeCodes = _getChallengeResponse(_latestChallenge!);
|
||||
|
||||
// Send challenge response
|
||||
await UniversalBle.write(
|
||||
device.deviceId,
|
||||
_serviceUuid!,
|
||||
SterzoConstants.CONTROL_POINT_CHARACTERISTIC_UUID,
|
||||
Uint8List.fromList([0x03, 0x11, challengeCodes[0], challengeCodes[1]]),
|
||||
withoutResponse: false,
|
||||
);
|
||||
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// Activate measurements
|
||||
await UniversalBle.write(
|
||||
device.deviceId,
|
||||
_serviceUuid!,
|
||||
SterzoConstants.CONTROL_POINT_CHARACTERISTIC_UUID,
|
||||
Uint8List.fromList([0x02, 0x02]),
|
||||
withoutResponse: false,
|
||||
);
|
||||
|
||||
actionStreamInternal.add(LogNotification('Elite Sterzo: Steering measurements activated'));
|
||||
}
|
||||
|
||||
static Future<void> _ensureChallengeCodesLoaded() async {
|
||||
if (_challengeCodesData != null) {
|
||||
return; // Already loaded
|
||||
}
|
||||
|
||||
// Wait if already loading
|
||||
while (_isLoadingChallenges) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
// Check again after waiting
|
||||
if (_challengeCodesData != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
_isLoadingChallenges = true;
|
||||
|
||||
try {
|
||||
if (kIsWeb) {
|
||||
// On web, always fetch from HTTP
|
||||
_challengeCodesData = await _fetchChallengeCodes();
|
||||
} else {
|
||||
// On native platforms, try to load from cache first
|
||||
_challengeCodesData = await _loadCachedChallengeCodes();
|
||||
|
||||
if (_challengeCodesData == null) {
|
||||
// Cache miss - fetch from HTTP and cache it
|
||||
_challengeCodesData = await _fetchChallengeCodes();
|
||||
if (_challengeCodesData != null) {
|
||||
await _cacheChallengeCodes(_challengeCodesData!);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
_isLoadingChallenges = false;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Uint8List?> _fetchChallengeCodes() async {
|
||||
final url = kIsWeb
|
||||
? 'https://corsproxy.io/${SterzoConstants.CHALLENGE_CODES_URL}'
|
||||
: SterzoConstants.CHALLENGE_CODES_URL;
|
||||
try {
|
||||
final response = await http.get(Uri.parse(url));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.bodyBytes;
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to fetch challenge codes for URL $url: $e');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<Uint8List?> _loadCachedChallengeCodes() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final cached = prefs.getString(SterzoConstants.CACHE_KEY);
|
||||
|
||||
if (cached != null) {
|
||||
// Decode from base64
|
||||
return base64Decode(cached);
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to load cached challenge codes: $e');
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<void> _cacheChallengeCodes(Uint8List data) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
// Encode to base64 for storage
|
||||
await prefs.setString(SterzoConstants.CACHE_KEY, base64Encode(data));
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('Failed to cache challenge codes: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _handleSteeringMeasurement(Uint8List bytes) {
|
||||
if (bytes.length >= 4) {
|
||||
// Steering angle is a 32-bit float (little-endian)
|
||||
final rawAngle = ByteData.sublistView(bytes).getFloat32(0, Endian.little);
|
||||
|
||||
// Ignore NaN readings during initial connection
|
||||
if (rawAngle.isNaN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle calibration: collect initial samples to compute offset
|
||||
if (!_isCalibrated) {
|
||||
_calibrationSamples.add(rawAngle);
|
||||
if (_calibrationSamples.length >= SterzoConstants.CALIBRATION_SAMPLE_COUNT) {
|
||||
// Compute average offset from collected samples
|
||||
_calibrationOffset = _calibrationSamples.reduce((a, b) => a + b) / _calibrationSamples.length;
|
||||
_isCalibrated = true;
|
||||
actionStreamInternal.add(
|
||||
LogNotification('Elite Sterzo: Calibration complete, offset: ${_calibrationOffset.toStringAsFixed(2)}°'),
|
||||
);
|
||||
}
|
||||
return; // Don't process steering during calibration
|
||||
}
|
||||
|
||||
// Apply calibration offset
|
||||
final calibratedAngle = rawAngle - _calibrationOffset;
|
||||
|
||||
// Round to whole degrees to reduce noise
|
||||
final roundedAngle = calibratedAngle.round();
|
||||
|
||||
// Only log and process steering when rounded value changes to reduce verbosity
|
||||
if (_lastRoundedAngle != roundedAngle) {
|
||||
actionStreamInternal.add(LogNotification('Steering angle: $roundedAngle°'));
|
||||
_lastRoundedAngle = roundedAngle;
|
||||
|
||||
// Apply PWM-like steering behavior only when angle changes
|
||||
_applyPWMSteering(roundedAngle);
|
||||
}
|
||||
|
||||
_lastAngle = calibratedAngle;
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies PWM-like steering behavior with repeated keypresses proportional to angle magnitude
|
||||
void _applyPWMSteering(int roundedAngle) {
|
||||
// Cancel any pending keypress timer
|
||||
_keypressTimer?.cancel();
|
||||
|
||||
// Determine if we're steering
|
||||
if (roundedAngle.abs() > SterzoConstants.STEERING_THRESHOLD) {
|
||||
// Determine direction
|
||||
final button = roundedAngle > 0 ? SterzoButtons.rightSteer : SterzoButtons.leftSteer;
|
||||
|
||||
// Calculate number of keypress levels based on angle magnitude
|
||||
final levels = _calculateKeypressLevels(roundedAngle.abs());
|
||||
|
||||
// Only trigger new keypresses when rounded angle changes to avoid overlap
|
||||
// The check for _lastRoundedAngle change is already done in _handleSteeringMeasurement
|
||||
// so we know this is a new angle value
|
||||
_scheduleRepeatedKeypresses(button, levels);
|
||||
} else {
|
||||
// Center position - release any held buttons
|
||||
handleButtonsClicked([]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the number of keypress levels based on angle magnitude
|
||||
int _calculateKeypressLevels(int absAngle) {
|
||||
final levels = (absAngle / SterzoConstants.LEVEL_DEGREE_STEP).floor();
|
||||
return levels.clamp(1, SterzoConstants.MAX_LEVELS);
|
||||
}
|
||||
|
||||
/// Schedules repeated keypresses to simulate PWM behavior
|
||||
Future<void> _scheduleRepeatedKeypresses(ControllerButton button, int levels) async {
|
||||
// Don't overlap keypress sequences
|
||||
if (_isProcessingKeypresses) {
|
||||
return;
|
||||
}
|
||||
|
||||
_isProcessingKeypresses = true;
|
||||
|
||||
// Send keypresses in sequence with delays between them
|
||||
for (int i = 0; i < levels; i++) {
|
||||
await Future.delayed(Duration(milliseconds: SterzoConstants.KEY_REPEAT_INTERVAL_MS));
|
||||
handleButtonsClicked([button]);
|
||||
}
|
||||
|
||||
_isProcessingKeypresses = false;
|
||||
}
|
||||
|
||||
List<int> _getChallengeResponse(int challenge) {
|
||||
if (_challengeCodesData == null) {
|
||||
// Fallback if data not loaded
|
||||
return [0x96, 0x96];
|
||||
}
|
||||
|
||||
final index = challenge * 2;
|
||||
if (index >= 0 && index < _challengeCodesData!.length - 1) {
|
||||
return [_challengeCodesData![index], _challengeCodesData![index + 1]];
|
||||
}
|
||||
|
||||
// Fallback for out of range challenges
|
||||
return [0x96, 0x96];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
_keypressTimer?.cancel();
|
||||
await super.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
class SterzoConstants {
|
||||
static const String DEVICE_NAME = "STERZO";
|
||||
|
||||
// Elite Sterzo Smart characteristic UUIDs
|
||||
static const String MEASUREMENT_CHARACTERISTIC_UUID = "347b0030-7635-408b-8918-8ff3949ce592";
|
||||
static const String CONTROL_POINT_CHARACTERISTIC_UUID = "347b0031-7635-408b-8918-8ff3949ce592";
|
||||
static const String CHALLENGE_CODE_CHARACTERISTIC_UUID = "347b0032-7635-408b-8918-8ff3949ce592";
|
||||
|
||||
// Service UUID pattern (matches Elite devices)
|
||||
static const String SERVICE_UUID = "347b0001-7635-408b-8918-8ff3949ce592";
|
||||
|
||||
// Steering angle threshold in degrees to trigger steering action
|
||||
static const double STEERING_THRESHOLD = 10.0;
|
||||
|
||||
static const int RECONNECT_DELAY = 5; // seconds between reconnection attempts
|
||||
|
||||
// URL to fetch challenge codes
|
||||
static const String CHALLENGE_CODES_URL =
|
||||
'https://github.com/zacharyedwardbull/pycycling/raw/refs/heads/master/pycycling/data/sterzo-challenge-codes.dat';
|
||||
|
||||
// Cache key for SharedPreferences
|
||||
static const String CACHE_KEY = 'elite_sterzo_challenge_codes';
|
||||
|
||||
// Calibration settings
|
||||
// Number of initial valid samples to collect for calibration offset
|
||||
static const int CALIBRATION_SAMPLE_COUNT = 10;
|
||||
|
||||
// PWM-like steering behavior constants
|
||||
// Degrees per level for repeated keypress behavior
|
||||
static const double LEVEL_DEGREE_STEP = 10.0;
|
||||
// Maximum number of keypress levels
|
||||
static const int MAX_LEVELS = 5;
|
||||
// Interval between repeated keypresses in milliseconds
|
||||
static const int KEY_REPEAT_INTERVAL_MS = 40;
|
||||
}
|
||||
|
||||
class SterzoButtons {
|
||||
static final ControllerButton leftSteer = ControllerButton(
|
||||
'leftSteer',
|
||||
action: InGameAction.steerLeft,
|
||||
);
|
||||
static final ControllerButton rightSteer = ControllerButton(
|
||||
'rightSteer',
|
||||
action: InGameAction.steerRight,
|
||||
);
|
||||
|
||||
static List<ControllerButton> get values => [
|
||||
leftSteer,
|
||||
rightSteer,
|
||||
];
|
||||
}
|
||||
63
lib/bluetooth/devices/gamepad/gamepad_device.dart
Normal file
63
lib/bluetooth/devices/gamepad/gamepad_device.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gamepads/gamepads.dart';
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:swift_control/bluetooth/messages/notification.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/device.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/widgets/beta_pill.dart';
|
||||
|
||||
import '../../../widgets/warning.dart';
|
||||
|
||||
class GamepadDevice extends BaseDevice {
|
||||
final String id;
|
||||
|
||||
GamepadDevice(super.name, {required this.id}) : super(availableButtons: [], isBeta: true);
|
||||
|
||||
List<ControllerButton> _lastButtonsClicked = [];
|
||||
|
||||
@override
|
||||
Future<void> connect() async {
|
||||
Gamepads.eventsByGamepad(id).listen((event) {
|
||||
actionStreamInternal.add(LogNotification('Gamepad event: $event'));
|
||||
|
||||
ControllerButton? button = getOrAddButton(event.key, () => ControllerButton(event.key));
|
||||
|
||||
final buttonsClicked = event.value == 0.0 && button != null ? [button] : <ControllerButton>[];
|
||||
if (_lastButtonsClicked.contentEquals(buttonsClicked) == false) {
|
||||
handleButtonsClicked(buttonsClicked);
|
||||
}
|
||||
_lastButtonsClicked = buttonsClicked;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget showInformation(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Column(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
name.screenshot,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (isBeta) BetaPill(),
|
||||
],
|
||||
),
|
||||
|
||||
if (actionHandler.supportedApp is! CustomApp)
|
||||
Warning(
|
||||
children: [
|
||||
Text('Use a custom keymap to use the buttons on $name.'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
149
lib/bluetooth/devices/link/link.dart
Normal file
149
lib/bluetooth/devices/link/link.dart
Normal file
@@ -0,0 +1,149 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
class WhooshLink {
|
||||
Socket? _socket;
|
||||
ServerSocket? _server;
|
||||
|
||||
static final List<InGameAction> supportedActions = [
|
||||
InGameAction.shiftUp,
|
||||
InGameAction.shiftDown,
|
||||
InGameAction.cameraAngle,
|
||||
InGameAction.emote,
|
||||
InGameAction.uturn,
|
||||
InGameAction.steerLeft,
|
||||
InGameAction.steerRight,
|
||||
];
|
||||
|
||||
final ValueNotifier<bool> isStarted = ValueNotifier(false);
|
||||
final ValueNotifier<bool> isConnected = ValueNotifier(false);
|
||||
|
||||
void stopServer() async {
|
||||
if (isStarted.value) {
|
||||
await _socket?.close();
|
||||
await _server?.close();
|
||||
isConnected.value = false;
|
||||
isStarted.value = false;
|
||||
if (kDebugMode) {
|
||||
print('Server stopped.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> startServer({
|
||||
required void Function(Socket socket) onConnected,
|
||||
required void Function(Socket socket) onDisconnected,
|
||||
}) async {
|
||||
// Create and bind server socket
|
||||
_server = await ServerSocket.bind(
|
||||
InternetAddress.anyIPv6,
|
||||
21587,
|
||||
shared: true,
|
||||
v6Only: false,
|
||||
);
|
||||
isStarted.value = true;
|
||||
if (kDebugMode) {
|
||||
print('Server started on port ${_server!.port}');
|
||||
}
|
||||
|
||||
// Accept connection
|
||||
_server!.listen((Socket socket) {
|
||||
_socket = socket;
|
||||
onConnected(socket);
|
||||
isConnected.value = true;
|
||||
if (kDebugMode) {
|
||||
print('Client connected: ${socket.remoteAddress.address}:${socket.remotePort}');
|
||||
}
|
||||
|
||||
// Listen for data from the client
|
||||
socket.listen(
|
||||
(List<int> data) {
|
||||
try {
|
||||
if (kDebugMode) {
|
||||
// TODO we could check if virtual shifting is enabled
|
||||
final message = utf8.decode(data);
|
||||
print('Received message: $message');
|
||||
}
|
||||
} catch (_) {}
|
||||
},
|
||||
onDone: () {
|
||||
print('Client disconnected: $socket');
|
||||
onDisconnected(socket);
|
||||
isConnected.value = false;
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
String sendAction(InGameAction action, int? value) {
|
||||
final jsonObject = switch (action) {
|
||||
InGameAction.shiftUp => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'GearShifting': '1',
|
||||
},
|
||||
},
|
||||
InGameAction.shiftDown => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'GearShifting': '-1',
|
||||
},
|
||||
},
|
||||
InGameAction.cameraAngle => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'CameraAngle': '$value',
|
||||
},
|
||||
},
|
||||
InGameAction.emote => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'Emote': '$value',
|
||||
},
|
||||
},
|
||||
InGameAction.uturn => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'UTurn': 'true',
|
||||
},
|
||||
},
|
||||
InGameAction.steerLeft => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'Steering': '-1',
|
||||
},
|
||||
},
|
||||
InGameAction.steerRight => {
|
||||
'MessageType': 'Controls',
|
||||
'InGameControls': {
|
||||
'Steering': '1',
|
||||
},
|
||||
},
|
||||
InGameAction.increaseResistance => null,
|
||||
InGameAction.decreaseResistance => null,
|
||||
InGameAction.navigateLeft => null,
|
||||
InGameAction.navigateRight => null,
|
||||
InGameAction.toggleUi => null,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (jsonObject != null) {
|
||||
final jsonString = jsonEncode(jsonObject);
|
||||
_socket?.writeln(jsonString);
|
||||
return 'Sent action to MyWhoosh: $action ${value ?? ''}';
|
||||
} else {
|
||||
return 'No action available for button: $action';
|
||||
}
|
||||
}
|
||||
|
||||
bool isCompatible(Target target) {
|
||||
return switch (target) {
|
||||
Target.thisDevice => Platform.isAndroid || Platform.isWindows,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
}
|
||||
90
lib/bluetooth/devices/link/link_device.dart
Normal file
90
lib/bluetooth/devices/link/link_device.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/remote.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class LinkDevice extends BaseDevice {
|
||||
String identifier;
|
||||
|
||||
LinkDevice(this.identifier) : super('MyWhoosh Link', availableButtons: []);
|
||||
|
||||
@override
|
||||
Future<void> connect() async {
|
||||
isConnected = true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
super.disconnect();
|
||||
whooshLink.stopServer();
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget showInformation(BuildContext context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: whooshLink.isConnected,
|
||||
builder: (context, isConnected, _) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
final myWhooshExplanation = actionHandler is RemoteActions
|
||||
? 'MyWhoosh Link allows you to do some additional features such as Emotes and turn directions.'
|
||||
: 'MyWhoosh Link is optional, but allows you to do some additional features such as Emotes and turn directions.';
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: settings.getMyWhooshLinkEnabled(),
|
||||
onChanged: (value) {
|
||||
settings.setMyWhooshLinkEnabled(value);
|
||||
if (!value) {
|
||||
disconnect();
|
||||
connection.disconnect(this, forget: true);
|
||||
} else if (value) {
|
||||
connection.startMyWhooshServer();
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
title: Text('Enable MyWhoosh Link'),
|
||||
subtitle: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
if (!settings.getMyWhooshLinkEnabled())
|
||||
Expanded(
|
||||
child: Text(
|
||||
myWhooshExplanation,
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
Expanded(
|
||||
child: Text(
|
||||
isConnected ? "Connected" : "Connecting to MyWhoosh...\n$myWhooshExplanation",
|
||||
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
if (!isConnected) SmallProgressIndicator(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
launchUrlString('https://www.youtube.com/watch?v=p8sgQhuufeI');
|
||||
},
|
||||
icon: Icon(Icons.help_outline),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
83
lib/bluetooth/devices/shimano/shimano_di2.dart
Normal file
83
lib/bluetooth/devices/shimano/shimano_di2.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/messages/notification.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
import '../bluetooth_device.dart';
|
||||
|
||||
class ShimanoDi2 extends BluetoothDevice {
|
||||
ShimanoDi2(super.scanResult) : super(availableButtons: []);
|
||||
|
||||
@override
|
||||
Future<void> handleServices(List<BleService> services) async {
|
||||
final service = services.firstWhere(
|
||||
(e) => e.uuid.toLowerCase() == ShimanoDi2Constants.SERVICE_UUID.toLowerCase(),
|
||||
orElse: () => throw Exception('Service not found: ${ShimanoDi2Constants.SERVICE_UUID}'),
|
||||
);
|
||||
final characteristic = service.characteristics.firstWhere(
|
||||
(e) => e.uuid.toLowerCase() == ShimanoDi2Constants.D_FLY_CHANNEL_UUID.toLowerCase(),
|
||||
orElse: () => throw Exception('Characteristic not found: ${ShimanoDi2Constants.D_FLY_CHANNEL_UUID}'),
|
||||
);
|
||||
|
||||
await UniversalBle.subscribeIndications(device.deviceId, service.uuid, characteristic.uuid);
|
||||
|
||||
if (actionHandler.supportedApp is! CustomApp) {
|
||||
actionStreamInternal.add(LogNotification('Use a custom keymap to support ${scanResult.name}'));
|
||||
}
|
||||
}
|
||||
|
||||
final _lastButtons = <int, int>{};
|
||||
|
||||
@override
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes) {
|
||||
if (characteristic.toLowerCase() == ShimanoDi2Constants.D_FLY_CHANNEL_UUID) {
|
||||
final channels = bytes.sublist(1);
|
||||
final clickedButtons = <ControllerButton>[];
|
||||
|
||||
channels.forEachIndexed((int value, int index) {
|
||||
final didChange = !_lastButtons.containsKey(index) || _lastButtons[index] != value;
|
||||
_lastButtons[index] = value;
|
||||
|
||||
final readableIndex = index + 1;
|
||||
|
||||
final button = getOrAddButton(
|
||||
'D-Fly Channel $readableIndex',
|
||||
() => ControllerButton('D-Fly Channel $readableIndex'),
|
||||
);
|
||||
if (didChange && button != null) {
|
||||
clickedButtons.add(button);
|
||||
}
|
||||
});
|
||||
|
||||
if (clickedButtons.isNotEmpty) {
|
||||
handleButtonsClicked(clickedButtons);
|
||||
handleButtonsClicked([]);
|
||||
}
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget showInformation(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
super.showInformation(context),
|
||||
Text(
|
||||
'Make sure to set your Di2 buttons to D-Fly channels in the Shimano E-TUBE app.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ShimanoDi2Constants {
|
||||
static const String SERVICE_UUID = "000018ef-5348-494d-414e-4f5f424c4500";
|
||||
|
||||
static const String D_FLY_CHANNEL_UUID = "00002ac2-5348-494d-414e-4f5f424c4500";
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
class WahooKickrBikeShift extends BaseDevice {
|
||||
import '../bluetooth_device.dart';
|
||||
|
||||
class WahooKickrBikeShift extends BluetoothDevice {
|
||||
WahooKickrBikeShift(super.scanResult)
|
||||
: super(
|
||||
availableButtons: WahooKickrBikeShiftConstants.prefixToButton.values.toList(),
|
||||
isBeta: true,
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -112,17 +113,75 @@ class WahooKickrBikeShiftConstants {
|
||||
|
||||
// https://support.wahoofitness.com/hc/en-us/articles/22259367275410-Shifter-and-button-configuration-for-KICKR-BIKE-1-2
|
||||
static const Map<String, ControllerButton> prefixToButton = {
|
||||
'0001': ControllerButton.powerUpRight, //'Right Up',
|
||||
'8000': ControllerButton.sideButtonRight, //'Right Down',
|
||||
'0008': ControllerButton.navigationRight, //'Right Steer',
|
||||
'0200': ControllerButton.powerUpLeft, // 'Left Up',
|
||||
'0400': ControllerButton.sideButtonLeft, //'Left Down',
|
||||
'2000': ControllerButton.navigationLeft, //'Left Steer',
|
||||
'0004': ControllerButton.shiftUpRight, // 'Right Shift Up',
|
||||
'0002': ControllerButton.shiftDownRight, // 'Right Shift Down',
|
||||
'1000': ControllerButton.shiftUpLeft, //'Left Shift Up',
|
||||
'0800': ControllerButton.shiftDownLeft, //'Left Shift Down',
|
||||
'4000': ControllerButton.paddleRight, //'Right Brake',
|
||||
'0100': ControllerButton.paddleLeft, //'Left Brake',
|
||||
'0001': WahooKickrShiftButtons.rightUp, //'Right Up',
|
||||
'8000': WahooKickrShiftButtons.rightDown, //'Right Down',
|
||||
'0008': WahooKickrShiftButtons.rightSteer, //'Right Steer',
|
||||
'0200': WahooKickrShiftButtons.leftUp, // 'Left Up',
|
||||
'0400': WahooKickrShiftButtons.leftDown, //'Left Down',
|
||||
'2000': WahooKickrShiftButtons.leftSteer, //'Left Steer',
|
||||
'0004': WahooKickrShiftButtons.shiftUpRight, // 'Right Shift Up',
|
||||
'0002': WahooKickrShiftButtons.shiftDownRight, // 'Right Shift Down',
|
||||
'1000': WahooKickrShiftButtons.shiftUpLeft, //'Left Shift Up',
|
||||
'0800': WahooKickrShiftButtons.shiftDownLeft, //'Left Shift Down',
|
||||
'4000': WahooKickrShiftButtons.rightBrake, //'Right Brake',
|
||||
'0100': WahooKickrShiftButtons.leftBrake, //'Left Brake',
|
||||
};
|
||||
}
|
||||
|
||||
class WahooKickrShiftButtons {
|
||||
static const ControllerButton leftSteer = ControllerButton(
|
||||
'leftSteer',
|
||||
action: InGameAction.navigateLeft,
|
||||
icon: Icons.keyboard_arrow_left,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton rightSteer = ControllerButton(
|
||||
'rightSteer',
|
||||
action: InGameAction.navigateRight,
|
||||
icon: Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton leftDown = ControllerButton('leftDown', action: InGameAction.shiftDown);
|
||||
static const ControllerButton leftBrake = ControllerButton('leftBrake', action: InGameAction.shiftDown);
|
||||
|
||||
static const ControllerButton shiftUpLeft = ControllerButton(
|
||||
'shiftUpLeft',
|
||||
action: InGameAction.shiftDown,
|
||||
icon: Icons.remove,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton shiftDownLeft = ControllerButton(
|
||||
'shiftDownLeft',
|
||||
action: InGameAction.shiftDown,
|
||||
icon: Icons.remove,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton leftUp = ControllerButton('leftUp', action: InGameAction.shiftDown);
|
||||
|
||||
static const ControllerButton rightDown = ControllerButton('rightDown', action: InGameAction.shiftUp);
|
||||
static const ControllerButton rightBrake = ControllerButton('rightBrake', action: InGameAction.shiftUp);
|
||||
|
||||
static const ControllerButton shiftUpRight = ControllerButton(
|
||||
'shiftUpRight',
|
||||
action: InGameAction.shiftUp,
|
||||
icon: Icons.add,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton shiftDownRight = ControllerButton('shiftDownRight', action: InGameAction.shiftUp);
|
||||
static const ControllerButton rightUp = ControllerButton('rightUp', action: InGameAction.shiftUp);
|
||||
|
||||
static const List<ControllerButton> values = [
|
||||
leftSteer,
|
||||
rightSteer,
|
||||
leftDown,
|
||||
leftBrake,
|
||||
shiftUpLeft,
|
||||
shiftDownLeft,
|
||||
leftUp,
|
||||
rightDown,
|
||||
rightBrake,
|
||||
shiftUpRight,
|
||||
shiftDownRight,
|
||||
rightUp,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
|
||||
class ZwiftConstants {
|
||||
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();
|
||||
static const ZWIFT_CUSTOM_SERVICE_UUID = "00000001-19CA-4651-86E5-FA29DCDD09D1";
|
||||
static const ZWIFT_RIDE_CUSTOM_SERVICE_UUID = "0000fc82-0000-1000-8000-00805f9b34fb";
|
||||
static const ZWIFT_RIDE_CUSTOM_SERVICE_UUID_SHORT = "fc82";
|
||||
static const ZWIFT_ASYNC_CHARACTERISTIC_UUID = "00000002-19CA-4651-86E5-FA29DCDD09D1";
|
||||
static const ZWIFT_SYNC_RX_CHARACTERISTIC_UUID = "00000003-19CA-4651-86E5-FA29DCDD09D1";
|
||||
static const ZWIFT_SYNC_TX_CHARACTERISTIC_UUID = "00000004-19CA-4651-86E5-FA29DCDD09D1";
|
||||
|
||||
static const ZWIFT_MANUFACTURER_ID = 2378; // Zwift, Inc => 0x094A
|
||||
|
||||
@@ -29,51 +33,21 @@ class ZwiftConstants {
|
||||
static final VIBRATE_PATTERN = Uint8List.fromList([0x12, 0x12, 0x08, 0x0A, 0x06, 0x08, 0x02, 0x10, 0x00, 0x18]);
|
||||
|
||||
// these don't actually seem to matter, its just the header has to be 7 bytes RIDEON + 2
|
||||
static final REQUEST_START = Uint8List.fromList([0, 9]); //byteArrayOf(1, 2)
|
||||
static final RESPONSE_START_CLICK = Uint8List.fromList([1, 3]); // from device
|
||||
static final RESPONSE_START_PLAY = Uint8List.fromList([1, 4]); // from device
|
||||
static final REQUEST_START = Uint8List.fromList([0x00, 0x09]); //byteArrayOf(1, 2)
|
||||
static final RESPONSE_START_CLICK = Uint8List.fromList([0x01, 0x03]); // from device
|
||||
static final RESPONSE_START_PLAY = Uint8List.fromList([0x01, 0x04]); // from device
|
||||
static final RESPONSE_START_CLICK_V2 = Uint8List.fromList([0x02, 0x03]); // from device
|
||||
static final RESPONSE_STOPPED_CLICK_V2 = Uint8List.fromList([
|
||||
0xff,
|
||||
0x05,
|
||||
0x00,
|
||||
0xea,
|
||||
0x05,
|
||||
0x19,
|
||||
0x0a,
|
||||
0x0c,
|
||||
0x35,
|
||||
0x38,
|
||||
0x44,
|
||||
0x31,
|
||||
0x35,
|
||||
0x41,
|
||||
0x42,
|
||||
0x42,
|
||||
0x34,
|
||||
0x33,
|
||||
0x36,
|
||||
0x33,
|
||||
0x10,
|
||||
0x01,
|
||||
0x18,
|
||||
0x84,
|
||||
0x07,
|
||||
0x20,
|
||||
0x08,
|
||||
0x28,
|
||||
0x09,
|
||||
0x30,
|
||||
]); // from device
|
||||
static final RESPONSE_STOPPED_CLICK_V2_VARIANT_1 = Uint8List.fromList([0xff, 0x05, 0x00, 0xea, 0x05]); // from device
|
||||
static final RESPONSE_STOPPED_CLICK_V2_VARIANT_2 = Uint8List.fromList([0xff, 0x05, 0x00, 0xfa, 0x05]); // from device
|
||||
|
||||
// Message types received from device
|
||||
static const CONTROLLER_NOTIFICATION_MESSAGE_TYPE = 07;
|
||||
static const EMPTY_MESSAGE_TYPE = 21;
|
||||
static const EMPTY_MESSAGE_TYPE = 21; // 0x15
|
||||
static const BATTERY_LEVEL_TYPE = 25;
|
||||
static const UNKNOWN_CLICKV2_TYPE = 0x3C;
|
||||
|
||||
// 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 CLICK_NOTIFICATION_MESSAGE_TYPE = 55; // 0x37
|
||||
static const int PLAY_NOTIFICATION_MESSAGE_TYPE = 7;
|
||||
static const int RIDE_NOTIFICATION_MESSAGE_TYPE = 35; // 0x23
|
||||
|
||||
@@ -81,6 +55,94 @@ class ZwiftConstants {
|
||||
static const DISCONNECT_MESSAGE_TYPE = 0xFE;
|
||||
}
|
||||
|
||||
class ZwiftButtons {
|
||||
// left controller
|
||||
static const ControllerButton navigationUp = ControllerButton(
|
||||
'navigationUp',
|
||||
action: InGameAction.toggleUi,
|
||||
icon: Icons.keyboard_arrow_up,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton navigationDown = ControllerButton(
|
||||
'navigationDown',
|
||||
action: InGameAction.uturn,
|
||||
icon: Icons.keyboard_arrow_down,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton navigationLeft = ControllerButton(
|
||||
'navigationLeft',
|
||||
action: InGameAction.navigateLeft,
|
||||
icon: Icons.keyboard_arrow_left,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton navigationRight = ControllerButton(
|
||||
'navigationRight',
|
||||
action: InGameAction.navigateRight,
|
||||
icon: Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton onOffLeft = ControllerButton('onOffLeft', action: InGameAction.toggleUi);
|
||||
static const ControllerButton sideButtonLeft = ControllerButton('sideButtonLeft', action: InGameAction.shiftDown);
|
||||
static const ControllerButton paddleLeft = ControllerButton('paddleLeft', action: InGameAction.shiftDown);
|
||||
|
||||
// zwift ride only
|
||||
static const ControllerButton shiftUpLeft = ControllerButton(
|
||||
'shiftUpLeft',
|
||||
action: InGameAction.shiftDown,
|
||||
icon: Icons.remove,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton shiftDownLeft = ControllerButton(
|
||||
'shiftDownLeft',
|
||||
action: InGameAction.shiftDown,
|
||||
);
|
||||
static const ControllerButton powerUpLeft = ControllerButton('powerUpLeft', action: InGameAction.shiftDown);
|
||||
|
||||
// right controller
|
||||
static const ControllerButton a = ControllerButton('a', action: null, color: Colors.lightGreen);
|
||||
static const ControllerButton b = ControllerButton('b', action: null, color: Colors.pinkAccent);
|
||||
static const ControllerButton z = ControllerButton('z', action: null, color: Colors.deepOrangeAccent);
|
||||
static const ControllerButton y = ControllerButton('y', action: null, color: Colors.lightBlue);
|
||||
static const ControllerButton onOffRight = ControllerButton('onOffRight', action: InGameAction.toggleUi);
|
||||
static const ControllerButton sideButtonRight = ControllerButton('sideButtonRight', action: InGameAction.shiftUp);
|
||||
static const ControllerButton paddleRight = ControllerButton('paddleRight', action: InGameAction.shiftUp);
|
||||
|
||||
// zwift ride only
|
||||
static const ControllerButton shiftUpRight = ControllerButton(
|
||||
'shiftUpRight',
|
||||
action: InGameAction.shiftUp,
|
||||
icon: Icons.add,
|
||||
color: Colors.black,
|
||||
);
|
||||
static const ControllerButton shiftDownRight = ControllerButton('shiftDownRight', action: InGameAction.shiftUp);
|
||||
static const ControllerButton powerUpRight = ControllerButton('powerUpRight', action: InGameAction.shiftUp);
|
||||
|
||||
static List<ControllerButton> get values => [
|
||||
// left
|
||||
navigationUp,
|
||||
navigationDown,
|
||||
navigationLeft,
|
||||
navigationRight,
|
||||
onOffLeft,
|
||||
sideButtonLeft,
|
||||
paddleLeft,
|
||||
shiftUpLeft,
|
||||
shiftDownLeft,
|
||||
powerUpLeft,
|
||||
// right
|
||||
a,
|
||||
b,
|
||||
z,
|
||||
y,
|
||||
onOffRight,
|
||||
sideButtonRight,
|
||||
paddleRight,
|
||||
shiftUpRight,
|
||||
shiftDownRight,
|
||||
powerUpRight,
|
||||
];
|
||||
}
|
||||
|
||||
enum ZwiftDeviceType {
|
||||
click,
|
||||
clickV2Right,
|
||||
|
||||
@@ -3,17 +3,21 @@ import 'package:swift_control/bluetooth/devices/zwift/protocol/zwift.pb.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_device.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
|
||||
class ZwiftClick extends ZwiftDevice {
|
||||
ZwiftClick(super.scanResult)
|
||||
: super(availableButtons: [ControllerButton.shiftUpRight, ControllerButton.shiftDownLeft]);
|
||||
ZwiftClick(super.scanResult) : super(availableButtons: [ZwiftButtons.shiftUpRight, ZwiftButtons.shiftUpLeft]);
|
||||
|
||||
@override
|
||||
List<ControllerButton> processClickNotification(Uint8List message) {
|
||||
final status = ClickKeyPadStatus.fromBuffer(message);
|
||||
final buttonsClicked = [
|
||||
if (status.buttonPlus == PlayButtonStatus.ON) ControllerButton.shiftUpRight,
|
||||
if (status.buttonMinus == PlayButtonStatus.ON) ControllerButton.shiftDownLeft,
|
||||
if (status.buttonPlus == PlayButtonStatus.ON) ZwiftButtons.shiftUpRight,
|
||||
if (status.buttonMinus == PlayButtonStatus.ON) ZwiftButtons.shiftUpLeft,
|
||||
];
|
||||
return buttonsClicked;
|
||||
}
|
||||
|
||||
@override
|
||||
String get latestFirmwareVersion => '1.1.0';
|
||||
}
|
||||
|
||||
@@ -1,21 +1,93 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/protocol/zp.pbenum.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_ride.dart';
|
||||
import 'package:swift_control/pages/markdown.dart';
|
||||
import 'package:swift_control/widgets/warning.dart';
|
||||
|
||||
class ZwiftClickV2 extends ZwiftRide {
|
||||
ZwiftClickV2(super.scanResult) : super(isBeta: true);
|
||||
ZwiftClickV2(super.scanResult)
|
||||
: super(
|
||||
isBeta: true,
|
||||
availableButtons: [
|
||||
ZwiftButtons.navigationLeft,
|
||||
ZwiftButtons.navigationRight,
|
||||
ZwiftButtons.navigationUp,
|
||||
ZwiftButtons.navigationDown,
|
||||
ZwiftButtons.a,
|
||||
ZwiftButtons.b,
|
||||
ZwiftButtons.y,
|
||||
ZwiftButtons.z,
|
||||
ZwiftButtons.shiftUpLeft,
|
||||
ZwiftButtons.shiftUpRight,
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
List<int> get startCommand => ZwiftConstants.RIDE_ON + ZwiftConstants.RESPONSE_START_CLICK_V2;
|
||||
|
||||
@override
|
||||
String get latestFirmwareVersion => '1.1.0';
|
||||
|
||||
@override
|
||||
Future<void> setupHandshake() async {
|
||||
super.setupHandshake();
|
||||
await sendCommandBuffer(Uint8List.fromList([0xFF, 0x04, 0x00]));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget showInformation(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
super.showInformation(context),
|
||||
|
||||
if (isConnected)
|
||||
Warning(
|
||||
children: [
|
||||
Text(
|
||||
'''To make your Zwift Click V2 work best you should connect it in the Zwift app once each day.\nIf you don't do that SwiftControl will need to reconnect every minute.
|
||||
|
||||
1. Open Zwift app
|
||||
2. Log in (subscription not required) and open the device connection screen
|
||||
3. Connect your Trainer, then connect the Zwift Click V2
|
||||
4. Close the Zwift app again and connect again in SwiftControl''',
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
sendCommand(Opcode.RESET, null);
|
||||
},
|
||||
child: Text('Reset now'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text('Troubleshooting'),
|
||||
),
|
||||
if (kDebugMode)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
test();
|
||||
},
|
||||
child: Text('Test'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test() async {
|
||||
await sendCommand(Opcode.RESET, null);
|
||||
//await sendCommand(Opcode.GET, Get(dataObjectId: VendorDO.PAGE_DEVICE_PAIRING.value)); // 0008 82E0 03
|
||||
|
||||
@@ -2,8 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:swift_control/bluetooth/ble.dart';
|
||||
import 'package:swift_control/bluetooth/devices/base_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/bluetooth_device.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/messages/notification.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
@@ -11,19 +10,20 @@ import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/single_line_exception.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
abstract class ZwiftDevice extends BaseDevice {
|
||||
abstract class ZwiftDevice extends BluetoothDevice {
|
||||
ZwiftDevice(super.scanResult, {required super.availableButtons, super.isBeta});
|
||||
|
||||
BleCharacteristic? syncRxCharacteristic;
|
||||
|
||||
List<ControllerButton>? _lastButtonsClicked;
|
||||
|
||||
String get latestFirmwareVersion;
|
||||
List<int> get startCommand => ZwiftConstants.RIDE_ON + ZwiftConstants.RESPONSE_START_CLICK;
|
||||
String get customServiceId => ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID;
|
||||
|
||||
@override
|
||||
Future<void> handleServices(List<BleService> services) async {
|
||||
final customService = services.firstOrNullWhere((service) => service.uuid == customServiceId);
|
||||
final customService = services.firstOrNullWhere((service) => service.uuid == customServiceId.toLowerCase());
|
||||
|
||||
if (customService == null) {
|
||||
throw Exception(
|
||||
@@ -31,30 +31,14 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
);
|
||||
}
|
||||
|
||||
final deviceInformationService = services.firstOrNullWhere(
|
||||
(service) => service.uuid == BleUuid.DEVICE_INFORMATION_SERVICE_UUID,
|
||||
);
|
||||
final firmwareCharacteristic = deviceInformationService?.characteristics.firstOrNullWhere(
|
||||
(c) => c.uuid == BleUuid.DEVICE_INFORMATION_CHARACTERISTIC_FIRMWARE_REVISION,
|
||||
);
|
||||
if (firmwareCharacteristic != null) {
|
||||
final firmwareData = await UniversalBle.read(
|
||||
device.deviceId,
|
||||
deviceInformationService!.uuid,
|
||||
firmwareCharacteristic.uuid,
|
||||
);
|
||||
firmwareVersion = String.fromCharCodes(firmwareData);
|
||||
connection.signalChange(this);
|
||||
}
|
||||
|
||||
final asyncCharacteristic = customService.characteristics.firstOrNullWhere(
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_ASYNC_CHARACTERISTIC_UUID,
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_ASYNC_CHARACTERISTIC_UUID.toLowerCase(),
|
||||
);
|
||||
final syncTxCharacteristic = customService.characteristics.firstOrNullWhere(
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_SYNC_TX_CHARACTERISTIC_UUID,
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_SYNC_TX_CHARACTERISTIC_UUID.toLowerCase(),
|
||||
);
|
||||
syncRxCharacteristic = customService.characteristics.firstOrNullWhere(
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_SYNC_RX_CHARACTERISTIC_UUID,
|
||||
(characteristic) => characteristic.uuid == ZwiftConstants.ZWIFT_SYNC_RX_CHARACTERISTIC_UUID.toLowerCase(),
|
||||
);
|
||||
|
||||
if (asyncCharacteristic == null || syncTxCharacteristic == null || syncRxCharacteristic == null) {
|
||||
@@ -65,6 +49,14 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
await UniversalBle.subscribeIndications(device.deviceId, customService.uuid, syncTxCharacteristic.uuid);
|
||||
|
||||
await setupHandshake();
|
||||
|
||||
if (firmwareVersion != latestFirmwareVersion) {
|
||||
actionStreamInternal.add(
|
||||
LogNotification(
|
||||
'A new firmware version is available for ${device.name ?? device.rawName}: $latestFirmwareVersion (current: $firmwareVersion). Please update it in Zwift Companion app.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setupHandshake() async {
|
||||
@@ -79,7 +71,7 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
|
||||
@override
|
||||
Future<void> processCharacteristic(String characteristic, Uint8List bytes) async {
|
||||
if (kDebugMode && false) {
|
||||
if (kDebugMode) {
|
||||
print(
|
||||
"${DateTime.now().toString().split(" ").last} Received data on $characteristic: ${bytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(' ')}",
|
||||
);
|
||||
@@ -90,7 +82,7 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
|
||||
try {
|
||||
if (bytes.startsWith(startCommand)) {
|
||||
_processDevicePublicKeyResponse(bytes);
|
||||
processDevicePublicKeyResponse(bytes);
|
||||
} else {
|
||||
processData(bytes);
|
||||
}
|
||||
@@ -105,7 +97,7 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
}
|
||||
}
|
||||
|
||||
void _processDevicePublicKeyResponse(Uint8List bytes) {
|
||||
void processDevicePublicKeyResponse(Uint8List bytes) {
|
||||
final devicePublicKeyBytes = bytes.sublist(
|
||||
ZwiftConstants.RIDE_ON.length + ZwiftConstants.RESPONSE_START_CLICK.length,
|
||||
);
|
||||
@@ -144,7 +136,7 @@ abstract class ZwiftDevice extends BaseDevice {
|
||||
@override
|
||||
Future<void> handleButtonsClicked(List<ControllerButton>? buttonsClicked) async {
|
||||
// the same messages are sent multiple times, so ignore
|
||||
if (_lastButtonsClicked?.contentEquals(buttonsClicked ?? []) == false) {
|
||||
if (_lastButtonsClicked == null || _lastButtonsClicked?.contentEquals(buttonsClicked ?? []) == false) {
|
||||
super.handleButtonsClicked(buttonsClicked);
|
||||
}
|
||||
_lastButtonsClicked = buttonsClicked;
|
||||
|
||||
367
lib/bluetooth/devices/zwift/zwift_emulator.dart
Normal file
367
lib/bluetooth/devices/zwift/zwift_emulator.dart
Normal file
@@ -0,0 +1,367 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:bluetooth_low_energy/bluetooth_low_energy.dart';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart' hide ConnectionState;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:swift_control/bluetooth/ble.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/protocol/zp.pbenum.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_ride.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
import 'package:swift_control/widgets/title.dart';
|
||||
|
||||
import 'protocol/zwift.pb.dart' show RideKeyPadStatus;
|
||||
|
||||
final zwiftEmulator = ZwiftEmulator();
|
||||
|
||||
class ZwiftEmulator {
|
||||
static final List<InGameAction> supportedActions = [
|
||||
InGameAction.shiftUp,
|
||||
InGameAction.shiftDown,
|
||||
InGameAction.uturn,
|
||||
InGameAction.steerLeft,
|
||||
InGameAction.steerRight,
|
||||
InGameAction.openActionBar,
|
||||
InGameAction.usePowerUp,
|
||||
InGameAction.select,
|
||||
InGameAction.back,
|
||||
InGameAction.rideOnBomb,
|
||||
];
|
||||
|
||||
ValueNotifier<bool> isConnected = ValueNotifier<bool>(false);
|
||||
bool get isAdvertising => _isAdvertising;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
final peripheralManager = PeripheralManager();
|
||||
bool _isAdvertising = false;
|
||||
bool _isLoading = false;
|
||||
bool _isServiceAdded = false;
|
||||
bool _isSubscribedToEvents = false;
|
||||
Central? _central;
|
||||
GATTCharacteristic? _asyncCharacteristic;
|
||||
|
||||
Future<void> reconnect() async {
|
||||
await peripheralManager.stopAdvertising();
|
||||
await peripheralManager.removeAllServices();
|
||||
_isServiceAdded = false;
|
||||
_isAdvertising = false;
|
||||
startAdvertising(() {});
|
||||
}
|
||||
|
||||
Future<void> startAdvertising(VoidCallback onUpdate) async {
|
||||
_isLoading = true;
|
||||
onUpdate();
|
||||
|
||||
peripheralManager.stateChanged.forEach((state) {
|
||||
print('Peripheral manager state: ${state.state}');
|
||||
});
|
||||
|
||||
if (!kIsWeb && Platform.isAndroid) {
|
||||
if (Platform.isAndroid) {
|
||||
peripheralManager.connectionStateChanged.forEach((state) {
|
||||
print('Peripheral connection state: ${state.state} of ${state.central.uuid}');
|
||||
if (state.state == ConnectionState.connected) {
|
||||
} else if (state.state == ConnectionState.disconnected) {
|
||||
_central = null;
|
||||
isConnected.value = false;
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final status = await Permission.bluetoothAdvertise.request();
|
||||
if (!status.isGranted) {
|
||||
print('Bluetooth advertise permission not granted');
|
||||
_isAdvertising = false;
|
||||
onUpdate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (peripheralManager.state != BluetoothLowEnergyState.poweredOn) {
|
||||
print('Waiting for peripheral manager to be powered on...');
|
||||
if (settings.getLastTarget() == Target.thisDevice) {
|
||||
return;
|
||||
}
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
|
||||
final syncTxCharacteristic = GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString(ZwiftConstants.ZWIFT_SYNC_TX_CHARACTERISTIC_UUID),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.read,
|
||||
GATTCharacteristicProperty.indicate,
|
||||
],
|
||||
permissions: [
|
||||
GATTCharacteristicPermission.read,
|
||||
],
|
||||
);
|
||||
|
||||
_asyncCharacteristic = GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString(ZwiftConstants.ZWIFT_ASYNC_CHARACTERISTIC_UUID),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.notify,
|
||||
],
|
||||
permissions: [],
|
||||
);
|
||||
|
||||
if (!_isServiceAdded) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
|
||||
if (!_isSubscribedToEvents) {
|
||||
_isSubscribedToEvents = true;
|
||||
peripheralManager.characteristicReadRequested.forEach((eventArgs) async {
|
||||
print('Read request for characteristic: ${eventArgs.characteristic.uuid}');
|
||||
|
||||
switch (eventArgs.characteristic.uuid.toString().toUpperCase()) {
|
||||
case ZwiftConstants.ZWIFT_SYNC_TX_CHARACTERISTIC_UUID:
|
||||
print('Handling read request for SYNC TX characteristic');
|
||||
break;
|
||||
case BleUuid.DEVICE_INFORMATION_CHARACTERISTIC_BATTERY_LEVEL:
|
||||
await peripheralManager.respondReadRequestWithValue(
|
||||
eventArgs.request,
|
||||
value: Uint8List.fromList([100]),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
print('Unhandled read request for characteristic: ${eventArgs.characteristic.uuid}');
|
||||
}
|
||||
|
||||
final request = eventArgs.request;
|
||||
final trimmedValue = Uint8List.fromList([]);
|
||||
await peripheralManager.respondReadRequestWithValue(
|
||||
request,
|
||||
value: trimmedValue,
|
||||
);
|
||||
// You can respond to read requests here if needed
|
||||
});
|
||||
|
||||
peripheralManager.characteristicNotifyStateChanged.forEach((char) {
|
||||
print(
|
||||
'Notify state changed for characteristic: ${char.characteristic.uuid}: ${char.state}',
|
||||
);
|
||||
});
|
||||
peripheralManager.characteristicWriteRequested.forEach((eventArgs) async {
|
||||
_central = eventArgs.central;
|
||||
isConnected.value = true;
|
||||
|
||||
final characteristic = eventArgs.characteristic;
|
||||
final request = eventArgs.request;
|
||||
final value = request.value;
|
||||
print(
|
||||
'Write request for characteristic: ${characteristic.uuid}',
|
||||
);
|
||||
|
||||
switch (eventArgs.characteristic.uuid.toString().toUpperCase()) {
|
||||
case ZwiftConstants.ZWIFT_SYNC_RX_CHARACTERISTIC_UUID:
|
||||
print(
|
||||
'Handling write request for SYNC RX characteristic, value: ${value.map((e) => e.toRadixString(16).padLeft(2, '0')).join(' ')}\n${String.fromCharCodes(value)}',
|
||||
);
|
||||
|
||||
final handshake = [...ZwiftConstants.RIDE_ON, ...ZwiftConstants.RESPONSE_START_CLICK_V2];
|
||||
final handshakeAlternative = ZwiftConstants.RIDE_ON; // e.g. Rouvy
|
||||
|
||||
if (value.contentEquals(handshake) || value.contentEquals(handshakeAlternative)) {
|
||||
print('Sending handshake');
|
||||
await peripheralManager.notifyCharacteristic(
|
||||
_central!,
|
||||
syncTxCharacteristic,
|
||||
value: ZwiftConstants.RIDE_ON,
|
||||
);
|
||||
onUpdate();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print('Unhandled write request for characteristic: ${eventArgs.characteristic.uuid}');
|
||||
}
|
||||
|
||||
await peripheralManager.respondWriteRequest(request);
|
||||
});
|
||||
}
|
||||
|
||||
// Device Information
|
||||
await peripheralManager.addService(
|
||||
GATTService(
|
||||
uuid: UUID.fromString('180A'),
|
||||
isPrimary: true,
|
||||
characteristics: [
|
||||
GATTCharacteristic.immutable(
|
||||
uuid: UUID.fromString('2A29'),
|
||||
value: Uint8List.fromList('SwiftControl'.codeUnits),
|
||||
descriptors: [],
|
||||
),
|
||||
GATTCharacteristic.immutable(
|
||||
uuid: UUID.fromString('2A25'),
|
||||
value: Uint8List.fromList('09-B48123283828F1337'.codeUnits),
|
||||
descriptors: [],
|
||||
),
|
||||
GATTCharacteristic.immutable(
|
||||
uuid: UUID.fromString('2A27'),
|
||||
value: Uint8List.fromList('A.0'.codeUnits),
|
||||
descriptors: [],
|
||||
),
|
||||
GATTCharacteristic.immutable(
|
||||
uuid: UUID.fromString('2A26'),
|
||||
value: Uint8List.fromList((packageInfoValue?.version ?? '1.0.0').codeUnits),
|
||||
descriptors: [],
|
||||
),
|
||||
],
|
||||
includedServices: [],
|
||||
),
|
||||
);
|
||||
|
||||
// Battery Service
|
||||
await peripheralManager.addService(
|
||||
GATTService(
|
||||
uuid: UUID.fromString('180F'),
|
||||
isPrimary: true,
|
||||
characteristics: [
|
||||
GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString('2A19'),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.read,
|
||||
GATTCharacteristicProperty.notify,
|
||||
],
|
||||
permissions: [
|
||||
GATTCharacteristicPermission.read,
|
||||
],
|
||||
),
|
||||
],
|
||||
includedServices: [],
|
||||
),
|
||||
);
|
||||
|
||||
// Unknown Service
|
||||
await peripheralManager.addService(
|
||||
GATTService(
|
||||
uuid: UUID.fromString(ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID_SHORT),
|
||||
isPrimary: true,
|
||||
characteristics: [
|
||||
_asyncCharacteristic!,
|
||||
GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString(ZwiftConstants.ZWIFT_SYNC_RX_CHARACTERISTIC_UUID),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.writeWithoutResponse,
|
||||
],
|
||||
permissions: [],
|
||||
),
|
||||
syncTxCharacteristic,
|
||||
GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString('00000005-19CA-4651-86E5-FA29DCDD09D1'),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.notify,
|
||||
],
|
||||
permissions: [],
|
||||
),
|
||||
GATTCharacteristic.mutable(
|
||||
uuid: UUID.fromString('00000006-19CA-4651-86E5-FA29DCDD09D1'),
|
||||
descriptors: [],
|
||||
properties: [
|
||||
GATTCharacteristicProperty.indicate,
|
||||
GATTCharacteristicProperty.read,
|
||||
GATTCharacteristicProperty.writeWithoutResponse,
|
||||
GATTCharacteristicProperty.write,
|
||||
],
|
||||
permissions: [
|
||||
GATTCharacteristicPermission.read,
|
||||
GATTCharacteristicPermission.write,
|
||||
],
|
||||
),
|
||||
],
|
||||
includedServices: [],
|
||||
),
|
||||
);
|
||||
_isServiceAdded = true;
|
||||
}
|
||||
|
||||
final advertisement = Advertisement(
|
||||
name: 'SwiftControl',
|
||||
serviceUUIDs: [UUID.fromString(ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID_SHORT)],
|
||||
serviceData: {
|
||||
UUID.fromString(ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID_SHORT): Uint8List.fromList([0x02]),
|
||||
},
|
||||
manufacturerSpecificData: [
|
||||
ManufacturerSpecificData(
|
||||
id: 0x094A,
|
||||
data: Uint8List.fromList([ZwiftConstants.CLICK_V2_LEFT_SIDE, 0x13, 0x37]),
|
||||
),
|
||||
],
|
||||
);
|
||||
print('Starting advertising with HID service...');
|
||||
|
||||
await peripheralManager.startAdvertising(advertisement);
|
||||
_isAdvertising = true;
|
||||
_isLoading = false;
|
||||
onUpdate();
|
||||
}
|
||||
|
||||
Future<void> stopAdvertising() async {
|
||||
await peripheralManager.stopAdvertising();
|
||||
_isAdvertising = false;
|
||||
_isLoading = false;
|
||||
}
|
||||
|
||||
Future<String> sendAction(InGameAction inGameAction, int? inGameActionValue) async {
|
||||
final button = switch (inGameAction) {
|
||||
InGameAction.shiftUp => RideButtonMask.SHFT_UP_R_BTN,
|
||||
InGameAction.shiftDown => RideButtonMask.SHFT_UP_L_BTN,
|
||||
InGameAction.uturn => RideButtonMask.DOWN_BTN,
|
||||
InGameAction.steerLeft => RideButtonMask.LEFT_BTN,
|
||||
InGameAction.steerRight => RideButtonMask.RIGHT_BTN,
|
||||
InGameAction.openActionBar => RideButtonMask.UP_BTN,
|
||||
InGameAction.usePowerUp => RideButtonMask.Y_BTN,
|
||||
InGameAction.select => RideButtonMask.A_BTN,
|
||||
InGameAction.back => RideButtonMask.B_BTN,
|
||||
InGameAction.rideOnBomb => RideButtonMask.Z_BTN,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (button == null) {
|
||||
return 'Action ${inGameAction.name} not supported by Zwift Emulator';
|
||||
}
|
||||
|
||||
final status = RideKeyPadStatus()
|
||||
..buttonMap = (~button.mask) & 0xFFFFFFFF
|
||||
..analogPaddles.clear();
|
||||
|
||||
final bytes = status.writeToBuffer();
|
||||
|
||||
final commandProto = Uint8List.fromList([
|
||||
Opcode.CONTROLLER_NOTIFICATION.value,
|
||||
...bytes,
|
||||
]);
|
||||
|
||||
peripheralManager.notifyCharacteristic(_central!, _asyncCharacteristic!, value: commandProto);
|
||||
|
||||
final zero = Uint8List.fromList([0x23, 0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F]);
|
||||
peripheralManager.notifyCharacteristic(_central!, _asyncCharacteristic!, value: zero);
|
||||
return 'Sent action: ${inGameAction.name}';
|
||||
}
|
||||
}
|
||||
|
||||
class ZwiftEmulatorInformation extends StatelessWidget {
|
||||
const ZwiftEmulatorInformation({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: zwiftEmulator.isConnected,
|
||||
builder: (context, isConnected, _) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return Text('Zwift is ${isConnected ? 'connected' : 'not connected'}');
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,20 @@ class ZwiftPlay extends ZwiftDevice {
|
||||
ZwiftPlay(super.scanResult)
|
||||
: super(
|
||||
availableButtons: [
|
||||
ControllerButton.y,
|
||||
ControllerButton.z,
|
||||
ControllerButton.a,
|
||||
ControllerButton.b,
|
||||
ControllerButton.onOffRight,
|
||||
ControllerButton.sideButtonRight,
|
||||
ControllerButton.paddleRight,
|
||||
ControllerButton.navigationUp,
|
||||
ControllerButton.navigationLeft,
|
||||
ControllerButton.navigationRight,
|
||||
ControllerButton.navigationDown,
|
||||
ControllerButton.onOffLeft,
|
||||
ControllerButton.sideButtonLeft,
|
||||
ControllerButton.paddleLeft,
|
||||
ZwiftButtons.y,
|
||||
ZwiftButtons.z,
|
||||
ZwiftButtons.a,
|
||||
ZwiftButtons.b,
|
||||
ZwiftButtons.onOffRight,
|
||||
ZwiftButtons.sideButtonRight,
|
||||
ZwiftButtons.paddleRight,
|
||||
ZwiftButtons.navigationUp,
|
||||
ZwiftButtons.navigationLeft,
|
||||
ZwiftButtons.navigationRight,
|
||||
ZwiftButtons.navigationDown,
|
||||
ZwiftButtons.onOffLeft,
|
||||
ZwiftButtons.sideButtonLeft,
|
||||
ZwiftButtons.paddleLeft,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -34,23 +34,26 @@ class ZwiftPlay extends ZwiftDevice {
|
||||
|
||||
return [
|
||||
if (status.rightPad == PlayButtonStatus.ON) ...[
|
||||
if (status.buttonYUp == PlayButtonStatus.ON) ControllerButton.y,
|
||||
if (status.buttonZLeft == PlayButtonStatus.ON) ControllerButton.z,
|
||||
if (status.buttonARight == PlayButtonStatus.ON) ControllerButton.a,
|
||||
if (status.buttonBDown == PlayButtonStatus.ON) ControllerButton.b,
|
||||
if (status.buttonOn == PlayButtonStatus.ON) ControllerButton.onOffRight,
|
||||
if (status.buttonShift == PlayButtonStatus.ON) ControllerButton.sideButtonRight,
|
||||
if (status.analogLR.abs() == 100) ControllerButton.paddleRight,
|
||||
if (status.buttonYUp == PlayButtonStatus.ON) ZwiftButtons.y,
|
||||
if (status.buttonZLeft == PlayButtonStatus.ON) ZwiftButtons.z,
|
||||
if (status.buttonARight == PlayButtonStatus.ON) ZwiftButtons.a,
|
||||
if (status.buttonBDown == PlayButtonStatus.ON) ZwiftButtons.b,
|
||||
if (status.buttonOn == PlayButtonStatus.ON) ZwiftButtons.onOffRight,
|
||||
if (status.buttonShift == PlayButtonStatus.ON) ZwiftButtons.sideButtonRight,
|
||||
if (status.analogLR.abs() == 100) ZwiftButtons.paddleRight,
|
||||
],
|
||||
if (status.rightPad == PlayButtonStatus.OFF) ...[
|
||||
if (status.buttonYUp == PlayButtonStatus.ON) ControllerButton.navigationUp,
|
||||
if (status.buttonZLeft == PlayButtonStatus.ON) ControllerButton.navigationLeft,
|
||||
if (status.buttonARight == PlayButtonStatus.ON) ControllerButton.navigationRight,
|
||||
if (status.buttonBDown == PlayButtonStatus.ON) ControllerButton.navigationDown,
|
||||
if (status.buttonOn == PlayButtonStatus.ON) ControllerButton.onOffLeft,
|
||||
if (status.buttonShift == PlayButtonStatus.ON) ControllerButton.sideButtonLeft,
|
||||
if (status.analogLR.abs() == 100) ControllerButton.paddleLeft,
|
||||
if (status.buttonYUp == PlayButtonStatus.ON) ZwiftButtons.navigationUp,
|
||||
if (status.buttonZLeft == PlayButtonStatus.ON) ZwiftButtons.navigationLeft,
|
||||
if (status.buttonARight == PlayButtonStatus.ON) ZwiftButtons.navigationRight,
|
||||
if (status.buttonBDown == PlayButtonStatus.ON) ZwiftButtons.navigationDown,
|
||||
if (status.buttonOn == PlayButtonStatus.ON) ZwiftButtons.onOffLeft,
|
||||
if (status.buttonShift == PlayButtonStatus.ON) ZwiftButtons.sideButtonLeft,
|
||||
if (status.analogLR.abs() == 100) ZwiftButtons.paddleLeft,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
String get latestFirmwareVersion => '1.3.1';
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/protocol/zp.pb.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/protocol/zp_vendor.pb.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/protocol/zwift.pb.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_clickv2.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_device.dart';
|
||||
import 'package:swift_control/bluetooth/messages/notification.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
@@ -18,33 +17,38 @@ class ZwiftRide extends ZwiftDevice {
|
||||
/// analog drift or light touches.
|
||||
static const int analogPaddleThreshold = 25;
|
||||
|
||||
ZwiftRide(super.scanResult, {super.isBeta})
|
||||
ZwiftRide(super.scanResult, {super.isBeta, List<ControllerButton>? availableButtons})
|
||||
: super(
|
||||
availableButtons: [
|
||||
ControllerButton.navigationLeft,
|
||||
ControllerButton.navigationRight,
|
||||
ControllerButton.navigationUp,
|
||||
ControllerButton.navigationDown,
|
||||
ControllerButton.a,
|
||||
ControllerButton.b,
|
||||
ControllerButton.y,
|
||||
ControllerButton.z,
|
||||
ControllerButton.shiftUpLeft,
|
||||
ControllerButton.shiftDownLeft,
|
||||
ControllerButton.shiftUpRight,
|
||||
ControllerButton.shiftDownRight,
|
||||
ControllerButton.powerUpLeft,
|
||||
ControllerButton.powerUpRight,
|
||||
ControllerButton.onOffLeft,
|
||||
ControllerButton.onOffRight,
|
||||
ControllerButton.paddleLeft,
|
||||
ControllerButton.paddleRight,
|
||||
],
|
||||
availableButtons:
|
||||
availableButtons ??
|
||||
[
|
||||
ZwiftButtons.navigationLeft,
|
||||
ZwiftButtons.navigationRight,
|
||||
ZwiftButtons.navigationUp,
|
||||
ZwiftButtons.navigationDown,
|
||||
ZwiftButtons.a,
|
||||
ZwiftButtons.b,
|
||||
ZwiftButtons.y,
|
||||
ZwiftButtons.z,
|
||||
ZwiftButtons.shiftUpLeft,
|
||||
ZwiftButtons.shiftDownLeft,
|
||||
ZwiftButtons.shiftUpRight,
|
||||
ZwiftButtons.shiftDownRight,
|
||||
ZwiftButtons.powerUpLeft,
|
||||
ZwiftButtons.powerUpRight,
|
||||
ZwiftButtons.onOffLeft,
|
||||
ZwiftButtons.onOffRight,
|
||||
ZwiftButtons.paddleLeft,
|
||||
ZwiftButtons.paddleRight,
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
String get customServiceId => ZwiftConstants.ZWIFT_RIDE_CUSTOM_SERVICE_UUID;
|
||||
|
||||
@override
|
||||
String get latestFirmwareVersion => '1.2.0';
|
||||
|
||||
@override
|
||||
Future<void> processData(Uint8List bytes) async {
|
||||
Opcode? opcode = Opcode.valueOf(bytes[0]);
|
||||
@@ -56,15 +60,6 @@ class ZwiftRide extends ZwiftDevice {
|
||||
);
|
||||
}
|
||||
|
||||
if (bytes.startsWith(ZwiftConstants.RESPONSE_STOPPED_CLICK_V2) && this is ZwiftClickV2) {
|
||||
actionStreamInternal.add(
|
||||
LogNotification(
|
||||
'Your Zwift Click V2 no longer sends events. Connect it in the Zwift app once per day. Resetting the device now.',
|
||||
),
|
||||
);
|
||||
sendCommand(Opcode.RESET, null);
|
||||
}
|
||||
|
||||
switch (opcode) {
|
||||
case Opcode.RIDE_ON:
|
||||
//print("Empty RideOn response - unencrypted mode");
|
||||
@@ -181,31 +176,23 @@ class ZwiftRide extends ZwiftDevice {
|
||||
|
||||
// Process DIGITAL buttons separately
|
||||
final buttonsClicked = [
|
||||
if (status.buttonMap & _RideButtonMask.LEFT_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.navigationLeft,
|
||||
if (status.buttonMap & _RideButtonMask.RIGHT_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.navigationRight,
|
||||
if (status.buttonMap & _RideButtonMask.UP_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.navigationUp,
|
||||
if (status.buttonMap & _RideButtonMask.DOWN_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.navigationDown,
|
||||
if (status.buttonMap & _RideButtonMask.A_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.a,
|
||||
if (status.buttonMap & _RideButtonMask.B_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.b,
|
||||
if (status.buttonMap & _RideButtonMask.Y_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.y,
|
||||
if (status.buttonMap & _RideButtonMask.Z_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.z,
|
||||
if (status.buttonMap & _RideButtonMask.SHFT_UP_L_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.shiftUpLeft,
|
||||
if (status.buttonMap & _RideButtonMask.SHFT_DN_L_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.shiftDownLeft,
|
||||
if (status.buttonMap & _RideButtonMask.SHFT_UP_R_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.shiftUpRight,
|
||||
if (status.buttonMap & _RideButtonMask.SHFT_DN_R_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.shiftDownRight,
|
||||
if (status.buttonMap & _RideButtonMask.POWERUP_L_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.powerUpLeft,
|
||||
if (status.buttonMap & _RideButtonMask.POWERUP_R_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ControllerButton.powerUpRight,
|
||||
if (status.buttonMap & _RideButtonMask.ONOFF_L_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.onOffLeft,
|
||||
if (status.buttonMap & _RideButtonMask.ONOFF_R_BTN.mask == PlayButtonStatus.ON.value) ControllerButton.onOffRight,
|
||||
if (status.buttonMap & RideButtonMask.LEFT_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.navigationLeft,
|
||||
if (status.buttonMap & RideButtonMask.RIGHT_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.navigationRight,
|
||||
if (status.buttonMap & RideButtonMask.UP_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.navigationUp,
|
||||
if (status.buttonMap & RideButtonMask.DOWN_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.navigationDown,
|
||||
if (status.buttonMap & RideButtonMask.A_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.a,
|
||||
if (status.buttonMap & RideButtonMask.B_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.b,
|
||||
if (status.buttonMap & RideButtonMask.Y_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.y,
|
||||
if (status.buttonMap & RideButtonMask.Z_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.z,
|
||||
if (status.buttonMap & RideButtonMask.SHFT_UP_L_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.shiftUpLeft,
|
||||
if (status.buttonMap & RideButtonMask.SHFT_DN_L_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.shiftDownLeft,
|
||||
if (status.buttonMap & RideButtonMask.SHFT_UP_R_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.shiftUpRight,
|
||||
if (status.buttonMap & RideButtonMask.SHFT_DN_R_BTN.mask == PlayButtonStatus.ON.value)
|
||||
ZwiftButtons.shiftDownRight,
|
||||
if (status.buttonMap & RideButtonMask.POWERUP_L_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.powerUpLeft,
|
||||
if (status.buttonMap & RideButtonMask.POWERUP_R_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.powerUpRight,
|
||||
if (status.buttonMap & RideButtonMask.ONOFF_L_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.onOffLeft,
|
||||
if (status.buttonMap & RideButtonMask.ONOFF_R_BTN.mask == PlayButtonStatus.ON.value) ZwiftButtons.onOffRight,
|
||||
];
|
||||
|
||||
// Process ANALOG inputs separately - now properly separated from digital
|
||||
@@ -216,8 +203,8 @@ class ZwiftRide extends ZwiftDevice {
|
||||
if (paddle.hasLocation() && paddle.hasAnalogValue()) {
|
||||
if (paddle.analogValue.abs() >= analogPaddleThreshold) {
|
||||
final button = switch (paddle.location.value) {
|
||||
0 => ControllerButton.paddleLeft, // L0 = left paddle
|
||||
1 => ControllerButton.paddleRight, // L1 = right paddle
|
||||
0 => ZwiftButtons.paddleLeft, // L0 = left paddle
|
||||
1 => ZwiftButtons.paddleRight, // L1 = right paddle
|
||||
_ => null, // L2, L3 unused
|
||||
};
|
||||
|
||||
@@ -265,7 +252,7 @@ class ZwiftRide extends ZwiftDevice {
|
||||
}
|
||||
}
|
||||
|
||||
enum _RideButtonMask {
|
||||
enum RideButtonMask {
|
||||
LEFT_BTN(0x00001),
|
||||
UP_BTN(0x00002),
|
||||
RIGHT_BTN(0x00004),
|
||||
@@ -288,5 +275,5 @@ enum _RideButtonMask {
|
||||
|
||||
final int mask;
|
||||
|
||||
const _RideButtonMask(this.mask);
|
||||
const RideButtonMask(this.mask);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,17 @@ class LogNotification extends BaseNotification {
|
||||
}
|
||||
}
|
||||
|
||||
class BluetoothAvailabilityNotification extends BaseNotification {
|
||||
final bool isAvailable;
|
||||
|
||||
BluetoothAvailabilityNotification(this.isAvailable);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Bluetooth is ${isAvailable ? "available" : "unavailable"}';
|
||||
}
|
||||
}
|
||||
|
||||
class ButtonNotification extends BaseNotification {
|
||||
List<ControllerButton> buttonsClicked;
|
||||
|
||||
|
||||
@@ -10,49 +10,55 @@ import 'package:swift_control/utils/actions/android.dart';
|
||||
import 'package:swift_control/utils/actions/desktop.dart';
|
||||
import 'package:swift_control/utils/actions/remote.dart';
|
||||
import 'package:swift_control/utils/settings/settings.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'bluetooth/connection.dart';
|
||||
import 'bluetooth/devices/link/link.dart';
|
||||
import 'utils/actions/base_actions.dart';
|
||||
|
||||
final connection = Connection();
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
late BaseActions actionHandler;
|
||||
final accessibilityHandler = Accessibility();
|
||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
final settings = Settings();
|
||||
final whooshLink = WhooshLink();
|
||||
const screenshotMode = false;
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
initializeActions(true);
|
||||
if (actionHandler is DesktopActions) {
|
||||
// Must add this line.
|
||||
await windowManager.ensureInitialized();
|
||||
windowManager.setSize(Size(1280, 800));
|
||||
}
|
||||
|
||||
runApp(const SwiftPlayApp());
|
||||
}
|
||||
|
||||
Future<void> initializeActions(bool local) async {
|
||||
enum ConnectionType {
|
||||
unknown,
|
||||
local,
|
||||
remote,
|
||||
}
|
||||
|
||||
Future<void> initializeActions(ConnectionType connectionType) async {
|
||||
if (kIsWeb) {
|
||||
actionHandler = StubActions();
|
||||
} else if (Platform.isAndroid) {
|
||||
if (local) {
|
||||
actionHandler = AndroidActions();
|
||||
} else {
|
||||
actionHandler = RemoteActions();
|
||||
}
|
||||
actionHandler = switch (connectionType) {
|
||||
ConnectionType.local => AndroidActions(),
|
||||
ConnectionType.remote => RemoteActions(),
|
||||
ConnectionType.unknown => StubActions(),
|
||||
};
|
||||
} else if (Platform.isIOS) {
|
||||
actionHandler = RemoteActions();
|
||||
actionHandler = switch (connectionType) {
|
||||
ConnectionType.local => StubActions(),
|
||||
ConnectionType.remote => RemoteActions(),
|
||||
ConnectionType.unknown => StubActions(),
|
||||
};
|
||||
} else {
|
||||
if (local) {
|
||||
actionHandler = DesktopActions();
|
||||
} else {
|
||||
actionHandler = RemoteActions();
|
||||
}
|
||||
actionHandler = switch (connectionType) {
|
||||
ConnectionType.local => DesktopActions(),
|
||||
ConnectionType.remote => RemoteActions(),
|
||||
ConnectionType.unknown => StubActions(),
|
||||
};
|
||||
}
|
||||
actionHandler.init(settings.getKeyMap());
|
||||
}
|
||||
|
||||
class SwiftPlayApp extends StatelessWidget {
|
||||
@@ -61,6 +67,7 @@ class SwiftPlayApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
navigatorKey: navigatorKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'SwiftControl',
|
||||
theme: AppTheme.light,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -56,29 +56,28 @@ class _ChangelogPageState extends State<MarkdownPage> {
|
||||
title: Text(widget.assetPath.replaceAll('.md', '').toLowerCase().capitalize),
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
),
|
||||
body:
|
||||
_error != null
|
||||
? Center(child: Text(_error!))
|
||||
: _markdown == null
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MarkdownWidget(
|
||||
markdown: _markdown!,
|
||||
theme: MarkdownThemeData(
|
||||
textStyle: TextStyle(fontSize: 14.0, color: Colors.black87),
|
||||
onLinkTap: (title, url) {
|
||||
launchUrlString(url);
|
||||
},
|
||||
),
|
||||
body: _error != null
|
||||
? Center(child: Text(_error!))
|
||||
: _markdown == null
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MarkdownWidget(
|
||||
markdown: _markdown!,
|
||||
theme: MarkdownThemeData(
|
||||
textStyle: TextStyle(fontSize: 14.0, color: Colors.black87),
|
||||
onLinkTap: (title, url) {
|
||||
launchUrlString(url);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'dart:io';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/widgets/changelog_dialog.dart';
|
||||
import 'package:swift_control/widgets/menu.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
import 'package:swift_control/widgets/title.dart';
|
||||
|
||||
import 'device.dart';
|
||||
@@ -21,7 +21,6 @@ class RequirementsPage extends StatefulWidget {
|
||||
|
||||
class _RequirementsPageState extends State<RequirementsPage> with WidgetsBindingObserver {
|
||||
int _currentStep = 0;
|
||||
var _local = true;
|
||||
|
||||
List<PlatformRequirement> _requirements = [];
|
||||
|
||||
@@ -30,12 +29,9 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
_local = kIsWeb || !Platform.isIOS;
|
||||
|
||||
// call after first frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
settings.init().then((_) {
|
||||
_checkAndShowChangelog();
|
||||
if (!kIsWeb && Platform.isMacOS) {
|
||||
// add more delay due to CBManagerStateUnknown
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
@@ -46,29 +42,6 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
connection.hasDevices.addListener(() {
|
||||
if (connection.hasDevices.value) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (c) => DevicePage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _checkAndShowChangelog() async {
|
||||
try {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
final currentVersion = packageInfo.version;
|
||||
final lastSeenVersion = settings.getLastSeenVersion();
|
||||
|
||||
if (mounted) {
|
||||
await ChangelogDialog.showIfNeeded(context, currentVersion, lastSeenVersion);
|
||||
}
|
||||
|
||||
// Update last seen version
|
||||
await settings.setLastSeenVersion(currentVersion);
|
||||
} catch (e) {
|
||||
print('Failed to check changelog: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -92,36 +65,48 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
actions: buildMenuButtons(),
|
||||
),
|
||||
body: _requirements.isEmpty
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
spacing: 12,
|
||||
children: [
|
||||
SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
value: _local,
|
||||
title: Text('Trainer app is running on this device'),
|
||||
subtitle: Text('Turn off if you want to control another device, e.g. your tablet'),
|
||||
onChanged: (local) {
|
||||
if (kIsWeb || Platform.isIOS) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('This platform only supports controlling trainer apps on other devices'),
|
||||
Image.asset('icon.png', width: 64, height: 64),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Welcome to SwiftControl!', style: Theme.of(context).textTheme.titleMedium),
|
||||
Container(
|
||||
constraints: BoxConstraints(maxWidth: MediaQuery.sizeOf(context).width - 140),
|
||||
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: 'Need help? Click on the '),
|
||||
WidgetSpan(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Icon(Icons.help_outline),
|
||||
),
|
||||
),
|
||||
TextSpan(text: ' button on top and don\'t hesitate to contact us.'),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
initializeActions(local);
|
||||
setState(() {
|
||||
_local = local;
|
||||
_reloadRequirements();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16),
|
||||
],
|
||||
),
|
||||
_requirements.isEmpty
|
||||
? Center(child: SmallProgressIndicator())
|
||||
: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
||||
child: Stepper(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
currentStep: _currentStep,
|
||||
connectorColor: WidgetStateProperty.resolveWith<Color>(
|
||||
(Set<WidgetState> states) => Theme.of(context).colorScheme.primary,
|
||||
@@ -134,11 +119,13 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
}
|
||||
: null,
|
||||
onStepTapped: (step) {
|
||||
if (_requirements[step].status) {
|
||||
if (_requirements[step].status && _requirements[step] is! TargetRequirement) {
|
||||
return;
|
||||
}
|
||||
final hasEarlierIncomplete = _requirements.indexWhere((req) => !req.status) < step;
|
||||
if (hasEarlierIncomplete && !kDebugMode) {
|
||||
final hasEarlierIncomplete =
|
||||
_requirements.indexWhere((req) => !req.status) != -1 &&
|
||||
_requirements.indexWhere((req) => !req.status) < step;
|
||||
if (hasEarlierIncomplete) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
@@ -150,7 +137,8 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
.mapIndexed(
|
||||
(index, req) => Step(
|
||||
title: Text(req.name, style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
subtitle: req.description != null ? Text(req.description!) : null,
|
||||
subtitle:
|
||||
req.buildDescription() ?? (req.description != null ? Text(req.description!) : null),
|
||||
content: Container(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
@@ -175,9 +163,9 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -188,9 +176,29 @@ class _RequirementsPageState extends State<RequirementsPage> with WidgetsBinding
|
||||
}
|
||||
|
||||
void _reloadRequirements() {
|
||||
getRequirements(_local).then((req) {
|
||||
getRequirements(
|
||||
settings.getLastTarget()?.connectionType ?? ConnectionType.unknown,
|
||||
).then((req) {
|
||||
_requirements = req;
|
||||
_currentStep = req.indexWhere((req) => !req.status);
|
||||
final unresolvedIndex = req.indexWhere((req) => !req.status);
|
||||
if (unresolvedIndex != -1) {
|
||||
_currentStep = unresolvedIndex;
|
||||
} else if (mounted) {
|
||||
String? currentPath;
|
||||
navigatorKey.currentState?.popUntil((route) {
|
||||
currentPath = route.settings.name;
|
||||
return true;
|
||||
});
|
||||
if (currentPath == '/') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => DevicePage(),
|
||||
settings: RouteSettings(name: '/device'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/markdown.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
|
||||
import '../widgets/logviewer.dart';
|
||||
|
||||
class ScanWidget extends StatefulWidget {
|
||||
const ScanWidget({super.key});
|
||||
|
||||
@override
|
||||
State<ScanWidget> createState() => _ScanWidgetState();
|
||||
}
|
||||
|
||||
class _ScanWidgetState extends State<ScanWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
connection.initialize();
|
||||
|
||||
/*_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
|
||||
_isScanning = state;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});*/
|
||||
|
||||
// after the first frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// must be called from a button
|
||||
if (!kIsWeb) {
|
||||
Future.delayed(Duration(seconds: 1))
|
||||
.then((_) {
|
||||
return connection.performScanning();
|
||||
})
|
||||
.catchError((e) {
|
||||
print(e);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
constraints: BoxConstraints(minHeight: 200),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: connection.isScanning,
|
||||
builder: (context, isScanning, widget) {
|
||||
if (isScanning) {
|
||||
return Column(
|
||||
spacing: 12,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Scanning for devices... Make sure they are powered on and in range and not connected to another device.',
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
||||
);
|
||||
},
|
||||
child: const Text("Show Troubleshooting Guide"),
|
||||
),
|
||||
SmallProgressIndicator(),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
connection.performScanning();
|
||||
},
|
||||
child: const Text("SCAN"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (kDebugMode && false) SizedBox(height: 500, child: LogViewer()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,71 +2,79 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:keypress_simulator/keypress_simulator.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
|
||||
import 'package:swift_control/widgets/button_widget.dart';
|
||||
import 'package:swift_control/widgets/keymap_explanation.dart';
|
||||
import 'package:swift_control/widgets/menu.dart';
|
||||
import 'package:swift_control/widgets/testbed.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../bluetooth/messages/notification.dart';
|
||||
import '../utils/actions/base_actions.dart';
|
||||
import '../utils/keymap/apps/custom_app.dart';
|
||||
import '../utils/keymap/buttons.dart';
|
||||
import '../utils/keymap/keymap.dart';
|
||||
import '../widgets/custom_keymap_selector.dart';
|
||||
|
||||
final touchAreaSize = 42.0;
|
||||
|
||||
class TouchAreaSetupPage extends StatefulWidget {
|
||||
const TouchAreaSetupPage({super.key});
|
||||
final KeyPair keyPair;
|
||||
const TouchAreaSetupPage({super.key, required this.keyPair});
|
||||
|
||||
@override
|
||||
State<TouchAreaSetupPage> createState() => _TouchAreaSetupPageState();
|
||||
}
|
||||
|
||||
class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
File? _backgroundImage;
|
||||
late StreamSubscription<BaseNotification> _actionSubscription;
|
||||
ControllerButton? _pressedButton;
|
||||
Uint8List? _backgroundImage;
|
||||
final TransformationController _transformationController = TransformationController();
|
||||
|
||||
late Rect _imageRect;
|
||||
|
||||
bool _showFaded = true;
|
||||
|
||||
Future<void> _pickScreenshot() async {
|
||||
final picker = ImagePicker();
|
||||
final result = await picker.pickImage(source: ImageSource.gallery);
|
||||
if (result != null) {
|
||||
final image = File(result.path);
|
||||
|
||||
// need to decode image to get its size so we can have a percentage mapping
|
||||
final decodedImage = await decodeImageFromList(image.readAsBytesSync());
|
||||
// calculate image rectangle in the current screen, given it's boxfit contain
|
||||
final screenSize = MediaQuery.sizeOf(context);
|
||||
final imageAspectRatio = decodedImage.width / decodedImage.height;
|
||||
final screenAspectRatio = screenSize.width / screenSize.height;
|
||||
if (imageAspectRatio > screenAspectRatio) {
|
||||
// image is wider than screen
|
||||
final width = screenSize.width;
|
||||
final height = width / imageAspectRatio;
|
||||
final top = (screenSize.height - height) / 2;
|
||||
_imageRect = Rect.fromLTWH(0, top, width, height);
|
||||
} else {
|
||||
// image is taller than screen
|
||||
final height = screenSize.height;
|
||||
final width = height * imageAspectRatio;
|
||||
final left = (screenSize.width - width) / 2;
|
||||
_imageRect = Rect.fromLTWH(left, 0, width, height);
|
||||
}
|
||||
_backgroundImage = image;
|
||||
setState(() {});
|
||||
final Directory tempDir = await getTemporaryDirectory();
|
||||
final tempImage = File('${tempDir.path}/${actionHandler.supportedApp?.name ?? 'temp'}_screenshot.png');
|
||||
await image.copy(tempImage.path);
|
||||
_backgroundImage = tempImage.readAsBytesSync();
|
||||
await _calculateBounds();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _calculateBounds() async {
|
||||
if (_backgroundImage == null) return;
|
||||
|
||||
// need to decode image to get its size so we can have a percentage mapping
|
||||
final decodedImage = await decodeImageFromList(_backgroundImage!);
|
||||
// calculate image rectangle in the current screen, given it's boxfit contain
|
||||
final screenSize = MediaQuery.sizeOf(context);
|
||||
final imageAspectRatio = decodedImage.width / decodedImage.height;
|
||||
final screenAspectRatio = screenSize.width / screenSize.height;
|
||||
if (imageAspectRatio > screenAspectRatio) {
|
||||
// image is wider than screen
|
||||
final width = screenSize.width;
|
||||
final height = width / imageAspectRatio;
|
||||
final top = (screenSize.height - height) / 2;
|
||||
_imageRect = Rect.fromLTWH(0, top, width, height);
|
||||
} else {
|
||||
// image is taller than screen
|
||||
final height = screenSize.height;
|
||||
final width = height * imageAspectRatio;
|
||||
final left = (screenSize.width - width) / 2;
|
||||
_imageRect = Rect.fromLTWH(left, 0, width, height);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _saveAndClose() {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
@@ -74,7 +82,6 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_actionSubscription.cancel();
|
||||
// Exit full screen
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
|
||||
// Reset orientation preferences to allow all orientations
|
||||
@@ -105,35 +112,16 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
windowManager.setFullScreen(true);
|
||||
}
|
||||
_actionSubscription = connection.actionStream.listen((data) async {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
if (data is ButtonNotification) {
|
||||
_pressedButton = data.buttonsClicked.singleOrNull;
|
||||
}
|
||||
getTemporaryDirectory().then((tempDir) async {
|
||||
final tempImage = File('${tempDir.path}/${actionHandler.supportedApp?.name ?? 'temp'}_screenshot.png');
|
||||
if (tempImage.existsSync()) {
|
||||
_backgroundImage = tempImage.readAsBytesSync();
|
||||
setState(() {});
|
||||
|
||||
if (_pressedButton != null) {
|
||||
if (actionHandler.supportedApp!.keymap.getKeyPair(_pressedButton!) == null) {
|
||||
final KeyPair keyPair;
|
||||
actionHandler.supportedApp!.keymap.keyPairs.add(
|
||||
keyPair = KeyPair(
|
||||
touchPosition: Offset((actionHandler.supportedApp!.keymap.keyPairs.length + 1) * 10, 10),
|
||||
buttons: [_pressedButton!],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
isLongPress: false,
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
|
||||
// open menu
|
||||
if (Platform.isMacOS || Platform.isWindows) {
|
||||
await Future.delayed(Duration(milliseconds: 300));
|
||||
await keyPressSimulator.simulateMouseClickDown(keyPair.touchPosition);
|
||||
await keyPressSimulator.simulateMouseClickUp(keyPair.touchPosition);
|
||||
}
|
||||
}
|
||||
// wait a bit until device rotation is done
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
_calculateBounds();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -173,93 +161,6 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
_imageRect.top + relativeY * _imageRect.height - differenceInHeight - iconSize / 2,
|
||||
);
|
||||
|
||||
final actions = [
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.keyboard))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.keyboard_alt_outlined),
|
||||
title: const Text('Simulate Keyboard shortcut'),
|
||||
trailing: keyPair.physicalKey != null ? Checkbox(value: true, onChanged: null) : null,
|
||||
),
|
||||
onTap: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // enable Escape key
|
||||
builder: (c) =>
|
||||
HotKeyListenerDialog(customApp: actionHandler.supportedApp! as CustomApp, keyPair: keyPair),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.touch))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
child: ListTile(
|
||||
title: const Text('Simulate Touch'),
|
||||
leading: Icon(Icons.touch_app_outlined),
|
||||
trailing: keyPair.physicalKey == null && keyPair.touchPosition != Offset.zero
|
||||
? Checkbox(value: true, onChanged: null)
|
||||
: null,
|
||||
),
|
||||
onTap: () {
|
||||
keyPair.physicalKey = null;
|
||||
keyPair.logicalKey = null;
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.media))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
child: PopupMenuButton<PhysicalKeyboardKey>(
|
||||
padding: EdgeInsets.zero,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaPlayPause,
|
||||
child: const Text('Media: Play/Pause'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaStop,
|
||||
child: const Text('Media: Stop'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaTrackPrevious,
|
||||
child: const Text('Media: Previous'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaTrackNext,
|
||||
child: const Text('Media: Next'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.audioVolumeUp,
|
||||
child: const Text('Media: Volume Up'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.audioVolumeDown,
|
||||
child: const Text('Media: Volume Down'),
|
||||
),
|
||||
],
|
||||
onSelected: (key) {
|
||||
keyPair.physicalKey = key;
|
||||
keyPair.logicalKey = null;
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.music_note_outlined),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (keyPair.isSpecialKey) Checkbox(value: true, onChanged: null),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
title: Text('Simulate Media key'),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
final icon = Container(
|
||||
constraints: BoxConstraints(minHeight: iconSize, minWidth: iconSize),
|
||||
child: Column(
|
||||
@@ -287,51 +188,7 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuButton<PhysicalKeyboardKey>(
|
||||
enabled: enableTouch,
|
||||
itemBuilder: (context) => [
|
||||
if (actions.length > 1) ...actions,
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
onTap: () {
|
||||
keyPair.isLongPress = !keyPair.isLongPress;
|
||||
setState(() {});
|
||||
},
|
||||
child: CheckboxListTile(
|
||||
value: keyPair.isLongPress,
|
||||
onChanged: (value) {
|
||||
keyPair.isLongPress = value ?? false;
|
||||
setState(() {});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
title: const Text('Long Press Mode (vs. repeating)'),
|
||||
),
|
||||
),
|
||||
PopupMenuDivider(),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
child: ListTile(
|
||||
title: const Text('Delete Keymap'),
|
||||
leading: Icon(Icons.delete, color: Colors.red),
|
||||
),
|
||||
onTap: () {
|
||||
actionHandler.supportedApp!.keymap.keyPairs.remove(keyPair);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
onSelected: (key) {
|
||||
keyPair.physicalKey = key;
|
||||
keyPair.logicalKey = null;
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
KeypairExplanation(withKey: true, keyPair: keyPair),
|
||||
Icon(Icons.more_vert),
|
||||
],
|
||||
),
|
||||
),
|
||||
KeypairExplanation(withKey: true, keyPair: keyPair),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -341,41 +198,50 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
top: position.dy,
|
||||
child: Tooltip(
|
||||
message: 'Drag to reposition',
|
||||
child: Draggable(
|
||||
dragAnchorStrategy: (widget, context, position) {
|
||||
final scale = _transformationController.value.getMaxScaleOnAxis();
|
||||
final RenderBox renderObject = context.findRenderObject() as RenderBox;
|
||||
return renderObject.globalToLocal(position).scale(scale, scale);
|
||||
},
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: AnimatedOpacity(
|
||||
opacity: _showFaded && widget.keyPair != keyPair ? 0.2 : 1.0,
|
||||
duration: Duration(milliseconds: 300),
|
||||
child: Draggable(
|
||||
dragAnchorStrategy: (widget, context, position) {
|
||||
final scale = _transformationController.value.getMaxScaleOnAxis();
|
||||
final RenderBox renderObject = context.findRenderObject() as RenderBox;
|
||||
return renderObject.globalToLocal(position).scale(scale, scale);
|
||||
},
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: icon,
|
||||
),
|
||||
childWhenDragging: const SizedBox.shrink(),
|
||||
onDragStarted: () {
|
||||
// Capture the starting position to calculate drag distance later
|
||||
dragStartPosition = position;
|
||||
if (keyPair != widget.keyPair && _showFaded) {
|
||||
setState(() {
|
||||
_showFaded = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
onDragEnd: (details) {
|
||||
// Calculate drag distance to prevent accidental repositioning from clicks
|
||||
// while allowing legitimate drags even with low velocity (e.g., when overlapping buttons)
|
||||
final dragDistance = dragStartPosition != null
|
||||
? (details.offset - dragStartPosition!).distance
|
||||
: double.infinity;
|
||||
|
||||
// Only update position if dragged more than 5 pixels (prevents accidental clicks)
|
||||
if (dragDistance > 5) {
|
||||
final matrix = Matrix4.inverted(_transformationController.value);
|
||||
final height = 0;
|
||||
final sceneY = details.offset.dy - height;
|
||||
final viewportPoint = MatrixUtils.transformPoint(
|
||||
matrix,
|
||||
Offset(details.offset.dx, sceneY) + Offset(iconSize / 2, differenceInHeight + iconSize / 2),
|
||||
);
|
||||
setState(() => onPositionChanged(viewportPoint));
|
||||
}
|
||||
},
|
||||
child: icon,
|
||||
),
|
||||
childWhenDragging: const SizedBox.shrink(),
|
||||
onDragStarted: () {
|
||||
// Capture the starting position to calculate drag distance later
|
||||
dragStartPosition = position;
|
||||
},
|
||||
onDragEnd: (details) {
|
||||
// Calculate drag distance to prevent accidental repositioning from clicks
|
||||
// while allowing legitimate drags even with low velocity (e.g., when overlapping buttons)
|
||||
final dragDistance = dragStartPosition != null
|
||||
? (details.offset - dragStartPosition!).distance
|
||||
: double.infinity;
|
||||
|
||||
// Only update position if dragged more than 5 pixels (prevents accidental clicks)
|
||||
if (dragDistance > 5) {
|
||||
final matrix = Matrix4.inverted(_transformationController.value);
|
||||
final height = 0;
|
||||
final sceneY = details.offset.dy - height;
|
||||
final viewportPoint = MatrixUtils.transformPoint(
|
||||
matrix,
|
||||
Offset(details.offset.dx, sceneY) + Offset(iconSize / 2, differenceInHeight + iconSize / 2),
|
||||
);
|
||||
setState(() => onPositionChanged(viewportPoint));
|
||||
}
|
||||
},
|
||||
child: icon,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -389,6 +255,11 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
if (_backgroundImage == null && constraints.biggest != _imageRect.size) {
|
||||
_imageRect = Rect.fromLTWH(0, 0, constraints.maxWidth, constraints.maxHeight);
|
||||
}
|
||||
final keyPairsToShow =
|
||||
actionHandler.supportedApp?.keymap.keyPairs
|
||||
.where((kp) => kp.touchPosition != Offset.zero && !kp.isSpecialKey)
|
||||
.toList() ??
|
||||
[];
|
||||
return InteractiveViewer(
|
||||
transformationController: _transformationController,
|
||||
child: Stack(
|
||||
@@ -397,7 +268,7 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
Positioned.fill(
|
||||
child: Opacity(
|
||||
opacity: 0.5,
|
||||
child: Image.file(
|
||||
child: Image.memory(
|
||||
_backgroundImage!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
@@ -417,8 +288,8 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
),
|
||||
),
|
||||
|
||||
...?actionHandler.supportedApp?.keymap.keyPairs.map((keyPair) {
|
||||
return _buildDraggableArea(
|
||||
for (final keyPair in keyPairsToShow)
|
||||
_buildDraggableArea(
|
||||
enableTouch: true,
|
||||
keyPair: keyPair,
|
||||
onPositionChanged: (newPos) {
|
||||
@@ -429,8 +300,7 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
setState(() {});
|
||||
},
|
||||
color: Colors.red,
|
||||
);
|
||||
}),
|
||||
),
|
||||
|
||||
Positioned.fill(child: Testbed()),
|
||||
|
||||
@@ -476,10 +346,17 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
),
|
||||
PopupMenuButton(
|
||||
itemBuilder: (c) => [
|
||||
PopupMenuItem(
|
||||
child: Text('Choose another screenshot'),
|
||||
onTap: () {
|
||||
_pickScreenshot();
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Reset'),
|
||||
onTap: () {
|
||||
_backgroundImage = null;
|
||||
|
||||
actionHandler.supportedApp?.keymap.reset();
|
||||
setState(() {});
|
||||
},
|
||||
@@ -487,7 +364,6 @@ class _TouchAreaSetupPageState extends State<TouchAreaSetupPage> {
|
||||
],
|
||||
icon: Icon(Icons.more_vert),
|
||||
),
|
||||
if (kDebugMode) MenuButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -510,6 +386,7 @@ class KeypairExplanation extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (withKey)
|
||||
@@ -518,8 +395,17 @@ class KeypairExplanation extends StatelessWidget {
|
||||
)
|
||||
else
|
||||
Icon(keyPair.icon),
|
||||
if (keyPair.physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard)) ...[
|
||||
KeyWidget(
|
||||
if (keyPair.inGameAction != null &&
|
||||
((settings.getTrainerApp() is MyWhoosh && settings.getMyWhooshLinkEnabled()) ||
|
||||
(settings.getTrainerApp()?.supportsZwiftEmulation == true && settings.getZwiftEmulatorEnabled())))
|
||||
_KeyWidget(
|
||||
label: [
|
||||
keyPair.inGameAction.toString().split('.').last,
|
||||
if (keyPair.inGameActionValue != null) ': ${keyPair.inGameActionValue}',
|
||||
].joinToString(separator: ''),
|
||||
)
|
||||
else if (keyPair.isSpecialKey && actionHandler.supportedModes.contains(SupportedMode.media))
|
||||
_KeyWidget(
|
||||
label: switch (keyPair.physicalKey) {
|
||||
PhysicalKeyboardKey.mediaPlayPause => 'Play/Pause',
|
||||
PhysicalKeyboardKey.mediaStop => 'Stop',
|
||||
@@ -527,16 +413,50 @@ class KeypairExplanation extends StatelessWidget {
|
||||
PhysicalKeyboardKey.mediaTrackNext => 'Next',
|
||||
PhysicalKeyboardKey.audioVolumeUp => 'Volume Up',
|
||||
PhysicalKeyboardKey.audioVolumeDown => 'Volume Down',
|
||||
_ => keyPair.logicalKey?.keyLabel ?? 'Unknown',
|
||||
_ => 'Unknown',
|
||||
},
|
||||
)
|
||||
else if (keyPair.physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard)) ...[
|
||||
_KeyWidget(
|
||||
label: keyPair.logicalKey?.keyLabel ?? 'Unknown',
|
||||
),
|
||||
if (keyPair.isLongPress) Text('long\npress', style: TextStyle(fontSize: 10)),
|
||||
] else ...[
|
||||
if (!withKey)
|
||||
KeyWidget(label: 'X: ${keyPair.touchPosition.dx.toInt()}, Y: ${keyPair.touchPosition.dy.toInt()}'),
|
||||
if (!withKey && keyPair.touchPosition != Offset.zero)
|
||||
_KeyWidget(label: 'X:${keyPair.touchPosition.dx.toInt()}, Y:${keyPair.touchPosition.dy.toInt()}'),
|
||||
if (keyPair.isLongPress) Text('long\npress', style: TextStyle(fontSize: 10)),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _KeyWidget extends StatelessWidget {
|
||||
final String label;
|
||||
const _KeyWidget({super.key, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IntrinsicWidth(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
constraints: BoxConstraints(minWidth: 30),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Theme.of(context).colorScheme.primary),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label.splitByUpperCase(),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:accessibility/accessibility.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_emulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/base_actions.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/widgets/keymap_explanation.dart';
|
||||
|
||||
@@ -30,28 +30,40 @@ class AndroidActions extends BaseActions {
|
||||
return ("Could not perform ${button.name.splitByUpperCase()}: No keymap set");
|
||||
}
|
||||
|
||||
if (supportedApp is CustomApp) {
|
||||
final keyPair = supportedApp!.keymap.getKeyPair(button);
|
||||
if (keyPair != null && keyPair.isSpecialKey) {
|
||||
await accessibilityHandler.controlMedia(switch (keyPair.physicalKey) {
|
||||
PhysicalKeyboardKey.mediaTrackNext => MediaAction.next,
|
||||
PhysicalKeyboardKey.mediaPlayPause => MediaAction.playPause,
|
||||
PhysicalKeyboardKey.audioVolumeUp => MediaAction.volumeUp,
|
||||
PhysicalKeyboardKey.audioVolumeDown => MediaAction.volumeDown,
|
||||
_ => throw SingleLineException("No action for key: ${keyPair.physicalKey}"),
|
||||
});
|
||||
return "Key pressed: ${keyPair.toString()}";
|
||||
}
|
||||
final keyPair = supportedApp!.keymap.getKeyPair(button);
|
||||
|
||||
if (keyPair == null) {
|
||||
return ("Could not perform ${button.name.splitByUpperCase()}: No action assigned");
|
||||
}
|
||||
final point = await resolveTouchPosition(action: button, windowInfo: windowInfo);
|
||||
|
||||
if (keyPair.inGameAction != null && whooshLink.isConnected.value) {
|
||||
return whooshLink.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (keyPair.inGameAction != null && zwiftEmulator.isConnected.value) {
|
||||
return zwiftEmulator.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (keyPair.isSpecialKey) {
|
||||
await accessibilityHandler.controlMedia(switch (keyPair.physicalKey) {
|
||||
PhysicalKeyboardKey.mediaTrackNext => MediaAction.next,
|
||||
PhysicalKeyboardKey.mediaPlayPause => MediaAction.playPause,
|
||||
PhysicalKeyboardKey.audioVolumeUp => MediaAction.volumeUp,
|
||||
PhysicalKeyboardKey.audioVolumeDown => MediaAction.volumeDown,
|
||||
_ => throw SingleLineException("No action for key: ${keyPair.physicalKey}"),
|
||||
});
|
||||
return "Key pressed: ${keyPair.toString()}";
|
||||
}
|
||||
|
||||
final point = await resolveTouchPosition(keyPair: keyPair, windowInfo: windowInfo);
|
||||
if (point != Offset.zero) {
|
||||
accessibilityHandler.performTouch(point.dx, point.dy, isKeyDown: isKeyDown, isKeyUp: isKeyUp);
|
||||
try {
|
||||
await accessibilityHandler.performTouch(point.dx, point.dy, isKeyDown: isKeyDown, isKeyUp: isKeyUp);
|
||||
} on PlatformException catch (e) {
|
||||
return "Accessibility Service not working. Follow instructions at https://dontkillmyapp.com/";
|
||||
}
|
||||
return "Touch performed at: ${point.dx.toInt()}, ${point.dy.toInt()} -> ${isKeyDown && isKeyUp
|
||||
? "click"
|
||||
: isKeyDown
|
||||
? "down"
|
||||
: "up"}";
|
||||
}
|
||||
return "No touch performed";
|
||||
return "No action assigned";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:accessibility/accessibility.dart';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:screen_retriever/screen_retriever.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/android.dart';
|
||||
import 'package:swift_control/utils/actions/desktop.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
|
||||
import '../keymap/apps/supported_app.dart';
|
||||
|
||||
@@ -21,56 +25,70 @@ abstract class BaseActions {
|
||||
|
||||
void init(SupportedApp? supportedApp) {
|
||||
this.supportedApp = supportedApp;
|
||||
print('Supported app: ${supportedApp?.name ?? "None"}');
|
||||
|
||||
if (supportedApp != null) {
|
||||
final allButtons = connection.devices.map((e) => e.availableButtons).flatten().distinct();
|
||||
|
||||
final newButtons = allButtons.filter(
|
||||
(button) => supportedApp.keymap.getKeyPair(button) == null,
|
||||
);
|
||||
for (final button in newButtons) {
|
||||
supportedApp.keymap.addKeyPair(
|
||||
KeyPair(
|
||||
touchPosition: Offset.zero,
|
||||
buttons: [button],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
isLongPress: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<Offset> resolveTouchPosition({required ControllerButton action, required WindowEvent? windowInfo}) async {
|
||||
final keyPair = supportedApp!.keymap.getKeyPair(action);
|
||||
if (keyPair != null && keyPair.touchPosition != Offset.zero) {
|
||||
Future<Offset> resolveTouchPosition({required KeyPair keyPair, required WindowEvent? windowInfo}) async {
|
||||
if (keyPair.touchPosition != Offset.zero) {
|
||||
// convert relative position to absolute position based on window info
|
||||
|
||||
if (windowInfo != null && windowInfo.top > 0) {
|
||||
final x = windowInfo.left + (keyPair.touchPosition.dx / 100) * (windowInfo.right - windowInfo.left);
|
||||
final y = windowInfo.top + (keyPair.touchPosition.dy / 100) * (windowInfo.bottom - windowInfo.top);
|
||||
|
||||
if (kDebugMode) {
|
||||
print("Window info: ${windowInfo.encode()} => Touch at: $x, $y");
|
||||
}
|
||||
return Offset(x, y);
|
||||
// TODO support multiple screens
|
||||
final Size displaySize;
|
||||
final double devicePixelRatio;
|
||||
if (Platform.isWindows) {
|
||||
// TODO remove once https://github.com/flutter/flutter/pull/164460 is available in stable
|
||||
final display = await screenRetriever.getPrimaryDisplay();
|
||||
displaySize = display.size;
|
||||
devicePixelRatio = 1.0;
|
||||
} else {
|
||||
// TODO support multiple screens
|
||||
final Size displaySize;
|
||||
final double devicePixelRatio;
|
||||
if (Platform.isWindows) {
|
||||
// TODO remove once https://github.com/flutter/flutter/pull/164460 is available in stable
|
||||
final display = await screenRetriever.getPrimaryDisplay();
|
||||
displaySize = display.size;
|
||||
devicePixelRatio = 1.0;
|
||||
} else {
|
||||
final display = WidgetsBinding.instance.platformDispatcher.views.first.display;
|
||||
displaySize = display.size;
|
||||
devicePixelRatio = display.devicePixelRatio;
|
||||
}
|
||||
final display = WidgetsBinding.instance.platformDispatcher.views.first.display;
|
||||
displaySize = display.size;
|
||||
devicePixelRatio = display.devicePixelRatio;
|
||||
}
|
||||
|
||||
late final Size physicalSize;
|
||||
if (this is AndroidActions) {
|
||||
late final Size physicalSize;
|
||||
if (this is AndroidActions) {
|
||||
if (windowInfo != null && windowInfo.packageName != 'de.jonasbark.swiftcontrol') {
|
||||
// a trainer app is in foreground, so use the always assume landscape
|
||||
physicalSize = Size(max(displaySize.width, displaySize.height), min(displaySize.width, displaySize.height));
|
||||
} else {
|
||||
// display size is already in physical pixels
|
||||
physicalSize = displaySize;
|
||||
} else if (this is DesktopActions) {
|
||||
// display size is in logical pixels, convert to physical pixels
|
||||
// TODO on macOS the notch is included here, but it's not part of the usable screen area, so we should exclude it
|
||||
physicalSize = displaySize / devicePixelRatio;
|
||||
} else {
|
||||
physicalSize = displaySize;
|
||||
}
|
||||
|
||||
final x = (keyPair.touchPosition.dx / 100.0) * physicalSize.width;
|
||||
final y = (keyPair.touchPosition.dy / 100.0) * physicalSize.height;
|
||||
|
||||
if (kDebugMode) {
|
||||
print("Screen size: $physicalSize => Touch at: $x, $y");
|
||||
}
|
||||
return Offset(x, y);
|
||||
} else if (this is DesktopActions) {
|
||||
// display size is in logical pixels, convert to physical pixels
|
||||
// TODO on macOS the notch is included here, but it's not part of the usable screen area, so we should exclude it
|
||||
physicalSize = displaySize / devicePixelRatio;
|
||||
} else {
|
||||
physicalSize = displaySize;
|
||||
}
|
||||
|
||||
final x = (keyPair.touchPosition.dx / 100.0) * physicalSize.width;
|
||||
final y = (keyPair.touchPosition.dy / 100.0) * physicalSize.height;
|
||||
|
||||
if (kDebugMode) {
|
||||
print("Screen size: $physicalSize vs $displaySize => Touch at: $x, $y");
|
||||
}
|
||||
return Offset(x, y);
|
||||
}
|
||||
return Offset.zero;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:keypress_simulator/keypress_simulator.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_emulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/base_actions.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/widgets/keymap_explanation.dart';
|
||||
@@ -20,7 +24,11 @@ class DesktopActions extends BaseActions {
|
||||
}
|
||||
|
||||
// Handle regular key press mode (existing behavior)
|
||||
if (keyPair.physicalKey != null) {
|
||||
if (keyPair.inGameAction != null && whooshLink.isConnected.value) {
|
||||
return whooshLink.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (keyPair.inGameAction != null && zwiftEmulator.isConnected.value) {
|
||||
return zwiftEmulator.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (keyPair.physicalKey != null) {
|
||||
if (isKeyDown && isKeyUp) {
|
||||
await keyPressSimulator.simulateKeyDown(keyPair.physicalKey);
|
||||
await keyPressSimulator.simulateKeyUp(keyPair.physicalKey);
|
||||
@@ -33,17 +41,22 @@ class DesktopActions extends BaseActions {
|
||||
return 'Key released: $keyPair';
|
||||
}
|
||||
} else {
|
||||
final point = await resolveTouchPosition(action: action, windowInfo: null);
|
||||
if (isKeyDown && isKeyUp) {
|
||||
await keyPressSimulator.simulateMouseClickDown(point);
|
||||
await keyPressSimulator.simulateMouseClickUp(point);
|
||||
return 'Mouse clicked at: ${point.dx} ${point.dy}';
|
||||
} else if (isKeyDown) {
|
||||
await keyPressSimulator.simulateMouseClickDown(point);
|
||||
return 'Mouse down at: ${point.dx} ${point.dy}';
|
||||
final point = await resolveTouchPosition(keyPair: keyPair, windowInfo: null);
|
||||
if (point != Offset.zero) {
|
||||
if (isKeyDown && isKeyUp) {
|
||||
await keyPressSimulator.simulateMouseClickDown(point);
|
||||
// slight move to register clicks on some apps, see issue #116
|
||||
await keyPressSimulator.simulateMouseClickUp(point);
|
||||
return 'Mouse clicked at: ${point.dx.toInt()} ${point.dy.toInt()}';
|
||||
} else if (isKeyDown) {
|
||||
await keyPressSimulator.simulateMouseClickDown(point);
|
||||
return 'Mouse down at: ${point.dx.toInt()} ${point.dy.toInt()}';
|
||||
} else {
|
||||
await keyPressSimulator.simulateMouseClickUp(point);
|
||||
return 'Mouse up at: ${point.dx.toInt()} ${point.dy.toInt()}';
|
||||
}
|
||||
} else {
|
||||
await keyPressSimulator.simulateMouseClickUp(point);
|
||||
return 'Mouse up at: ${point.dx} ${point.dy}';
|
||||
return 'No action assigned';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import 'package:accessibility/accessibility.dart';
|
||||
import 'package:bluetooth_low_energy/bluetooth_low_energy.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_click.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_emulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/actions/base_actions.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
import 'package:swift_control/widgets/keymap_explanation.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
@@ -26,30 +28,31 @@ class RemoteActions extends BaseActions {
|
||||
return 'Keymap entry not found for action: ${action.toString().splitByUpperCase()}';
|
||||
}
|
||||
|
||||
if (!(actionHandler as RemoteActions).isConnected) {
|
||||
return 'Not connected to a device';
|
||||
if (keyPair.inGameAction != null && whooshLink.isConnected.value) {
|
||||
return whooshLink.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (keyPair.inGameAction != null && zwiftEmulator.isConnected.value) {
|
||||
return zwiftEmulator.sendAction(keyPair.inGameAction!, keyPair.inGameActionValue);
|
||||
} else if (!(actionHandler as RemoteActions).isConnected) {
|
||||
return 'Not connected to a ${settings.getLastTarget()?.name ?? 'remote'} device';
|
||||
}
|
||||
|
||||
if (keyPair.physicalKey != null && keyPair.touchPosition == Offset.zero) {
|
||||
return ('Physical key actions are not supported, yet');
|
||||
} else {
|
||||
final point = await resolveTouchPosition(action: action, windowInfo: null);
|
||||
final point = await resolveTouchPosition(keyPair: keyPair, windowInfo: null);
|
||||
final point2 = point; //Offset(100, 99.0);
|
||||
await sendAbsMouseReport(0, point2.dx.toInt(), point2.dy.toInt());
|
||||
await sendAbsMouseReport(1, point2.dx.toInt(), point2.dy.toInt());
|
||||
await sendAbsMouseReport(0, point2.dx.toInt(), point2.dy.toInt());
|
||||
return 'Mouse clicked at: ${point2.dx} ${point2.dy}';
|
||||
|
||||
return 'Mouse clicked at: ${point2.dx.toInt()} ${point2.dy.toInt()}';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Offset> resolveTouchPosition({required ControllerButton action, required WindowEvent? windowInfo}) async {
|
||||
Future<Offset> resolveTouchPosition({required KeyPair keyPair, required WindowEvent? windowInfo}) async {
|
||||
// for remote actions we use the relative position only
|
||||
final keyPair = supportedApp!.keymap.getKeyPair(action);
|
||||
if (keyPair != null && keyPair.touchPosition != Offset.zero) {
|
||||
return keyPair.touchPosition;
|
||||
}
|
||||
return Offset.zero;
|
||||
return keyPair.touchPosition;
|
||||
}
|
||||
|
||||
Uint8List absMouseReport(int buttons3bit, int x, int y) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../buttons.dart';
|
||||
import '../keymap.dart';
|
||||
@@ -10,6 +13,8 @@ class Biketerra extends SupportedApp {
|
||||
: super(
|
||||
name: 'Biketerra',
|
||||
packageName: "biketerra",
|
||||
compatibleTargets: Target.values,
|
||||
supportsZwiftEmulation: !(Platform.isIOS || Platform.isMacOS),
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
KeyPair(
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../buttons.dart';
|
||||
import '../keymap.dart';
|
||||
@@ -8,10 +12,20 @@ import '../keymap.dart';
|
||||
class CustomApp extends SupportedApp {
|
||||
final String profileName;
|
||||
|
||||
CustomApp({this.profileName = 'Custom'})
|
||||
CustomApp({this.profileName = 'Other'})
|
||||
: super(
|
||||
name: profileName,
|
||||
compatibleTargets: kIsWeb
|
||||
? [Target.thisDevice]
|
||||
: [
|
||||
if (!Platform.isIOS) Target.thisDevice,
|
||||
Target.macOS,
|
||||
Target.windows,
|
||||
Target.iOS,
|
||||
Target.android,
|
||||
],
|
||||
packageName: "custom_$profileName",
|
||||
supportsZwiftEmulation: !kIsWeb && !(Platform.isIOS || Platform.isMacOS),
|
||||
keymap: Keymap(keyPairs: []),
|
||||
);
|
||||
|
||||
@@ -49,7 +63,7 @@ class CustomApp extends SupportedApp {
|
||||
keyPair.isLongPress = isLongPress;
|
||||
keyPair.touchPosition = touchPosition ?? Offset.zero;
|
||||
} else {
|
||||
keymap.keyPairs.add(
|
||||
keymap.addKeyPair(
|
||||
KeyPair(
|
||||
buttons: [zwiftButton],
|
||||
physicalKey: physicalKey,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../buttons.dart';
|
||||
import '../keymap.dart';
|
||||
@@ -10,6 +11,8 @@ class MyWhoosh extends SupportedApp {
|
||||
: super(
|
||||
name: 'MyWhoosh',
|
||||
packageName: "com.mywhoosh.whooshgame",
|
||||
compatibleTargets: Target.values,
|
||||
supportsZwiftEmulation: false,
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
KeyPair(
|
||||
@@ -17,19 +20,22 @@ class MyWhoosh extends SupportedApp {
|
||||
physicalKey: PhysicalKeyboardKey.keyI,
|
||||
logicalKey: LogicalKeyboardKey.keyI,
|
||||
touchPosition: Offset(80, 94),
|
||||
inGameAction: InGameAction.shiftDown,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.shiftUp).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.keyK,
|
||||
logicalKey: LogicalKeyboardKey.keyK,
|
||||
touchPosition: Offset(98, 94),
|
||||
touchPosition: Offset(97, 94),
|
||||
inGameAction: InGameAction.shiftUp,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.navigateRight).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.arrowRight,
|
||||
logicalKey: LogicalKeyboardKey.arrowRight,
|
||||
touchPosition: Offset(98, 80),
|
||||
touchPosition: Offset(60, 80),
|
||||
isLongPress: true,
|
||||
inGameAction: InGameAction.navigateRight,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.navigateLeft).toList(),
|
||||
@@ -37,11 +43,13 @@ class MyWhoosh extends SupportedApp {
|
||||
logicalKey: LogicalKeyboardKey.arrowLeft,
|
||||
touchPosition: Offset(32, 80),
|
||||
isLongPress: true,
|
||||
inGameAction: InGameAction.navigateLeft,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.toggleUi).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.keyH,
|
||||
logicalKey: LogicalKeyboardKey.keyH,
|
||||
inGameAction: InGameAction.toggleUi,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
32
lib/utils/keymap/apps/rouvy.dart
Normal file
32
lib/utils/keymap/apps/rouvy.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../keymap.dart';
|
||||
|
||||
class Rouvy extends SupportedApp {
|
||||
Rouvy()
|
||||
: super(
|
||||
name: 'Rouvy',
|
||||
packageName: "eu.virtualtraining.rouvy.android",
|
||||
compatibleTargets: Target.values,
|
||||
supportsZwiftEmulation: true,
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.shiftDown).toList(),
|
||||
inGameAction: InGameAction.shiftDown,
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.shiftUp).toList(),
|
||||
inGameAction: InGameAction.shiftUp,
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,36 @@
|
||||
import 'package:swift_control/utils/keymap/apps/biketerra.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/rouvy.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/training_peaks.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/zwift.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../keymap.dart';
|
||||
import 'custom_app.dart';
|
||||
import 'my_whoosh.dart';
|
||||
|
||||
abstract class SupportedApp {
|
||||
final List<Target> compatibleTargets;
|
||||
final String packageName;
|
||||
final String name;
|
||||
final Keymap keymap;
|
||||
final bool supportsZwiftEmulation;
|
||||
|
||||
const SupportedApp({required this.name, required this.packageName, required this.keymap});
|
||||
const SupportedApp({
|
||||
required this.name,
|
||||
required this.packageName,
|
||||
required this.keymap,
|
||||
required this.compatibleTargets,
|
||||
required this.supportsZwiftEmulation,
|
||||
});
|
||||
|
||||
static final List<SupportedApp> supportedApps = [MyWhoosh(), TrainingPeaks(), Biketerra(), CustomApp()];
|
||||
static final List<SupportedApp> supportedApps = [
|
||||
MyWhoosh(),
|
||||
Zwift(),
|
||||
TrainingPeaks(),
|
||||
Biketerra(),
|
||||
Rouvy(),
|
||||
CustomApp(),
|
||||
];
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/bluetooth/devices/elite/elite_square.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../keymap.dart';
|
||||
|
||||
@@ -10,31 +13,83 @@ class TrainingPeaks extends SupportedApp {
|
||||
: super(
|
||||
name: 'TrainingPeaks Virtual / IndieVelo',
|
||||
packageName: "com.indieVelo.client",
|
||||
compatibleTargets: Target.values,
|
||||
supportsZwiftEmulation: false,
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
// https://help.trainingpeaks.com/hc/en-us/articles/31340399556877-TrainingPeaks-Virtual-Controls-and-Keyboard-Shortcuts
|
||||
// Explicit controller-button mappings with updated touch coordinates
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.shiftDown).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.numpadSubtract,
|
||||
logicalKey: LogicalKeyboardKey.numpadSubtract,
|
||||
touchPosition: Offset(50 * 1.32, 74),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.shiftUp).toList(),
|
||||
buttons: [ZwiftButtons.shiftUpRight],
|
||||
physicalKey: PhysicalKeyboardKey.numpadAdd,
|
||||
logicalKey: LogicalKeyboardKey.numpadAdd,
|
||||
touchPosition: Offset(50 * 1.15, 74),
|
||||
touchPosition: Offset(22.65384615384622, 7.0769230769229665),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.navigateRight).toList(),
|
||||
buttons: [ZwiftButtons.shiftUpLeft],
|
||||
physicalKey: PhysicalKeyboardKey.numpadAdd,
|
||||
logicalKey: LogicalKeyboardKey.numpadAdd,
|
||||
touchPosition: Offset(18.14448747554958, 6.772862761010401),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftDownLeft],
|
||||
physicalKey: PhysicalKeyboardKey.numpadSubtract,
|
||||
logicalKey: LogicalKeyboardKey.numpadSubtract,
|
||||
touchPosition: Offset(18.128205128205135, 6.75213675213675),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftDownRight],
|
||||
physicalKey: PhysicalKeyboardKey.numpadSubtract,
|
||||
logicalKey: LogicalKeyboardKey.numpadSubtract,
|
||||
touchPosition: Offset(22.61769250748708, 8.13909075507417),
|
||||
),
|
||||
|
||||
// Navigation buttons (keep arrow key mappings and add touch positions)
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.steerRight).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.arrowRight,
|
||||
logicalKey: LogicalKeyboardKey.arrowRight,
|
||||
touchPosition: Offset(56.75858807279006, 92.42753954973301),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.navigateLeft).toList(),
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.steerLeft).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.arrowLeft,
|
||||
logicalKey: LogicalKeyboardKey.arrowLeft,
|
||||
touchPosition: Offset(41.11538461538456, 92.64957264957286),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.navigationUp],
|
||||
physicalKey: PhysicalKeyboardKey.arrowUp,
|
||||
logicalKey: LogicalKeyboardKey.arrowUp,
|
||||
touchPosition: Offset(42.28406293368177, 92.61854987939971),
|
||||
),
|
||||
|
||||
// Face buttons with touch positions and keyboard fallbacks where sensible
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.z, EliteSquareButtons.z],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(33.993890038715456, 92.43667306401531),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.a, EliteSquareButtons.a],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(47.37191097597044, 92.86963594239016),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.b, EliteSquareButtons.b],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(41.12364102683652, 83.72743323236598),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.y, EliteSquareButtons.y],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(58.52936866684111, 84.31131200977018),
|
||||
),
|
||||
|
||||
// Keep other existing mappings (toggle UI, increase/decrease resistance)
|
||||
KeyPair(
|
||||
buttons: ControllerButton.values.filter((e) => e.action == InGameAction.toggleUi).toList(),
|
||||
physicalKey: PhysicalKeyboardKey.keyH,
|
||||
|
||||
113
lib/utils/keymap/apps/zwift.dart
Normal file
113
lib/utils/keymap/apps/zwift.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
|
||||
import '../keymap.dart';
|
||||
|
||||
class Zwift extends SupportedApp {
|
||||
Zwift()
|
||||
: super(
|
||||
name: 'Zwift',
|
||||
packageName: "com.zwift.zwiftgame",
|
||||
supportsZwiftEmulation: !(Platform.isIOS || Platform.isMacOS),
|
||||
compatibleTargets: [
|
||||
if (!Platform.isIOS) Target.thisDevice,
|
||||
Target.macOS,
|
||||
Target.windows,
|
||||
Target.iOS,
|
||||
Target.android,
|
||||
],
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.navigationUp],
|
||||
physicalKey: PhysicalKeyboardKey.arrowUp,
|
||||
logicalKey: LogicalKeyboardKey.arrowUp,
|
||||
inGameAction: InGameAction.openActionBar,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.navigationDown],
|
||||
physicalKey: PhysicalKeyboardKey.arrowDown,
|
||||
logicalKey: LogicalKeyboardKey.arrowDown,
|
||||
inGameAction: InGameAction.uturn,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.navigationLeft],
|
||||
physicalKey: PhysicalKeyboardKey.arrowLeft,
|
||||
logicalKey: LogicalKeyboardKey.arrowLeft,
|
||||
inGameAction: InGameAction.steerLeft,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.navigationRight],
|
||||
physicalKey: PhysicalKeyboardKey.arrowRight,
|
||||
logicalKey: LogicalKeyboardKey.arrowRight,
|
||||
inGameAction: InGameAction.steerRight,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftUpLeft],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftDown,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftUpRight],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftUp,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftDownLeft],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftDown,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.shiftDownRight],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftUp,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.paddleLeft],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftDown,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.paddleRight],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.shiftUp,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.y],
|
||||
physicalKey: PhysicalKeyboardKey.space,
|
||||
logicalKey: LogicalKeyboardKey.space,
|
||||
inGameAction: InGameAction.usePowerUp,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.a],
|
||||
physicalKey: PhysicalKeyboardKey.enter,
|
||||
logicalKey: LogicalKeyboardKey.enter,
|
||||
inGameAction: InGameAction.select,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.b],
|
||||
physicalKey: PhysicalKeyboardKey.escape,
|
||||
logicalKey: LogicalKeyboardKey.escape,
|
||||
inGameAction: InGameAction.back,
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.z],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.rideOnBomb,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,60 +1,81 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/bluetooth/devices/cycplus/cycplus_bc2.dart';
|
||||
import 'package:swift_control/bluetooth/devices/elite/elite_square.dart';
|
||||
import 'package:swift_control/bluetooth/devices/elite/elite_sterzo.dart';
|
||||
import 'package:swift_control/bluetooth/devices/wahoo/wahoo_kickr_bike_shift.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
|
||||
enum InGameAction {
|
||||
shiftUp,
|
||||
shiftDown,
|
||||
navigateLeft,
|
||||
navigateRight,
|
||||
toggleUi,
|
||||
increaseResistance,
|
||||
decreaseResistance;
|
||||
shiftUp('Shift Up'),
|
||||
shiftDown('Shift Down'),
|
||||
uturn('U-Turn'),
|
||||
steerLeft('Steer Left'),
|
||||
steerRight('Steer Right'),
|
||||
|
||||
// mywhoosh
|
||||
cameraAngle('Change Camera Angle', possibleValues: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
|
||||
emote('Emote', possibleValues: [1, 2, 3, 4, 5, 6]),
|
||||
toggleUi('Toggle UI'),
|
||||
navigateLeft('Navigate Left'),
|
||||
navigateRight('Navigate Right'),
|
||||
increaseResistance('Increase Resistance'),
|
||||
decreaseResistance('Decrease Resistance'),
|
||||
|
||||
// zwift
|
||||
openActionBar('Open Action Bar'),
|
||||
usePowerUp('Use Power-Up'),
|
||||
select('Select'),
|
||||
back('Back'),
|
||||
rideOnBomb('Ride On Bomb');
|
||||
|
||||
final String title;
|
||||
final List<int>? possibleValues;
|
||||
|
||||
const InGameAction(this.title, {this.possibleValues});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
enum ControllerButton {
|
||||
// left controller
|
||||
navigationUp._(InGameAction.increaseResistance, icon: Icons.keyboard_arrow_up, color: Colors.black),
|
||||
navigationDown._(InGameAction.decreaseResistance, icon: Icons.keyboard_arrow_down, color: Colors.black),
|
||||
navigationLeft._(InGameAction.navigateLeft, icon: Icons.keyboard_arrow_left, color: Colors.black),
|
||||
navigationRight._(InGameAction.navigateRight, icon: Icons.keyboard_arrow_right, color: Colors.black),
|
||||
onOffLeft._(InGameAction.toggleUi),
|
||||
sideButtonLeft._(InGameAction.shiftDown),
|
||||
paddleLeft._(InGameAction.shiftDown),
|
||||
|
||||
// zwift ride only
|
||||
shiftUpLeft._(InGameAction.shiftDown, icon: Icons.remove, color: Colors.black),
|
||||
shiftDownLeft._(InGameAction.shiftDown, icon: Icons.remove, color: Colors.black),
|
||||
powerUpLeft._(InGameAction.shiftDown),
|
||||
|
||||
// right controller
|
||||
a._(null, color: Colors.lightGreen),
|
||||
b._(null, color: Colors.pinkAccent),
|
||||
z._(null, color: Colors.deepOrangeAccent),
|
||||
y._(null, color: Colors.lightBlue),
|
||||
onOffRight._(InGameAction.toggleUi),
|
||||
sideButtonRight._(InGameAction.shiftUp),
|
||||
paddleRight._(InGameAction.shiftUp),
|
||||
|
||||
// zwift ride only
|
||||
shiftUpRight._(InGameAction.shiftUp, icon: Icons.add, color: Colors.black),
|
||||
shiftDownRight._(InGameAction.shiftUp),
|
||||
powerUpRight._(InGameAction.shiftUp),
|
||||
|
||||
// elite square only
|
||||
campagnoloLeft._(InGameAction.shiftDown),
|
||||
campagnoloRight._(InGameAction.shiftUp);
|
||||
|
||||
class ControllerButton {
|
||||
final String name;
|
||||
final InGameAction? action;
|
||||
final Color? color;
|
||||
final IconData? icon;
|
||||
const ControllerButton._(this.action, {this.color, this.icon});
|
||||
|
||||
const ControllerButton(
|
||||
this.name, {
|
||||
this.color,
|
||||
this.icon,
|
||||
this.action,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ControllerButton &&
|
||||
runtimeType == other.runtimeType &&
|
||||
name == other.name &&
|
||||
action == other.action &&
|
||||
color == other.color &&
|
||||
icon == other.icon;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(name, action, color, icon);
|
||||
|
||||
static List<ControllerButton> get values => [
|
||||
...SterzoButtons.values,
|
||||
...ZwiftButtons.values,
|
||||
...EliteSquareButtons.values,
|
||||
...WahooKickrShiftButtons.values,
|
||||
...CycplusBc2Buttons.values,
|
||||
].distinct().toList();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
|
||||
import '../actions/base_actions.dart';
|
||||
import 'apps/custom_app.dart';
|
||||
|
||||
class Keymap {
|
||||
static Keymap custom = Keymap(keyPairs: []);
|
||||
@@ -15,6 +18,9 @@ class Keymap {
|
||||
|
||||
Keymap({required this.keyPairs});
|
||||
|
||||
final StreamController<void> _updateStream = StreamController<void>.broadcast();
|
||||
Stream<void> get updateStream => _updateStream.stream;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return keyPairs.joinToString(
|
||||
@@ -35,7 +41,24 @@ class Keymap {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
keyPairs = [];
|
||||
for (final keyPair in keyPairs) {
|
||||
keyPair.physicalKey = null;
|
||||
keyPair.logicalKey = null;
|
||||
keyPair.touchPosition = Offset.zero;
|
||||
keyPair.isLongPress = false;
|
||||
keyPair.inGameAction = null;
|
||||
keyPair.inGameActionValue = null;
|
||||
}
|
||||
_updateStream.add(null);
|
||||
}
|
||||
|
||||
void addKeyPair(KeyPair keyPair) {
|
||||
keyPairs.add(keyPair);
|
||||
_updateStream.add(null);
|
||||
|
||||
if (actionHandler.supportedApp is CustomApp) {
|
||||
settings.setKeyMap(actionHandler.supportedApp!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +68,8 @@ class KeyPair {
|
||||
LogicalKeyboardKey? logicalKey;
|
||||
Offset touchPosition;
|
||||
bool isLongPress;
|
||||
InGameAction? inGameAction;
|
||||
int? inGameActionValue;
|
||||
|
||||
KeyPair({
|
||||
required this.buttons,
|
||||
@@ -52,6 +77,8 @@ class KeyPair {
|
||||
required this.logicalKey,
|
||||
this.touchPosition = Offset.zero,
|
||||
this.isLongPress = false,
|
||||
this.inGameAction,
|
||||
this.inGameActionValue,
|
||||
});
|
||||
|
||||
bool get isSpecialKey =>
|
||||
@@ -70,10 +97,13 @@ class KeyPair {
|
||||
PhysicalKeyboardKey.mediaTrackNext ||
|
||||
PhysicalKeyboardKey.audioVolumeUp ||
|
||||
PhysicalKeyboardKey.audioVolumeDown => Icons.music_note_outlined,
|
||||
_ =>
|
||||
physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard)
|
||||
? Icons.keyboard
|
||||
: Icons.touch_app,
|
||||
_ when physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard) => Icons.keyboard,
|
||||
_
|
||||
when inGameAction != null &&
|
||||
((settings.getTrainerApp() is MyWhoosh && settings.getMyWhooshLinkEnabled()) ||
|
||||
(settings.getTrainerApp()?.supportsZwiftEmulation == true && settings.getZwiftEmulatorEnabled())) =>
|
||||
Icons.link,
|
||||
_ => Icons.touch_app,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -100,6 +130,8 @@ class KeyPair {
|
||||
if (physicalKey != null) 'physicalKey': physicalKey?.usbHidUsage.toString() ?? '0',
|
||||
if (touchPosition != Offset.zero) 'touchPosition': {'x': touchPosition.dx, 'y': touchPosition.dy},
|
||||
'isLongPress': isLongPress,
|
||||
'inGameAction': inGameAction?.name,
|
||||
'inGameActionValue': inGameActionValue,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,10 +147,17 @@ class KeyPair {
|
||||
)
|
||||
: Offset.zero;
|
||||
|
||||
final buttons = decoded['actions']
|
||||
.map<ControllerButton>(
|
||||
(e) => ControllerButton.values.firstOrNullWhere((element) => element.name == e) ?? ControllerButton(e),
|
||||
)
|
||||
.cast<ControllerButton>()
|
||||
.toList();
|
||||
if (buttons.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return KeyPair(
|
||||
buttons: decoded['actions']
|
||||
.map<ControllerButton>((e) => ControllerButton.values.firstWhere((element) => element.name == e))
|
||||
.toList(),
|
||||
buttons: buttons,
|
||||
logicalKey: decoded.containsKey('logicalKey') && int.parse(decoded['logicalKey']) != 0
|
||||
? LogicalKeyboardKey(int.parse(decoded['logicalKey']))
|
||||
: null,
|
||||
@@ -127,6 +166,10 @@ class KeyPair {
|
||||
: null,
|
||||
touchPosition: touchPosition,
|
||||
isLongPress: decoded['isLongPress'] ?? false,
|
||||
inGameAction: decoded.containsKey('inGameAction')
|
||||
? InGameAction.values.firstOrNullWhere((element) => element.name == decoded['inGameAction'])
|
||||
: null,
|
||||
inGameActionValue: decoded['inGameActionValue'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
275
lib/utils/keymap/manager.dart
Normal file
275
lib/utils/keymap/manager.dart
Normal file
@@ -0,0 +1,275 @@
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
|
||||
import 'apps/custom_app.dart';
|
||||
|
||||
class KeymapManager {
|
||||
// Singleton instance
|
||||
static final KeymapManager _instance = KeymapManager._internal();
|
||||
|
||||
// Private constructor
|
||||
KeymapManager._internal();
|
||||
|
||||
// Factory constructor to return the singleton instance
|
||||
factory KeymapManager() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Future<String?> showNewProfileDialog(BuildContext context) async {
|
||||
final controller = TextEditingController();
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('New Custom Profile'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: 'Profile Name', hintText: 'e.g., Workout, Race, Event'),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(onPressed: () => Navigator.pop(context, controller.text), child: Text('Create')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PopupMenuButton<String> getManageProfileDialog(
|
||||
BuildContext context,
|
||||
String? currentProfile, {
|
||||
required VoidCallback onDone,
|
||||
}) {
|
||||
return PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
if (currentProfile != null && actionHandler.supportedApp is CustomApp)
|
||||
PopupMenuItem(
|
||||
child: Text('Rename'),
|
||||
onTap: () async {
|
||||
final newName = await _showRenameProfileDialog(
|
||||
context,
|
||||
currentProfile,
|
||||
);
|
||||
if (newName != null && newName.isNotEmpty && newName != currentProfile) {
|
||||
await settings.duplicateCustomAppProfile(currentProfile, newName);
|
||||
await settings.deleteCustomAppProfile(currentProfile);
|
||||
final customApp = CustomApp(profileName: newName);
|
||||
final savedKeymap = settings.getCustomAppKeymap(newName);
|
||||
if (savedKeymap != null) {
|
||||
customApp.decodeKeymap(savedKeymap);
|
||||
}
|
||||
actionHandler.supportedApp = customApp;
|
||||
await settings.setKeyMap(customApp);
|
||||
}
|
||||
onDone();
|
||||
},
|
||||
),
|
||||
if (currentProfile != null)
|
||||
PopupMenuItem(
|
||||
child: Text('Duplicate'),
|
||||
onTap: () async {
|
||||
final newName = await duplicate(
|
||||
context,
|
||||
currentProfile,
|
||||
);
|
||||
onDone();
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Import'),
|
||||
onTap: () async {
|
||||
final jsonData = await _showImportDialog(context);
|
||||
if (jsonData != null && jsonData.isNotEmpty) {
|
||||
final success = await settings.importCustomAppProfile(jsonData);
|
||||
if (success) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Profile imported successfully'),
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to import profile. Invalid format.'),
|
||||
duration: Duration(seconds: 5),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
if (currentProfile != null)
|
||||
PopupMenuItem(
|
||||
child: Text('Export'),
|
||||
onTap: () {
|
||||
final currentProfile = (actionHandler.supportedApp as CustomApp).profileName;
|
||||
final jsonData = settings.exportCustomAppProfile(currentProfile);
|
||||
if (jsonData != null) {
|
||||
Clipboard.setData(ClipboardData(text: jsonData));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Profile "$currentProfile" exported to clipboard',
|
||||
),
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (currentProfile != null)
|
||||
PopupMenuItem(
|
||||
value: 'delete',
|
||||
onTap: () async {
|
||||
final confirmed = await _showDeleteConfirmDialog(
|
||||
context,
|
||||
currentProfile,
|
||||
);
|
||||
if (confirmed == true) {
|
||||
await settings.deleteCustomAppProfile(currentProfile);
|
||||
}
|
||||
onDone();
|
||||
},
|
||||
child: Text('Delete', style: TextStyle(color: Theme.of(context).colorScheme.error)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _showRenameProfileDialog(BuildContext context, String currentName) async {
|
||||
final controller = TextEditingController(text: currentName);
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Rename Profile'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: 'Profile Name'),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(onPressed: () => Navigator.pop(context, controller.text), child: Text('Rename')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _showDuplicateProfileDialog(BuildContext context, String currentName) async {
|
||||
final controller = TextEditingController(text: '$currentName (Copy)');
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Create new custom profile by duplicating "$currentName"'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: 'New Profile Name'),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(onPressed: () => Navigator.pop(context, controller.text), child: Text('Duplicate')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool?> _showDeleteConfirmDialog(BuildContext context, String profileName) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Delete Profile'),
|
||||
content: Text('Are you sure you want to delete "$profileName"? This action cannot be undone.'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context, false), child: Text('Cancel')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text('Delete'),
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _showImportDialog(BuildContext context) async {
|
||||
final controller = TextEditingController();
|
||||
|
||||
// Try to get data from clipboard
|
||||
try {
|
||||
final clipboardData = await Clipboard.getData('text/plain');
|
||||
if (clipboardData?.text != null) {
|
||||
controller.text = clipboardData!.text!;
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore clipboard errors
|
||||
}
|
||||
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Import Profile'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Paste the exported JSON data below:'),
|
||||
SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: 'JSON Data', border: OutlineInputBorder()),
|
||||
maxLines: 5,
|
||||
autofocus: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
|
||||
TextButton(onPressed: () => Navigator.pop(context, controller.text), child: Text('Import')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> duplicate(BuildContext context, String currentProfile) async {
|
||||
final newName = await _showDuplicateProfileDialog(context, currentProfile);
|
||||
if (newName != null && newName.isNotEmpty) {
|
||||
if (actionHandler.supportedApp is CustomApp) {
|
||||
await settings.duplicateCustomAppProfile(currentProfile, newName);
|
||||
final customApp = CustomApp(profileName: newName);
|
||||
final savedKeymap = settings.getCustomAppKeymap(newName);
|
||||
if (savedKeymap != null) {
|
||||
customApp.decodeKeymap(savedKeymap);
|
||||
}
|
||||
actionHandler.supportedApp = customApp;
|
||||
await settings.setKeyMap(customApp);
|
||||
return newName;
|
||||
} else {
|
||||
final customApp = CustomApp(profileName: newName);
|
||||
|
||||
final connectedDevice = connection.devices.firstOrNull;
|
||||
actionHandler.supportedApp!.keymap.keyPairs.forEachIndexed((pair, index) {
|
||||
pair.buttons.filter((button) => connectedDevice?.availableButtons.contains(button) == true).forEachIndexed((
|
||||
button,
|
||||
indexB,
|
||||
) {
|
||||
customApp.setKey(
|
||||
button,
|
||||
physicalKey: pair.physicalKey,
|
||||
logicalKey: pair.logicalKey,
|
||||
isLongPress: pair.isLongPress,
|
||||
touchPosition: pair.touchPosition,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
actionHandler.supportedApp = customApp;
|
||||
await settings.setKeyMap(customApp);
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
@@ -6,6 +7,7 @@ import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/widgets/accessibility_disclosure_dialog.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
class AccessibilityRequirement extends PlatformRequirement {
|
||||
AccessibilityRequirement()
|
||||
@@ -152,20 +154,30 @@ class NotificationRequirement extends PlatformRequirement {
|
||||
channelGroupId,
|
||||
'Allows SwiftControl to keep running in background',
|
||||
foregroundServiceTypes: {AndroidServiceForegroundType.foregroundServiceTypeConnectedDevice},
|
||||
startType: AndroidServiceStartType.startRedeliverIntent,
|
||||
notificationDetails: AndroidNotificationDetails(
|
||||
channelGroupId,
|
||||
'Keep Alive',
|
||||
actions: [AndroidNotificationAction('Exit', 'Exit', cancelNotification: true, showsUserInterface: false)],
|
||||
),
|
||||
);
|
||||
|
||||
final receivePort = ReceivePort();
|
||||
IsolateNameServer.registerPortWithName(receivePort.sendPort, '_backgroundChannelKey');
|
||||
final backgroundMessagePort = receivePort.asBroadcastStream();
|
||||
backgroundMessagePort.listen((_) {
|
||||
UniversalBle.onAvailabilityChange = null;
|
||||
connection.reset();
|
||||
//exit(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void notificationTapBackground(NotificationResponse notificationResponse) {
|
||||
if (notificationResponse.actionId != null) {
|
||||
AndroidFlutterLocalNotificationsPlugin().stopForegroundService().then((_) {
|
||||
exit(0);
|
||||
});
|
||||
final sendPort = IsolateNameServer.lookupPortByName('_backgroundChannelKey');
|
||||
sendPort?.send('notificationResponse');
|
||||
//exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:keypress_simulator/keypress_simulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/scan.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/zwift.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/utils/requirements/remote.dart';
|
||||
import 'package:swift_control/widgets/beta_pill.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
class KeyboardRequirement extends PlatformRequirement {
|
||||
@@ -35,14 +39,30 @@ class BluetoothTurnedOn extends PlatformRequirement {
|
||||
|
||||
@override
|
||||
Future<void> call(BuildContext context, VoidCallback onUpdate) async {
|
||||
final currentState = await UniversalBle.getBluetoothAvailabilityState();
|
||||
if (!kIsWeb && Platform.isIOS) {
|
||||
// on iOS we cannot programmatically enable Bluetooth, just open settings
|
||||
await peripheralManager.showAppSettings();
|
||||
} else {
|
||||
} else if (currentState == AvailabilityState.poweredOff) {
|
||||
await UniversalBle.enableBluetooth();
|
||||
} else {
|
||||
// I guess bluetooth is on now
|
||||
// TODO move UniversalBle.onAvailabilityChange
|
||||
getStatus();
|
||||
onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? build(BuildContext context, VoidCallback onUpdate) {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
call(context, onUpdate);
|
||||
},
|
||||
child: Text('Enable Bluetooth'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {
|
||||
final currentState = await UniversalBle.getBluetoothAvailabilityState();
|
||||
@@ -51,7 +71,8 @@ class BluetoothTurnedOn extends PlatformRequirement {
|
||||
}
|
||||
|
||||
class UnsupportedPlatform extends PlatformRequirement {
|
||||
UnsupportedPlatform() : super('Unsupported platform :(') {
|
||||
UnsupportedPlatform()
|
||||
: super('This ${kIsWeb ? 'Browser does not support Web Bluetooth and ' : 'platform'} is not supported :(') {
|
||||
status = false;
|
||||
}
|
||||
|
||||
@@ -62,8 +83,102 @@ class UnsupportedPlatform extends PlatformRequirement {
|
||||
Future<void> getStatus() async {}
|
||||
}
|
||||
|
||||
class BluetoothScanning extends PlatformRequirement {
|
||||
BluetoothScanning() : super('Finding your Controller...') {
|
||||
typedef BoolFunction = bool Function();
|
||||
|
||||
enum Target {
|
||||
thisDevice(
|
||||
title: 'This Device',
|
||||
icon: Icons.devices,
|
||||
),
|
||||
iOS(
|
||||
title: 'iPhone / iPad / Apple TV',
|
||||
icon: Icons.settings_remote_outlined,
|
||||
),
|
||||
android(
|
||||
title: 'Android Device',
|
||||
icon: Icons.settings_remote_outlined,
|
||||
),
|
||||
macOS(
|
||||
title: 'Mac',
|
||||
icon: Icons.settings_remote_outlined,
|
||||
),
|
||||
windows(
|
||||
title: 'Windows PC',
|
||||
icon: Icons.settings_remote_outlined,
|
||||
);
|
||||
|
||||
final String title;
|
||||
final IconData icon;
|
||||
|
||||
const Target({required this.title, required this.icon});
|
||||
|
||||
bool get isCompatible {
|
||||
return settings.getTrainerApp()?.compatibleTargets.contains(this) == true;
|
||||
}
|
||||
|
||||
bool get isBeta {
|
||||
final supportedApp = settings.getTrainerApp();
|
||||
|
||||
if (supportedApp is Zwift && !(Platform.isIOS || Platform.isMacOS)) {
|
||||
// everything is supported, this device is not compatible anyway
|
||||
return false;
|
||||
}
|
||||
|
||||
return switch (this) {
|
||||
Target.thisDevice => false,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
|
||||
String getDescription(SupportedApp? app) {
|
||||
return switch (this) {
|
||||
Target.thisDevice when !isCompatible =>
|
||||
'Due to platform restrictions only controlling ${app?.name ?? 'the Trainer app'} on other devices is supported.',
|
||||
Target.thisDevice => 'Run ${app?.name ?? 'the Trainer app'} on this device.',
|
||||
Target.iOS =>
|
||||
'Run ${app?.name ?? 'the Trainer app'} on your Apple device and control it remotely from this device${app is MyWhoosh ? ', e.g. by using MyWhoosh Link method' : ''}.',
|
||||
Target.android =>
|
||||
'Run ${app?.name ?? 'the Trainer app'} on your Android device and control it remotely from this device${app is MyWhoosh ? ', e.g. by using MyWhoosh Link method' : ''}.',
|
||||
Target.macOS =>
|
||||
'Run ${app?.name ?? 'the Trainer app'} on your Mac and control it remotely from this device${app is MyWhoosh ? ', e.g. by using MyWhoosh Link method' : ''}.',
|
||||
Target.windows =>
|
||||
'Run ${app?.name ?? 'the Trainer app'} on your Windows PC and control it remotely from this device${app is MyWhoosh ? ', e.g. by using MyWhoosh Link method' : ''}.',
|
||||
};
|
||||
}
|
||||
|
||||
String? get warning {
|
||||
if (settings.getTrainerApp()?.supportsZwiftEmulation == true) {
|
||||
// no warnings for zwift emulation
|
||||
return null;
|
||||
}
|
||||
return switch (this) {
|
||||
Target.android when Platform.isAndroid =>
|
||||
"Select 'This device' unless you want to control another Android device. Are you sure?",
|
||||
Target.macOS when Platform.isMacOS =>
|
||||
"Select 'This device' unless you want to control another macOS device. Are you sure?",
|
||||
Target.windows when Platform.isWindows =>
|
||||
"Select 'This device' unless you want to control another Windows device. Are you sure?",
|
||||
Target.android => "Download and use SwiftControl on that Android device.",
|
||||
Target.macOS => "Download and use SwiftControl on that macOS device.",
|
||||
Target.windows => "Download and use SwiftControl on that Windows device.",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
ConnectionType get connectionType {
|
||||
return switch (this) {
|
||||
Target.thisDevice => ConnectionType.local,
|
||||
_ => ConnectionType.remote,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class TargetRequirement extends PlatformRequirement {
|
||||
TargetRequirement()
|
||||
: super(
|
||||
'Select Trainer App & Target Device',
|
||||
description: 'Select your Target Device where you want to run your trainer app on',
|
||||
) {
|
||||
status = false;
|
||||
}
|
||||
|
||||
@@ -71,10 +186,168 @@ class BluetoothScanning extends PlatformRequirement {
|
||||
Future<void> call(BuildContext context, VoidCallback onUpdate) async {}
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {}
|
||||
Future<void> getStatus() async {
|
||||
status = settings.getLastTarget() != null && settings.getTrainerApp() != null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? build(BuildContext context, VoidCallback onUpdate) {
|
||||
return ScanWidget();
|
||||
return StatefulBuilder(
|
||||
builder: (c, setState) => Column(
|
||||
spacing: 8,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Select Trainer App', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
DropdownMenu<SupportedApp>(
|
||||
dropdownMenuEntries: SupportedApp.supportedApps.map((app) {
|
||||
return DropdownMenuEntry(
|
||||
value: app,
|
||||
label: app.name,
|
||||
labelWidget: app is Zwift && !(Platform.isWindows || Platform.isAndroid)
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(app.name),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'When running SwiftControl on Apple devices you are limited to on-screen controls (so no virtual shifting) only due to platform restrictions :(',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
Icon(Icons.warning_amber),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}).toList(),
|
||||
hintText: 'Select Trainer app',
|
||||
initialSelection: settings.getTrainerApp(),
|
||||
onSelected: (selectedApp) async {
|
||||
if (settings.getTrainerApp() is MyWhoosh && selectedApp is! MyWhoosh && whooshLink.isStarted.value) {
|
||||
whooshLink.stopServer();
|
||||
}
|
||||
settings.setTrainerApp(selectedApp!);
|
||||
if (actionHandler.supportedApp == null ||
|
||||
(actionHandler.supportedApp is! CustomApp && selectedApp is! CustomApp)) {
|
||||
actionHandler.init(selectedApp);
|
||||
settings.setKeyMap(selectedApp);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Select Target where ${settings.getTrainerApp()?.name ?? 'the Trainer app'} runs on',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
DropdownMenu<Target>(
|
||||
dropdownMenuEntries: Target.values.map((target) {
|
||||
return DropdownMenuEntry(
|
||||
value: target,
|
||||
label: target.title,
|
||||
enabled: target.isCompatible,
|
||||
trailingIcon: Icon(target.icon),
|
||||
labelWidget: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(target.title, style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
if (target.isBeta) BetaPill(),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
target.getDescription(settings.getTrainerApp()),
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
if (target == Target.thisDevice)
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 12),
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).dividerColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
hintText: 'Select Target device',
|
||||
initialSelection: settings.getLastTarget(),
|
||||
onSelected: (target) async {
|
||||
if (target != null) {
|
||||
await settings.setLastTarget(target);
|
||||
initializeActions(target.connectionType);
|
||||
if (target.warning != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(target.warning!),
|
||||
duration: Duration(seconds: 10),
|
||||
),
|
||||
);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: settings.getTrainerApp() != null && settings.getLastTarget() != null
|
||||
? () {
|
||||
onUpdate();
|
||||
}
|
||||
: null,
|
||||
child: Text('Continue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? buildDescription() {
|
||||
final trainer = settings.getTrainerApp();
|
||||
final target = settings.getLastTarget();
|
||||
|
||||
if (target != null && trainer != null) {
|
||||
if (target.warning != null) {
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.red, size: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
settings.getLastTarget()!.warning!,
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Text('${trainer.name} on ${target.title}');
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceholderRequirement extends PlatformRequirement {
|
||||
PlaceholderRequirement() : super('Requirement');
|
||||
|
||||
@override
|
||||
Future<void> call(BuildContext context, VoidCallback onUpdate) async {}
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ import 'dart:io';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/requirements/android.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
import 'package:swift_control/utils/requirements/remote.dart';
|
||||
import 'package:universal_ble/universal_ble.dart';
|
||||
|
||||
abstract class PlatformRequirement {
|
||||
String name;
|
||||
@@ -21,24 +23,57 @@ abstract class PlatformRequirement {
|
||||
Widget? build(BuildContext context, VoidCallback onUpdate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Widget? buildDescription() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PlatformRequirement>> getRequirements(bool local) async {
|
||||
Future<List<PlatformRequirement>> getRequirements(ConnectionType connectionType) async {
|
||||
List<PlatformRequirement> list;
|
||||
if (kIsWeb) {
|
||||
list = [BluetoothTurnedOn(), BluetoothScanning()];
|
||||
final availablity = await UniversalBle.getBluetoothAvailabilityState();
|
||||
if (availablity == AvailabilityState.unsupported) {
|
||||
list = [UnsupportedPlatform()];
|
||||
} else {
|
||||
list = [BluetoothTurnedOn()];
|
||||
}
|
||||
} else if (Platform.isMacOS) {
|
||||
list = [BluetoothTurnedOn(), local ? KeyboardRequirement() : RemoteRequirement(), BluetoothScanning()];
|
||||
list = [
|
||||
TargetRequirement(),
|
||||
BluetoothTurnedOn(),
|
||||
switch (connectionType) {
|
||||
ConnectionType.local => KeyboardRequirement(),
|
||||
ConnectionType.remote => RemoteRequirement(),
|
||||
ConnectionType.unknown => PlaceholderRequirement(),
|
||||
},
|
||||
];
|
||||
} else if (Platform.isIOS) {
|
||||
list = [BluetoothTurnedOn(), RemoteRequirement(), BluetoothScanning()];
|
||||
list = [
|
||||
TargetRequirement(),
|
||||
BluetoothTurnedOn(),
|
||||
switch (connectionType) {
|
||||
ConnectionType.local => RemoteRequirement(),
|
||||
ConnectionType.remote => RemoteRequirement(),
|
||||
ConnectionType.unknown => PlaceholderRequirement(),
|
||||
},
|
||||
];
|
||||
} else if (Platform.isWindows) {
|
||||
list = [BluetoothTurnedOn(), local ? KeyboardRequirement() : RemoteRequirement(), BluetoothScanning()];
|
||||
list = [
|
||||
TargetRequirement(),
|
||||
BluetoothTurnedOn(),
|
||||
switch (connectionType) {
|
||||
ConnectionType.local => KeyboardRequirement(),
|
||||
ConnectionType.remote => RemoteRequirement(),
|
||||
ConnectionType.unknown => PlaceholderRequirement(),
|
||||
},
|
||||
];
|
||||
} else if (Platform.isAndroid) {
|
||||
final deviceInfoPlugin = DeviceInfoPlugin();
|
||||
final deviceInfo = await deviceInfoPlugin.androidInfo;
|
||||
list = [
|
||||
TargetRequirement(),
|
||||
BluetoothTurnedOn(),
|
||||
local ? AccessibilityRequirement() : RemoteRequirement(),
|
||||
NotificationRequirement(),
|
||||
if (deviceInfo.version.sdkInt <= 30)
|
||||
LocationRequirement()
|
||||
@@ -46,7 +81,11 @@ Future<List<PlatformRequirement>> getRequirements(bool local) async {
|
||||
BluetoothScanRequirement(),
|
||||
BluetoothConnectRequirement(),
|
||||
],
|
||||
BluetoothScanning(),
|
||||
switch (connectionType) {
|
||||
ConnectionType.local => AccessibilityRequirement(),
|
||||
ConnectionType.remote => RemoteRequirement(),
|
||||
ConnectionType.unknown => PlaceholderRequirement(),
|
||||
},
|
||||
];
|
||||
} else {
|
||||
list = [UnsupportedPlatform()];
|
||||
|
||||
@@ -5,8 +5,12 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart' hide ConnectionState;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/device.dart';
|
||||
import 'package:swift_control/utils/actions/remote.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/widgets/beta_pill.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
|
||||
import '../../pages/markdown.dart';
|
||||
@@ -18,11 +22,19 @@ bool _isServiceAdded = false;
|
||||
bool _isSubscribedToEvents = false;
|
||||
|
||||
class RemoteRequirement extends PlatformRequirement {
|
||||
RemoteRequirement() : super('Connect to your other device');
|
||||
RemoteRequirement()
|
||||
: super(
|
||||
'Connect to your target device',
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> call(BuildContext context, VoidCallback onUpdate) async {}
|
||||
|
||||
@override
|
||||
Widget? buildDescription() {
|
||||
return Text('Choose your preferred connection method');
|
||||
}
|
||||
|
||||
Future<void> reconnect() async {
|
||||
await peripheralManager.stopAdvertising();
|
||||
await peripheralManager.removeAllServices();
|
||||
@@ -74,12 +86,18 @@ class RemoteRequirement extends PlatformRequirement {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (peripheralManager.state != BluetoothLowEnergyState.poweredOn &&
|
||||
peripheralManager.state != BluetoothLowEnergyState.unknown) {
|
||||
print('Waiting for peripheral manager to be powered on...');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
if (kDebugMode && false) {
|
||||
print('Continuing');
|
||||
return;
|
||||
}
|
||||
|
||||
while (peripheralManager.state != BluetoothLowEnergyState.poweredOn) {
|
||||
print('Waiting for peripheral manager to be powered on... ${peripheralManager.state}');
|
||||
if (settings.getLastTarget() == Target.thisDevice) {
|
||||
return;
|
||||
}
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
if (!_isServiceAdded) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
final reportMapDataAbsolute = Uint8List.fromList([
|
||||
@@ -257,7 +275,7 @@ class RemoteRequirement extends PlatformRequirement {
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {
|
||||
status = (actionHandler as RemoteActions).isConnected || screenshotMode;
|
||||
status = (actionHandler is RemoteActions && (actionHandler as RemoteActions).isConnected) || screenshotMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,15 +294,71 @@ class _PairWidgetState extends State<_PairWidget> {
|
||||
super.initState();
|
||||
// after first frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
toggle();
|
||||
if (actionHandler.supportedApp?.supportsZwiftEmulation == false) {
|
||||
toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
spacing: 10,
|
||||
spacing: 16,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (settings.getTrainerApp() is MyWhoosh)
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
settings.setMyWhooshLinkEnabled(true);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => DevicePage(),
|
||||
settings: RouteSettings(name: '/device'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Connect via MyWhoosh Link'),
|
||||
Text(
|
||||
'Most reliable way to control MyWhoosh.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.normal),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (settings.getTrainerApp()?.supportsZwiftEmulation == true)
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (c) => DevicePage(),
|
||||
settings: RouteSettings(name: '/device'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Connect to ${settings.getTrainerApp()?.name} as controller'),
|
||||
Text(
|
||||
'Most reliable way to control ${settings.getTrainerApp()?.name}.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.normal),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
@@ -292,24 +366,40 @@ class _PairWidgetState extends State<_PairWidget> {
|
||||
onPressed: () async {
|
||||
await toggle();
|
||||
},
|
||||
child: Text(_isAdvertising ? 'Stop Pairing' : 'Start Pairing'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_isAdvertising ? 'Stop Pairing process' : 'Start Pairing',
|
||||
),
|
||||
Text(
|
||||
'Pairing allows full customizability,\nbut may not work on all devices.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.black87, fontWeight: FontWeight.normal),
|
||||
),
|
||||
],
|
||||
),
|
||||
BetaPill(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_isAdvertising || _isLoading) SizedBox(height: 20, width: 20, child: SmallProgressIndicator()),
|
||||
if (kDebugMode && !screenshotMode)
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
(actionHandler as RemoteActions).sendAbsMouseReport(0, 90, 90);
|
||||
(actionHandler as RemoteActions).sendAbsMouseReport(1, 90, 90);
|
||||
(actionHandler as RemoteActions).sendAbsMouseReport(0, 90, 90);
|
||||
},
|
||||
child: Text('Test'),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_isAdvertising) ...[
|
||||
if (_isAdvertising)
|
||||
Text(
|
||||
'If your other device is an iOS device, go to Settings > Accessibility > Touch > AssistiveTouch > Pointer Devices > Devices and pair your device. Make sure AssistiveTouch is enabled.',
|
||||
switch (settings.getLastTarget()) {
|
||||
Target.iOS =>
|
||||
'On your iPad go to Settings > Accessibility > Touch > AssistiveTouch > Pointer Devices > Devices and pair your device. Make sure AssistiveTouch is enabled.',
|
||||
_ =>
|
||||
'On your ${settings.getLastTarget()?.title} go into Bluetooth settings and look for SwiftControl or your machines name. Pairing is required if you want to use the remote control feature.',
|
||||
},
|
||||
),
|
||||
if (_isAdvertising) ...[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')));
|
||||
@@ -334,7 +424,7 @@ class _PairWidgetState extends State<_PairWidget> {
|
||||
setState(() {});
|
||||
await widget.requirement.startAdvertising(widget.onUpdate);
|
||||
_isLoading = false;
|
||||
setState(() {});
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
lib/utils/requirements/zwift.dart
Normal file
83
lib/utils/requirements/zwift.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart' hide ConnectionState;
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_emulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/rouvy.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/zwift.dart';
|
||||
import 'package:swift_control/utils/requirements/platform.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
|
||||
class ZwiftRequirement extends PlatformRequirement {
|
||||
ZwiftRequirement()
|
||||
: super(
|
||||
'Pair SwiftControl with Zwift',
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> call(BuildContext context, VoidCallback onUpdate) async {}
|
||||
|
||||
@override
|
||||
Widget? buildDescription() {
|
||||
return settings.getLastTarget() == null
|
||||
? null
|
||||
: Text(
|
||||
'In Zwift on your ${settings.getLastTarget()?.title} go into the Pairing settings and select SwiftControl from the list of available controllers.',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget? build(BuildContext context, VoidCallback onUpdate) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: zwiftEmulator.isConnected,
|
||||
builder: (context, isConnected, _) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: settings.getZwiftEmulatorEnabled(),
|
||||
onChanged: (value) {
|
||||
settings.setZwiftEmulatorEnabled(value);
|
||||
if (!value) {
|
||||
zwiftEmulator.stopAdvertising();
|
||||
} else if (value) {
|
||||
zwiftEmulator.startAdvertising(onUpdate);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
title: Text('Enable Zwift Controller'),
|
||||
subtitle: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
if (!settings.getZwiftEmulatorEnabled())
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Disabled. ${settings.getTrainerApp() is Zwift
|
||||
? 'Virtual shifting and on screen navigation will not work.'
|
||||
: settings.getTrainerApp() is Rouvy
|
||||
? 'Virtual shifting will not work.'
|
||||
: ''}',
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
Expanded(
|
||||
child: Text(
|
||||
isConnected
|
||||
? "Connected"
|
||||
: "Waiting for connection. Choose SwiftControl in ${settings.getTrainerApp()?.name}'s controller pairing menu.",
|
||||
),
|
||||
),
|
||||
if (!isConnected) SmallProgressIndicator(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> getStatus() async {
|
||||
status = zwiftEmulator.isConnected.value || screenshotMode;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/supported_app.dart';
|
||||
import 'package:swift_control/utils/requirements/multi.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../../main.dart';
|
||||
import '../actions/desktop.dart';
|
||||
import '../keymap/apps/custom_app.dart';
|
||||
|
||||
class Settings {
|
||||
@@ -13,49 +15,16 @@ class Settings {
|
||||
|
||||
Future<void> init() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
initializeActions(getLastTarget()?.connectionType ?? ConnectionType.unknown);
|
||||
|
||||
if (actionHandler is DesktopActions) {
|
||||
// Must add this line.
|
||||
await windowManager.ensureInitialized();
|
||||
}
|
||||
|
||||
try {
|
||||
// Get screen size for migrations
|
||||
Size? screenSize;
|
||||
try {
|
||||
final view = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
screenSize = view.physicalSize / view.devicePixelRatio;
|
||||
} catch (e) {
|
||||
screenSize = null;
|
||||
}
|
||||
|
||||
// Handle migration from old "customapp" key to new "customapp_Custom" key
|
||||
if (prefs.containsKey('customapp') && !prefs.containsKey('customapp_Custom')) {
|
||||
final oldCustomApp = prefs.getStringList('customapp');
|
||||
if (oldCustomApp != null) {
|
||||
// Migrate pixel-based to percentage-based if screen size available
|
||||
if (screenSize != null) {
|
||||
final migratedData = await _migrateToPercentageBased(oldCustomApp, screenSize);
|
||||
await prefs.setStringList('customapp_Custom', migratedData);
|
||||
} else {
|
||||
await prefs.setStringList('customapp_Custom', oldCustomApp);
|
||||
}
|
||||
await prefs.remove('customapp');
|
||||
}
|
||||
}
|
||||
|
||||
final appName = prefs.getString('app');
|
||||
if (appName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's a custom app with a profile name
|
||||
if (appName.startsWith('Custom') || prefs.containsKey('customapp_$appName')) {
|
||||
final customApp = CustomApp(profileName: appName);
|
||||
final appSetting = prefs.getStringList('customapp_$appName');
|
||||
if (appSetting != null) {
|
||||
customApp.decodeKeymap(appSetting);
|
||||
}
|
||||
actionHandler.init(customApp);
|
||||
} else {
|
||||
final app = SupportedApp.supportedApps.firstOrNullWhere((e) => e.name == appName);
|
||||
actionHandler.init(app);
|
||||
}
|
||||
final app = getKeyMap();
|
||||
actionHandler.init(app);
|
||||
} catch (e) {
|
||||
// couldn't decode, reset
|
||||
await prefs.clear();
|
||||
@@ -68,13 +37,44 @@ class Settings {
|
||||
actionHandler.init(null);
|
||||
}
|
||||
|
||||
Future<void> setApp(SupportedApp app) async {
|
||||
void setTrainerApp(SupportedApp app) {
|
||||
prefs.setString('trainer_app', app.name);
|
||||
}
|
||||
|
||||
SupportedApp? getTrainerApp() {
|
||||
final appName = prefs.getString('trainer_app');
|
||||
if (appName == null) {
|
||||
return null;
|
||||
}
|
||||
return SupportedApp.supportedApps.firstOrNullWhere((e) => e.name == appName);
|
||||
}
|
||||
|
||||
Future<void> setKeyMap(SupportedApp app) async {
|
||||
if (app is CustomApp) {
|
||||
await prefs.setStringList('customapp_${app.profileName}', app.encodeKeymap());
|
||||
}
|
||||
await prefs.setString('app', app.name);
|
||||
}
|
||||
|
||||
SupportedApp? getKeyMap() {
|
||||
final appName = prefs.getString('app');
|
||||
if (appName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if it's a custom app with a profile name
|
||||
if (appName.startsWith('Custom') || prefs.containsKey('customapp_$appName')) {
|
||||
final customApp = CustomApp(profileName: appName);
|
||||
final appSetting = prefs.getStringList('customapp_$appName');
|
||||
if (appSetting != null) {
|
||||
customApp.decodeKeymap(appSetting);
|
||||
}
|
||||
return customApp;
|
||||
} else {
|
||||
return SupportedApp.supportedApps.firstOrNullWhere((e) => e.name == appName);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> getCustomAppProfiles() {
|
||||
// Get all keys starting with 'customapp_'
|
||||
final keys = prefs.getKeys().where((key) => key.startsWith('customapp_')).toList();
|
||||
@@ -136,6 +136,16 @@ class Settings {
|
||||
return prefs.getString('last_seen_version');
|
||||
}
|
||||
|
||||
Target? getLastTarget() {
|
||||
final targetString = prefs.getString('last_target');
|
||||
if (targetString == null) return null;
|
||||
return Target.values.firstOrNullWhere((e) => e.name == targetString);
|
||||
}
|
||||
|
||||
Future<void> setLastTarget(Target target) async {
|
||||
await prefs.setString('last_target', target.name);
|
||||
}
|
||||
|
||||
Future<void> setLastSeenVersion(String version) async {
|
||||
await prefs.setString('last_seen_version', version);
|
||||
}
|
||||
@@ -148,39 +158,27 @@ class Settings {
|
||||
await prefs.setBool('vibration_enabled', enabled);
|
||||
}
|
||||
|
||||
Future<List<String>> _migrateToPercentageBased(List<String> keymapData, Size screenSize) async {
|
||||
final migratedData = <String>[];
|
||||
bool getMyWhooshLinkEnabled() {
|
||||
return prefs.getBool('mywhoosh_link_enabled') ?? true;
|
||||
}
|
||||
|
||||
final needMigrations = keymapData.associateWith((encodedKeyPair) {
|
||||
final decoded = jsonDecode(encodedKeyPair);
|
||||
final touchPosData = decoded['touchPosition'];
|
||||
Future<void> setMyWhooshLinkEnabled(bool enabled) async {
|
||||
await prefs.setBool('mywhoosh_link_enabled', enabled);
|
||||
}
|
||||
|
||||
// Convert pixel-based to percentage-based
|
||||
final x = (touchPosData['x'] as num).toDouble();
|
||||
final y = (touchPosData['y'] as num).toDouble();
|
||||
return x > 100.0 || y > 100.0;
|
||||
});
|
||||
bool getZwiftEmulatorEnabled() {
|
||||
return prefs.getBool('zwift_emulator_enabled') ?? true;
|
||||
}
|
||||
|
||||
for (final entry in needMigrations.entries) {
|
||||
if (entry.value) {
|
||||
final decoded = jsonDecode(entry.key);
|
||||
final touchPosData = decoded['touchPosition'];
|
||||
Future<void> setZwiftEmulatorEnabled(bool enabled) async {
|
||||
await prefs.setBool('zwift_emulator_enabled', enabled);
|
||||
}
|
||||
|
||||
// Convert pixel-based to percentage-based
|
||||
final x = (touchPosData['x'] as num).toDouble();
|
||||
final y = (touchPosData['y'] as num).toDouble();
|
||||
final newX = (x / screenSize.width).clamp(0.0, 1.0) * 100.0;
|
||||
final newY = (y / screenSize.height).clamp(0.0, 1.0) * 100.0;
|
||||
bool getMiuiWarningDismissed() {
|
||||
return prefs.getBool('miui_warning_dismissed') ?? false;
|
||||
}
|
||||
|
||||
// Update the JSON structure
|
||||
decoded['touchPosition'] = {'x': newX, 'y': newY};
|
||||
|
||||
migratedData.add(jsonEncode(decoded));
|
||||
} else {
|
||||
migratedData.add(entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
return migratedData;
|
||||
Future<void> setMiuiWarningDismissed(bool dismissed) async {
|
||||
await prefs.setBool('miui_warning_dismissed', dismissed);
|
||||
}
|
||||
}
|
||||
|
||||
28
lib/widgets/beta_pill.dart
Normal file
28
lib/widgets/beta_pill.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BetaPill extends StatelessWidget {
|
||||
final String text;
|
||||
const BetaPill({super.key, this.text = 'BETA'});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
45
lib/widgets/button_widget.dart
Normal file
45
lib/widgets/button_widget.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/widgets/keymap_explanation.dart';
|
||||
|
||||
class ButtonWidget extends StatelessWidget {
|
||||
final ControllerButton button;
|
||||
final bool big;
|
||||
const ButtonWidget({super.key, required this.button, this.big = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IntrinsicWidth(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
constraints: BoxConstraints(
|
||||
minWidth: big && button.color != null ? 40 : 30,
|
||||
minHeight: big && button.color != null ? 40 : 0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: button.color != null ? Colors.black : Theme.of(context).colorScheme.primary),
|
||||
shape: button.color != null || button.icon != null ? BoxShape.circle : BoxShape.rectangle,
|
||||
borderRadius: button.color != null || button.icon != null ? null : BorderRadius.circular(4),
|
||||
color: button.color ?? Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
child: Center(
|
||||
child: button.icon != null
|
||||
? Icon(
|
||||
button.icon,
|
||||
color: Colors.white,
|
||||
size: big && button.color != null ? null : 14,
|
||||
)
|
||||
: Text(
|
||||
button.name.splitByUpperCase(),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: big && button.color != null ? 20 : 12,
|
||||
fontWeight: button.color != null ? FontWeight.bold : null,
|
||||
color: button.color != null ? Colors.white : Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,10 @@ class ChangelogDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final latestVersion = Markdown(blocks: entry.blocks.skip(1).take(2).toList(), markdown: entry.markdown);
|
||||
final latestVersion = Markdown(
|
||||
blocks: entry.blocks.skip(1).takeWhile((b) => b.type != 'heading').toList(),
|
||||
markdown: entry.markdown,
|
||||
);
|
||||
return AlertDialog(
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -41,6 +44,7 @@ class ChangelogDialog extends StatelessWidget {
|
||||
showDialog(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
routeSettings: RouteSettings(name: '/changelog'),
|
||||
builder: (context) => ChangelogDialog(entry: markdown),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,45 +1,71 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/zwift_emulator.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/device.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/utils/actions/base_actions.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
import 'package:swift_control/utils/keymap/manager.dart';
|
||||
import 'package:swift_control/widgets/button_widget.dart';
|
||||
import 'package:swift_control/widgets/custom_keymap_selector.dart';
|
||||
|
||||
import '../bluetooth/devices/link/link.dart';
|
||||
import '../pages/touch_area.dart';
|
||||
import '../utils/actions/base_actions.dart';
|
||||
|
||||
class KeymapExplanation extends StatelessWidget {
|
||||
class KeymapExplanation extends StatefulWidget {
|
||||
final Keymap keymap;
|
||||
final VoidCallback onUpdate;
|
||||
const KeymapExplanation({super.key, required this.keymap, required this.onUpdate});
|
||||
|
||||
@override
|
||||
State<KeymapExplanation> createState() => _KeymapExplanationState();
|
||||
}
|
||||
|
||||
class _KeymapExplanationState extends State<KeymapExplanation> {
|
||||
late StreamSubscription<void> _updateStreamListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateStreamListener = widget.keymap.updateStream.listen((_) {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(KeymapExplanation oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.keymap != widget.keymap) {
|
||||
_updateStreamListener.cancel();
|
||||
_updateStreamListener = widget.keymap.updateStream.listen((_) {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_updateStreamListener.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final connectedDevice = connection.devices.firstOrNull;
|
||||
final availableKeypairs = widget.keymap.keyPairs;
|
||||
final allAvailableButtons = connection.devices.flatMap((d) => d.availableButtons);
|
||||
|
||||
final availableKeypairs = keymap.keyPairs.filter(
|
||||
(e) => connectedDevice?.availableButtons.containsAny(e.buttons) ?? true,
|
||||
);
|
||||
|
||||
final keyboardGroups = availableKeypairs
|
||||
.filter((e) => e.physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard))
|
||||
.groupBy((element) => '${element.physicalKey?.usbHidUsage}-${element.isLongPress}');
|
||||
final touchGroups = availableKeypairs
|
||||
.filter(
|
||||
(e) =>
|
||||
(e.physicalKey == null || !actionHandler.supportedModes.contains(SupportedMode.keyboard)) &&
|
||||
e.touchPosition != Offset.zero,
|
||||
)
|
||||
.groupBy((element) => '${element.touchPosition.dx}-${element.touchPosition.dy}-${element.isLongPress}');
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (keymap.keyPairs.isEmpty)
|
||||
Text('No key mappings found. Please customize the keymap.')
|
||||
else
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: whooshLink.isConnected,
|
||||
builder: (c, _, _) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
Table(
|
||||
border: TableBorder.symmetric(
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
@@ -56,7 +82,7 @@ class KeymapExplanation extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Text(
|
||||
'Button on your ${connectedDevice?.device.name?.screenshot ?? connectedDevice?.runtimeType ?? 'device'}',
|
||||
'Button on your ${connection.devices.isEmpty ? 'Device' : connection.devices.joinToString(transform: (d) => d.name.screenshot)}',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
@@ -69,125 +95,335 @@ class KeymapExplanation extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
for (final pair in keyboardGroups.entries) ...[
|
||||
for (final keyPair in availableKeypairs) ...[
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final keyPair in pair.value)
|
||||
for (final button in keyPair.buttons)
|
||||
if (connectedDevice?.availableButtons.contains(button) ?? true)
|
||||
IntrinsicWidth(child: ButtonWidget(button: button)),
|
||||
],
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (actionHandler.supportedApp is! CustomApp)
|
||||
if (keyPair.buttons.filter((b) => allAvailableButtons.contains(b)).isEmpty)
|
||||
Text('No button assigned for your connected device')
|
||||
else
|
||||
for (final button in keyPair.buttons.filter((b) => allAvailableButtons.contains(b)))
|
||||
IntrinsicWidth(child: ButtonWidget(button: button))
|
||||
else
|
||||
for (final button in keyPair.buttons) IntrinsicWidth(child: ButtonWidget(button: button)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: KeypairExplanation(keyPair: pair.value.first),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
for (final pair in touchGroups.entries) ...[
|
||||
TableRow(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final keyPair in pair.value)
|
||||
for (final button in keyPair.buttons)
|
||||
if (connectedDevice?.availableButtons.contains(button) ?? true)
|
||||
ButtonWidget(button: button),
|
||||
],
|
||||
TableCell(
|
||||
verticalAlignment: TableCellVerticalAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: _ButtonEditor(keyPair: keyPair, onUpdate: widget.onUpdate),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: KeypairExplanation(keyPair: pair.value.first),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class KeyWidget extends StatelessWidget {
|
||||
final String label;
|
||||
const KeyWidget({super.key, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IntrinsicWidth(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
constraints: BoxConstraints(minWidth: 30),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Theme.of(context).colorScheme.primary),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label.splitByUpperCase(),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ButtonWidget extends StatelessWidget {
|
||||
final ControllerButton button;
|
||||
final bool big;
|
||||
const ButtonWidget({super.key, required this.button, this.big = false});
|
||||
class _ButtonEditor extends StatelessWidget {
|
||||
final KeyPair keyPair;
|
||||
final VoidCallback onUpdate;
|
||||
const _ButtonEditor({required this.onUpdate, super.key, required this.keyPair});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IntrinsicWidth(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
constraints: BoxConstraints(
|
||||
minWidth: big && button.color != null ? 40 : 30,
|
||||
minHeight: big && button.color != null ? 40 : 0,
|
||||
final actions = <PopupMenuEntry>[
|
||||
if (settings.getMyWhooshLinkEnabled() && settings.getTrainerApp() is MyWhoosh)
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
child: PopupMenuButton(
|
||||
itemBuilder: (_) => WhooshLink.supportedActions.map(
|
||||
(ingame) {
|
||||
return PopupMenuItem(
|
||||
value: ingame,
|
||||
child: ingame.possibleValues != null
|
||||
? PopupMenuButton(
|
||||
itemBuilder: (c) => ingame.possibleValues!
|
||||
.map(
|
||||
(value) => PopupMenuItem(
|
||||
value: value,
|
||||
child: Text(value.toString()),
|
||||
onTap: () {
|
||||
keyPair.inGameAction = ingame;
|
||||
keyPair.inGameActionValue = value;
|
||||
onUpdate();
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(ingame.toString())),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Text(ingame.toString()),
|
||||
onTap: () {
|
||||
keyPair.inGameAction = ingame;
|
||||
keyPair.inGameActionValue = null;
|
||||
onUpdate();
|
||||
},
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
child: SizedBox(
|
||||
height: 52,
|
||||
child: Row(
|
||||
spacing: 14,
|
||||
children: [
|
||||
Icon(Icons.link),
|
||||
Expanded(child: Text('MyWhoosh Link Action')),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: button.color != null ? Colors.black : Theme.of(context).colorScheme.primary),
|
||||
shape: button.color != null || button.icon != null ? BoxShape.circle : BoxShape.rectangle,
|
||||
borderRadius: button.color != null || button.icon != null ? null : BorderRadius.circular(4),
|
||||
color: button.color ?? Theme.of(context).colorScheme.primaryContainer,
|
||||
if (settings.getZwiftEmulatorEnabled() && settings.getTrainerApp()?.supportsZwiftEmulation == true)
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
child: PopupMenuButton(
|
||||
itemBuilder: (_) => ZwiftEmulator.supportedActions.map(
|
||||
(ingame) {
|
||||
return PopupMenuItem(
|
||||
value: ingame,
|
||||
child: ingame.possibleValues != null
|
||||
? PopupMenuButton(
|
||||
itemBuilder: (c) => ingame.possibleValues!
|
||||
.map(
|
||||
(value) => PopupMenuItem(
|
||||
value: value,
|
||||
child: Text(value.toString()),
|
||||
onTap: () {
|
||||
keyPair.inGameAction = ingame;
|
||||
keyPair.inGameActionValue = value;
|
||||
onUpdate();
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: Text(ingame.toString())),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Text(ingame.toString()),
|
||||
onTap: () {
|
||||
keyPair.inGameAction = ingame;
|
||||
keyPair.inGameActionValue = null;
|
||||
onUpdate();
|
||||
},
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
child: SizedBox(
|
||||
height: 52,
|
||||
child: Row(
|
||||
spacing: 14,
|
||||
children: [
|
||||
Icon(Icons.link),
|
||||
Expanded(child: Text('Zwift Controller Action')),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: button.icon != null
|
||||
? Icon(
|
||||
button.icon,
|
||||
color: Colors.white,
|
||||
size: big && button.color != null ? null : 14,
|
||||
)
|
||||
: Text(
|
||||
button.name.splitByUpperCase(),
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: big && button.color != null ? 20 : 12,
|
||||
fontWeight: button.color != null ? FontWeight.bold : null,
|
||||
color: button.color != null ? Colors.white : Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.keyboard))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.keyboard_alt_outlined),
|
||||
title: const Text('Simulate Keyboard shortcut'),
|
||||
trailing: keyPair.physicalKey != null ? Checkbox(value: true, onChanged: null) : null,
|
||||
),
|
||||
onTap: () async {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // enable Escape key
|
||||
builder: (c) =>
|
||||
HotKeyListenerDialog(customApp: actionHandler.supportedApp! as CustomApp, keyPair: keyPair),
|
||||
);
|
||||
onUpdate();
|
||||
},
|
||||
),
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.touch))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
child: ListTile(
|
||||
title: const Text('Simulate Touch'),
|
||||
leading: Icon(Icons.touch_app_outlined),
|
||||
trailing: keyPair.physicalKey == null && keyPair.touchPosition != Offset.zero
|
||||
? Checkbox(value: true, onChanged: null)
|
||||
: null,
|
||||
),
|
||||
onTap: () async {
|
||||
if (keyPair.touchPosition == Offset.zero) {
|
||||
keyPair.touchPosition = Offset(50, 50);
|
||||
}
|
||||
keyPair.physicalKey = null;
|
||||
keyPair.logicalKey = null;
|
||||
await Navigator.of(context).push<bool?>(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => TouchAreaSetupPage(
|
||||
keyPair: keyPair,
|
||||
),
|
||||
),
|
||||
);
|
||||
onUpdate();
|
||||
},
|
||||
),
|
||||
|
||||
if (actionHandler.supportedModes.contains(SupportedMode.media))
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
child: PopupMenuButton<PhysicalKeyboardKey>(
|
||||
padding: EdgeInsets.zero,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaPlayPause,
|
||||
child: const Text('Media: Play/Pause'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaStop,
|
||||
child: const Text('Media: Stop'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaTrackPrevious,
|
||||
child: const Text('Media: Previous'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.mediaTrackNext,
|
||||
child: const Text('Media: Next'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.audioVolumeUp,
|
||||
child: const Text('Media: Volume Up'),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: PhysicalKeyboardKey.audioVolumeDown,
|
||||
child: const Text('Media: Volume Down'),
|
||||
),
|
||||
],
|
||||
onSelected: (key) {
|
||||
keyPair.physicalKey = key;
|
||||
keyPair.logicalKey = null;
|
||||
|
||||
onUpdate();
|
||||
},
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.music_note_outlined),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (keyPair.isSpecialKey) Checkbox(value: true, onChanged: null),
|
||||
Icon(Icons.arrow_right),
|
||||
],
|
||||
),
|
||||
title: Text('Simulate Media key'),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
PopupMenuDivider(),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
onTap: () {
|
||||
keyPair.isLongPress = !keyPair.isLongPress;
|
||||
onUpdate();
|
||||
},
|
||||
padding: EdgeInsets.zero,
|
||||
child: Row(
|
||||
spacing: 6,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: keyPair.isLongPress,
|
||||
onChanged: (value) {
|
||||
keyPair.isLongPress = value ?? false;
|
||||
|
||||
onUpdate();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
const Text('Long Press Mode (vs. repeating)'),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem<PhysicalKeyboardKey>(
|
||||
value: null,
|
||||
onTap: () {
|
||||
keyPair.isLongPress = false;
|
||||
keyPair.physicalKey = null;
|
||||
keyPair.logicalKey = null;
|
||||
keyPair.touchPosition = Offset.zero;
|
||||
keyPair.inGameAction = null;
|
||||
keyPair.inGameActionValue = null;
|
||||
onUpdate();
|
||||
},
|
||||
child: Row(
|
||||
spacing: 14,
|
||||
children: [
|
||||
Icon(Icons.delete_outline),
|
||||
const Text('Unassign action'),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
return Container(
|
||||
constraints: BoxConstraints(minHeight: kMinInteractiveDimension - 6),
|
||||
padding: EdgeInsets.only(right: actionHandler.supportedApp is CustomApp ? 4 : 0),
|
||||
child: PopupMenuButton<dynamic>(
|
||||
itemBuilder: (c) => actions,
|
||||
enabled: actionHandler.supportedApp is CustomApp,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
spacing: 6,
|
||||
children: [
|
||||
if (keyPair.buttons.isNotEmpty &&
|
||||
(keyPair.physicalKey != null || keyPair.touchPosition != Offset.zero || keyPair.inGameAction != null))
|
||||
Expanded(
|
||||
child: KeypairExplanation(
|
||||
keyPair: keyPair,
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: Text(
|
||||
'No action assigned',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
|
||||
if (actionHandler.supportedApp is! CustomApp)
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
final currentProfile = actionHandler.supportedApp!.name;
|
||||
await KeymapManager().duplicate(context, currentProfile);
|
||||
onUpdate();
|
||||
},
|
||||
icon: Icon(Icons.edit),
|
||||
)
|
||||
else
|
||||
Icon(Icons.edit, size: 14),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
54
lib/widgets/link.dart
Normal file
54
lib/widgets/link.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/markdown.dart';
|
||||
import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
|
||||
class LinkWidget extends StatefulWidget {
|
||||
final VoidCallback onUpdate;
|
||||
const LinkWidget({super.key, required this.onUpdate});
|
||||
|
||||
@override
|
||||
State<LinkWidget> createState() => _LinkWidgetState();
|
||||
}
|
||||
|
||||
class _LinkWidgetState extends State<LinkWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 8,
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: whooshLink.isStarted,
|
||||
builder: (BuildContext context, value, Widget? child) {
|
||||
return Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: value ? null : () async {},
|
||||
child: Text(value ? 'Waiting for MyWhoosh...' : 'Start Listening for MyWhoosh'),
|
||||
),
|
||||
if (value) SmallProgressIndicator(),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
Text('Verify with the MyWhoosh Link app if connection is possible.'),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
||||
);
|
||||
},
|
||||
child: const Text("Show Troubleshooting Guide"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../bluetooth/messages/notification.dart';
|
||||
@@ -25,9 +26,14 @@ class _LogviewerState extends State<LogViewer> {
|
||||
|
||||
_actionSubscription = connection.actionStream.listen((data) {
|
||||
if (mounted) {
|
||||
if (data is BluetoothAvailabilityNotification) {
|
||||
if (!data.isAvailable && Navigator.canPop(context)) {
|
||||
Navigator.popUntil(context, (route) => route.isFirst);
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
_actions.add((date: DateTime.now(), entry: data.toString()));
|
||||
_actions = _actions.takeLast(60).toList();
|
||||
_actions = _actions.takeLast(kIsWeb ? 1000 : 60).toList();
|
||||
});
|
||||
if (_scrollController.hasClients) {
|
||||
// scroll to the bottom
|
||||
|
||||
@@ -51,6 +51,54 @@ List<Widget> buildMenuButtons() {
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
],
|
||||
PopupMenuButton(
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text('Instructions'),
|
||||
onTap: () {
|
||||
final instructions = Platform.isAndroid
|
||||
? 'INSTRUCTIONS_ANDROID.md'
|
||||
: Platform.isIOS
|
||||
? 'INSTRUCTIONS_IOS.md'
|
||||
: Platform.isMacOS
|
||||
? 'INSTRUCTIONS_MACOS.md'
|
||||
: 'INSTRUCTIONS_WINDOWS.md';
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: instructions)),
|
||||
);
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Troubleshooting Guide'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
||||
);
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Provide Feedback'),
|
||||
onTap: () {
|
||||
launchUrlString('https://github.com/jonasbark/swiftcontrol/issues');
|
||||
},
|
||||
),
|
||||
if (!kIsWeb)
|
||||
PopupMenuItem(
|
||||
child: Text('Get Support'),
|
||||
onTap: () {
|
||||
final isFromStore = (Platform.isAndroid ? isFromPlayStore == true : Platform.isIOS);
|
||||
final suffix = isFromStore ? '' : 'ler';
|
||||
launchUrlString('mailto:jonas.t.bark+swiftcontrol$suffix@gmail.com');
|
||||
},
|
||||
),
|
||||
];
|
||||
},
|
||||
icon: Icon(Icons.help_outline),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
const MenuButton(),
|
||||
SizedBox(width: 8),
|
||||
];
|
||||
@@ -106,21 +154,7 @@ class MenuButton extends StatelessWidget {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'CHANGELOG.md')));
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Troubleshooting Guide'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
||||
);
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text('Feedback'),
|
||||
onTap: () {
|
||||
launchUrlString('https://github.com/jonasbark/swiftcontrol/issues');
|
||||
},
|
||||
),
|
||||
|
||||
PopupMenuItem(
|
||||
child: Text('License'),
|
||||
onTap: () {
|
||||
|
||||
89
lib/widgets/scan.dart
Normal file
89
lib/widgets/scan.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/pages/markdown.dart';
|
||||
|
||||
class ScanWidget extends StatefulWidget {
|
||||
const ScanWidget({super.key});
|
||||
|
||||
@override
|
||||
State<ScanWidget> createState() => _ScanWidgetState();
|
||||
}
|
||||
|
||||
class _ScanWidgetState extends State<ScanWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
connection.initialize();
|
||||
|
||||
/*_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
|
||||
_isScanning = state;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});*/
|
||||
|
||||
// after the first frame
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// must be called from a button
|
||||
if (!kIsWeb) {
|
||||
Future.delayed(Duration(seconds: 1))
|
||||
.then((_) {
|
||||
return connection.performScanning();
|
||||
})
|
||||
.catchError((e) {
|
||||
print(e);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: connection.isScanning,
|
||||
builder: (context, isScanning, widget) {
|
||||
if (isScanning) {
|
||||
return Column(
|
||||
spacing: 12,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Scanning for devices... Make sure they are powered on and in range and not connected to another device.',
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (c) => MarkdownPage(assetPath: 'TROUBLESHOOTING.md')),
|
||||
);
|
||||
},
|
||||
child: const Text("Show Troubleshooting Guide"),
|
||||
),
|
||||
SizedBox(),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
connection.performScanning();
|
||||
},
|
||||
child: const Text("SCAN"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:swift_control/main.dart';
|
||||
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/widgets/button_widget.dart';
|
||||
|
||||
import '../bluetooth/messages/notification.dart';
|
||||
|
||||
/// A developer overlay that visualizes touches and keyboard events.
|
||||
/// - Touch dots appear where you touch and fade out over [touchRevealDuration].
|
||||
@@ -14,8 +21,8 @@ class Testbed extends StatefulWidget {
|
||||
this.enabled = true,
|
||||
this.showTouches = true,
|
||||
this.showKeyboard = true,
|
||||
this.touchRevealDuration = const Duration(seconds: 2),
|
||||
this.keyboardRevealDuration = const Duration(seconds: 2),
|
||||
this.touchRevealDuration = const Duration(seconds: 3),
|
||||
this.keyboardRevealDuration = const Duration(seconds: 3),
|
||||
this.maxKeyboardEvents = 6,
|
||||
this.touchColor = const Color(0xFF00BCD4), // cyan-ish
|
||||
this.keyboardBadgeColor = const Color(0xCC000000), // translucent black
|
||||
@@ -40,6 +47,7 @@ class Testbed extends StatefulWidget {
|
||||
|
||||
class _TestbedState extends State<Testbed> with SingleTickerProviderStateMixin {
|
||||
late final Ticker _ticker;
|
||||
late StreamSubscription<BaseNotification> _actionSubscription;
|
||||
|
||||
// ----- Touch tracking -----
|
||||
final Map<int, _TouchSample> _active = <int, _TouchSample>{};
|
||||
@@ -55,6 +63,49 @@ class _TestbedState extends State<Testbed> with SingleTickerProviderStateMixin {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode = FocusNode(debugLabel: 'TestbedFocus', canRequestFocus: true, skipTraversal: true);
|
||||
_actionSubscription = connection.actionStream.listen((data) async {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
if (data is ButtonNotification) {
|
||||
for (final button in data.buttonsClicked) {
|
||||
final sample = _KeySample(
|
||||
button: button,
|
||||
text: '🔘 ${button.name}',
|
||||
timestamp: DateTime.now(),
|
||||
);
|
||||
_keys.insert(0, sample);
|
||||
if (_keys.length > widget.maxKeyboardEvents) {
|
||||
_keys.removeLast();
|
||||
}
|
||||
|
||||
if (actionHandler.supportedApp is! CustomApp &&
|
||||
actionHandler.supportedApp?.keymap.getKeyPair(button) == null) {
|
||||
ScaffoldMessenger.maybeOf(
|
||||
context,
|
||||
)?.showSnackBar(
|
||||
SnackBar(
|
||||
padding: EdgeInsets.only(left: 70, top: 12, bottom: 12, right: 12),
|
||||
content: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
const TextSpan(text: 'Use a custom keymap to support the '),
|
||||
WidgetSpan(
|
||||
child: ButtonWidget(button: button),
|
||||
),
|
||||
const TextSpan(
|
||||
text: ' button.',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
|
||||
_ticker = createTicker((_) {
|
||||
// Cull expired touch and key samples.
|
||||
@@ -215,10 +266,9 @@ class _TouchesPainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint =
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2;
|
||||
final paint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2;
|
||||
|
||||
for (final s in samples) {
|
||||
final age = now.difference(s.timestamp);
|
||||
@@ -242,17 +292,15 @@ class _TouchesPainter extends CustomPainter {
|
||||
canvas.drawCircle(s.position, rOuter, paint);
|
||||
|
||||
// Inner fill (stronger)
|
||||
final fill =
|
||||
Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = color.withOpacity(0.35 + 0.35 * fade);
|
||||
final fill = Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = color.withOpacity(0.35 + 0.35 * fade);
|
||||
canvas.drawCircle(s.position, rInner, fill);
|
||||
|
||||
// Tiny center dot for precision
|
||||
final center =
|
||||
Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = color.withOpacity(0.9 * fade);
|
||||
final center = Paint()
|
||||
..style = PaintingStyle.fill
|
||||
..color = color.withOpacity(0.9 * fade);
|
||||
canvas.drawCircle(s.position, 2.5, center);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +317,8 @@ class _TouchesPainter extends CustomPainter {
|
||||
// ===== Keyboard overlay =====
|
||||
|
||||
class _KeySample {
|
||||
_KeySample({required this.text, required this.timestamp});
|
||||
_KeySample({required this.text, required this.timestamp, this.button});
|
||||
final ControllerButton? button;
|
||||
final String text;
|
||||
final DateTime timestamp;
|
||||
}
|
||||
@@ -297,7 +346,7 @@ class _KeyboardOverlay extends StatelessWidget {
|
||||
children: [
|
||||
for (final item in items)
|
||||
_KeyboardToast(
|
||||
text: item.text,
|
||||
item: item,
|
||||
age: now.difference(item.timestamp),
|
||||
duration: duration,
|
||||
badgeColor: badgeColor,
|
||||
@@ -310,14 +359,14 @@ class _KeyboardOverlay extends StatelessWidget {
|
||||
|
||||
class _KeyboardToast extends StatelessWidget {
|
||||
const _KeyboardToast({
|
||||
required this.text,
|
||||
required this.item,
|
||||
required this.age,
|
||||
required this.duration,
|
||||
required this.badgeColor,
|
||||
required this.textStyle,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final _KeySample item;
|
||||
final Duration age;
|
||||
final Duration duration;
|
||||
final Color badgeColor;
|
||||
@@ -329,13 +378,14 @@ class _KeyboardToast extends StatelessWidget {
|
||||
final fade = 1.0 - t;
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: Opacity(
|
||||
opacity: fade,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(color: badgeColor, borderRadius: BorderRadius.circular(12)),
|
||||
child: Text(text, style: textStyle),
|
||||
child: item.button != null ? ButtonWidget(button: item.button!) : Text(item.text, style: textStyle),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -14,7 +13,7 @@ import 'package:swift_control/widgets/small_progress_indicator.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:version/version.dart';
|
||||
|
||||
PackageInfo? _packageInfoValue;
|
||||
PackageInfo? packageInfoValue;
|
||||
bool? isFromPlayStore;
|
||||
|
||||
class AppTitle extends StatefulWidget {
|
||||
@@ -28,37 +27,6 @@ class _AppTitleState extends State<AppTitle> {
|
||||
final updater = ShorebirdUpdater();
|
||||
Patch? _shorebirdPatch;
|
||||
|
||||
Future<Pair<Version, String>?> _getLatestVersionUrlIfNewer() async {
|
||||
final response = await http.get(Uri.parse('https://api.github.com/repos/jonasbark/swiftcontrol/releases/latest'));
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
final tagName = data['tag_name'] as String;
|
||||
final prerelase = data['prerelease'] as bool;
|
||||
final latestVersion = Version.parse(tagName.split('+').first.replaceAll('v', ''));
|
||||
final currentVersion = Version.parse(_packageInfoValue!.version);
|
||||
|
||||
// +1337 releases are considered beta
|
||||
if (latestVersion > currentVersion && !prerelase) {
|
||||
final assets = data['assets'] as List;
|
||||
if (Platform.isAndroid) {
|
||||
final apkUrl = assets.firstOrNullWhere((asset) => asset['name'].endsWith('.apk'))['browser_download_url'];
|
||||
return Pair(latestVersion, apkUrl);
|
||||
} else if (Platform.isMacOS) {
|
||||
final dmgUrl = assets.firstOrNullWhere(
|
||||
(asset) => asset['name'].endsWith('.macos.zip'),
|
||||
)['browser_download_url'];
|
||||
return Pair(latestVersion, dmgUrl);
|
||||
} else if (Platform.isWindows) {
|
||||
final appImageUrl = assets.firstOrNullWhere(
|
||||
(asset) => asset['name'].endsWith('.windows.zip'),
|
||||
)['browser_download_url'];
|
||||
return Pair(latestVersion, appImageUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -71,10 +39,10 @@ class _AppTitleState extends State<AppTitle> {
|
||||
});
|
||||
}
|
||||
|
||||
if (_packageInfoValue == null) {
|
||||
if (packageInfoValue == null) {
|
||||
PackageInfo.fromPlatform().then((value) {
|
||||
setState(() {
|
||||
_packageInfoValue = value;
|
||||
packageInfoValue = value;
|
||||
});
|
||||
_checkForUpdate();
|
||||
});
|
||||
@@ -85,30 +53,19 @@ class _AppTitleState extends State<AppTitle> {
|
||||
if (updater.isAvailable) {
|
||||
final updateStatus = await updater.checkForUpdate();
|
||||
if (updateStatus == UpdateStatus.outdated) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('New version available'),
|
||||
duration: Duration(seconds: 1337),
|
||||
action: SnackBarAction(
|
||||
label: 'Update',
|
||||
onPressed: () {
|
||||
updater
|
||||
.update()
|
||||
.then((value) {
|
||||
_showShorebirdRestartSnackbar();
|
||||
})
|
||||
.catchError((e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to update: $e'),
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
updater
|
||||
.update()
|
||||
.then((value) {
|
||||
_showShorebirdRestartSnackbar();
|
||||
})
|
||||
.catchError((e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to update: $e'),
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
});
|
||||
} else if (updateStatus == UpdateStatus.restartRequired) {
|
||||
_showShorebirdRestartSnackbar();
|
||||
}
|
||||
@@ -169,10 +126,14 @@ class _AppTitleState extends State<AppTitle> {
|
||||
_compareVersion(versionString);
|
||||
}
|
||||
} else if (Platform.isWindows) {
|
||||
final updatePair = await _getLatestVersionUrlIfNewer();
|
||||
if (updatePair != null && mounted && !kDebugMode) {
|
||||
_showUpdateSnackbar(updatePair.first, updatePair.second);
|
||||
}
|
||||
final url = Uri.parse(
|
||||
'https://raw.githubusercontent.com/jonasbark/swiftcontrol/refs/heads/main/WINDOWS_STORE_VERSION.txt',
|
||||
);
|
||||
final res = await http.get(url, headers: {'User-Agent': 'Mozilla/5.0'});
|
||||
if (res.statusCode != 200) return null;
|
||||
|
||||
final body = res.body.trim();
|
||||
_compareVersion(body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,9 +143,9 @@ class _AppTitleState extends State<AppTitle> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('SwiftControl', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
if (_packageInfoValue != null)
|
||||
if (packageInfoValue != null)
|
||||
Text(
|
||||
'v${_packageInfoValue!.version}${_shorebirdPatch != null ? '+${_shorebirdPatch!.number}' : ''}${kIsWeb || (Platform.isAndroid && isFromPlayStore == false) ? ' (sideloaded)' : ''}',
|
||||
'v${packageInfoValue!.version}${_shorebirdPatch != null ? '+${_shorebirdPatch!.number}' : ''}${kIsWeb || (Platform.isAndroid && isFromPlayStore == false) ? ' (sideloaded)' : ''}',
|
||||
style: TextStyle(fontFamily: "monospace", fontFamilyFallback: <String>["Courier"], fontSize: 12),
|
||||
)
|
||||
else
|
||||
@@ -196,12 +157,12 @@ class _AppTitleState extends State<AppTitle> {
|
||||
void _showShorebirdRestartSnackbar() {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Restart the app to use the new version'),
|
||||
content: Text('Force-close the app to use the new version'),
|
||||
duration: Duration(seconds: 10),
|
||||
action: SnackBarAction(
|
||||
label: 'Restart',
|
||||
onPressed: () {
|
||||
if (Platform.isIOS || Platform.isAndroid) {
|
||||
if (Platform.isIOS) {
|
||||
connection.reset();
|
||||
Restart.restartApp(delayBeforeRestart: 1000);
|
||||
} else {
|
||||
@@ -216,12 +177,14 @@ class _AppTitleState extends State<AppTitle> {
|
||||
|
||||
void _compareVersion(String versionString) {
|
||||
final parsed = Version.parse(versionString);
|
||||
final current = Version.parse(_packageInfoValue!.version);
|
||||
final current = Version.parse(packageInfoValue!.version);
|
||||
if (parsed > current && mounted && !kDebugMode) {
|
||||
if (Platform.isAndroid) {
|
||||
_showUpdateSnackbar(parsed, 'https://play.google.com/store/apps/details?id=org.jonasbark.swiftcontrol');
|
||||
} else if (Platform.isIOS || Platform.isMacOS) {
|
||||
_showUpdateSnackbar(parsed, 'https://apps.apple.com/app/id6753721284');
|
||||
} else if (Platform.isWindows) {
|
||||
_showUpdateSnackbar(parsed, 'ms-windows-store://pdp/?productid=9NP42GS03Z26');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
lib/widgets/warning.dart
Normal file
24
lib/widgets/warning.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Warning extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
const Warning({super.key, required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 6),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <bluetooth_low_energy_linux/bluetooth_low_energy_linux_plugin.h>
|
||||
#include <file_selector_linux/file_selector_plugin.h>
|
||||
#include <gamepads_linux/gamepads_linux_plugin.h>
|
||||
#include <screen_retriever_linux/screen_retriever_linux_plugin.h>
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
@@ -19,6 +20,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
|
||||
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) gamepads_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "GamepadsLinuxPlugin");
|
||||
gamepads_linux_plugin_register_with_registrar(gamepads_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin");
|
||||
screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
bluetooth_low_energy_linux
|
||||
file_selector_linux
|
||||
gamepads_linux
|
||||
screen_retriever_linux
|
||||
url_launcher_linux
|
||||
window_manager
|
||||
|
||||
@@ -9,8 +9,10 @@ import bluetooth_low_energy_darwin
|
||||
import device_info_plus
|
||||
import file_selector_macos
|
||||
import flutter_local_notifications
|
||||
import gamepads_darwin
|
||||
import keypress_simulator_macos
|
||||
import package_info_plus
|
||||
import path_provider_foundation
|
||||
import screen_retriever_macos
|
||||
import shared_preferences_foundation
|
||||
import universal_ble
|
||||
@@ -23,8 +25,10 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||
GamepadsDarwinPlugin.register(with: registry.registrar(forPlugin: "GamepadsDarwinPlugin"))
|
||||
KeypressSimulatorMacosPlugin.register(with: registry.registrar(forPlugin: "KeypressSimulatorMacosPlugin"))
|
||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
UniversalBlePlugin.register(with: registry.registrar(forPlugin: "UniversalBlePlugin"))
|
||||
|
||||
@@ -9,10 +9,15 @@ PODS:
|
||||
- flutter_local_notifications (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- gamepads_darwin (0.1.1):
|
||||
- FlutterMacOS
|
||||
- keypress_simulator_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- package_info_plus (0.0.1):
|
||||
- FlutterMacOS
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- screen_retriever_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- shared_preferences_foundation (0.0.1):
|
||||
@@ -34,8 +39,10 @@ DEPENDENCIES:
|
||||
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
|
||||
- flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- gamepads_darwin (from `Flutter/ephemeral/.symlinks/plugins/gamepads_darwin/macos`)
|
||||
- keypress_simulator_macos (from `Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos`)
|
||||
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
|
||||
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`)
|
||||
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
|
||||
- universal_ble (from `Flutter/ephemeral/.symlinks/plugins/universal_ble/darwin`)
|
||||
@@ -54,10 +61,14 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
gamepads_darwin:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/gamepads_darwin/macos
|
||||
keypress_simulator_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos
|
||||
package_info_plus:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
|
||||
path_provider_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
|
||||
screen_retriever_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos
|
||||
shared_preferences_foundation:
|
||||
@@ -77,8 +88,10 @@ SPEC CHECKSUMS:
|
||||
file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d
|
||||
flutter_local_notifications: 4ccab5b7a22835214a6672e3f9c5e8ae207dab36
|
||||
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
|
||||
gamepads_darwin: 07af6c60c282902b66574c800e20b2b26e68fda8
|
||||
keypress_simulator_macos: f8556f9101f9f2f175652e0bceddf0fe82a4c6b2
|
||||
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
|
||||
path_provider_foundation: 0b743cbb62d8e47eab856f09262bb8c1ddcfe6ba
|
||||
screen_retriever_macos: 776e0fa5d42c6163d2bf772d22478df4b302b161
|
||||
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
|
||||
universal_ble: cf52a7b3fd2e7c14d6d7262e9fdadb72ab6b88a6
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>SwiftControl requires Bluetooth to connect to your devices.</string>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>This app connects to your trainer app on your local network.</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>$(PRODUCT_COPYRIGHT)</string>
|
||||
<key>NSMainNibFile</key>
|
||||
|
||||
@@ -10,5 +10,7 @@
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
89
pubspec.lock
89
pubspec.lock
@@ -168,6 +168,15 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.11"
|
||||
device_auto_rotate_checker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "2cd4bb52733f664875cec2780a8091d4698226cb"
|
||||
url: "https://github.com/mpcreza/device_auto_rotate_checker.git"
|
||||
source: git
|
||||
version: "0.0.2"
|
||||
device_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -343,6 +352,62 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
gamepads:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: gamepads
|
||||
sha256: "5f8f1f31e241bce1c77e7bc5dcf5c03d9ea51a04ed775c8c299e788c512e0b54"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.8+2"
|
||||
gamepads_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_android
|
||||
sha256: "7913cd171ff06d5b588cb3e1dae64390c6e1352dd2999ff19a96d822eb7441fd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.6"
|
||||
gamepads_darwin:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_darwin
|
||||
sha256: "91250975ee196703816c55117502ec53ce4a1b881ca50dec1d0fbcb9fbb75eff"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.2+2"
|
||||
gamepads_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_ios
|
||||
sha256: "085459e2f677c18c4b15aee5dacc66e0b05491d4ed32bd3041c8328394e00d3a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.3+1"
|
||||
gamepads_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_linux
|
||||
sha256: f4c17915a84400d7f624aadb6371424ada596eedff2a25663121453e65917e0d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.1+3"
|
||||
gamepads_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_platform_interface
|
||||
sha256: ddab8677a4137d92e381b04cc97a8081ae4b75673dc0f24c846618d2b5226c4f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.2+1"
|
||||
gamepads_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gamepads_windows
|
||||
sha256: "454320638b8ad73890530545a2f788d83a752471010edade0f00b1636c1b382d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.4+1"
|
||||
get_it:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -611,6 +676,30 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_provider:
|
||||
dependency: "direct main"
|
||||
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: e122c5ea805bb6773bb12ce667611265980940145be920cd09a4b0ec0285cb16
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.20"
|
||||
path_provider_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_foundation
|
||||
sha256: efaec349ddfc181528345c56f8eda9d6cccd71c177511b132c6a0ddaefaa2738
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
18
pubspec.yaml
18
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: 3.1.0+28
|
||||
version: 3.3.2+36
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.0
|
||||
@@ -17,7 +17,9 @@ dependencies:
|
||||
universal_ble:
|
||||
git:
|
||||
url: https://github.com/jonasbark/universal_ble.git
|
||||
gamepads: ^0.1.8+2
|
||||
|
||||
path_provider: ^2.1.5
|
||||
intl: any
|
||||
version: ^3.0.0
|
||||
bluetooth_low_energy: ^6.1.0
|
||||
@@ -36,7 +38,11 @@ dependencies:
|
||||
accessibility:
|
||||
path: accessibility
|
||||
|
||||
# shorebird related
|
||||
device_auto_rotate_checker:
|
||||
git:
|
||||
url: https://github.com/mpcreza/device_auto_rotate_checker.git
|
||||
|
||||
# app update related
|
||||
shorebird_code_push: ^2.0.5
|
||||
restart_app:
|
||||
git:
|
||||
@@ -58,7 +64,12 @@ flutter:
|
||||
assets:
|
||||
- CHANGELOG.md
|
||||
- TROUBLESHOOTING.md
|
||||
- INSTRUCTIONS_ANDROID.md
|
||||
- INSTRUCTIONS_IOS.md
|
||||
- INSTRUCTIONS_WINDOWS.md
|
||||
- INSTRUCTIONS_MACOS.md
|
||||
- shorebird.yaml
|
||||
- icon.png
|
||||
|
||||
msix_config:
|
||||
display_name: SwiftControl
|
||||
@@ -66,7 +77,6 @@ msix_config:
|
||||
identity_name: JonasBark.SwiftControl
|
||||
publisher: CN=EDA6D86E-3E52-4054-9F3A-4277AFCCB2C4
|
||||
store: true
|
||||
msix_version: 1.0.0.0
|
||||
logo_path: logo.jpg
|
||||
logo_path: logo.png
|
||||
build_windows: false
|
||||
capabilities: internetClient,bluetooth,inputInjectionBrokered
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
I recommend downloading from the official stores:
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=de.jonasbark.swiftcontrol"><img width="270" height="80" alt="GetItOnGooglePlay_Badge_Web_color_English" src="https://github.com/user-attachments/assets/a059d5a1-2efb-4f65-8117-ef6a99823b21" /></a>
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" height="80" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a>
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=mac"><img width="270" height="80" alt="Mac App Store" src="https://github.com/user-attachments/assets/b3552436-409c-43b0-ba7d-b6a72ae30ff1" /></a>
|
||||
<a href="https://play.google.com/store/apps/details?id=de.jonasbark.swiftcontrol"><img width="270" alt="GetItOnGooglePlay_Badge_Web_color_English" src="https://github.com/user-attachments/assets/a059d5a1-2efb-4f65-8117-ef6a99823b21" /></a>
|
||||
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=iphone"><img width="270" alt="App Store" src="https://github.com/user-attachments/assets/c23f977a-48f6-4951-811e-ae530dbfa014" /></a>
|
||||
|
||||
<a href="https://apps.apple.com/us/app/swiftcontrol/id6753721284?platform=mac"><img width="270" alt="Mac App Store" src="https://github.com/user-attachments/assets/b3552436-409c-43b0-ba7d-b6a72ae30ff1" /></a>
|
||||
|
||||
<a href="https://apps.microsoft.com/detail/9NP42GS03Z26"><img width="270" alt="Microsoft Store" src="https://github.com/user-attachments/assets/7a8a3cd6-ec26-4678-a850-732eedd27c48" /></a>
|
||||
|
||||
@@ -28,8 +28,8 @@ void main() {
|
||||
|
||||
test('Should save and retrieve custom profile', () async {
|
||||
final customApp = CustomApp(profileName: 'Race');
|
||||
await settings.setApp(customApp);
|
||||
|
||||
await settings.setKeyMap(customApp);
|
||||
|
||||
final profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('Race'), true);
|
||||
});
|
||||
@@ -38,11 +38,11 @@ void main() {
|
||||
final workout = CustomApp(profileName: 'Workout');
|
||||
final race = CustomApp(profileName: 'Race');
|
||||
final event = CustomApp(profileName: 'Event');
|
||||
|
||||
await settings.setApp(workout);
|
||||
await settings.setApp(race);
|
||||
await settings.setApp(event);
|
||||
|
||||
|
||||
await settings.setKeyMap(workout);
|
||||
await settings.setKeyMap(race);
|
||||
await settings.setKeyMap(event);
|
||||
|
||||
final profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('Workout'), true);
|
||||
expect(profiles.contains('Race'), true);
|
||||
@@ -52,10 +52,10 @@ void main() {
|
||||
|
||||
test('Should duplicate custom profile', () async {
|
||||
final original = CustomApp(profileName: 'Original');
|
||||
await settings.setApp(original);
|
||||
|
||||
await settings.setKeyMap(original);
|
||||
|
||||
await settings.duplicateCustomAppProfile('Original', 'Copy');
|
||||
|
||||
|
||||
final profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('Original'), true);
|
||||
expect(profiles.contains('Copy'), true);
|
||||
@@ -64,13 +64,13 @@ void main() {
|
||||
|
||||
test('Should delete custom profile', () async {
|
||||
final customApp = CustomApp(profileName: 'ToDelete');
|
||||
await settings.setApp(customApp);
|
||||
|
||||
await settings.setKeyMap(customApp);
|
||||
|
||||
var profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('ToDelete'), true);
|
||||
|
||||
|
||||
await settings.deleteCustomAppProfile('ToDelete');
|
||||
|
||||
|
||||
profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('ToDelete'), false);
|
||||
});
|
||||
@@ -81,10 +81,10 @@ void main() {
|
||||
'customapp': ['test_data'],
|
||||
'app': 'Custom',
|
||||
});
|
||||
|
||||
|
||||
final newSettings = Settings();
|
||||
await newSettings.init();
|
||||
|
||||
|
||||
// Check that migration happened
|
||||
expect(newSettings.prefs.containsKey('customapp'), false);
|
||||
expect(newSettings.prefs.containsKey('customapp_Custom'), true);
|
||||
@@ -96,10 +96,10 @@ void main() {
|
||||
'customapp_Custom': ['new_data'],
|
||||
'app': 'Custom',
|
||||
});
|
||||
|
||||
|
||||
final newSettings = Settings();
|
||||
await newSettings.init();
|
||||
|
||||
|
||||
// Old key should still exist because new key already existed
|
||||
expect(newSettings.getCustomAppKeymap('customapp'), null);
|
||||
final customKeymap = newSettings.getCustomAppKeymap('Custom');
|
||||
@@ -108,8 +108,8 @@ void main() {
|
||||
|
||||
test('Should export custom profile as JSON', () async {
|
||||
final customApp = CustomApp(profileName: 'TestProfile');
|
||||
await settings.setApp(customApp);
|
||||
|
||||
await settings.setKeyMap(customApp);
|
||||
|
||||
final jsonData = settings.exportCustomAppProfile('TestProfile');
|
||||
expect(jsonData, isNotNull);
|
||||
expect(jsonData, contains('version'));
|
||||
@@ -120,12 +120,12 @@ void main() {
|
||||
test('Should import custom profile from JSON', () async {
|
||||
// First export a profile
|
||||
final customApp = CustomApp(profileName: 'ExportTest');
|
||||
await settings.setApp(customApp);
|
||||
await settings.setKeyMap(customApp);
|
||||
final jsonData = settings.exportCustomAppProfile('ExportTest');
|
||||
|
||||
|
||||
// Import with a new name
|
||||
final success = await settings.importCustomAppProfile(jsonData!, newProfileName: 'ImportTest');
|
||||
|
||||
|
||||
expect(success, true);
|
||||
final profiles = settings.getCustomAppProfiles();
|
||||
expect(profiles.contains('ImportTest'), true);
|
||||
|
||||
106
test/cycplus_bc2_test.dart
Normal file
106
test/cycplus_bc2_test.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CYCPLUS BC2 Virtual Shifter Tests', () {
|
||||
test('Should recognize shift up button code', () {
|
||||
// Test button code recognition
|
||||
const shiftUpCode = 0x01;
|
||||
const shiftDownCode = 0x02;
|
||||
const releaseCode = 0x00;
|
||||
|
||||
expect(shiftUpCode, equals(0x01));
|
||||
expect(shiftDownCode, equals(0x02));
|
||||
expect(releaseCode, equals(0x00));
|
||||
});
|
||||
|
||||
test('Should handle button press and release cycle', () {
|
||||
// Test button state transitions
|
||||
final states = [0x01, 0x00, 0x02, 0x00];
|
||||
|
||||
expect(states[0], equals(0x01)); // Shift up pressed
|
||||
expect(states[1], equals(0x00)); // Button released
|
||||
expect(states[2], equals(0x02)); // Shift down pressed
|
||||
expect(states[3], equals(0x00)); // Button released
|
||||
});
|
||||
|
||||
test('Should validate UART service UUID format', () {
|
||||
// Nordic UART Service UUID
|
||||
const serviceUuid = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
|
||||
expect(serviceUuid.length, equals(36));
|
||||
expect(serviceUuid.contains('-'), isTrue);
|
||||
expect(serviceUuid.toLowerCase(), equals(serviceUuid));
|
||||
});
|
||||
|
||||
test('Should validate TX characteristic UUID format', () {
|
||||
// TX Characteristic UUID (device to app)
|
||||
const txCharUuid = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
|
||||
expect(txCharUuid.length, equals(36));
|
||||
expect(txCharUuid.contains('-'), isTrue);
|
||||
expect(txCharUuid.toLowerCase(), equals(txCharUuid));
|
||||
});
|
||||
|
||||
test('Should validate RX characteristic UUID format', () {
|
||||
// RX Characteristic UUID (app to device)
|
||||
const rxCharUuid = "6e400002-b5a3-f393-e0a9-e50e24dcca9e";
|
||||
|
||||
expect(rxCharUuid.length, equals(36));
|
||||
expect(rxCharUuid.contains('-'), isTrue);
|
||||
expect(rxCharUuid.toLowerCase(), equals(rxCharUuid));
|
||||
});
|
||||
});
|
||||
|
||||
group('CYCPLUS BC2 Button Code Tests', () {
|
||||
test('Should differentiate between shift up and shift down', () {
|
||||
const shiftUpCode = 0x01;
|
||||
const shiftDownCode = 0x02;
|
||||
|
||||
expect(shiftUpCode != shiftDownCode, isTrue);
|
||||
expect(shiftUpCode < shiftDownCode, isTrue);
|
||||
});
|
||||
|
||||
test('Should recognize release code as different from press codes', () {
|
||||
const releaseCode = 0x00;
|
||||
const shiftUpCode = 0x01;
|
||||
const shiftDownCode = 0x02;
|
||||
|
||||
expect(releaseCode != shiftUpCode, isTrue);
|
||||
expect(releaseCode != shiftDownCode, isTrue);
|
||||
expect(releaseCode < shiftUpCode, isTrue);
|
||||
expect(releaseCode < shiftDownCode, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('CYCPLUS BC2 Device Name Recognition Tests', () {
|
||||
test('Should recognize CYCPLUS device name', () {
|
||||
const deviceName1 = 'CYCPLUS BC2';
|
||||
const deviceName2 = 'Cycplus BC2';
|
||||
const deviceName3 = 'CYCPLUS';
|
||||
|
||||
expect(deviceName1.toUpperCase().startsWith('CYCPLUS'), isTrue);
|
||||
expect(deviceName2.toUpperCase().startsWith('CYCPLUS'), isTrue);
|
||||
expect(deviceName3.toUpperCase().startsWith('CYCPLUS'), isTrue);
|
||||
});
|
||||
|
||||
test('Should recognize BC2 in device name', () {
|
||||
const deviceName1 = 'CYCPLUS BC2';
|
||||
const deviceName2 = 'BC2 Shifter';
|
||||
const deviceName3 = 'Virtual BC2';
|
||||
|
||||
expect(deviceName1.toUpperCase().contains('BC2'), isTrue);
|
||||
expect(deviceName2.toUpperCase().contains('BC2'), isTrue);
|
||||
expect(deviceName3.toUpperCase().contains('BC2'), isTrue);
|
||||
});
|
||||
|
||||
test('Should not match non-CYCPLUS devices', () {
|
||||
const deviceName1 = 'Zwift Click';
|
||||
const deviceName2 = 'Elite Sterzo';
|
||||
const deviceName3 = 'Wahoo KICKR';
|
||||
|
||||
expect(deviceName1.toUpperCase().startsWith('CYCPLUS'), isFalse);
|
||||
expect(deviceName2.toUpperCase().startsWith('CYCPLUS'), isFalse);
|
||||
expect(deviceName3.toUpperCase().startsWith('CYCPLUS'), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
70
test/elite_sterzo_test.dart
Normal file
70
test/elite_sterzo_test.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Elite Sterzo Smart Calibration Tests', () {
|
||||
test('Should ignore NaN values during calibration', () {
|
||||
// Test that NaN values are filtered out
|
||||
final samples = [double.nan, 1.5, 2.0, 2.5, 3.0, double.nan, 3.5, 4.0, 4.5, 5.0, 5.5];
|
||||
final validSamples = samples.where((s) => !s.isNaN).take(10).toList();
|
||||
|
||||
expect(validSamples.length, equals(10));
|
||||
expect(validSamples.every((s) => !s.isNaN), isTrue);
|
||||
});
|
||||
|
||||
test('Should compute correct calibration offset from samples', () {
|
||||
// Test offset calculation
|
||||
final samples = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
|
||||
final offset = samples.reduce((a, b) => a + b) / samples.length;
|
||||
|
||||
expect(offset, equals(5.5));
|
||||
});
|
||||
|
||||
test('Should round angles to whole degrees', () {
|
||||
// Test rounding behavior
|
||||
expect(4.3.round(), equals(4));
|
||||
expect(4.6.round(), equals(5));
|
||||
expect(4.7.round(), equals(5));
|
||||
expect((-4.3).round(), equals(-4));
|
||||
expect((-4.6).round(), equals(-5));
|
||||
});
|
||||
});
|
||||
|
||||
group('Elite Sterzo Smart PWM Keypress Tests', () {
|
||||
test('Should calculate correct keypress levels', () {
|
||||
// Test level calculation with LEVEL_DEGREE_STEP = 10 and MAX_LEVELS = 5
|
||||
const levelDegreeStep = 10.0;
|
||||
const maxLevels = 5;
|
||||
|
||||
int calculateLevels(int absAngle) {
|
||||
final levels = (absAngle / levelDegreeStep).floor();
|
||||
return levels.clamp(1, maxLevels);
|
||||
}
|
||||
|
||||
expect(calculateLevels(5), equals(1)); // Below threshold but level 1
|
||||
expect(calculateLevels(10), equals(1)); // 10 / 10 = 1
|
||||
expect(calculateLevels(15), equals(1)); // 15 / 10 = 1.5 floor = 1
|
||||
expect(calculateLevels(20), equals(2)); // 20 / 10 = 2
|
||||
expect(calculateLevels(35), equals(3)); // 35 / 10 = 3.5 floor = 3
|
||||
expect(calculateLevels(50), equals(5)); // 50 / 10 = 5 (max)
|
||||
expect(calculateLevels(100), equals(5)); // 100 / 10 = 10 but clamped to 5
|
||||
});
|
||||
|
||||
test('Should determine correct steering direction', () {
|
||||
// Test direction determination
|
||||
expect(25 > 0, isTrue); // Positive = RIGHT
|
||||
expect(-25 > 0, isFalse); // Negative = LEFT
|
||||
});
|
||||
});
|
||||
|
||||
group('Elite Sterzo Smart Threshold Tests', () {
|
||||
test('Should correctly apply steering threshold', () {
|
||||
const steeringThreshold = 10.0;
|
||||
|
||||
// Test threshold logic
|
||||
expect(5.abs() > steeringThreshold, isFalse); // Below threshold
|
||||
expect(10.abs() > steeringThreshold, isFalse); // At threshold
|
||||
expect(11.abs() > steeringThreshold, isTrue); // Above threshold
|
||||
expect((-11).abs() > steeringThreshold, isTrue); // Above threshold (negative)
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
|
||||
void main() {
|
||||
@@ -8,7 +8,7 @@ void main() {
|
||||
test('KeyPair should encode and decode isLongPress property', () {
|
||||
// Create a KeyPair with long press enabled
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.a],
|
||||
buttons: [ZwiftButtons.a],
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
isLongPress: true,
|
||||
@@ -23,7 +23,7 @@ void main() {
|
||||
// Verify the decoded KeyPair has the correct properties
|
||||
expect(decoded, isNotNull);
|
||||
expect(decoded!.isLongPress, true);
|
||||
expect(decoded.buttons, equals([ControllerButton.a]));
|
||||
expect(decoded.buttons, equals([ZwiftButtons.a]));
|
||||
expect(decoded.physicalKey, equals(PhysicalKeyboardKey.keyA));
|
||||
expect(decoded.logicalKey, equals(LogicalKeyboardKey.keyA));
|
||||
});
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
|
||||
test('KeyPair constructor should default isLongPress to false', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.a],
|
||||
buttons: [ZwiftButtons.a],
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
);
|
||||
@@ -59,7 +59,7 @@ void main() {
|
||||
|
||||
test('KeyPair should correctly encode isLongPress false', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.a],
|
||||
buttons: [ZwiftButtons.a],
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
isLongPress: false,
|
||||
|
||||
@@ -2,24 +2,29 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:swift_control/pages/touch_area.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
|
||||
void main() {
|
||||
group('TouchAreaSetupPage Orientation Tests', () {
|
||||
testWidgets('TouchAreaSetupPage should force landscape orientation on init', (WidgetTester tester) async {
|
||||
// Track system chrome method calls
|
||||
final List<MethodCall> systemChromeCalls = [];
|
||||
|
||||
|
||||
// Mock SystemChrome.setPreferredOrientations
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
|
||||
systemChromeCalls.add(methodCall);
|
||||
return null;
|
||||
});
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(MethodCall methodCall) async {
|
||||
systemChromeCalls.add(methodCall);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
// Build the TouchAreaSetupPage
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: TouchAreaSetupPage(),
|
||||
MaterialApp(
|
||||
home: TouchAreaSetupPage(
|
||||
keyPair: KeyPair(buttons: [], physicalKey: null, logicalKey: null),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -27,13 +32,13 @@ void main() {
|
||||
final orientationCalls = systemChromeCalls
|
||||
.where((call) => call.method == 'SystemChrome.setPreferredOrientations')
|
||||
.toList();
|
||||
|
||||
|
||||
expect(orientationCalls, isNotEmpty);
|
||||
|
||||
|
||||
// Check if landscape orientations were set
|
||||
final lastOrientationCall = orientationCalls.last;
|
||||
final orientations = lastOrientationCall.arguments as List<String>;
|
||||
|
||||
|
||||
expect(orientations, contains('DeviceOrientation.landscapeLeft'));
|
||||
expect(orientations, contains('DeviceOrientation.landscapeRight'));
|
||||
expect(orientations, hasLength(2)); // Only landscape orientations
|
||||
@@ -47,7 +52,7 @@ void main() {
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
];
|
||||
|
||||
|
||||
expect(orientations, hasLength(4));
|
||||
expect(orientations, contains(DeviceOrientation.landscapeLeft));
|
||||
expect(orientations, contains(DeviceOrientation.landscapeRight));
|
||||
@@ -55,4 +60,4 @@ void main() {
|
||||
expect(orientations, contains(DeviceOrientation.portraitDown));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:swift_control/utils/keymap/buttons.dart';
|
||||
import 'package:swift_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:swift_control/utils/keymap/keymap.dart';
|
||||
|
||||
void main() {
|
||||
group('Percentage-based Keymap Tests', () {
|
||||
test('Should encode touch position as percentage using fallback screen size', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.paddleRight],
|
||||
buttons: [ZwiftButtons.shiftUpRight],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(960, 540), // Center of 1920x1080 fallback
|
||||
@@ -22,7 +22,7 @@ void main() {
|
||||
|
||||
test('Should encode touch position as percentages with fallback when screen size not available', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.paddleRight],
|
||||
buttons: [ZwiftButtons.shiftDownLeft],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(960, 540), // Center of 1920x1080 fallback
|
||||
@@ -57,7 +57,7 @@ void main() {
|
||||
|
||||
test('Should handle zero touch position correctly', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.paddleRight],
|
||||
buttons: [ZwiftButtons.shiftUpLeft],
|
||||
physicalKey: PhysicalKeyboardKey.keyA,
|
||||
logicalKey: LogicalKeyboardKey.keyA,
|
||||
touchPosition: Offset.zero,
|
||||
@@ -72,7 +72,7 @@ void main() {
|
||||
|
||||
test('Should encode and decode with fallback screen size', () {
|
||||
final keyPair = KeyPair(
|
||||
buttons: [ControllerButton.paddleRight],
|
||||
buttons: [ZwiftButtons.shiftUpRight],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
touchPosition: Offset(480, 270), // 25% of 1920x1080
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <bluetooth_low_energy_windows/bluetooth_low_energy_windows_plugin_c_api.h>
|
||||
#include <file_selector_windows/file_selector_windows.h>
|
||||
#include <gamepads_windows/gamepads_windows_plugin_c_api.h>
|
||||
#include <keypress_simulator_windows/keypress_simulator_windows_plugin_c_api.h>
|
||||
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
||||
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
|
||||
@@ -20,6 +21,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
registry->GetRegistrarForPlugin("BluetoothLowEnergyWindowsPluginCApi"));
|
||||
FileSelectorWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FileSelectorWindows"));
|
||||
GamepadsWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("GamepadsWindowsPluginCApi"));
|
||||
KeypressSimulatorWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("KeypressSimulatorWindowsPluginCApi"));
|
||||
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
bluetooth_low_energy_windows
|
||||
file_selector_windows
|
||||
gamepads_windows
|
||||
keypress_simulator_windows
|
||||
permission_handler_windows
|
||||
screen_retriever_windows
|
||||
|
||||
Reference in New Issue
Block a user