mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Kickr BTLE Support (Beta)
This finalises beta support for the Wahoo Kickr using their WFConnector API for BTLE. This support will only work on Mac OSX - pending ANT+ support to be available and/or BTLE support is made available on Windows and Linux. Fixes #446.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <QMutex>
|
||||
#include <QFile>
|
||||
#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;
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
55
src/WFApi.mm
55
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..."<<status;
|
||||
}
|
||||
|
||||
void
|
||||
WFApi::connectionTimeout()
|
||||
{
|
||||
qDebug()<<"connection timed out...";
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user