From 8a9fb5585058ffd1a00ffeabeade0f3badffc563 Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Sat, 8 Jun 2024 18:26:08 +0200 Subject: [PATCH] example 'meshtastic': fix node map --- examples/meshtastic-qt6/qml/ext/group/Map.qml | 4 +-- examples/meshtastic-qt6/qml/main.qml | 9 +++-- examples/meshtastic/cpp/android.cpp | 1 + examples/meshtastic/lisp/location.lisp | 34 +++++++++++++------ examples/meshtastic/lisp/lora.lisp | 15 ++++---- examples/meshtastic/lisp/messages.lisp | 5 +-- examples/meshtastic/lisp/package.lisp | 1 + examples/meshtastic/qml/ext/group/Map.qml | 4 +-- examples/meshtastic/qml/main.qml | 9 +++-- 9 files changed, 53 insertions(+), 29 deletions(-) diff --git a/examples/meshtastic-qt6/qml/ext/group/Map.qml b/examples/meshtastic-qt6/qml/ext/group/Map.qml index ceec262..06acb08 100644 --- a/examples/meshtastic-qt6/qml/ext/group/Map.qml +++ b/examples/meshtastic-qt6/qml/ext/group/Map.qml @@ -62,7 +62,7 @@ Item { if (pos) { var marker = markers.itemAt(n) marker.radioName = name - marker.customName = customName + marker.customName = (customName === "~") ? "" : customName marker.coordinate = coordinate(pos) marker.visible = true } @@ -71,7 +71,7 @@ Item { function updatePositions(myNum, myName, group) { var n = 0 showMarker(n++, myNum, myName) - for (var i = 0; i < group.count; i++) { + for (var i = 1; i < group.count; i++) { var data = group.get(i) showMarker(n++, data.nodeNum, data.radioName, data.customName) } diff --git a/examples/meshtastic-qt6/qml/main.qml b/examples/meshtastic-qt6/qml/main.qml index a3ba1b7..e3b7c75 100644 --- a/examples/meshtastic-qt6/qml/main.qml +++ b/examples/meshtastic-qt6/qml/main.qml @@ -56,8 +56,9 @@ Item { Com.MenuItem { objectName: "share_location" - text: qsTr("Share my location...") - onTriggered: Lisp.call("loc:share-my-location") + text: qsTr("Share my location") + checkable: true + onTriggered: Lisp.call("loc:share-my-location", checked) } MenuSeparator {} @@ -179,6 +180,7 @@ Item { property double lat: 0 property double lon: 0 + property double alt: 0 property string time: "0" // no 'long' in JS onPositionChanged: { @@ -186,6 +188,7 @@ Item { var coor = position.coordinate; lat = coor.latitude lon = coor.longitude + alt = position.altitudeValid ? coor.altitude : 0 if (position.timestamp) { var stime = String(position.timestamp.getTime()) time = stime.substring(0, stime.length - 3) @@ -196,7 +199,7 @@ Item { } function lastPosition() { - return [lat, lon, time] + return [lat, lon, alt, time] } } diff --git a/examples/meshtastic/cpp/android.cpp b/examples/meshtastic/cpp/android.cpp index 4e851aa..8189dd5 100644 --- a/examples/meshtastic/cpp/android.cpp +++ b/examples/meshtastic/cpp/android.cpp @@ -101,6 +101,7 @@ QVariant QT::lastPosition() { QVariantList pos; pos << getDoubleField("position_lat") << getDoubleField("position_lon") + << getDoubleField("position_alt") << getLongField("position_time"); return pos; } diff --git a/examples/meshtastic/lisp/location.lisp b/examples/meshtastic/lisp/location.lisp index 421c130..1dcf292 100644 --- a/examples/meshtastic/lisp/location.lisp +++ b/examples/meshtastic/lisp/location.lisp @@ -1,13 +1,17 @@ (in-package :loc) +(defvar *share-location* nil) (defvar *positions* nil) (defvar *manual-position* nil) (defvar *gps-position* nil) +(defvar *last-updated* 0) -(defparameter *default-position* (list :lat 41.89193 :lon 12.51133 :time 0) ; Rome +(defparameter *default-position* (list :lat 41.89193 :lon 12.51133 :alt 0 :time 0) ; Rome "Position of map center for manual position selection (no GPS).") (defun ini () + (setf *share-location* (app:setting :share-location)) + (q> |checked| ui:*share-location* *share-location*) #+android (qt:ini-positioning qt:*cpp*) #+(or ios sfos) (q> |active| ui:*position-source* t) (x:when-it (app:setting :selected-position) @@ -22,30 +26,37 @@ (setf (third pos) (parse-integer time))) ; see QML pos)) -(defun share-my-location () ; see QML +(defun share-my-location (share) ; see QML "Share GPS position (ad hoc only)." - (app:confirm-dialog (tr "Share my location now?") 'do-share-my-location) + (setf *share-location* share) + (app:change-setting :share-location share) + (send-to-radio) (values)) -(defun do-share-my-location (share) - (when share - (send-to-radio))) - #+(or android ios sfos) (defun update-my-position (&optional (sec 60)) ; try for 1 min "Store current position internally, without sharing it, so we have a base for eventual manual position setting." - (destructuring-bind (lat lon time) + (destructuring-bind (lat lon alt time) (latest-gps-position) (if (zerop lat) (unless (zerop sec) (qsingle-shot 1000 (lambda () (update-my-position (1- sec))))) - (let ((pos (list :lat lat :lon lon :time time))) + (let ((pos (list :lat lat :lon lon :alt alt :time time))) (setf *gps-position* pos) - (qlog "position-updated: ~A" pos))))) + (qlog "position-updated: ~A" pos) + (send-to-radio))))) + +(defun check-position-update () + #+(or android ios sfos) + (let ((now (get-universal-time)) + (15min 900)) + (when (> (- now *last-updated*) 15min) + (setf *last-updated* now) + (update-my-position)))) (defun send-to-radio () - (when (app:setting :share-location) + (when *share-location* (if lora:*config-complete* (lora:send-position (or *manual-position* *gps-position*)) (qsingle-shot (* 15 1000) 'send-to-radio)))) @@ -71,6 +82,7 @@ (app:change-setting :selected-position *manual-position*) (qlog "position-updated: ~A" pos)) (q> |visible| ui:*remove-marker* t) + (qlater 'send-to-radio) (values)) (defun remove-marker () ; see QML diff --git a/examples/meshtastic/lisp/lora.lisp b/examples/meshtastic/lisp/lora.lisp index a9fb59e..c70a458 100644 --- a/examples/meshtastic/lisp/lora.lisp +++ b/examples/meshtastic/lisp/lora.lisp @@ -11,11 +11,12 @@ (defvar *config-lora* nil) (defvar *ble-names* nil) -(defvar *print-json* #+mobile nil - #-mobile t +(defvar *print-json* #+mobile nil + #-mobile t "Print all sent/received protobuf packets as json to terminal.") -(defvar *log-packets* t +(defvar *log-packets* #+mobile nil + #-mobile t "Write all raw protobuf data sent/received to a file.") (defun ini () @@ -176,7 +177,8 @@ (qt:write* qt:*cpp* bytes))) ((:usb :wifi) (qrun* - (qt:write* qt:*cpp* (concatenate 'vector header bytes))))))) + (qt:write* qt:*cpp* (concatenate 'vector header bytes)))))) + (loc:check-position-update)) (let (queue) (defun send-enqueued (&rest functions) ; see Qt @@ -379,7 +381,8 @@ (me:name (me:settings *my-channel*)))) (qlater 'config-device)) (radios:choose-region)))))) - (setf *received* nil))) + (setf *received* nil) + (loc:check-position-update))) (defun radio-ready-p () (or (and *config-complete* @@ -485,7 +488,7 @@ (me:make-position :latitude-i (to-int (getf pos :lat)) :longitude-i (to-int (getf pos :lon)) - :time (getf pos :time)) + :altitude (max 0 (min #.(expt 10 5) (floor (or (getf pos :alt) 0))))) (me:make-position))) ; unset :want-response t))))) diff --git a/examples/meshtastic/lisp/messages.lisp b/examples/meshtastic/lisp/messages.lisp index 1e35cad..8caa4f4 100644 --- a/examples/meshtastic/lisp/messages.lisp +++ b/examples/meshtastic/lisp/messages.lisp @@ -31,8 +31,9 @@ :hidden" (x:when-it (getf message (if (getf message :me) :receiver :sender)) (unless (or loading (getf message :me)) - (x:when-it* (app:setting (getf message :sender) :custom-name) - (setf (getf message :sender-name) x:it*))) + (let ((name (app:setting (getf message :sender) :custom-name))) + (when (and name (string/= "~" name)) + (setf (getf message :sender-name) name)))) (unless loading (let ((id (getf message :mid))) (remf message :mid) diff --git a/examples/meshtastic/lisp/package.lisp b/examples/meshtastic/lisp/package.lisp index d060e13..ed7d841 100644 --- a/examples/meshtastic/lisp/package.lisp +++ b/examples/meshtastic/lisp/package.lisp @@ -142,6 +142,7 @@ #:*positions* #:activate-map #:add-manual-marker + #:check-position-update #:distance #:extract-map-bin #:ini diff --git a/examples/meshtastic/qml/ext/group/Map.qml b/examples/meshtastic/qml/ext/group/Map.qml index ed978f1..65ff7db 100644 --- a/examples/meshtastic/qml/ext/group/Map.qml +++ b/examples/meshtastic/qml/ext/group/Map.qml @@ -59,7 +59,7 @@ Item { if (pos) { var marker = markers.itemAt(n) marker.radioName = name - marker.customName = customName + marker.customName = (customName === "~") ? "" : customName marker.coordinate = coordinate(pos) marker.visible = true } @@ -68,7 +68,7 @@ Item { function updatePositions(myNum, myName, group) { var n = 0 showMarker(n++, myNum, myName) - for (var i = 0; i < group.count; i++) { + for (var i = 1; i < group.count; i++) { var data = group.get(i) showMarker(n++, data.nodeNum, data.radioName, data.customName) } diff --git a/examples/meshtastic/qml/main.qml b/examples/meshtastic/qml/main.qml index 97d2658..c6f53be 100644 --- a/examples/meshtastic/qml/main.qml +++ b/examples/meshtastic/qml/main.qml @@ -55,8 +55,9 @@ Item { Com.MenuItem { objectName: "share_location" - text: qsTr("Share my location...") - onTriggered: Lisp.call("loc:share-my-location") + text: qsTr("Share my location") + checkable: true + onTriggered: Lisp.call("loc:share-my-location", checked) } MenuSeparator {} @@ -178,6 +179,7 @@ Item { property double lat: 0 property double lon: 0 + property double alt: 0 property string time: "0" // no 'long' in JS onPositionChanged: { @@ -185,6 +187,7 @@ Item { var coor = position.coordinate; lat = coor.latitude lon = coor.longitude + alt = position.altitudeValid ? coor.altitude : 0 if (position.timestamp) { var stime = String(position.timestamp.getTime()) time = stime.substring(0, stime.length - 3) @@ -195,7 +198,7 @@ Item { } function lastPosition() { - return [lat, lon, time] + return [lat, lon, alt, time] } }