Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix ajchellew/zwiftplay#7 #8

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ollypsilon
Copy link

Hi,
these changes might fix #7

image

Still some work to do, as I encounter unknown messages:

Decrypt failed: Value cannot be null. (Parameter 'collection')
Unprocessed - Type: 42 Data: 2A 08 52 12 10 12 0E 08 12 10 00 18 90 03 22 05 FF 07 F0 FF 1F

But before I continue let's fix this state.

Best

Oliver

Add the IDisposable interface and Dispose method to the ZwiftPlayBleManager class.

RegisterCharacteristics handles TaskCanceledException that can occur during BLE characteristic registration and provides clear feedback about the connection state.

ConnectAsync method with proper null checks: checking for null references before proceeding with the BLE connection steps.
ConnectAsync method more robust by using async/await properly and adding error handling.
The RequestLEScanAsync method needs BluetoothLEScanOptions.

Handle the ObjectDisposedException by updating the scanning task.
Enhance the error handling in Program.cs by adding TaskCanceledException to catch blocks.

Add a null check for the ManufacturerData in the AdvertisementReceived event handler: This will ensure the code handles BLE advertisements without manufacturer data correctly and continues scanning for valid Zwift Play controllers.
@dylix
Copy link

dylix commented Dec 18, 2024

Awesome, this is pretty much what I had fixed, but I'm a terrible github user.. so nothing was ever submitted..

I've been using more or less the same code for two weeks. I haven't had any issues with the 'unprocessed type 42' stuff.. and I know nothing of BT, so its blackmagic to me..

I've been using this console for indievelo to change virtual gears, change spotify music, brakes, u turn, etc.. fun times :) Glad my controllers have a use again!

Unreachable part removed
Added logging class and methods

Moved some config parameters to new class
@ollypsilon
Copy link
Author

Just some changes to add a logging facility, helping to identify decrypt issue.

SendKeys no longer defined in code, instead moved to config and can be set on command line as well (--sendkeys)
@ollypsilon
Copy link
Author

Moved SendKeys to configuration and command line
SendKeys no longer defined in code, instead moved to config and can be set on command line as well (--sendkeys)

@ollypsilon
Copy link
Author

Added keyboard mapping to configuration

- Moved configuration to JSON file.
-- Moved BleScanConfig part into AppSettings.
- Added MappingFile optionto use a JSON file which contains keyboard mapping.
-- Added default TPVirtual.json file.
-- Keyboard mapping allows shift key combinations to use
- More robust BT device implementation with cleanup
-- Possible ToDo: implement BLE retry logic
- App class now IDisposable
@ollypsilon
Copy link
Author

  • Moved configuration to JSON file.
    • Moved BleScanConfig part into AppSettings.
  • Added MappingFile optionto use a JSON file which contains keyboard mapping.
    • Added default TPVirtual.json file.
    • Keyboard mapping allows shift key combinations to use
  • More robust BT device implementation with cleanup
    • Possible ToDo: implement BLE retry logic
  • App class now IDisposable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows console App
2 participants