* refactor: removed UITask dependency from MyMesh. New MyMesh::Listener interface

* UITask's are now a MyMesh task Listener
This commit is contained in:
Scott Powell
2026-09-16 21:03:44 +10:00
parent 0ec5ed5fe7
commit 3caf033de2
10 changed files with 152 additions and 75 deletions
+16 -32
View File
@@ -368,10 +368,6 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
_serial->writeFrame(out_frame, 1 + PUB_KEY_SIZE);
}
} else {
#ifdef DISPLAY_CLASS
if (_ui) _ui->notify(UIEventType::newContactMessage);
#endif
}
// add inbound-path to mem cache
@@ -395,6 +391,8 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
p->path_len = mesh::Packet::copyPath(p->path, path, path_len);
}
if (_listener) _listener->onDiscoveredContact(contact, is_new, path_len, path);
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
}
@@ -520,16 +518,12 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
_serial->writeFrame(frame, 1);
}
#ifdef DISPLAY_CLASS
// we only want to show text messages on display, not cli data
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
if (should_display && _ui) {
_ui->newMsg(path_len, from.name, text, offline_queue_len);
if (!_serial->isConnected()) {
_ui->notify(UIEventType::contactMessage);
}
if (should_display && _listener) {
_listener->onMessageRecv(path_len, from.name, text);
_listener->onQueueSizeChanged(offline_queue_len);
}
#endif
}
bool MyMesh::filterRecvFloodPacket(mesh::Packet* packet) {
@@ -640,20 +634,16 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
uint8_t frame[1];
frame[0] = PUSH_CODE_MSG_WAITING; // send push 'tickle'
_serial->writeFrame(frame, 1);
} else {
#ifdef DISPLAY_CLASS
if (_ui) _ui->notify(UIEventType::channelMessage);
#endif
}
#ifdef DISPLAY_CLASS
// Get the channel name from the channel index
const char *channel_name = "Unknown";
ChannelDetails channel_details;
if (getChannel(channel_idx, channel_details)) {
channel_name = channel_details.name;
if (_listener) {
// Get the channel name from the channel index
ChannelDetails channel_details;
if (!getChannel(channel_idx, channel_details)) {
strcpy(channel_details.name, "Unknown");
}
_listener->onChannelMsgRecv(channel_details, path_len, text);
_listener->onQueueSizeChanged(offline_queue_len);
}
if (_ui) _ui->newMsg(path_len, channel_name, text, offline_queue_len);
#endif
}
void MyMesh::onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint16_t data_type,
@@ -930,9 +920,9 @@ uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t
void MyMesh::onSendTimeout() {}
MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui)
MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store)
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables),
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _ui(ui), _iter(0) {
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _listener(NULL), _iter(0) {
_iter_started = false;
_cli_rescue = false;
cli_command[0] = 0;
@@ -1463,9 +1453,7 @@ void MyMesh::handleCmdFrame(size_t len) {
int out_len;
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
_serial->writeFrame(out_frame, out_len);
#ifdef DISPLAY_CLASS
if (_ui) _ui->msgRead(offline_queue_len);
#endif
if (_listener) _listener->onQueueSizeChanged(offline_queue_len);
} else {
out_frame[0] = RESP_CODE_NO_MORE_MESSAGES;
_serial->writeFrame(out_frame, 1);
@@ -2466,10 +2454,6 @@ void MyMesh::loop() {
saveContacts();
dirty_contacts_expiry = 0;
}
#ifdef DISPLAY_CLASS
if (_ui) _ui->setHasConnection(_serial->isConnected());
#endif
}
bool MyMesh::advert() {