Skip to content

Commit

Permalink
fixing get gears from zwift for new firmware version of zwift ride
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Nov 15, 2024
1 parent d0360ea commit 5abc9ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/devices/zwifthubbike/zwifthubbike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@ import Foundation

return fullData
}

public static func ridingData(power: UInt32, cadence: UInt32, speed: Double, HR: UInt32) throws -> Data {
var physical = BLEReceiver_Zwift_HubRidingData()
physical.cadence = cadence
physical.power = power
physical.speedX100 = UInt32(speed * 100.0)
physical.hr = HR
physical.unknown1 = 2864
physical.unknown2 = 25714

let data = try physical.serializedData()
var fullData = Data([0x03])
fullData.append(data)

return fullData
}
}
22 changes: 16 additions & 6 deletions src/ios/virtualbike_zwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class BLEPeripheralManagerZwift: NSObject, CBPeripheralManagerDelegate {
self.peripheralManager.updateValue(responseData, for: self.FitnessMachineControlPointCharacteristic, onSubscribedCentrals: nil)
} else if requests.first!.characteristic == ZwiftPlayWriteCharacteristic && zwift_play_emulator {
let receivedData = requests.first!.value ?? Data()
let expectedHexArray: [UInt8] = [0x52, 0x69, 0x64, 0x65, 0x4F, 0x6E, 0x02, 0x01]
let expectedHexArray: [UInt8] = [0x52, 0x69, 0x64, 0x65, 0x4F, 0x6E, 0x02]
let expectedHexArray2: [UInt8] = [0x41, 0x08, 0x05]
let expectedHexArray3: [UInt8] = [0x00, 0x08, 0x88, 0x04]
let expectedHexArray4: [UInt8] = [0x04, 0x2a, 0x0a, 0x10, 0xc0, 0xbb, 0x01, 0x20]
Expand Down Expand Up @@ -854,12 +854,22 @@ class BLEPeripheralManagerZwift: NSObject, CBPeripheralManagerDelegate {
}
} else if(zwift_play_emulator) {
if(!sendUpdates()) {
let ZwiftPlayArray : [UInt8] = [ 0x03, 0x08, 0x00, 0x10, 0x00, 0x18, 0xe7, 0x02, 0x20, 0x00, 0x28, 0x00, 0x30, 0x9b, 0xed, 0x01 ]
let ZwiftPlayData = Data(bytes: ZwiftPlayArray, count: 16)
let ok = self.peripheralManager.updateValue(ZwiftPlayData, for: self.ZwiftPlayReadCharacteristic, onSubscribedCentrals: nil)
if(ok) {
/*
do {
let ZwiftPlayData = try ZwiftHubBike.ridingData(power: UInt32(self.CurrentWatt), cadence: UInt32(self.CurrentCadence), speed: Double(self.NormalizeSpeed), HR: UInt32(self.heartRate))
let ok = self.peripheralManager.updateValue(ZwiftPlayData, for: self.ZwiftPlayReadCharacteristic, onSubscribedCentrals: nil)
if(ok) {
self.serviceToggle = self.serviceToggle + 1
}
} catch {
self.serviceToggle = self.serviceToggle + 1
}
}*/
let ZwiftPlayArray : [UInt8] = [ 0x03, 0x08, 0x00, 0x10, 0x00, 0x18, 0xe7, 0x02, 0x20, 0x00, 0x28, 0x00, 0x30, 0x9b, 0xed, 0x01 ]
let ZwiftPlayData = Data(bytes: ZwiftPlayArray, count: 16)
let ok = self.peripheralManager.updateValue(ZwiftPlayData, for: self.ZwiftPlayReadCharacteristic, onSubscribedCentrals: nil)
if(ok) {
self.serviceToggle = self.serviceToggle + 1
}
} else {
self.serviceToggle = self.serviceToggle + 1
}
Expand Down
2 changes: 1 addition & 1 deletion src/virtualdevices/virtualbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void virtualbike::characteristicChanged(const QLowEnergyCharacteristic &characte
//********************ZWIFT PLAY**************

if(characteristic.uuid().toString().contains(QStringLiteral("00000003-19ca-4651-86e5-fa29dcdd09d1")) && zwift_play_emulator) {
static const QByteArray expectedHexArray = QByteArray::fromHex("52696465 4F6E0201");
static const QByteArray expectedHexArray = QByteArray::fromHex("52696465 4F6E02");
static const QByteArray expectedHexArray2 = QByteArray::fromHex("410805");
static const QByteArray expectedHexArray3 = QByteArray::fromHex("00088804");
static const QByteArray expectedHexArray4 = QByteArray::fromHex("042A0A10 C0BB0120");
Expand Down

1 comment on commit 5abc9ac

@cagnulein
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.