diff --git a/src/BT40.cpp b/src/BT40.cpp index 216149b96..f9c9c8617 100644 --- a/src/BT40.cpp +++ b/src/BT40.cpp @@ -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.." + <deviceUUID(n-1) + <deviceType(n-1); + emit foundDevice(w->deviceUUID(n-1), w->deviceType(n-1)); + } +} + bool BT40::find() { diff --git a/src/BT40.h b/src/BT40.h index 6565f64c3..8a7b8ae04 100644 --- a/src/BT40.h +++ b/src/BT40.h @@ -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 diff --git a/src/BT40Controller.cpp b/src/BT40Controller.cpp index 83d8588be..498d20c52 100644 --- a/src/BT40Controller.cpp +++ b/src/BT40Controller.cpp @@ -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 diff --git a/src/BT40Controller.h b/src/BT40Controller.h index 216d6dc81..030cfc4f5 100644 --- a/src/BT40Controller.h +++ b/src/BT40Controller.h @@ -56,6 +56,7 @@ public: QString id() { return myBT40->id(); } signals: + void foundDevice(QString uuid, int type); private: diff --git a/src/Kickr.cpp b/src/Kickr.cpp index a19417a9c..87be4f7d4 100644 --- a/src/Kickr.cpp +++ b/src/Kickr.cpp @@ -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.." + <deviceUUID(n-1) + <deviceType(n-1); + emit foundDevice(w->deviceUUID(n-1), w->deviceType(n-1)); + } +} + bool Kickr::find() { diff --git a/src/Kickr.h b/src/Kickr.h index 464920acc..2ba5488ea 100644 --- a/src/Kickr.h +++ b/src/Kickr.h @@ -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 diff --git a/src/KickrController.cpp b/src/KickrController.cpp index 50e5883eb..bcf607914 100644 --- a/src/KickrController.cpp +++ b/src/KickrController.cpp @@ -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 diff --git a/src/KickrController.h b/src/KickrController.h index 48f1d3837..64f3c4f2e 100644 --- a/src/KickrController.h +++ b/src/KickrController.h @@ -56,6 +56,7 @@ public: QString id() { return myKickr->id(); } signals: + void foundDevice(QString uuid, int type); private: diff --git a/src/WFApi.h b/src/WFApi.h index 509e3b2c0..62da2b51d 100644 --- a/src/WFApi.h +++ b/src/WFApi.h @@ -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 diff --git a/src/WFApi.mm b/src/WFApi.mm index 5c165e649..a2d609783 100644 --- a/src/WFApi.mm +++ b/src/WFApi.mm @@ -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=0 && n=0 && n