From 088587c8fbe2a69f85ed9bc0f44a90cf472c083f Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 1 Dec 2011 21:35:39 +0000 Subject: [PATCH] Fix Target load Dial When working with ANT+ devices the load dial always showed zero, because the ANT device was not updating the realtime data with the desired load. In addition, the target load telemetry always showed watts even when working in slope mode (where it should show the gradient). Fixes #532. --- src/ANT.cpp | 13 +++++++-- src/ANT.h | 2 +- src/ANTlocalController.cpp | 2 +- src/ComputrainerController.cpp | 2 +- src/DialWindow.cpp | 10 +++++++ src/DialWindow.h | 1 + src/RealtimeData.cpp | 8 +++++ src/RealtimeData.h | 6 +++- src/TrainTool.cpp | 53 +++++++++++++++++++--------------- src/TrainTool.h | 5 ++-- 10 files changed, 69 insertions(+), 33 deletions(-) diff --git a/src/ANT.cpp b/src/ANT.cpp index c91fb2b7e..6067e9b12 100644 --- a/src/ANT.cpp +++ b/src/ANT.cpp @@ -281,10 +281,17 @@ ANT::quit(int code) return 0; } -RealtimeData -ANT::getRealtimeData() +void +ANT::getRealtimeData(RealtimeData &rtData) { - return telemetry; + int mode = rtData.mode; + long load = rtData.getLoad(); + double slope = rtData.getSlope(); + + rtData = telemetry; + rtData.mode = mode; + rtData.setLoad(load); + rtData.setSlope(slope); } /*====================================================================== diff --git a/src/ANT.h b/src/ANT.h index 324a80f96..ef041909c 100644 --- a/src/ANT.h +++ b/src/ANT.h @@ -259,7 +259,7 @@ public slots: void searchComplete(int number); // search completed successfully // get telemetry - RealtimeData getRealtimeData(); // return current realtime data + void getRealtimeData(RealtimeData &); // return current realtime data public: diff --git a/src/ANTlocalController.cpp b/src/ANTlocalController.cpp index aa7e17fea..201e1712b 100644 --- a/src/ANTlocalController.cpp +++ b/src/ANTlocalController.cpp @@ -87,7 +87,7 @@ ANTlocalController::getRealtimeData(RealtimeData &rtData) return; } // get latest telemetry - rtData = myANTlocal->getRealtimeData(); + myANTlocal->getRealtimeData(rtData); processRealtimeData(rtData); } diff --git a/src/ComputrainerController.cpp b/src/ComputrainerController.cpp index 792b3ee4f..b80127e3a 100644 --- a/src/ComputrainerController.cpp +++ b/src/ComputrainerController.cpp @@ -127,7 +127,7 @@ ComputrainerController::getRealtimeData(RealtimeData &rtData) if ((Buttons&CT_MINUS) && !(Buttons&CT_F3)) { parent->Lower(); } - rtData.setLoad(Load); + //rtData.setLoad(Load); #if 0 // F3 now toggles calibration // FFWD/REWIND diff --git a/src/DialWindow.cpp b/src/DialWindow.cpp index 274e45dd4..176f3223a 100644 --- a/src/DialWindow.cpp +++ b/src/DialWindow.cpp @@ -328,6 +328,16 @@ DialWindow::telemetryUpdate(const RealtimeData &rtData) } break; + case RealtimeData::Load: + if (rtData.mode == ERG || rtData.mode == MRC) { + value = rtData.getLoad(); + valueLabel->setText(QString("%1").arg(round(value))); + } else { + value = rtData.getSlope(); + valueLabel->setText(QString("%1%").arg(value, 0, 'f', 1)); + } + break; + default: valueLabel->setText(QString("%1").arg(round(value))); break; diff --git a/src/DialWindow.h b/src/DialWindow.h index 82d1731e8..130408a81 100644 --- a/src/DialWindow.h +++ b/src/DialWindow.h @@ -27,6 +27,7 @@ #include "MainWindow.h" #include "Zones.h" // for data series types #include "RideFile.h" // for data series types +#include "ErgFile.h" // for workout modes #include "RealtimeData.h" // for realtimedata structure #include "Settings.h" // for realtimedata structure diff --git a/src/RealtimeData.cpp b/src/RealtimeData.cpp index 56153272f..61bd3cf0d 100644 --- a/src/RealtimeData.cpp +++ b/src/RealtimeData.cpp @@ -53,6 +53,10 @@ void RealtimeData::setCadence(double aCadence) { cadence = (int)aCadence; } +void RealtimeData::setSlope(double slope) +{ + this->slope = slope; +} void RealtimeData::setLoad(double load) { this->load = load; @@ -94,6 +98,10 @@ double RealtimeData::getCadence() const { return cadence; } +double RealtimeData::getSlope() const +{ + return slope; +} double RealtimeData::getLoad() const { return load; diff --git a/src/RealtimeData.h b/src/RealtimeData.h index 1062b3146..1afdacce4 100644 --- a/src/RealtimeData.h +++ b/src/RealtimeData.h @@ -30,6 +30,8 @@ class RealtimeData public: + int mode; + // abstract to dataseries enum dataseries { None=0, Time, LapTime, Distance, Lap, Watts, Speed, Cadence, HeartRate, Load, @@ -53,6 +55,7 @@ public: void setWheelRpm(double wheelRpm); void setCadence(double aCadence); void setLoad(double load); + void setSlope(double slope); void setMsecs(long); void setLapMsecs(long); void setDistance(double); @@ -69,6 +72,7 @@ public: double getWheelRpm() const; double getCadence() const; double getLoad() const; + double getSlope() const; long getMsecs() const; long getLapMsecs() const; double getDistance() const; @@ -80,7 +84,7 @@ private: char name[64]; // realtime telemetry - double hr, watts, speed, wheelRpm, load; + double hr, watts, speed, wheelRpm, load, slope; double cadence; // in rpm // derived data diff --git a/src/TrainTool.cpp b/src/TrainTool.cpp index 6a24ed3d7..7836b62c0 100644 --- a/src/TrainTool.cpp +++ b/src/TrainTool.cpp @@ -287,7 +287,7 @@ TrainTool::TrainTool(MainWindow *parent, const QDir &home) : GcWindow(parent), h lodcount = 0; load_msecs = total_msecs = lap_msecs = 0; displayWorkoutDistance = displayDistance = displayPower = displayHeartRate = - displaySpeed = displayCadence = displayGradient = displayLoad = 0; + displaySpeed = displayCadence = slope = load = 0; connect(gui_timer, SIGNAL(timeout()), this, SLOT(guiUpdate())); connect(disk_timer, SIGNAL(timeout()), this, SLOT(diskUpdate())); @@ -664,6 +664,9 @@ void TrainTool::Start() // when start button is pressed setDeviceController(); if (deviceController == NULL) return; + load = 0; + slope = 0.0; + if (mode == ERG || mode == MRC) { status |= RT_MODE_ERGO; status &= ~RT_MODE_SPIN; @@ -773,8 +776,8 @@ void TrainTool::Pause() // pause capture to recalibrate void TrainTool::Stop(int deviceStatus) // when stop button is pressed { - if (deviceController == NULL) return; + if (deviceController == NULL) return; if ((status&RT_RUNNING) == 0) return; status &= ~RT_RUNNING; @@ -787,6 +790,9 @@ void TrainTool::Stop(int deviceStatus) // when stop button is pressed gui_timer->stop(); calibrating = false; + load = 0; + slope = 0.0; + QDateTime now = QDateTime::currentDateTime(); if (status & RT_RECORDING) { @@ -860,7 +866,7 @@ void TrainTool::updateData(RealtimeData &rtData) displayCadence = rtData.getCadence(); displayHeartRate = rtData.getHr(); displaySpeed = rtData.getSpeed(); - displayLoad = rtData.getLoad(); + load = rtData.getLoad(); // Gradient not supported return; } @@ -873,6 +879,7 @@ void TrainTool::guiUpdate() // refreshes the telemetry { RealtimeData rtData; rtData.setLap(displayLap + displayWorkoutLap); // user laps + predefined workout lap + rtData.mode = mode; if (deviceController == NULL) return; @@ -888,6 +895,8 @@ void TrainTool::guiUpdate() // refreshes the telemetry // get latest telemetry from device (if it is a pull device e.g. Computrainer // if (status&RT_RUNNING && deviceController->doesPull() == true) { + rtData.setLoad(load); // always set load.. + rtData.setSlope(slope); // always set load.. deviceController->getRealtimeData(rtData); // Distance assumes current speed for the last second. from km/h to km/sec @@ -908,7 +917,7 @@ void TrainTool::guiUpdate() // refreshes the telemetry displayCadence = rtData.getCadence(); displayHeartRate = rtData.getHr(); displaySpeed = rtData.getSpeed(); - displayLoad = rtData.getLoad(); + load = rtData.getLoad(); // go update the displays... main->notifyTelemetryUpdate(rtData); // signal everyone to update telemetry @@ -1036,8 +1045,6 @@ void TrainTool::diskUpdate() void TrainTool::loadUpdate() { int curLap; - long load; - double gradient; // we hold our horses whilst calibration is taking place... if (calibrating) return; @@ -1057,21 +1064,19 @@ void TrainTool::loadUpdate() if (load == -100) { Stop(DEVICE_OK); } else { - displayLoad = load; - deviceController->setLoad(displayLoad); + deviceController->setLoad(load); main->notifySetNow(load_msecs); } } else { - gradient = ergFile->gradientAt(displayWorkoutDistance*1000, curLap); + slope = ergFile->gradientAt(displayWorkoutDistance*1000, curLap); displayWorkoutLap = curLap; // we got to the end! - if (gradient == -100) { + if (slope == -100) { Stop(DEVICE_OK); } else { - displayGradient = gradient; - deviceController->setGradient(displayGradient); + deviceController->setGradient(slope); main->notifySetNow(displayWorkoutDistance * 1000); } } @@ -1171,14 +1176,14 @@ void TrainTool::Higher() } else { - if (status&RT_MODE_ERGO) displayLoad += 5; - else displayGradient += 0.1; + if (status&RT_MODE_ERGO) load += 5; + else slope += 0.1; - if (displayLoad >1500) displayLoad = 1500; - if (displayGradient >15) displayGradient = 15; + if (load >1500) load = 1500; + if (slope >15) slope = 15; - if (status&RT_MODE_ERGO) deviceController->setLoad(displayLoad); - else deviceController->setGradient(displayGradient); + if (status&RT_MODE_ERGO) deviceController->setLoad(load); + else deviceController->setGradient(slope); } } @@ -1193,14 +1198,14 @@ void TrainTool::Lower() intensitySlider->setValue(intensitySlider->value()-5); } else { - if (status&RT_MODE_ERGO) displayLoad -= 5; - else displayGradient -= 0.1; + if (status&RT_MODE_ERGO) load -= 5; + else slope -= 0.1; - if (displayLoad <0) displayLoad = 0; - if (displayGradient <-10) displayGradient = -10; + if (load <0) load = 0; + if (slope <-10) slope = -10; - if (status&RT_MODE_ERGO) deviceController->setLoad(displayLoad); - else deviceController->setGradient(displayGradient); + if (status&RT_MODE_ERGO) deviceController->setLoad(load); + else deviceController->setGradient(slope); } } diff --git a/src/TrainTool.h b/src/TrainTool.h index 5ddc9833e..97757fe7c 100644 --- a/src/TrainTool.h +++ b/src/TrainTool.h @@ -186,9 +186,10 @@ class TrainTool : public GcWindow // updated with a RealtimeData object either from // update() - from a push device (quarqd ANT+) // Device->getRealtimeData() - from a pull device (Computrainer) - double displayPower, displayHeartRate, displayCadence, - displayLoad, displayGradient, displaySpeed; + double displayPower, displayHeartRate, displayCadence, displaySpeed; double displayDistance, displayWorkoutDistance; + long load; + double slope; int displayLap; // user increment for Lap int displayWorkoutLap; // which Lap in the workout are we at?