BT40 / Kickr device discovery

Ensure the Kickr and BT40 devices can co-exist by
ignoring subtypes.

Also introduced a deviceFound signal so we can get a
device pairing page for BT40 (non-Kickr) devices.
This commit is contained in:
Mark Liversedge
2013-01-30 10:47:01 +00:00
parent 9a4919a210
commit f67aca2ffb
10 changed files with 116 additions and 9 deletions

View File

@@ -26,6 +26,8 @@ BT40::BT40(QObject *parent, DeviceConfiguration *devConf) : QThread(parent)
mode = -1;
load = 100;
slope = 1.0;
connect(WFApi::getInstance(), SIGNAL(discoveredDevices(int,bool)), this, SLOT(discoveredDevices(int,bool)));
}
BT40::~BT40()
@@ -189,6 +191,24 @@ void BT40::run()
quit(0);
}
void
BT40::discoveredDevices(int n, bool finished)
{
WFApi *w = WFApi::getInstance();
// need to emit signal with device uuid and type
// this is used by the add device wizard.
// but only emit as they are found, not at the end
// when search times out -- we want them as they
// arrive.
if (!finished && w->deviceSubType(n-1) != WFApi::WF_SENSOR_SUBTYPE_BIKE_POWER_KICKR) {
qDebug()<<"BT40 discovered a bluetooth device.."
<<w->deviceUUID(n-1)
<<w->deviceType(n-1);
emit foundDevice(w->deviceUUID(n-1), w->deviceType(n-1));
}
}
bool
BT40::find()
{

View File

@@ -68,6 +68,12 @@ public:
QString id() { return deviceUUID; }
signals:
void foundDevice(QString uuid, int type);
private slots:
void discoveredDevices(int,bool);
private:
void run(); // called by start to kick off the CT comtrol thread

View File

@@ -23,6 +23,7 @@
BT40Controller::BT40Controller(TrainTool *parent, DeviceConfiguration *dc) : RealtimeController(parent, dc)
{
myBT40 = new BT40(parent, dc);
connect(myBT40, SIGNAL(foundDevice(QString,int)), this, SIGNAL(foundDevice(QString,int)));
}
void

View File

@@ -56,6 +56,7 @@ public:
QString id() { return myBT40->id(); }
signals:
void foundDevice(QString uuid, int type);
private:

View File

@@ -26,6 +26,8 @@ Kickr::Kickr(QObject *parent, DeviceConfiguration *devConf) : QThread(parent)
mode = -1;
load = 100;
slope = 1.0;
connect(WFApi::getInstance(), SIGNAL(discoveredDevices(int,bool)), this, SLOT(discoveredDevices(int,bool)));
}
Kickr::~Kickr()
@@ -189,6 +191,24 @@ void Kickr::run()
quit(0);
}
void
Kickr::discoveredDevices(int n, bool finished)
{
WFApi *w = WFApi::getInstance();
// need to emit signal with device uuid and type
// this is used by the add device wizard.
// but only emit as they are found, not at the end
// when search times out -- we want them as they
// arrive.
if (!finished && w->deviceSubType(n-1) == WFApi::WF_SENSOR_SUBTYPE_BIKE_POWER_KICKR) {
qDebug()<<"KIKCR? discovered a device.."
<<w->deviceUUID(n-1)
<<w->deviceType(n-1);
emit foundDevice(w->deviceUUID(n-1), w->deviceType(n-1));
}
}
bool
Kickr::find()
{

View File

@@ -68,6 +68,12 @@ public:
QString id() { return deviceUUID; }
signals:
void foundDevice(QString uuid, int type);
private slots:
void discoveredDevices(int,bool);
private:
void run(); // called by start to kick off the CT comtrol thread

View File

@@ -23,6 +23,7 @@
KickrController::KickrController(TrainTool *parent, DeviceConfiguration *dc) : RealtimeController(parent, dc)
{
myKickr = new Kickr(parent, dc);
connect(myKickr, SIGNAL(foundDevice(QString,int)), this, SIGNAL(foundDevice(QString,int)));
}
void

View File

@@ -56,6 +56,7 @@ public:
QString id() { return myKickr->id(); }
signals:
void foundDevice(QString uuid, int type);
private:

View File

@@ -86,14 +86,42 @@ public:
int connectionStatus(int sd);
bool isConnected(int sd);
// just the types we need
// all the sensor types just the types we need
enum {
WF_SENSORTYPE_NONE = 0,
WF_SENSORTYPE_BIKE_POWER = 1 };
WF_SENSORTYPE_NONE = 0,
WF_SENSORTYPE_BIKE_POWER = 0x00000001, // kickr, inride etc
WF_SENSORTYPE_BIKE_SPEED = 0x00000002,
WF_SENSORTYPE_BIKE_CADENCE = 0x00000004,
WF_SENSORTYPE_BIKE_SPEED_CADENCE = 0x00000008,
WF_SENSORTYPE_FOOTPOD = 0x00000010,
WF_SENSORTYPE_HEARTRATE = 0x00000020,
WF_SENSORTYPE_WEIGHT_SCALE = 0x00000040,
WF_SENSORTYPE_ANT_FS = 0x00000080,
WF_SENSORTYPE_LOCATION = 0x00000100,
WF_SENSORTYPE_CALORIMETER = 0x00000200,
WF_SENSORTYPE_GEO_CACHE = 0x00000400,
WF_SENSORTYPE_FITNESS_EQUIPMENT = 0x00000800,
WF_SENSORTYPE_MULTISPORT_SPEED_DISTANCE = 0x00001000,
WF_SENSORTYPE_PROXIMITY = 0x00002000,
WF_SENSORTYPE_HEALTH_THERMOMETER = 0x00004000,
WF_SENSORTYPE_BLOOD_PRESSURE = 0x00008000,
WF_SENSORTYPE_BTLE_GLUCOSE = 0x00010000,
WF_SENSORTYPE_GLUCOSE = 0x00020000,
WF_SENSORTYPE_DISPLAY = 0x00800000 };
// subtypes -- esp. power
enum {
WF_SENSOR_SUBTYPE_UNSPECIFIED = 0,
WF_SENSOR_SUBTYPE_BIKE_POWER_KICKR = 1,
WF_SENSOR_SUBTYPE_BIKE_POWER_STAGE_ONE = 2,
WF_SENSOR_SUBTYPE_BIKE_POWER_IN_RIDE = 3 };
// scan
bool discoverDevicesOfType(int eSensorType);
int deviceCount();
QString deviceUUID(int); // return the UUID for device n
int deviceType(int); // return the device type
int deviceSubType(int); // return the subtype found
// connect and disconnect
int connectDevice(QString uuid); // connect the device n

