Index: sources/view/settings/VBluetooth.cpp =================================================================== diff -u -rb252cd2777aadbce2d04aa32cc275f193de0cf52 -raeb915075b9e13e5c1aaf2800ba6db03b6c24a0b --- sources/view/settings/VBluetooth.cpp (.../VBluetooth.cpp) (revision b252cd2777aadbce2d04aa32cc275f193de0cf52) +++ sources/view/settings/VBluetooth.cpp (.../VBluetooth.cpp) (revision aeb915075b9e13e5c1aaf2800ba6db03b6c24a0b) @@ -42,99 +42,157 @@ this , SLOT( onDeviceSelect(QString, QString ))); } +/*! + * \brief View::VBluetooth::rowCount + * \details QAbstractItemModel::rowCount override + * \return Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning the number of children of parent. + */ int View::VBluetooth::rowCount(const QModelIndex &) const { return _devices.count(); } +/*! + * \brief View::VBluetooth::data + * \details QAbstractItemModel::data override + * \param index - the row index + * \param role - the row role + * \return Returns the data stored under the given role for the item referred to by the index. + */ +QVariant View::VBluetooth::data(const QModelIndex &index, int role) const +{ + if (index.row() < rowCount()) + switch (role) { + case ToStringRole : return _devices.at(index.row()).toString(); + case AddrRole : return _devices.at(index.row()).addr; + case NameRole : return _devices.at(index.row()).name; + case PairRole : return _devices.at(index.row()).pair; + default: return QVariant(); + } + return QVariant(); +} + +/*! + * \brief View::VBluetooth::roleNames + * \details QAbstractItemModel::roleNames override + * \return Returns the model's role names. + */ +QHash View::VBluetooth::roleNames() const +{ + static const QHash roles { + { ToStringRole, "toString" }, + { AddrRole, "addr" }, + { NameRole, "name" }, + { PairRole, "pair" } + }; + return roles; +} + +/*! + * \brief View::VBluetooth::reset + * \details Clears the list of the devices. + */ void View::VBluetooth::reset() { beginResetModel(); _devices.clear(); endResetModel(); } +/*! + * \brief View::VBluetooth::onStateChange + * \details Updates the View when the Bluetooth Interface state change signal is received. + * \param vData - The Bluetooth Interface information data. + */ void View::VBluetooth::onStateChange(const BluetoothData &vData) { - if ( vData.state == MBluetooth::eIS_Local_Error_POST ) { + pairedAddr(""); + Model::MBluetooth::InterfaceStates state = vData.state; + if ( state == MBluetooth::eIS_Local_Error_POST ) { isInvalid( true ); - notify( vData.state ); + notify( state ); return; } - scanEnabled( ! (vData.state == MBluetooth::eIS_Close || - // local - vData.state == MBluetooth::eIS_Local_Init || - // device - vData.state == MBluetooth::eIS_Device_Connect || - // service - vData.state == MBluetooth::eIS_Service_Start || - vData.state == MBluetooth::eIS_Service_Discover || - vData.state == MBluetooth::eIS_Service_Detail )); + // TODO: re-evaluate the states for the scan button enable/disable. + // scanEnabled(state == MBluetooth::eIS_Idle || + // state == MBluetooth::eIS_Scan_Done || + // state == MBluetooth::eIS_Scan_NotFound || + // state == MBluetooth::eIS_Device_Error || + // state == MBluetooth::eIS_Device_Waiting + // ); - switch (vData.state) { + switch (state) { // The device name is not always available and the interface may be in investigation. - case MBluetooth::eIS_Scan_NotFound : - case MBluetooth::eIS_Scan_Discover : - case MBluetooth::eIS_Scan_Found : - deviceAddr (vData.deviceAddr ); - deviceName (vData.deviceName ); - devicePair (vData.devicePair ); - break; - case MBluetooth::eIS_Local_Init : localAddr (vData.localAddr ); localName (vData.localName ); break; - case MBluetooth::eIS_Detail_Change : - case MBluetooth::eIS_Detail_Read : - case MBluetooth::eIS_Detail_Write : - case MBluetooth::eIS_Config_Read : - case MBluetooth::eIS_Config_Write : - detailName (vData.detailName ); - detailAddr (vData.detailAddr ); - detailValue (vData.detailValue ); + case MBluetooth::eIS_Scan_Start : + reset(); break; - case MBluetooth::eIS_Scan_Start : - reset(); + case MBluetooth::eIS_Scan_Done : + if (! _devices.count()) state = MBluetooth::eIS_Scan_NotFound; break; - case MBluetooth::eIS_Idle : - case MBluetooth::eIS_Local_Connect : - case MBluetooth::eIS_Local_Error_Invalid : - case MBluetooth::eIS_Local_Error_POST : - case MBluetooth::eIS_Local_Error_Off : - case MBluetooth::eIS_Local_Error_IO : - case MBluetooth::eIS_Local_Error : - case MBluetooth::eIS_Local_Disconnect : - case MBluetooth::eIS_Scan_Reject : - case MBluetooth::eIS_Scan_Stop : - case MBluetooth::eIS_Scan_Done : - case MBluetooth::eIS_Device_Init : - case MBluetooth::eIS_Device_Start : - case MBluetooth::eIS_Device_Connect : - case MBluetooth::eIS_Device_Error_Init : - case MBluetooth::eIS_Device_Error : - case MBluetooth::eIS_Device_Done : - case MBluetooth::eIS_Device_Disconnect : - case MBluetooth::eIS_Service_Start : - case MBluetooth::eIS_Service_Error : - case MBluetooth::eIS_Service_Discover : - case MBluetooth::eIS_Service_Detail : - case MBluetooth::eIS_Service_Detail_Invalid : - case MBluetooth::eIS_Service_Detail_Error : - case MBluetooth::eIS_Service_Detail_Done : - case MBluetooth::eIS_Service_Done : - case MBluetooth::eIS_Close : + + case MBluetooth::eIS_Device_Waiting : // Selected device connected and is in waiting mode for read. + pairedAddr(vData.deviceAddr); + pairedBatt(vData.deviceBatt); break; + + case MBluetooth::eIS_Idle : + case MBluetooth::eIS_Local_Connect : + case MBluetooth::eIS_Local_Error_Invalid : + case MBluetooth::eIS_Local_Error_POST : + case MBluetooth::eIS_Local_Error_Off : + case MBluetooth::eIS_Local_Error_IO : + case MBluetooth::eIS_Local_Error : + case MBluetooth::eIS_Local_Disconnect : + + case MBluetooth::eIS_Scan_Reject : + case MBluetooth::eIS_Scan_NotFound : + case MBluetooth::eIS_Scan_Discover : + case MBluetooth::eIS_Scan_Found : + case MBluetooth::eIS_Scan_Stop : + + case MBluetooth::eIS_Device_Init : + case MBluetooth::eIS_Device_Start : + case MBluetooth::eIS_Device_Connect : + case MBluetooth::eIS_Device_Error_Init : + case MBluetooth::eIS_Device_Error : + case MBluetooth::eIS_Device_Done : + case MBluetooth::eIS_Device_Disconnect : + + case MBluetooth::eIS_Service_Start : + case MBluetooth::eIS_Service_Invalid : + case MBluetooth::eIS_Service_Error : + case MBluetooth::eIS_Service_Discover : + case MBluetooth::eIS_Service_Detail : + case MBluetooth::eIS_Service_Detail_Error : + case MBluetooth::eIS_Service_Detail_Done : + case MBluetooth::eIS_Service_Done : + + case MBluetooth::eIS_Detail_Change : + case MBluetooth::eIS_Detail_Read : + case MBluetooth::eIS_Detail_Write : + case MBluetooth::eIS_Config_Read : + case MBluetooth::eIS_Config_Write : + + case MBluetooth::eIS_Close : + break; } error (vData.error ); - devicePin (vData.devicePin ); - notify( vData.state ); + notify( state ); } +/*! + * \brief View::VBluetooth::onDeviceChange + * \details updates the list of devices when a device data has been received. Used with Discovery Agent to populate list of discovered devices to the QML/UI. + * \param vDevice - The device information + */ void View::VBluetooth::onDeviceChange(const BluetoothDeviceData &vDevice) { int row = 0; @@ -143,14 +201,21 @@ _devices.insert(row, vDevice); endInsertRows(); + /* DEBUG: Found BCuff devices debug qDebug() << _devices.count(); - for (auto device: _devices) { qDebug() << device.addr << device.name << device.pair; } + */ } +/*! + * \brief View::VBluetooth::onDeviceSelect + * \details The signal handler of the device selection by user on the Bluetooth Cuff setting screen + * \param vAddr - The selected device address + * \param vName - The selected device name + */ void View::VBluetooth::onDeviceSelect(const QString &vAddr, const QString &vName) { BluetoothDeviceData data; @@ -159,6 +224,12 @@ emit _BluetoothInterface.didDeviceSelect(data); } +/*! + * \brief View::VBluetooth::toText + * \details Maps the BluetoothInterface state vState to its corresponding text message. + * \param vState - current state. + * \return corresponding message text mapped from the state cState. + */ QString View::VBluetooth::toText(MBluetooth::InterfaceStates vState) const { QString message; @@ -178,25 +249,26 @@ case MBluetooth::eIS_Scan_NotFound : message = tr("No Valid device found" ); break; case MBluetooth::eIS_Scan_Start : message = tr("Scanning ..." ); break; case MBluetooth::eIS_Scan_Reject : message = tr("Scanning Rejected" ); break; - case MBluetooth::eIS_Scan_Discover : message = tr("Device Discovered" ); break; + case MBluetooth::eIS_Scan_Discover : message = tr("Device Discovering ..." ); break; case MBluetooth::eIS_Scan_Found : message = tr("Blood Pressure Device Found" ); break; case MBluetooth::eIS_Scan_Stop : message = tr("Scanning Stopped" ); break; case MBluetooth::eIS_Scan_Done : message = tr("Scanning Finished" ); break; case MBluetooth::eIS_Device_Init : message = tr("Device Initializing ..." ); break; case MBluetooth::eIS_Device_Error_Init : message = tr("Device Initialization Error" ); break; case MBluetooth::eIS_Device_Start : message = tr("Device Connecting ..." ); break; + case MBluetooth::eIS_Device_Waiting : message = tr("Device Waiting ..." ); break; case MBluetooth::eIS_Device_Error : message = tr("Device Connection Error" ); break; case MBluetooth::eIS_Device_Connect : message = tr("Device Connected" ); break; case MBluetooth::eIS_Device_Done : message = tr("Device Clean Up" ); break; case MBluetooth::eIS_Device_Disconnect : message = tr("Device Disconnected" ); break; case MBluetooth::eIS_Service_Start : message = tr("Service Scanning ..." ); break; case MBluetooth::eIS_Service_Error : message = tr("Service Error: %1" ).arg(_error ); break; + case MBluetooth::eIS_Service_Invalid : message = tr("Service Invalid" ); break; case MBluetooth::eIS_Service_Discover : message = tr("Service Discovered" ); break; case MBluetooth::eIS_Service_Detail : message = tr("Service Detail Discovering ..." ); break; case MBluetooth::eIS_Service_Detail_Error : message = tr("Service Detail Error" ); break; - case MBluetooth::eIS_Service_Detail_Invalid : message = tr("Service Detail Invalid" ); break; case MBluetooth::eIS_Service_Detail_Done : message = tr("Service Detail Done" ); break; case MBluetooth::eIS_Service_Done : message = tr("Service Clean Up" ); break; @@ -210,6 +282,11 @@ return message; } +/*! + * \brief View::VBluetooth::notify + * \details Notifies the QML/UI about the state change and sends its test mapping to the QML/UI observers. + * \param vState - The current state + */ void View::VBluetooth::notify(MBluetooth::InterfaceStates vState) { QString message = toText(vState); @@ -226,9 +303,9 @@ } } -void View::VBluetooth::doScan () { _BluetoothInterface.doScan (); } -void View::VBluetooth::doConnectToDevice () { _BluetoothInterface.doConnectToDevice (); } -void View::VBluetooth::doDiscoverServices () { _BluetoothInterface.doDiscoverServices (); } -void View::VBluetooth::doEnableNotify () { _BluetoothInterface.doEnableNotify (); } -void View::VBluetooth::doReadMeasurements () { _BluetoothInterface.doReadMeasurements (); } -void View::VBluetooth::doReadInformation () { _BluetoothInterface.doReadInformation (); } +/*! + * \brief View::VBluetooth::doScan + * \details calls the Bluetooth Interface scan to start discovering the Bluetooth devices. + */ +void View::VBluetooth::doScan() { + _BluetoothInterface.doScan(); }