example 'meshtastic': add option to exclude BLE support; revisions

This commit is contained in:
pls.153 2024-06-19 15:16:26 +02:00
parent 8a9fb55850
commit fed3fe1671
14 changed files with 94 additions and 20 deletions

View file

@ -1,10 +1,12 @@
#include "connection.h"
#include "ble/ble_me.h"
#include "wifi/wifi_me.h"
#include <QStandardPaths>
#include <QFile>
#include <QDataStream>
#ifndef NO_BLE
#include "ble/ble_me.h"
#endif
#ifndef NO_USB
#ifdef Q_OS_ANDROID
#include "usb/usb_me.android.h"
@ -31,7 +33,9 @@ Connection::Connection(QtAndroidService* service) {
}
#else
Connection::Connection() {
#ifndef NO_BLE
ble = new BLE_ME(this);
#endif
#ifndef NO_USB
usb = new USB_ME(this);
#endif
@ -47,21 +51,27 @@ void Connection::setConnectionType(const QVariant& var) {
void Connection::startDeviceDiscovery(const QVariant& var) {
switch (type) {
case BLE:
#ifndef NO_USB
#ifndef NO_BLE
#ifndef NO_USB
usb->disconnect();
#endif
#endif
wifi->disconnect();
ble->startDeviceDiscovery(var.toString());
#endif
break;
case USB:
#ifndef NO_USB
#ifndef NO_BLE
ble->disconnect();
#endif
wifi->disconnect();
usb->connectToRadio();
#endif
break;
case WiFi:
#ifndef NO_BLE
ble->disconnect();
#endif
#ifndef NO_USB
usb->disconnect();
#endif
@ -71,13 +81,17 @@ void Connection::startDeviceDiscovery(const QVariant& var) {
}
void Connection::stopDeviceDiscovery() {
#ifndef NO_BLE
ble->stopDeviceDiscovery();
#endif
}
void Connection::disconnect() {
switch (type) {
case BLE:
#ifndef NO_BLE
ble->disconnect();
#endif
break;
case USB:
#ifndef NO_USB
@ -91,18 +105,24 @@ void Connection::disconnect() {
}
void Connection::setDeviceFilter(const QVariant& vName) {
#ifndef NO_BLE
ble->setDeviceFilter(vName.toString());
#endif
}
void Connection::read2() {
#ifndef NO_BLE
ble->read();
#endif
}
void Connection::write2(const QVariant& vBytes) {
QByteArray bytes = vBytes.toByteArray();
switch (type) {
case BLE:
#ifndef NO_BLE
ble->write(bytes);
#endif
break;
case USB:
#ifndef NO_USB

View file

@ -3,9 +3,11 @@
#include <QObject>
#include <QVariant>
class BLE_ME;
class WiFi_ME;
#ifndef NO_BLE
class BLE_ME;
#endif
#ifndef NO_USB
class USB_ME;
#endif
@ -28,9 +30,13 @@ public:
BLE, USB, WiFi
};
WiFi_ME* wifi = nullptr;
#ifndef NO_BLE
Type type = BLE;
BLE_ME* ble = nullptr;
WiFi_ME* wifi = nullptr;
#else
Type type = USB;
#endif
#ifndef NO_USB
USB_ME* usb = nullptr;
#endif

View file

@ -152,6 +152,17 @@ QVariant QT::wifiConnectable(const QVariant& vIP) {
return QVariant();
}
QVariant QT::hasFeature(const QVariant& vName) {
auto name = vName.toString().toLower();
#ifndef NO_BLE
if (name == "ble") return true;
#endif
#ifndef NO_USB
if (name == "usb") return true;
#endif
return QVariant();
}
// SQLite
QVariant QT::iniDb(const QVariant& vName) {

View file

@ -31,6 +31,7 @@ public:
Q_INVOKABLE QVariant read2();
Q_INVOKABLE QVariant write2(const QVariant&);
Q_INVOKABLE QVariant wifiConnectable(const QVariant&);
Q_INVOKABLE QVariant hasFeature(const QVariant&);
// GPS
#ifdef Q_OS_ANDROID

View file

@ -1,3 +1,6 @@
# to set manually (when no BLE available)
#CONFIG += no_ble
QT += sql network bluetooth serialport
TEMPLATE = lib
CONFIG += c++17 plugin release no_keywords
@ -9,22 +12,32 @@ TARGET = qt
OBJECTS_DIR = ./tmp/
MOC_DIR = ./tmp/
no_ble {
DEFINES += NO_BLE
QT -= bluetooth
}
HEADERS += \
connection/connection.h \
connection/ble/ble.h \
connection/ble/ble_me.h \
connection/usb/usb_me.h \
connection/wifi/wifi_me.h \
qt.h
SOURCES += \
connection/connection.cpp \
connection/ble/ble.cpp \
connection/ble/ble_me.cpp \
connection/usb/usb_me.cpp \
connection/wifi/wifi_me.cpp \
qt.cpp
!no_ble {
HEADERS += \
connection/ble/ble.h \
connection/ble/ble_me.h
SOURCES += \
connection/ble/ble.cpp \
connection/ble/ble_me.cpp
}
linux {
LIBS += -L../../../platforms/linux/lib
}