From 536a722822985c8b7f8dbcce97f199b6d6d096f5 Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Thu, 18 Jul 2024 16:23:21 +0200 Subject: [PATCH] example 'meshtastic': add battery voltage --- .../meshtastic/cpp/connection/connection.cpp | 4 ++-- examples/meshtastic/cpp/connection/connection.h | 2 +- examples/meshtastic/lisp/lora.lisp | 5 ++--- examples/meshtastic/lisp/radios.lisp | 2 +- .../meshtastic/qml/ext/radios/BatteryLevel.qml | 16 ++++++++++------ examples/meshtastic/qml/ext/radios/Radios.qml | 3 ++- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/meshtastic/cpp/connection/connection.cpp b/examples/meshtastic/cpp/connection/connection.cpp index 0c96fb1..7b23d7b 100644 --- a/examples/meshtastic/cpp/connection/connection.cpp +++ b/examples/meshtastic/cpp/connection/connection.cpp @@ -44,8 +44,8 @@ Connection::Connection() { #endif void Connection::setConnectionType(const QVariant& var) { - type = Type(BLE + (QList() << "BLE" << "USB" << "WIFI") - .indexOf(var.toByteArray())); + type = Type(QByteArrayList({"BLE", "USB", "WIFI"}) + .indexOf(var.toByteArray())); } void Connection::startDeviceDiscovery(const QVariant& var) { diff --git a/examples/meshtastic/cpp/connection/connection.h b/examples/meshtastic/cpp/connection/connection.h index f55e061..b3dc574 100644 --- a/examples/meshtastic/cpp/connection/connection.h +++ b/examples/meshtastic/cpp/connection/connection.h @@ -29,7 +29,7 @@ public: #endif enum Type { - BLE, USB, WiFi + BLE = 0, USB, WiFi }; WiFi_ME* wifi = nullptr; diff --git a/examples/meshtastic/lisp/lora.lisp b/examples/meshtastic/lisp/lora.lisp index cf53f08..40d43b8 100644 --- a/examples/meshtastic/lisp/lora.lisp +++ b/examples/meshtastic/lisp/lora.lisp @@ -343,9 +343,8 @@ (radios:add-radio (list :name name :hw-model (symbol-name (me:hw-model x:it)) - :battery-level (float (if metrics - (max 0 (min 100 (me:battery-level metrics))) - 0)) + :voltage (format nil "~1$V" (if metrics (me:voltage metrics) 0)) + :battery-level (format nil "~D%" (if metrics (max 0 (min 100 (me:battery-level metrics))) 0)) :current current)) (when current (app:update-current-device name))))))) diff --git a/examples/meshtastic/lisp/radios.lisp b/examples/meshtastic/lisp/radios.lisp index 5a52f56..3d9e99f 100644 --- a/examples/meshtastic/lisp/radios.lisp +++ b/examples/meshtastic/lisp/radios.lisp @@ -96,7 +96,7 @@ (defun add-radio (radio) "Adds passed RADIO (a PLIST) to QML item model. The model keys are: - :name :hw-model :battery-level :current" + :name :hw-model :voltage :battery-level :current" (qjs |addRadio| ui:*radios* radio)) (defun clear () diff --git a/examples/meshtastic/qml/ext/radios/BatteryLevel.qml b/examples/meshtastic/qml/ext/radios/BatteryLevel.qml index 792653d..6ac2573 100644 --- a/examples/meshtastic/qml/ext/radios/BatteryLevel.qml +++ b/examples/meshtastic/qml/ext/radios/BatteryLevel.qml @@ -3,32 +3,36 @@ import QtQuick 2.15 Rectangle { anchors.verticalCenter: parent.verticalCenter width: 12 - height: 22 + height: 25 color: (level > 15) ? "#f0f0f0" : "yellow" radius: 2 border.width: 1 border.color: "#808080" - property int level: 0 + property string voltage + property string level + + function percent() { return parseInt(level, 10) } Rectangle { x: 1 width: parent.width - 2 - height: (parent.height - 2) * level / 100 + height: (parent.height - 2) * percent() / 100 anchors.bottom: parent.bottom anchors.bottomMargin: 1 - color: (level > 15) ? "#28c940" : "#ff5f57" + color: (percent() > 15) ? "#28c940" : "#ff5f57" } Text { x: -4 - paintedWidth height: parent.height verticalAlignment: Text.AlignVCenter - font.pixelSize: 12 + horizontalAlignment: Text.AlignRight + font.pixelSize: 11 font.family: fontText.name font.weight: Font.DemiBold color: "white" - text: level + "%" + text: voltage + "\n" + level } } diff --git a/examples/meshtastic/qml/ext/radios/Radios.qml b/examples/meshtastic/qml/ext/radios/Radios.qml index 4691cb2..a164045 100644 --- a/examples/meshtastic/qml/ext/radios/Radios.qml +++ b/examples/meshtastic/qml/ext/radios/Radios.qml @@ -48,7 +48,7 @@ Rectangle { // hack to define all model key _types_ ListElement { - name: ""; ini: false; hwModel: ""; batteryLevel: 0; current: false + name: ""; ini: false; hwModel: ""; voltage: ""; batteryLevel: ""; current: false } function addRadio(radio) { @@ -108,6 +108,7 @@ Rectangle { Rad.BatteryLevel { anchors.right: parent.right anchors.rightMargin: 14 + voltage: model.voltage level: model.batteryLevel visible: !model.ini }