diff --git a/examples/meshtastic/app.asd b/examples/meshtastic/app.asd index 1a140be..63cfe33 100644 --- a/examples/meshtastic/app.asd +++ b/examples/meshtastic/app.asd @@ -19,3 +19,4 @@ (:file "lisp/lora") (:file "lisp/location") (:file "lisp/main"))) + diff --git a/examples/meshtastic/cpp/qt.cpp b/examples/meshtastic/cpp/qt.cpp index b08b8d0..8f5bbfb 100644 --- a/examples/meshtastic/cpp/qt.cpp +++ b/examples/meshtastic/cpp/qt.cpp @@ -146,6 +146,17 @@ QVariant QT::sqlQuery(const QVariant& vQuery, const QVariant& vValues) { // etc +QVariant QT::dataPath() { + // for desktop + static QString path; + if (path.isEmpty()) { + path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + path.truncate(path.lastIndexOf(QChar('/'))); + path.append("/cl-meshtastic/data/"); + } + return path; +} + QVariant QT::localIp() { // Returns the local IP string. Private networks may use: // 10.*.*.* diff --git a/examples/meshtastic/cpp/qt.h b/examples/meshtastic/cpp/qt.h index 68098b6..6b18856 100644 --- a/examples/meshtastic/cpp/qt.h +++ b/examples/meshtastic/cpp/qt.h @@ -34,6 +34,7 @@ public: Q_INVOKABLE QVariant sqlQuery(const QVariant&, const QVariant&); // etc + Q_INVOKABLE QVariant dataPath(); Q_INVOKABLE QVariant localIp(); Q_INVOKABLE QVariant startTileServer(); diff --git a/examples/meshtastic/lisp/db.lisp b/examples/meshtastic/lisp/db.lisp index 6c2b428..7b4bde9 100644 --- a/examples/meshtastic/lisp/db.lisp +++ b/examples/meshtastic/lisp/db.lisp @@ -1,11 +1,12 @@ (in-package :db) -(defvar *file* (merge-pathnames "data/db")) +(defvar *file* nil) (defun query (query &rest values) (qt:sql-query qt:*cpp* query values)) (defun ini () + (setf *file* (app:in-data-path "db")) (ensure-directories-exist *file*) (qt:ini-db qt:*cpp* (namestring *file*)) (query "create table if not exists messages (mid integer primary key, uid integer, message text)")) diff --git a/examples/meshtastic/lisp/location.lisp b/examples/meshtastic/lisp/location.lisp index be6bbe9..1386de8 100644 --- a/examples/meshtastic/lisp/location.lisp +++ b/examples/meshtastic/lisp/location.lisp @@ -81,7 +81,7 @@ 0))) (defun tile-path () - (namestring (merge-pathnames "data/tiles/"))) + (namestring (app:in-data-path "tiles/"))) (defun activate-map () (unless (q< |active| ui:*map-loader*) diff --git a/examples/meshtastic/lisp/main.lisp b/examples/meshtastic/lisp/main.lisp index d6f57a9..0761ccf 100644 --- a/examples/meshtastic/lisp/main.lisp +++ b/examples/meshtastic/lisp/main.lisp @@ -18,6 +18,12 @@ (ensure-permissions :bluetooth-scan :bluetooth-connect)) ; android >= 12 (lora:start-device-discovery (or (setting :device) ""))) +(defun in-data-path (file) + #+mobile + (merge-pathnames (x:cc "data/" file)) + #-mobile + (x:cc (qt:data-path qt:*cpp*) file)) + (defun view-index-changed (index) ; see QML (when (and (= 1 index) (not (app:setting :latest-receiver))) @@ -37,17 +43,17 @@ ;;; settings -(defvar *file* (merge-pathnames "data/settings.exp")) - -(defun load-settings () - (when (probe-file *file*) - (with-open-file (s *file*) - (setf lora:*settings* (read s))))) - -(defun save-settings () - (with-open-file (s *file* :direction :output :if-exists :supersede) - (let ((*print-pretty* nil)) - (prin1 lora:*settings* s)))) +(let (file) + (defun load-settings () + (unless file + (setf file (in-data-path "settings.exp"))) + (when (probe-file file) + (with-open-file (s file) + (setf lora:*settings* (read s))))) + (defun save-settings () + (with-open-file (s file :direction :output :if-exists :supersede) + (let ((*print-pretty* nil)) + (prin1 lora:*settings* s))))) (defun kw (string) "Intern in KEYWORD package." diff --git a/examples/meshtastic/lisp/package.lisp b/examples/meshtastic/lisp/package.lisp index b837cbc..9eca34b 100644 --- a/examples/meshtastic/lisp/package.lisp +++ b/examples/meshtastic/lisp/package.lisp @@ -3,6 +3,7 @@ (:export #:change-setting #:icon-press-and-hold + #:in-data-path #:ini #:load-settings #:my-ip diff --git a/examples/meshtastic/lisp/qt.lisp b/examples/meshtastic/lisp/qt.lisp index 3026a56..a557ef2 100644 --- a/examples/meshtastic/lisp/qt.lisp +++ b/examples/meshtastic/lisp/qt.lisp @@ -2,6 +2,7 @@ (:use :cl :qml) (:export #:*cpp* + #:data-path #:ini #:ini-db #:ini-positioning diff --git a/examples/meshtastic/readme-usage.md b/examples/meshtastic/readme-usage.md index 168c631..2004c4b 100644 --- a/examples/meshtastic/readme-usage.md +++ b/examples/meshtastic/readme-usage.md @@ -99,8 +99,9 @@ Save / Restore data ------------------- A local web-server is included on mobile for saving and restoring the message -DB and the app settings. Just use special text message `:w` (for 'web-server') -and `:ws` (for 'stop web-server') after you're done. +DB, the app settings, plus eventually cached map tiles (for offline usage). +Just use special text message `:w` (for 'web-server') and `:ws` (for 'stop +web-server') after you're done. After starting the server, just enter the shown URL in your desktop browser, and follow the instructions. @@ -108,6 +109,12 @@ and follow the instructions. Using this method you can easily transfer all data from one mobile device to any other device. +The desktop data paths are: + +* Linux: `~/.local/share/cl-meshtastic/data/` +* macOS: `~/Library/Application Support/cl-meshtastic/data/` +* Windows: TODO + Tips ----