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

created and set totalTravel #585

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/BLE_Custom_Characteristic.h
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ const uint8_t BLE_simulatedTargetWatts = 0x28; // current target watts
const uint8_t BLE_simulateTargetWatts = 0x29; // are we sending target watts
const uint8_t BLE_hMin = 0x2A; // Minimum homing value
const uint8_t BLE_hMax = 0x2B; // Maximum homing value
const uint8_t BLE_totalTravel = 0x2C; // Total travel
const uint8_t BLE_calculatedTotalTravel = 0x2D; // Calculated Total Travel

class BLE_ss2kCustomCharacteristic {
public:
2 changes: 2 additions & 0 deletions include/ERG_Mode.h
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
class PowerEntry {
public:
int watts;
int resistance;
int32_t targetPosition;
int cad;
int readings;
@@ -28,6 +29,7 @@ class PowerEntry {
this->targetPosition = 0;
this->cad = 0;
this->readings = 0;
this->resistance = 0;
}
};

8 changes: 8 additions & 0 deletions include/SmartSpin_parameters.h
Original file line number Diff line number Diff line change
@@ -65,6 +65,8 @@ class RuntimeParameters {
int minResistance = -DEFAULT_RESISTANCE_RANGE;
int maxResistance = DEFAULT_RESISTANCE_RANGE;
bool simTargetWatts = false;
int32_t totalTravel = INT32_MIN;
int16_t calculatedTotalTravel = INT16_MIN;

public:
Measurement watts;
@@ -104,6 +106,12 @@ class RuntimeParameters {
void setMaxResistance(int max) { maxResistance = max; }
int getMaxResistance() { return maxResistance; }

void setTotalTravel(int32_t tT) { totalTravel = tT; }
int32_t getTotalTravel() { return totalTravel; }

void setCalculatedTotalTravel(int16_t calctT) { calculatedTotalTravel = calctT; }
int16_t getCalculatedTotalTravel() { return calculatedTotalTravel; }

String returnJSON();
};

45 changes: 45 additions & 0 deletions src/BLE_Custom_Characteristic.cpp
Original file line number Diff line number Diff line change
@@ -738,6 +738,39 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) {
ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24));
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getHMax());
}

case BLE_totalTravel: // 0x2C
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-totalTravel");
if (rxValue[0] == cc_read) {
returnValue[0] = cc_success;
returnValue[2] = (uint8_t)(rtConfig->getTotalTravel() & 0xff);
returnValue[3] = (uint8_t)(rtConfig->getTotalTravel() >> 8);
returnValue[4] = (uint8_t)(rtConfig->getTotalTravel() >> 16);
returnValue[5] = (uint8_t)(rtConfig->getTotalTravel() >> 24);
returnLength += 4;
}
if (rxValue[0] == cc_write) {
returnValue[0] = cc_success;
ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24));
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", rtConfig->getTotalTravel());
}

case BLE_calculatedTotalTravel: // 0x2D
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-calculatedTotalTravel");
if (rxValue[0] == cc_read) {
returnValue[0] = cc_success;
returnValue[2] = (uint8_t)(rtConfig->getCalculatedTotalTravel() & 0xff);
returnValue[3] = (uint8_t)(rtConfig->getCalculatedTotalTravel() >> 8);
returnValue[4] = (uint8_t)(rtConfig->getCalculatedTotalTravel() >> 16);
returnValue[5] = (uint8_t)(rtConfig->getCalculatedTotalTravel() >> 24);
returnLength += 4;
}
if (rxValue[0] == cc_write) {
returnValue[0] = cc_success;
ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24));
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", rtConfig->getCalculatedTotalTravel());
}

break;
}

@@ -900,4 +933,16 @@ void BLE_ss2kCustomCharacteristic::parseNemit() {
BLE_ss2kCustomCharacteristic::notify(BLE_hMax);
return;
}

if(rtConfig->getTotalTravel() != _oldRTParams.getTotalTravel()){
_oldRTParams.setTotalTravel(rtConfig->getTotalTravel());
BLE_ss2kCustomCharacteristic::notify(BLE_totalTravel);
return;
}

