diff --git a/src/Kickr.cpp b/src/Kickr.cpp index 96e9367b2..30bec815d 100644 --- a/src/Kickr.cpp +++ b/src/Kickr.cpp @@ -26,6 +26,9 @@ Kickr::Kickr(QObject *parent, DeviceConfiguration *devConf) : QThread(parent) this->parent = parent; this->devConf = devConf; scanned = false; + mode = -1; + load = 100; + slope = 1.0; } Kickr::~Kickr() @@ -45,7 +48,7 @@ void Kickr::setMode(int mode, double load, double gradient) pvars.lock(); this->mode = mode; this->load = load; - this->gradient = gradient; + this->slope = gradient; pvars.unlock(); } @@ -61,7 +64,7 @@ void Kickr::setLoad(double load) void Kickr::setGradient(double gradient) { pvars.lock(); - this->gradient = gradient; + this->slope = gradient; pvars.unlock(); } @@ -92,7 +95,7 @@ double Kickr::getGradient() { double tmp; pvars.lock(); - tmp = gradient; + tmp = slope; pvars.unlock(); return tmp; } @@ -136,6 +139,10 @@ int Kickr::quit(int code) *----------------------------------------------------------------------*/ void Kickr::run() { + int currentmode = -1; + int currentload = -1; + double currentslope= -1; + // Connect to the device if (connectKickr()) { quit(2); @@ -145,8 +152,36 @@ void Kickr::run() running = true; while(running) { - // send load - //XXX todo + // make sure we are the right mode + if (currentmode != mode) { + + switch (mode) { + + default: + case RT_MODE_ERGO : + currentmode = RT_MODE_ERGO; + WFApi::getInstance()->setErgoMode(); + break; + + case RT_MODE_SLOPE : + currentmode = RT_MODE_SLOPE; + WFApi::getInstance()->setSlopeMode(); + break; + + } + } + + // set load + if (mode == RT_MODE_ERGO && currentload != load) { + WFApi::getInstance()->setLoad(load); + currentload = load; + } + + // set slope + if (mode == RT_MODE_SLOPE && currentslope != slope) { + WFApi::getInstance()->setSlope(slope); + currentslope = slope; + } msleep(100); @@ -163,7 +198,6 @@ void Kickr::run() } disconnectKickr(); - quit(0); } diff --git a/src/Kickr.h b/src/Kickr.h index e0947d1d5..75b23f1d9 100644 --- a/src/Kickr.h +++ b/src/Kickr.h @@ -26,6 +26,7 @@ #include #include #include "RealtimeController.h" +#include "TrainTool.h" #include "DeviceConfiguration.h" #include "WFApi.h" @@ -77,9 +78,10 @@ private: QMutex pvars; bool scanned, running, connected; + volatile int mode; volatile double load; - volatile double gradient; + volatile double slope; QString deviceUUID; RealtimeData rt; diff --git a/src/KickrController.h b/src/KickrController.h index f38ee95c4..48f1d3837 100644 --- a/src/KickrController.h +++ b/src/KickrController.h @@ -48,7 +48,10 @@ public: bool doesPush(), doesPull(), doesLoad(); void getRealtimeData(RealtimeData &rtData); void pushRealtimeData(RealtimeData &rtData); - void setLoad(double) { return; } + + void setLoad(double x) { myKickr->setLoad(x); } + void setGradient(double x) { myKickr->setGradient(x); } + void setMode(int x) { myKickr->setMode(x); } QString id() { return myKickr->id(); } diff --git a/src/TrainTool.h b/src/TrainTool.h index 3d43a2d53..7b350c6f7 100644 --- a/src/TrainTool.h +++ b/src/TrainTool.h @@ -40,6 +40,7 @@ // Status settings #define RT_MODE_ERGO 0x0001 // load generation modes #define RT_MODE_SPIN 0x0002 // spinscan like modes +#define RT_MODE_SLOPE 0x0002 // same as spinscan but not so CT specific #define RT_MODE_CALIBRATE 0x0004 // calibrate #define RT_RUNNING 0x0100 // is running now diff --git a/src/WFApi.h b/src/WFApi.h index b58b50460..271bc44dc 100644 --- a/src/WFApi.h +++ b/src/WFApi.h @@ -77,6 +77,14 @@ public: bool hasData(); void getRealtimeData(RealtimeData *p); + // set slope or ergo mode + void setSlopeMode(); + void setErgoMode(); + + // set resistance slope or load + void setSlope(double slope); + void setLoad(int watts); + signals: void currentStateChanged(int); // hardware conncector state changed int discoveredDevices(int,bool); diff --git a/src/WFApi.mm b/src/WFApi.mm index 9a8af1dde..a9d7e7874 100644 --- a/src/WFApi.mm +++ b/src/WFApi.mm @@ -146,19 +146,38 @@ static QString toQString(const NSString *nsstr) - (BOOL)disconnectDevice { [sensorConnection disconnect]; return true; } - (void)connection:(WFSensorConnection*)connectionInfo stateChanged:(WFSensorConnectionStatus_t)connState { -qDebug()<<"connected!"; qtw->connectionState(connState); } - (void)connectionDidTimeout:(WFSensorConnection*)connectionInfo { -qDebug()<<"tiemout"; qtw->connectionTimeout(); } - (BOOL) hasData { return [sensorConnection hasData]; } - (WFBikePowerData*) getData { return (WFBikePowerData*)[sensorConnection getData]; } +- (void) setSlopeMode +{ + [sensorConnection trainerSetSimMode:85 rollingResistance:0.0004 windResistance:0.6]; +} + +- (void) setErgoMode +{ + [sensorConnection trainerSetErgMode:100]; +} + +- (void) setSlope:(double)slope +{ + [sensorConnection trainerSetGrade:slope]; +} + +- (void) setLoad:(int)load +{ + [sensorConnection trainerSetErgMode:load]; +} + + //********************************************************************** // EVENTS / SIGNALS //********************************************************************** @@ -191,7 +210,6 @@ qDebug()<<"tiemout"; -(void)hardwareConnectorHasData { -qDebug()<<"delegate says has data"; qtw->connectorHasData(); } @@ -273,6 +291,32 @@ WFApi::deviceCount() return [wf deviceCount]; } +// set slope or ergo mode +void +WFApi::setSlopeMode() +{ + [wf setSlopeMode]; +} + +void +WFApi::setErgoMode() +{ + [wf setErgoMode]; +} + +// set resistance slope or load +void +WFApi::setSlope(double n) +{ + [wf setSlope:n]; +} + +void +WFApi::setLoad(int n) +{ + [wf setLoad:n]; +} + //********************************************************************** // SLOTS //********************************************************************** @@ -280,7 +324,6 @@ WFApi::deviceCount() void WFApi::connectedSensor(void*) { -qDebug()<<"connectedSensor"; } void @@ -292,13 +335,11 @@ WFApi::didDiscoverDevices(int count, bool finished) void WFApi::disconnectedSensor(void*) { -qDebug()<<"disconnectedSensor"; } void WFApi::hasFirmwareUpdateAvalableForConnection() { -qDebug()<<"hasFirmwareUpdate..."; } void @@ -310,13 +351,11 @@ WFApi::stateChanged() void WFApi::connectionState(int status) { - qDebug()<<"connection state changed..."<