example 'meshtastic': review WiFi mode

This commit is contained in:
pls.153 2024-05-03 16:50:27 +02:00
parent df62fd4a21
commit 5e16e9594e
7 changed files with 90 additions and 45 deletions

View file

@ -59,7 +59,7 @@ win32 {
android {
QT += remoteobjects
DEFINES += INI_ASDF
DEFINES += INI_ASDF NO_USB
DEFINES -= DESKTOP_APP
INCLUDEPATH = $$ECL/include
ECL_VERSION = $$lower($$system($$ECL/../ecl-android-host/bin/ecl -v))
@ -105,7 +105,8 @@ android {
}
ios {
DEFINES += INI_ASDF
QT -= serialport
DEFINES += INI_ASDF NO_USB NO_WIFI
DEFINES -= DESKTOP_APP
INCLUDEPATH = $$(ECL_IOS)/include
ECL_VERSION = $$lower($$system($ECL_IOS/../ecl-ios-host/bin/ecl -v))
@ -177,6 +178,15 @@ SOURCES += \
cpp/connection/wifi/wifi_me.cpp
}
ios {
HEADERS -= \
cpp/connection/usb/usb_me.h \
cpp/connection/wifi/wifi_me.h
SOURCES -= \
cpp/connection/usb/usb_me.cpp \
cpp/connection/wifi/wifi_me.cpp
}
RESOURCES += $$files(qml/*)
RESOURCES += $$files(i18n/*.qm)
RESOURCES += $$files(lisp/proto/meshtastic/*.lisp)

View file

@ -1,6 +1,7 @@
QT += core bluetooth remoteobjects
QT += core bluetooth network remoteobjects
TEMPLATE = lib
CONFIG += c++17 dll
DEFINES += NO_USB
INCLUDEPATH += $$PWD
TARGET = service
DESTDIR = ../../build-android

View file

@ -1,17 +1,22 @@
#include "connection.h"
#include "ble/ble_me.h"
#include "wifi/wifi_me.h"
#include <QStandardPaths>
#include <QFile>
#include <QDataStream>
#ifndef NO_USB
#include "usb/usb_me.h"
#endif
#ifndef NO_WIFI
#include "wifi/wifi_me.h"
#endif
#ifdef Q_OS_ANDROID
#include "../android_service/qtandroidservice_ro.h"
#if (QT_VERSION < 0x060000)
#include <QAndroidService>
#endif
#else
#include "usb/usb_me.h"
#endif
#ifdef Q_OS_ANDROID
@ -25,8 +30,12 @@ Connection::Connection(QtAndroidService* service) {
#else
Connection::Connection() {
ble = new BLE_ME(this);
#ifndef NO_USB
usb = new USB_ME(this);
#endif
#ifndef NO_WIFI
wifi = new WiFi_ME(this);
#endif
}
#endif
@ -38,25 +47,31 @@ void Connection::setConnectionType(const QVariant& var) {
void Connection::startDeviceDiscovery(const QVariant& var) {
switch (type) {
case BLE:
#ifndef Q_OS_ANDROID
#ifndef NO_USB
usb->disconnect();
#endif
#ifndef NO_WIFI
wifi->disconnect();
#endif
ble->startDeviceDiscovery(var.toString());
break;
case USB:
ble->disconnect();
#ifndef NO_WIFI
wifi->disconnect();
#ifndef Q_OS_ANDROID
#endif
#ifndef NO_USB
usb->connectToRadio();
#endif
break;
case WiFi:
ble->disconnect();
#ifndef Q_OS_ANDROID
#ifndef NO_USB
usb->disconnect();
#endif
#ifndef NO_WIFI
wifi->connectToRadio(var.toString());
#endif
break;
}
}
@ -68,10 +83,12 @@ void Connection::stopDeviceDiscovery() {
void Connection::disconnect() {
switch (type) {
case BLE: ble->disconnect(); break;
#ifndef Q_OS_ANDROID
#ifndef NO_USB
case USB: usb->disconnect(); break;
#endif
#ifndef NO_WIFI
case WiFi: wifi->disconnect(); break;
#endif
}
}
@ -86,17 +103,13 @@ void Connection::read2() {
void Connection::write2(const QVariant& vBytes) {
QByteArray bytes = vBytes.toByteArray();
switch (type) {
case BLE:
ble->write(bytes);
break;
case USB:
#ifndef Q_OS_ANDROID
usb->write2(bytes);
case BLE: ble->write(bytes); break;
#ifndef NO_USB
case USB: usb->write2(bytes); break;
#endif
#ifndef NO_WIFI
case WiFi: wifi->write2(bytes); break;
#endif
break;
case WiFi:
wifi->write2(bytes);
break;
}
}

View file

@ -4,8 +4,13 @@
#include <QVariant>
class BLE_ME;
#ifndef NO_USB
class USB_ME;
#endif
#ifndef NO_WIFI
class WiFi_ME;
#endif
#ifdef Q_OS_ANDROID
class QtAndroidService;
@ -27,8 +32,12 @@ public:
Type type = BLE;
BLE_ME* ble = nullptr;
#ifndef NO_USB
USB_ME* usb = nullptr;
#endif
#ifndef NO_WIFI
WiFi_ME* wifi = nullptr;
#endif
bool backgroundMode = false;
void setConnectionType(const QVariant&);

View file

@ -106,13 +106,17 @@ QT::QT() : QObject() {
// background mode
QObject::connect(qGuiApp, &QGuiApplication::applicationStateChanged,
[&](Qt::ApplicationState state) {
static bool ok = false; // for startup
if (state == Qt::ApplicationInactive) {
ok = true;
con->setBackgroundMode(true);
ecl_fun("app:background-mode-changed", true);
} else if (state == Qt::ApplicationActive) {
if (ok) {
con->setBackgroundMode(false);
ecl_fun("app:background-mode-changed", false);
}
}
});
#endif
}

View file

@ -52,21 +52,8 @@ To manually restart device discovery, press-and-hold on the radio icon.
If your radio is not found, it may help to turn it off/on again.
</p>
%1
<h4>USB</h4>
Desktop only. You may need to install serial drivers first, and you need to use a data USB cable.
<h4>WiFi</h4>
<p>
Use the Python CLI to setup your connection like this:
</p>
<pre>
meshtastic &#92;
--set network.wifi_enabled true &#92;
--set network.wifi_ssid \"&lt;name&gt;\" &#92;
--set network.wifi_psk \"&lt;password&gt;\"
</pre>
<p>
The app will ask for your radio IP, which can be found on its screen as soon as it is connected to WiFi.
</p>
%2
%3
<h3>
<img src='../../img/group.png' width=60 height=60>
<br>Group
@ -146,9 +133,29 @@ Eventual backups are saved in above path under <code>backups/</code>. On the des
<p>
To autmatically restore data from a backup on the desktop, put the backup files directly in above path (that is, under <code>.../cl-meshtastic/</code>) and restart the app. The data will be restored and the (obsolete) backup files will be deleted.
</p>".arg((Qt.platform.os === "android")
? "<p>On some devices it may be necessary to first unpair your radio, then press-and-hold on the radio icon (to restart device discovery).</p><p><i>N.B: If you previously used a radio with the official app, you'll need to set the radio to 'None (disabled)' in the official app first, otherwise it will not show up in this app.</i></p>"
? "<p>On some devices it may be necessary to first unpair your radio, then press-and-hold on the radio icon (to restart device discovery).</p><p><i>N.B: If you previously used a radio with the official app, you'll need to disable the radio in the official app first, otherwise it will not show up in this app.</i></p>"
: "")
.arg(((Qt.platform.os !== "android") && (Qt.platform.os !== "ios"))
? "<h4>USB</h4>
<p>
You may need to install serial drivers first, and you need to use a data USB cable.
</p>"
: "")
.arg((Qt.platform.os !== "ios")
? "<h4>WiFi</h4>
<p>
Use the Python CLI to setup your connection like this:
</p>
<pre>
meshtastic &#92;
--set network.wifi_enabled true &#92;
--set network.wifi_ssid \"&lt;name&gt;\" &#92;
--set network.wifi_psk \"&lt;password&gt;\"
</pre>
<p>
The app will ask for your radio IP, which can be found on its screen as soon as it is connected to WiFi.
</p>"
: "")
}
}

View file

@ -88,6 +88,7 @@ Item {
text: "WiFi"
autoExclusive: true
checkable: true
enabled: (Qt.platform.os !== "ios")
onTriggered: connection.changed(objectName)
}
}