if(rtConfig->getCalculatedTotalTravel() != _oldRTParams.getCalculatedTotalTravel()){
_oldRTParams.setCalculatedTotalTravel(rtConfig->getCalculatedTotalTravel());
BLE_ss2kCustomCharacteristic::notify(BLE_calculatedTotalTravel);
return;
}
}
8 changes: 6 additions & 2 deletions src/BLE_Fitness_Machine_Service.cpp
Original file line number Diff line number Diff line change
@@ -130,13 +130,13 @@ void BLE_Fitness_Machine_Service::processFTMSWrite() {
switch ((uint8_t)rxValue[0]) {
case FitnessMachineControlPointProcedure::RequestControl:
returnValue[2] = FitnessMachineControlPointResultCode::Success; // 0x01;
rtConfig->watts.setTarget(0);
rtConfig->setSimTargetWatts(false);
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "-> Control Request");
ftmsTrainingStatus[1] = FitnessMachineTrainingStatus::Idle; // 0x01;
fitnessMachineTrainingStatus->setValue(ftmsTrainingStatus, 2);
ftmsStatus = {FitnessMachineStatus::StartedOrResumedByUser};
pCharacteristic->setValue(returnValue, 3);
rtConfig->watts.setTarget(0);
rtConfig->setSimTargetWatts(false);
break;

case FitnessMachineControlPointProcedure::Reset: {
@@ -147,6 +147,8 @@ void BLE_Fitness_Machine_Service::processFTMSWrite() {
ftmsStatus = {FitnessMachineStatus::Reset};
fitnessMachineTrainingStatus->setValue(ftmsTrainingStatus, 2);
pCharacteristic->setValue(returnValue, 3);
rtConfig->watts.setTarget(0);
rtConfig->setSimTargetWatts(false);
} break;

case FitnessMachineControlPointProcedure::SetTargetInclination: {
@@ -233,6 +235,8 @@ void BLE_Fitness_Machine_Service::processFTMSWrite() {
ftmsStatus = {FitnessMachineStatus::StoppedOrPausedByUser};
ftmsTrainingStatus[1] = FitnessMachineTrainingStatus::Other; // 0x00;
fitnessMachineTrainingStatus->setValue(ftmsTrainingStatus, 2);
rtConfig->watts.setTarget(0);
rtConfig->setSimTargetWatts(false);

} break;

2 changes: 2 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -639,6 +639,8 @@ void SS2K::goHome(bool bothDirections) {
if (bothDirections) {
userConfig->setHMin(rtConfig->getMinStep());
userConfig->setHMax(rtConfig->getMaxStep());
rtConfig->setTotalTravel(userConfig->getHMax() - userConfig->getHMin());
rtConfig->setCalculatedTotalTravel(rtConfig->getTotalTravel()/100);
}
// In case this was only one direction homing.
rtConfig->setMaxStep(userConfig->getHMax());
4 changes: 4 additions & 0 deletions src/SensorCollector.cpp
Original file line number Diff line number Diff line change
@@ -64,6 +64,10 @@ void collectAndSet(NimBLEUUID charUUID, NimBLEUUID serviceUUID, NimBLEAddress ad
if (sensorData->hasResistance()) {
if ((rtConfig->getMaxResistance() == MAX_PELOTON_RESISTANCE) && (charUUID != PELOTON_DATA_UUID)) {
// Peloton connected but using BLE Power Meter. So skip resistance for UUID's that aren't Peloton.
} else if (rtConfig->getHomed()) {
int resistance = rtConfig->getMaxResistance() *(ss2k->getCurrentPosition()/rtConfig->getCalculatedTotalTravel()); //might be total travel without dividing by 100
rtConfig->resistance.setValue(resistance);
logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, " RS(%d)", resistance % 1000);
} else {
int resistance = sensorData->getResistance();
rtConfig->resistance.setValue(resistance);