Compare commits

...

1 Commits

Author SHA1 Message Date
Roberto Viola
1c11d7f517 positive and negative elevation gain added to the virtual treadmill 2023-02-15 15:29:53 +01:00
4 changed files with 41 additions and 3 deletions

View File

@@ -115,6 +115,7 @@ bool bluetoothdevice::changeFanSpeed(uint8_t speed) {
}
bool bluetoothdevice::connected() { return false; }
metric bluetoothdevice::elevationGain() { return elevationAcc; }
metric bluetoothdevice::negativeElevationGain() { return negativeElevationAcc; }
void bluetoothdevice::heartRate(uint8_t heart) { Heart.setValue(heart); }
void bluetoothdevice::disconnectBluetooth() {
if (m_control) {

View File

@@ -212,10 +212,15 @@ class bluetoothdevice : public QObject {
virtual bool changeFanSpeed(uint8_t speed);
/**
* @brief elevationGain Gets a metric object to get and set the elevation gain. Units: ?
* @brief elevationGain Gets a metric object to get and set the elevation gain. Units: meter
*/
virtual metric elevationGain();
/**
* @brief negativeElevationGain Gets a metric object to get and set the negative elevation gain. Units: meter
*/
virtual metric negativeElevationGain();
/**
* @brief clearStats Clear the statistics.
*/
@@ -497,6 +502,11 @@ class bluetoothdevice : public QObject {
*/
metric elevationAcc;
/**
* @brief NegativeElevationAcc The negative elevation gain. Units: meters
*/
metric negativeElevationAcc;
/**
* @brief m_watt Metric to get and set the power expended in the session. Unit: watts
*/

View File

@@ -8,7 +8,7 @@ CharacteristicNotifier2ACD::CharacteristicNotifier2ACD(bluetoothdevice *Bike, QO
int CharacteristicNotifier2ACD::notify(QByteArray &value) {
bluetoothdevice::BLUETOOTH_TYPE dt = Bike->deviceType();
if (dt == bluetoothdevice::TREADMILL || dt == bluetoothdevice::ELLIPTICAL) {
value.append(0x08); // Inclination available
value.append(0x18); // Inclination available and elevation gain
value.append((char)0x01); // heart rate available
uint16_t normalizeSpeed = (uint16_t)qRound(Bike->currentSpeed().value() * 100);
@@ -35,12 +35,36 @@ int CharacteristicNotifier2ACD::notify(QByteArray &value) {
rampBytes.append(b);
rampBytes.append(a);
QByteArray positiveElevationGainBytes;
ramp = 0;
if (dt == bluetoothdevice::TREADMILL)
ramp = ((treadmill *)Bike)->elevationGain().value();
normalizeRamp = (int32_t)qRound(ramp * 10);
a = (normalizeRamp >> 8) & 0XFF;
b = normalizeRamp & 0XFF;
positiveElevationGainBytes.append(b);
positiveElevationGainBytes.append(a);
QByteArray negativeElevationGainBytes;
ramp = 0;
if (dt == bluetoothdevice::TREADMILL)
ramp = ((treadmill *)Bike)->negativeElevationGain().value();
normalizeRamp = (int32_t)qRound(ramp * 10);
a = (normalizeRamp >> 8) & 0XFF;
b = normalizeRamp & 0XFF;
negativeElevationGainBytes.append(b);
negativeElevationGainBytes.append(a);
value.append(speedBytes); // Actual value.
value.append(inclineBytes); // incline
value.append(rampBytes); // ramp angle
value.append(positiveElevationGainBytes); // positiveElevationGain angle
value.append(negativeElevationGainBytes); // negativeElevationGain angle
value.append(Bike->currentHeart().value()); // current heart rate
return CN_OK;
} else

View File

@@ -73,7 +73,10 @@ void treadmill::update_metrics(bool watt_calc, const double watts) {
}
METS = calculateMETS();
elevationAcc += (currentSpeed().value() / 3600.0) * 1000.0 * (currentInclination().value() / 100.0) * deltaTime;
if(currentInclination().value() > 0)
elevationAcc += (currentSpeed().value() / 3600.0) * 1000.0 * (currentInclination().value() / 100.0) * deltaTime;
else
negativeElevationAcc += (currentSpeed().value() / 3600.0) * 1000.0 * qAbs(currentInclination().value() / 100.0) * deltaTime;
_lastTimeUpdate = current;
_firstUpdate = false;