Skip to content

Commit

Permalink
Merge pull request #516 from doudar/TrainerDay_Fix
Browse files Browse the repository at this point in the history
TrainerDay Fix
  • Loading branch information
doudar authored Feb 7, 2024
2 parents f418f25 + 0f175d0 commit feddef8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed DNS server in AP mode.
- Fixed an issue with IC4 and variants not displaying device name in Bluetooth scanner. Fixes #500
- Switched from using Power Table to a Torque Table for better compensation in cad variations.
- added test for invalid Peloton data to keep stepper from running away without resistance information.
- added test for invalid Peloton data to keep stepper from running away without resistance information.
- Fixed a bug with Trainer Day and rapid ERG sending.

### Hardware
- Wire diameter reduced from 7.2mm to 6.0mm on the window passthrough to accommodate the latest batch of cables.
Expand Down
11 changes: 8 additions & 3 deletions src/BLE_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void processFTMSWrite() {
uint8_t returnValue[3] = {FitnessMachineControlPointProcedure::ResponseCode, (uint8_t)rxValue[0], FitnessMachineControlPointResultCode::OpCodeNotSupported};

ftmsStatus = {FitnessMachineStatus::ReservedForFutureUse};
rtConfig.setFTMSMode((uint8_t)rxValue[0]);


switch ((uint8_t)rxValue[0]) {
case FitnessMachineControlPointProcedure::RequestControl:
Expand All @@ -408,14 +408,14 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SetTargetInclination: {
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;
pCharacteristic->setValue(returnValue, 3);

port = (rxValue[2] << 8) + rxValue[1];
port *= 10;

rtConfig.setTargetIncline(port);

logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "-> Incline Mode: %2f", rtConfig.getTargetIncline() / 100);

ftmsStatus = {FitnessMachineStatus::TargetInclineChanged, (uint8_t)rxValue[1], (uint8_t)rxValue[2]};
Expand All @@ -424,6 +424,7 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SetTargetResistanceLevel: {
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;
ftmsTrainingStatus[1] = FitnessMachineTrainingStatus::Other; // 0x00;
fitnessMachineTrainingStatus->setValue(ftmsTrainingStatus, 2);
Expand All @@ -447,6 +448,7 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SetTargetPower: {
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
if (spinBLEClient.connectedPM || rtConfig.watts.getSimulate()) {
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;

Expand All @@ -455,7 +457,7 @@ void processFTMSWrite() {
rtConfig.watts.getValue(), rtConfig.getTargetIncline() / 100);

ftmsStatus = {FitnessMachineStatus::TargetPowerChanged, (uint8_t)rxValue[1], (uint8_t)rxValue[2]};
ftmsTrainingStatus[1] = FitnessMachineTrainingStatus::Other; // 0x0C;
ftmsTrainingStatus[1] = FitnessMachineTrainingStatus::WattControl; // 0x0C;
fitnessMachineTrainingStatus->setValue(ftmsTrainingStatus, 2);
// Adjust set point for powerCorrectionFactor and send to FTMS server (if connected)
int adjustedTarget = rtConfig.watts.getTarget() / userConfig.getPowerCorrectionFactor();
Expand Down Expand Up @@ -492,6 +494,7 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SetIndoorBikeSimulationParameters: { // sim mode
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;
pCharacteristic->setValue(returnValue, 3);

Expand Down Expand Up @@ -519,6 +522,7 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SpinDownControl: {
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
uint8_t controlPoint[6] = {FitnessMachineControlPointProcedure::ResponseCode, 0x01, 0x24, 0x03, 0x96, 0x0e}; // send low and high speed targets
pCharacteristic->setValue(controlPoint, 6);
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "-> Spin Down Requested");
Expand All @@ -530,6 +534,7 @@ void processFTMSWrite() {
} break;

case FitnessMachineControlPointProcedure::SetTargetedCadence: {
rtConfig.setFTMSMode((uint8_t)rxValue[0]);
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;
pCharacteristic->setValue(returnValue, 3);

Expand Down
2 changes: 1 addition & 1 deletion src/ERG_Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ void ErgMode::computeErg() {
}

// SetPoint changed
if (this->setPoint != newWatts.getTarget()) {
if (abs(this->setPoint - newWatts.getTarget() > 20)) {
_setPointChangeState(newCadence, newWatts);
return;
}
Expand Down

0 comments on commit feddef8

Please sign in to comment.