void Device
::connectToService(const QString &uuid
) {
QLowEnergyService *service = 0;
for (int i = 0; i < m_services.size(); i++) {
ServiceInfo *serviceInfo = (ServiceInfo*)m_services.at(i);
if (serviceInfo->getUuid() == uuid) {
service = serviceInfo->service();
break;
}
}
if (!service)
return;
qDeleteAll(m_characteristics);
m_characteristics.clear();
emit characteristicsUpdated();
if (service->state() == QLowEnergyService::DiscoveryRequired) {
//! [les-service-3]
connect(service, SIGNAL(stateChanged(QLowEnergyService::ServiceState)),
this, SLOT(serviceDetailsDiscovered(QLowEnergyService::ServiceState)));
service->discoverDetails();
setUpdate("Back\n(Discovering details...)");
//! [les-service-3]
return;
}
//discovery already done
const QList<QLowEnergyCharacteristic> chars = service->characteristics();
foreach (const QLowEnergyCharacteristic &ch, chars) {
CharacteristicInfo *cInfo = new CharacteristicInfo(ch);
m_characteristics.append(cInfo);
//GI new Code
// Write to motor
//const QLowEnergyCharacteristic link = service->characteristic(QBluetoothUuid(Device_UUID_Motor_Characteristic));
const QLowEnergyCharacteristic link = service->characteristic(QBluetoothUuid(Device_UUID_Session_Characteristic));
if (service->state() == QLowEnergyService::ServiceDiscovered){
//service->QLowEnergyService::writeCharacteristic(link,QByteArray::fromHex("01991000"),QLowEnergyService::WriteWithoutResponse);
//service->writeCharacteristic(link,QByteArray::fromHex("01330100"),QLowEnergyService::WriteWithoutResponse); //Motor
service
->writeCharacteristic
(link,
QByteArray::fromHex("000000003C03E80005015032"),QLowEnergyService
::WriteWithoutResponse);
//Session }
//End GI Code
}
QTimer::singleShot(0,
this,
SIGNAL(characteristicsUpdated
()));
}
void Device::connectToService(const QString &uuid)
{
QLowEnergyService *service = 0;
for (int i = 0; i < m_services.size(); i++) {
ServiceInfo *serviceInfo = (ServiceInfo*)m_services.at(i);
if (serviceInfo->getUuid() == uuid) {
service = serviceInfo->service();
break;
}
}
if (!service)
return;
qDeleteAll(m_characteristics);
m_characteristics.clear();
emit characteristicsUpdated();
if (service->state() == QLowEnergyService::DiscoveryRequired) {
//! [les-service-3]
connect(service, SIGNAL(stateChanged(QLowEnergyService::ServiceState)),
this, SLOT(serviceDetailsDiscovered(QLowEnergyService::ServiceState)));
service->discoverDetails();
setUpdate("Back\n(Discovering details...)");
//! [les-service-3]
return;
}
//discovery already done
const QList<QLowEnergyCharacteristic> chars = service->characteristics();
foreach (const QLowEnergyCharacteristic &ch, chars) {
CharacteristicInfo *cInfo = new CharacteristicInfo(ch);
m_characteristics.append(cInfo);
//GI new Code
// Write to motor
//const QLowEnergyCharacteristic link = service->characteristic(QBluetoothUuid(Device_UUID_Motor_Characteristic));
const QLowEnergyCharacteristic link = service->characteristic(QBluetoothUuid(Device_UUID_Session_Characteristic));
if (service->state() == QLowEnergyService::ServiceDiscovered){
//service->QLowEnergyService::writeCharacteristic(link,QByteArray::fromHex("01991000"),QLowEnergyService::WriteWithoutResponse);
//service->writeCharacteristic(link,QByteArray::fromHex("01330100"),QLowEnergyService::WriteWithoutResponse); //Motor
service->writeCharacteristic(link,QByteArray::fromHex("000000003C03E80005015032"),QLowEnergyService::WriteWithoutResponse); //Session
}
//End GI Code
}
QTimer::singleShot(0, this, SIGNAL(characteristicsUpdated()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks