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.
The model keys are:
: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))
(defun clear ()
@ -31,18 +39,20 @@
(q> |visible| ui:*unread-messages* state))
(defun set-unread (name n)
(unless (string= lora:*broadcast-name* name)
(qjs |setUnread| ui:*group*
name n)
(when (plusp n)
(set-unread-state t)))
(set-unread-state t))))
(defun receiver-changed ()
(let ((curr-name (app:setting :latest-receiver)))
(unless (string= lora:*broadcast-name* curr-name)
(app:change-setting curr-name 0 :sub-key :unread-messages)
(set-unread curr-name 0)
(dolist (name (radio-names))
(x:when-it (app:setting name :unread-messages)
(unless (zerop x:it)
(return-from receiver-changed))))
(set-unread-state nil)))
(set-unread-state nil))))

View file

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

View file

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

View file

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

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB