example 'meshtastic': add broadcast messages

This commit is contained in:
pls.153 2023-09-11 14:23:52 +02:00
parent 1d0bafb4f8
commit 62a97d2b4b
6 changed files with 56 additions and 25 deletions

View file

@ -13,6 +13,14 @@
"Adds passed PERSON (a PLIST) to QML item model. "Adds passed PERSON (a PLIST) to QML item model.
The model keys are: The model keys are:
:radio-name :custom-name :node-num :unread :current" :radio-name :custom-name :node-num :unread :current"
(when (zerop (q< |count| ui:*group*))
;; special item 'Broadcast'
(qjs |addPerson| ui:*group*
(list :radio-name lora:*broadcast-name*
:custom-name (tr "Broadcast")
:node-num lora:+broadcast-id+
:current (equal (app:setting :latest-receiver)
lora:*broadcast-name*))))
(qjs |addPerson| ui:*group* person)) (qjs |addPerson| ui:*group* person))
(defun clear () (defun clear ()
@ -31,18 +39,20 @@
(q> |visible| ui:*unread-messages* state)) (q> |visible| ui:*unread-messages* state))
(defun set-unread (name n) (defun set-unread (name n)
(qjs |setUnread| ui:*group* (unless (string= lora:*broadcast-name* name)
name n) (qjs |setUnread| ui:*group*
(when (plusp n) name n)
(set-unread-state t))) (when (plusp n)
(set-unread-state t))))
(defun receiver-changed () (defun receiver-changed ()
(let ((curr-name (app:setting :latest-receiver))) (let ((curr-name (app:setting :latest-receiver)))
(app:change-setting curr-name 0 :sub-key :unread-messages) (unless (string= lora:*broadcast-name* curr-name)
(set-unread curr-name 0) (app:change-setting curr-name 0 :sub-key :unread-messages)
(dolist (name (radio-names)) (set-unread curr-name 0)
(x:when-it (app:setting name :unread-messages) (dolist (name (radio-names))
(unless (zerop x:it) (x:when-it (app:setting name :unread-messages)
(return-from receiver-changed)))) (unless (zerop x:it)
(set-unread-state nil))) (return-from receiver-changed))))
(set-unread-state nil))))

View file

@ -28,6 +28,9 @@
;;; ini/send/receive ;;; ini/send/receive
(defconstant +broadcast-id+ #xffffffff)
(defparameter *broadcast-name* "ffff")
(defvar *config-id* 0) (defvar *config-id* 0)
(defvar *config-complete* nil) (defvar *config-complete* nil)
(defvar *notify-id* nil) (defvar *notify-id* nil)
@ -162,9 +165,11 @@
(values)) (values))
(defun node-to-name (num) (defun node-to-name (num)
(dolist (info *node-infos*) (if (= +broadcast-id+ num)
(when (= num (me:num info)) *broadcast-name*
(return (me:short-name (me:user info)))))) (dolist (info *node-infos*)
(when (= num (me:num info))
(return (me:short-name (me:user info)))))))
(defun name-to-node (name) (defun name-to-node (name)
(dolist (info *node-infos*) (dolist (info *node-infos*)

View file

@ -26,6 +26,8 @@
(:local-nicknames (:pr :cl-protobufs) (:local-nicknames (:pr :cl-protobufs)
(:me :cl-protobufs.meshtastic)) (:me :cl-protobufs.meshtastic))
(:export (:export
#:+broadcast-id+
#:*broadcast-name*
#:*channel* #:*channel*
#:*channels* #:*channels*
#:*config-complete* #:*config-complete*

View file

@ -54,27 +54,28 @@ Rectangle {
function addPerson(person) { function addPerson(person) {
// insert sorted // insert sorted
var i = 0; var i = 1; // 0 is broadcast
var broadcast = (count === 0)
for (; i < count; i++) { for (; i < count; i++) {
if (person.customName < get(i).customName) { if (person.customName < get(i).customName) {
insert(i, person) insert(i, person)
break break
} }
} }
if (i === count) { if (broadcast || (i === count)) {
append(person) append(person)
} }
if (person.current) { if (person.current) {
view.currentIndex = i view.currentIndex = broadcast ? 0 : i
view.positionViewAtIndex(view.currentIndex, ListView.Contain) view.positionViewAtIndex(view.currentIndex, ListView.Contain)
} }
} }
function sortRenamed(name, index) { function sortRenamed(name, index) {
var to = -1 var to = -1
if (name < get(0).customName) { if (name < get(1).customName) { // 0 is broadcast
to = 0 to = 1
} else if (name >= get(count - 1).customName) { } else if (name >= get(count - 1).customName) {
to = count - 1 to = count - 1
} else { } else {
@ -124,13 +125,21 @@ Rectangle {
Rectangle { Rectangle {
id: rectRadio id: rectRadio
x: 10 x: (index === 0) ? 18 : 10
width: 42 width: (index === 0) ? 28 : 42
height: 15 height: (index === 0) ? width : 15
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: "#f0f0f0" color: "#f0f0f0"
radius: height / 2 radius: height / 2
Image {
anchors.centerIn: parent
width: 20
height: width
source: "../img/broadcast.png"
visible: (index === 0)
}
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
font.pixelSize: 12 font.pixelSize: 12
@ -138,6 +147,7 @@ Rectangle {
font.weight: Font.DemiBold font.weight: Font.DemiBold
color: "black" color: "black"
text: model.radioName text: model.radioName
visible: (index !== 0)
} }
} }
@ -178,9 +188,11 @@ Rectangle {
} }
onPressAndHold: { onPressAndHold: {
readOnly = false if (index !== 0) {
selectAll() readOnly = false
forceActiveFocus() selectAll()
forceActiveFocus()
}
} }
onEditingFinished: { onEditingFinished: {

View file

@ -5,6 +5,8 @@ import "." as Ext
Item { Item {
anchors.fill: parent anchors.fill: parent
property alias currentIndex: swipeView.currentIndex
Rectangle { Rectangle {
id: header id: header
width: parent.width width: parent.width

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB