mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-09 12:00:32 -08:00
example 'meshtastic': let user select device, remember latest one used, update for android 12
This commit is contained in:
parent
ae461af4ca
commit
96d6843267
29 changed files with 461 additions and 216 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue