example 'meshtastic': let user select device, remember latest one used, update for android 12

This commit is contained in:
pls.153 2023-06-22 15:09:15 +02:00
parent ae461af4ca
commit 96d6843267
29 changed files with 461 additions and 216 deletions

View file

@ -20,14 +20,18 @@ BLE::BLE(const QBluetoothUuid& uuid) : mainServiceUuid(uuid) {
}
void BLE::startDeviceDiscovery() {
connected = false;
scanned = false;
currentDevice = QBluetoothDeviceInfo();
devices.clear();
qDebug() << "scanning for devices...";
discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
}
void BLE::addDevice(const QBluetoothDeviceInfo& device) {
if (deviceFilter(device)) {
qDebug() << "device added:" << device.name() << device.address().toString();
qDebug() << "device added:" << device.name();
}
}
@ -51,7 +55,7 @@ void BLE::scanServices() {
return;
}
if (!currentDevice.isValid()) {
if (initialDeviceName.isNull()) {
if (initialDeviceName.isEmpty()) {
currentDevice = devices.at(0);
} else {
for (auto device : qAsConst(devices)) {
@ -64,7 +68,7 @@ void BLE::scanServices() {
}
services.clear();
qDebug() << "connecting to device...";
if (controller && (previousAddress != currentDevice.address())) {
if (controller) {
Q_EMIT deviceDisconnecting();
controller->disconnectFromDevice();
delete controller; controller = nullptr;
@ -85,7 +89,6 @@ void BLE::scanServices() {
}
controller->connectToDevice();
previousAddress = currentDevice.address();
}
void BLE::setCurrentDevice(const QBluetoothDeviceInfo& device) {
@ -160,8 +163,7 @@ void BLE::disconnectFromDevice() {
}
void BLE::deviceDisconnected() {
connected = false;
qDebug() << "disconnect from device";
qDebug() << "disconnected from device";
}
void BLE::deviceScanError(QBluetoothDeviceDiscoveryAgent::Error error) {