View File

@@ -109,8 +109,18 @@ static inline NSString* fromQString(const QString &string)
-(int)deviceCount { return [discoveredSensors count]; }
-(NSString*)deviceUUID:(int)n
{
WFDeviceParams* connParams = (WFDeviceParams*)[discoveredSensors objectAtIndex:n];
return connParams.deviceUUIDString;
WFConnectionParams* connParams = (WFConnectionParams*)[discoveredSensors objectAtIndex:n];
return connParams.device1.deviceUUIDString;
}
-(int)deviceType:(int)n
{
WFConnectionParams* connParams = (WFConnectionParams*)[discoveredSensors objectAtIndex:n];
return (int)connParams.sensorType;
}
-(int)deviceSubType:(int)n
{
WFConnectionParams* connParams = (WFConnectionParams*)[discoveredSensors objectAtIndex:n];
return (int)connParams.sensorSubType;
}
//============================================================================
@@ -214,10 +224,13 @@ static inline NSString* fromQString(const QString &string)
// devices discovered
-(void)hardwareConnector:(WFHardwareConnector*)hwConnector didDiscoverDevices:(NSSet*)connectionParams searchCompleted:(BOOL)bCompleted
{ Q_UNUSED(hwConnector);
// add discovered devices.
for (WFConnectionParams* connParams in connectionParams) {
[discoveredSensors addObject:connParams.device1];
}
if (!bCompleted) {
// add discovered devices -- as they are discovered, not at the end.
for (WFConnectionParams* connParams in connectionParams) {
[discoveredSensors addObject:connParams];
}
}
qtw->didDiscoverDevices([connectionParams count], bCompleted);
}
@@ -263,6 +276,16 @@ QString WFApi::deviceUUID(int n)
if (n>=0 && n<deviceCount()) return toQString([wf deviceUUID:n]);
else return "";
}
int WFApi::deviceType(int n)
{
if (n>=0 && n<deviceCount()) return (int)[wf deviceType:n];
else return -1;
}
int WFApi::deviceSubType(int n)
{
if (n>=0 && n<deviceCount()) return (int)[wf deviceSubType:n];
else return -1;
}
int WFApi::connectionStatus(int sd) { return [wf connectionStatus:(WFSensorConnection*)connections.at(sd)]; }
bool WFApi::isConnected(int sd) { return [wf isConnected:(WFSensorConnection*)connections.at(sd)]; }