Fix bluetooth wifi setup for bluez backends
This commit is contained in:
parent
336e21aabc
commit
871e2c0ce8
@ -166,10 +166,13 @@ void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice:
|
|||||||
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothDiscovery::deviceDiscovered);
|
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothDiscovery::deviceDiscovered);
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &BluetoothDiscovery::deviceDiscovered);
|
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &BluetoothDiscovery::deviceDiscovered);
|
||||||
|
#elif (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
|
||||||
|
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred, this, &BluetoothDiscovery::onError);
|
||||||
|
#else
|
||||||
|
connect(m_discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onError(QBluetoothDeviceDiscoveryAgent::Error)));
|
||||||
#endif
|
#endif
|
||||||
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BluetoothDiscovery::discoveryFinished);
|
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BluetoothDiscovery::discoveryFinished);
|
||||||
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BluetoothDiscovery::discoveryCancelled);
|
connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BluetoothDiscovery::discoveryCancelled);
|
||||||
connect(m_discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onError(QBluetoothDeviceDiscoveryAgent::Error)));
|
|
||||||
}
|
}
|
||||||
if (m_discoveryEnabled && !m_discoveryAgent->isActive()) {
|
if (m_discoveryEnabled && !m_discoveryAgent->isActive()) {
|
||||||
start();
|
start();
|
||||||
|
|||||||
@ -54,6 +54,10 @@ BtWiFiSetup::BtWiFiSetup(QObject *parent) : QObject(parent)
|
|||||||
{
|
{
|
||||||
m_accessPoints = new WirelessAccessPoints(this);
|
m_accessPoints = new WirelessAccessPoints(this);
|
||||||
qRegisterMetaType<BluetoothDeviceInfo*>("const BluetoothDeviceInfo*");
|
qRegisterMetaType<BluetoothDeviceInfo*>("const BluetoothDeviceInfo*");
|
||||||
|
|
||||||
|
connect(this, &BtWiFiSetup::bluetoothStatusChanged, this, [this](){
|
||||||
|
qCDebug(dcBtWiFiSetup()) << "Bluetooth status changed" << m_bluetoothStatus;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BtWiFiSetup::~BtWiFiSetup()
|
BtWiFiSetup::~BtWiFiSetup()
|
||||||
@ -81,13 +85,18 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this);
|
m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this);
|
||||||
connect(m_btController, &QLowEnergyController::connected, this, [this](){
|
connect(m_btController, &QLowEnergyController::connected, this, [this, device](){
|
||||||
qCInfo(dcBtWiFiSetup()) << "Bluetooth connected";
|
qCInfo(dcBtWiFiSetup()) << "Bluetooth connected" << device->address() << device->name();
|
||||||
m_btController->discoverServices();
|
m_btController->discoverServices();
|
||||||
m_bluetoothStatus = BluetoothStatusConnectedToBluetooth;
|
m_bluetoothStatus = BluetoothStatusConnectedToBluetooth;
|
||||||
emit bluetoothStatusChanged(m_bluetoothStatus);
|
emit bluetoothStatusChanged(m_bluetoothStatus);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
|
||||||
|
connect(m_btController, &QLowEnergyController::stateChanged, this, [](QLowEnergyController::ControllerState state){
|
||||||
|
qCInfo(dcBtWiFiSetup()) << "Bluetooth constroller state changed" << state;
|
||||||
|
});
|
||||||
|
|
||||||
connect(m_btController, &QLowEnergyController::disconnected, this, [this](){
|
connect(m_btController, &QLowEnergyController::disconnected, this, [this](){
|
||||||
qCInfo(dcBtWiFiSetup()) << "Bluetooth disconnected";
|
qCInfo(dcBtWiFiSetup()) << "Bluetooth disconnected";
|
||||||
m_bluetoothStatus = BluetoothStatusDisconnected;
|
m_bluetoothStatus = BluetoothStatusDisconnected;
|
||||||
|
|||||||
@ -65,6 +65,8 @@ PlatformPermissions::PermissionStatus PlatformPermissionsAndroid::checkPermissio
|
|||||||
switch (platformPermission) {
|
switch (platformPermission) {
|
||||||
case PlatformPermissions::PermissionBluetooth: {
|
case PlatformPermissions::PermissionBluetooth: {
|
||||||
QBluetoothPermission permission;
|
QBluetoothPermission permission;
|
||||||
|
// Only request scan/connect access; advertising isn't needed and isn't declared in the manifest.
|
||||||
|
permission.setCommunicationModes(QBluetoothPermission::Access);
|
||||||
|
|
||||||
const auto permissionStatus = qApp->checkPermission(permission);
|
const auto permissionStatus = qApp->checkPermission(permission);
|
||||||
|
|
||||||
@ -194,7 +196,10 @@ void PlatformPermissionsAndroid::requestPermission(PlatformPermissions::Permissi
|
|||||||
switch (platformPermission) {
|
switch (platformPermission) {
|
||||||
case PlatformPermissions::PermissionBluetooth:
|
case PlatformPermissions::PermissionBluetooth:
|
||||||
qCDebug(dcPlatformPermissions()) << "Requesting bluetooth permission";
|
qCDebug(dcPlatformPermissions()) << "Requesting bluetooth permission";
|
||||||
qApp->requestPermission(QBluetoothPermission{}, [platformPermission](const QPermission &permission) {
|
{
|
||||||
|
QBluetoothPermission permission;
|
||||||
|
permission.setCommunicationModes(QBluetoothPermission::Access);
|
||||||
|
qApp->requestPermission(permission, [platformPermission](const QPermission &permission) {
|
||||||
if (permission.status() == Qt::PermissionStatus::Denied) {
|
if (permission.status() == Qt::PermissionStatus::Denied) {
|
||||||
qCWarning(dcPlatformPermissions()) << "Bluetooth permission denied.";
|
qCWarning(dcPlatformPermissions()) << "Bluetooth permission denied.";
|
||||||
s_instance->m_requestedButDeniedPermissions.append(platformPermission);
|
s_instance->m_requestedButDeniedPermissions.append(platformPermission);
|
||||||
@ -204,7 +209,8 @@ void PlatformPermissionsAndroid::requestPermission(PlatformPermissions::Permissi
|
|||||||
qCDebug(dcPlatformPermissions()) << "Bluetooth permission granted.";
|
qCDebug(dcPlatformPermissions()) << "Bluetooth permission granted.";
|
||||||
|
|
||||||
emit s_instance->bluetoothPermissionChanged();
|
emit s_instance->bluetoothPermissionChanged();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PlatformPermissions::PermissionLocation: {
|
case PlatformPermissions::PermissionLocation: {
|
||||||
QLocationPermission locationPermission;
|
QLocationPermission locationPermission;
|
||||||
|
|||||||
@ -297,7 +297,7 @@ WizardPageBase {
|
|||||||
callback: function() {
|
callback: function() {
|
||||||
var nymeaHost = hostsProxy.get(index);
|
var nymeaHost = hostsProxy.get(index);
|
||||||
var connectionInfoDialog = Qt.createComponent("/ui/components/ConnectionInfoDialog.qml")
|
var connectionInfoDialog = Qt.createComponent("/ui/components/ConnectionInfoDialog.qml")
|
||||||
print("**", connectionInfoDialog.errorString())
|
console.log("**", connectionInfoDialog.errorString())
|
||||||
var popup = connectionInfoDialog.createObject(app,{nymeaEngine: engine, nymeaHost: nymeaHost})
|
var popup = connectionInfoDialog.createObject(app,{nymeaEngine: engine, nymeaHost: nymeaHost})
|
||||||
popup.open()
|
popup.open()
|
||||||
popup.connectionSelected.connect(function(connection) {
|
popup.connectionSelected.connect(function(connection) {
|
||||||
@ -322,7 +322,7 @@ WizardPageBase {
|
|||||||
|
|
||||||
onNext: {
|
onNext: {
|
||||||
var rpcUrl = manualEntry.rpcUrl;
|
var rpcUrl = manualEntry.rpcUrl;
|
||||||
print("Try to connect ", rpcUrl)
|
console.log("Try to connect ", rpcUrl)
|
||||||
var host = nymeaDiscovery.nymeaHosts.createWanHost("Manual connection", rpcUrl);
|
var host = nymeaDiscovery.nymeaHosts.createWanHost("Manual connection", rpcUrl);
|
||||||
engine.jsonRpcClient.connectToHost(host)
|
engine.jsonRpcClient.connectToHost(host)
|
||||||
}
|
}
|
||||||
@ -390,8 +390,8 @@ WizardPageBase {
|
|||||||
BtWiFiSetup {
|
BtWiFiSetup {
|
||||||
id: wifiSetup
|
id: wifiSetup
|
||||||
|
|
||||||
onBluetoothStatusChanged: {
|
onBluetoothStatusChanged: (status) => {
|
||||||
print("status changed", status)
|
console.log("status changed", status)
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case BtWiFiSetup.BluetoothStatusDisconnected:
|
case BtWiFiSetup.BluetoothStatusDisconnected:
|
||||||
pageStack.pop(wirelessBluetoothDiscoveryPage)
|
pageStack.pop(wirelessBluetoothDiscoveryPage)
|
||||||
@ -419,12 +419,12 @@ WizardPageBase {
|
|||||||
|
|
||||||
onCurrentConnectionChanged: {
|
onCurrentConnectionChanged: {
|
||||||
if (wifiSetup.currentConnection) {
|
if (wifiSetup.currentConnection) {
|
||||||
print("**** connected!")
|
console.log("**** connected!")
|
||||||
pageStack.push(wirelessConnectionCompletedComponent, {wifiSetup: wifiSetup})
|
pageStack.push(wirelessConnectionCompletedComponent, {wifiSetup: wifiSetup})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onWirelessStatusChanged: {
|
onWirelessStatusChanged: {
|
||||||
print("Wireless status changed:", wifiSetup.networkStatus)
|
console.log("Wireless status changed:", wifiSetup.networkStatus)
|
||||||
if (wifiSetup.wirelessStatus === BtWiFiSetup.WirelessStatusFailed) {
|
if (wifiSetup.wirelessStatus === BtWiFiSetup.WirelessStatusFailed) {
|
||||||
pageStack.pop()
|
pageStack.pop()
|
||||||
}
|
}
|
||||||
@ -452,7 +452,9 @@ WizardPageBase {
|
|||||||
|
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count == 0 && bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled && PlatformHelper.locationServicesEnabled
|
visible: bluetoothDiscovery.discovering && deviceInfosProxy.count === 0 &&
|
||||||
|
bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled &&
|
||||||
|
PlatformHelper.locationServicesEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: NymeaSwipeDelegate {
|
delegate: NymeaSwipeDelegate {
|
||||||
@ -609,7 +611,7 @@ WizardPageBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
print("Connect to ", model.ssid, " --> ", model.macAddress)
|
console.log("Connect to ", model.ssid, " --> ", model.macAddress)
|
||||||
if (model.selectedNetwork) {
|
if (model.selectedNetwork) {
|
||||||
pageStack.push(networkInformationPage, { ssid: model.ssid})
|
pageStack.push(networkInformationPage, { ssid: model.ssid})
|
||||||
} else {
|
} else {
|
||||||
@ -642,7 +644,7 @@ WizardPageBase {
|
|||||||
onBack: pageStack.pop();
|
onBack: pageStack.pop();
|
||||||
|
|
||||||
onNext: {
|
onNext: {
|
||||||
print("connecting to", ssidTextField.text, passwordTextField.password)
|
console.log("connecting to", ssidTextField.text, passwordTextField.password)
|
||||||
wifiSetup.connectDeviceToWiFi(ssidTextField.text, passwordTextField.password, true)
|
wifiSetup.connectDeviceToWiFi(ssidTextField.text, passwordTextField.password, true)
|
||||||
pageStack.push(wirelessConnectingWiFiComponent)
|
pageStack.push(wirelessConnectingWiFiComponent)
|
||||||
}
|
}
|
||||||
@ -690,7 +692,7 @@ WizardPageBase {
|
|||||||
showNextButton: passwordTextField.isValidPassword
|
showNextButton: passwordTextField.isValidPassword
|
||||||
|
|
||||||
onNext: {
|
onNext: {
|
||||||
print("connecting to", ssid, passwordTextField.password)
|
console.log("connecting to", ssid, passwordTextField.password)
|
||||||
wifiSetup.connectDeviceToWiFi(ssid, passwordTextField.password)
|
wifiSetup.connectDeviceToWiFi(ssid, passwordTextField.password)
|
||||||
pageStack.push(wirelessConnectingWiFiComponent)
|
pageStack.push(wirelessConnectingWiFiComponent)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user