mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 19:02:00 +00:00
* refactored the UI_DISCOVER_* feature
This commit is contained in:
@@ -139,10 +139,6 @@
|
|||||||
#define ERR_CODE_FILE_IO_ERROR 5
|
#define ERR_CODE_FILE_IO_ERROR 5
|
||||||
#define ERR_CODE_ILLEGAL_ARG 6
|
#define ERR_CODE_ILLEGAL_ARG 6
|
||||||
|
|
||||||
// Copied from simple_repeater (could probably be shared)
|
|
||||||
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
|
|
||||||
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
|
|
||||||
|
|
||||||
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
|
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
|
||||||
|
|
||||||
// Auto-add config bitmask
|
// Auto-add config bitmask
|
||||||
@@ -410,53 +406,6 @@ int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
|
|||||||
return max_num;
|
return max_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
|
||||||
int MyMesh::getDiscoveredNodes(DiscoveredNode nodes[], int max_num) {
|
|
||||||
if (max_num > DISCOVERED_NODES_TABLE_SIZE) max_num = DISCOVERED_NODES_TABLE_SIZE;
|
|
||||||
if (max_num > disc_nodes_count) max_num = disc_nodes_count;
|
|
||||||
|
|
||||||
for (int i = 0; i < max_num; i++) {
|
|
||||||
nodes[i] = discovered_nodes[i];
|
|
||||||
}
|
|
||||||
return max_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyMesh::requestRepeatersDiscovery() {
|
|
||||||
uint8_t cmd_bytes[6];
|
|
||||||
cmd_bytes[0] = CTL_TYPE_NODE_DISCOVER_REQ | 1; // DISCOVER_REQ | prefix only
|
|
||||||
cmd_bytes[1] = 0xFF; // Repeaters
|
|
||||||
getRNG()->random(&cmd_bytes[2], 4); // tag
|
|
||||||
disc_nodes_count = 0;
|
|
||||||
disc_node_req_tag = *((uint32_t*)&cmd_bytes[2]);
|
|
||||||
mesh::Packet* req = createControlData(cmd_bytes, sizeof(cmd_bytes));
|
|
||||||
if (req) {
|
|
||||||
sendZeroHop(req);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyMesh::checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len) {
|
|
||||||
if ((p_len < 12)
|
|
||||||
|| (payload[0] & 0xF0 != CTL_TYPE_NODE_DISCOVER_RESP)
|
|
||||||
|| (disc_nodes_count >= DISCOVERED_NODES_TABLE_SIZE)
|
|
||||||
|| (memcmp(&payload[2], &disc_node_req_tag, 4))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memcpy(&discovered_nodes[disc_nodes_count].pubkey_prefix, &payload[6], 8);
|
|
||||||
discovered_nodes[disc_nodes_count].type = payload[0] & 0xF;
|
|
||||||
discovered_nodes[disc_nodes_count].snr_out = ((int8_t)payload[1]) / 4.0;
|
|
||||||
discovered_nodes[disc_nodes_count].snr_in = _radio->getLastSNR();
|
|
||||||
ContactInfo* c = lookupContactByPubKey(&payload[6], 8);
|
|
||||||
if (c != NULL) {
|
|
||||||
strncpy(discovered_nodes[disc_nodes_count].name, c->name, 32);
|
|
||||||
} else {
|
|
||||||
discovered_nodes[disc_nodes_count].name[0] = 0;
|
|
||||||
}
|
|
||||||
disc_nodes_count ++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
|
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
|
||||||
out_frame[0] = PUSH_CODE_PATH_UPDATED;
|
out_frame[0] = PUSH_CODE_PATH_UPDATED;
|
||||||
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
|
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
|
||||||
@@ -518,10 +467,8 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
|
|||||||
_serial->writeFrame(frame, 1);
|
_serial->writeFrame(frame, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we only want to show text messages on display, not cli data
|
if (_listener) {
|
||||||
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
|
_listener->onMessageRecv(from, txt_type, sender_timestamp, path_len, text);
|
||||||
if (should_display && _listener) {
|
|
||||||
_listener->onMessageRecv(path_len, from.name, text);
|
|
||||||
_listener->onQueueSizeChanged(offline_queue_len);
|
_listener->onQueueSizeChanged(offline_queue_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,9 +787,6 @@ void MyMesh::onControlDataRecv(mesh::Packet *packet) {
|
|||||||
MESH_DEBUG_PRINTLN("onControlDataRecv(), payload_len too long: %d", packet->payload_len);
|
MESH_DEBUG_PRINTLN("onControlDataRecv(), payload_len too long: %d", packet->payload_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
|
||||||
checkControlDataForPendingDiscovery(packet->payload, packet->payload_len);
|
|
||||||
#endif
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out_frame[i++] = PUSH_CODE_CONTROL_DATA;
|
out_frame[i++] = PUSH_CODE_CONTROL_DATA;
|
||||||
out_frame[i++] = (int8_t)(_radio->getLastSNR() * 4);
|
out_frame[i++] = (int8_t)(_radio->getLastSNR() * 4);
|
||||||
@@ -856,6 +800,8 @@ void MyMesh::onControlDataRecv(mesh::Packet *packet) {
|
|||||||
} else {
|
} else {
|
||||||
MESH_DEBUG_PRINTLN("onControlDataRecv(), data received while app offline");
|
MESH_DEBUG_PRINTLN("onControlDataRecv(), data received while app offline");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_listener) _listener->onControlDataRecv(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyMesh::onRawDataRecv(mesh::Packet *packet) {
|
void MyMesh::onRawDataRecv(mesh::Packet *packet) {
|
||||||
@@ -1039,7 +985,7 @@ void MyMesh::begin(bool has_display) {
|
|||||||
resetContacts();
|
resetContacts();
|
||||||
_store->loadContacts(this);
|
_store->loadContacts(this);
|
||||||
bootstrapRTCfromContacts();
|
bootstrapRTCfromContacts();
|
||||||
addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure Andy's public channel
|
addChannel("Public", PUBLIC_GROUP_PSK); // pre-configure public channel
|
||||||
_store->loadChannels(this);
|
_store->loadChannels(this);
|
||||||
|
|
||||||
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
|
radio_driver.setParams(_prefs.freq, _prefs.bw, _prefs.sf, _prefs.cr);
|
||||||
|
|||||||
@@ -75,6 +75,10 @@
|
|||||||
#define REQ_TYPE_KEEP_ALIVE 0x02
|
#define REQ_TYPE_KEEP_ALIVE 0x02
|
||||||
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
|
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
|
||||||
|
|
||||||
|
// Copied from simple_repeater
|
||||||
|
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
|
||||||
|
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
|
||||||
|
|
||||||
struct AdvertPath {
|
struct AdvertPath {
|
||||||
uint8_t pubkey_prefix[7];
|
uint8_t pubkey_prefix[7];
|
||||||
uint8_t path_len;
|
uint8_t path_len;
|
||||||
@@ -83,24 +87,15 @@ struct AdvertPath {
|
|||||||
uint8_t path[MAX_PATH_SIZE];
|
uint8_t path[MAX_PATH_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
|
||||||
struct DiscoveredNode {
|
|
||||||
uint8_t pubkey_prefix[9];
|
|
||||||
float snr_in;
|
|
||||||
float snr_out;
|
|
||||||
char name[32];
|
|
||||||
uint8_t type;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class MyMesh : public BaseChatMesh, public DataStoreHost {
|
class MyMesh : public BaseChatMesh, public DataStoreHost {
|
||||||
public:
|
public:
|
||||||
class Listener {
|
class Listener {
|
||||||
public:
|
public:
|
||||||
virtual void onMessageRecv(uint8_t path_len, const char* from_name, const char* text) = 0;
|
virtual void onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) = 0;
|
||||||
virtual void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) = 0;
|
virtual void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) = 0;
|
||||||
virtual void onQueueSizeChanged(int msgcount) = 0;
|
virtual void onQueueSizeChanged(int msgcount) = 0;
|
||||||
virtual void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
virtual void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
||||||
|
virtual void onControlDataRecv(const mesh::Packet* packet) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store);
|
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store);
|
||||||
@@ -120,11 +115,6 @@ public:
|
|||||||
|
|
||||||
int getRecentlyHeard(AdvertPath dest[], int max_num);
|
int getRecentlyHeard(AdvertPath dest[], int max_num);
|
||||||
|
|
||||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
|
||||||
bool requestRepeatersDiscovery();
|
|
||||||
int getDiscoveredNodes(DiscoveredNode nodes[], int max_num);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getAirtimeBudgetFactor() const override;
|
float getAirtimeBudgetFactor() const override;
|
||||||
int getInterferenceThreshold() const override;
|
int getInterferenceThreshold() const override;
|
||||||
@@ -287,19 +277,6 @@ private:
|
|||||||
|
|
||||||
#define ADVERT_PATH_TABLE_SIZE 16
|
#define ADVERT_PATH_TABLE_SIZE 16
|
||||||
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
||||||
|
|
||||||
#if defined(DISPLAY_CLASS) && !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
|
||||||
#ifdef UI_RECENT_LIST_SIZE
|
|
||||||
#define DISCOVERED_NODES_TABLE_SIZE UI_RECENT_LIST_SIZE
|
|
||||||
#else
|
|
||||||
#define DISCOVERED_NODES_TABLE_SIZE 4
|
|
||||||
#endif
|
|
||||||
DiscoveredNode discovered_nodes[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
|
|
||||||
uint32_t disc_node_req_tag = 0;
|
|
||||||
uint32_t disc_nodes_count = 0;
|
|
||||||
|
|
||||||
void checkControlDataForPendingDiscovery(uint8_t payload[], size_t p_len);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MyMesh the_mesh;
|
extern MyMesh the_mesh;
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class HomeScreen : public UIScreen {
|
|||||||
#if UI_SENSORS_PAGE == 1
|
#if UI_SENSORS_PAGE == 1
|
||||||
SENSORS,
|
SENSORS,
|
||||||
#endif
|
#endif
|
||||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
#if UI_DISCOVER_SCREEN
|
||||||
DISCOVERY,
|
DISCOVERY,
|
||||||
#endif
|
#endif
|
||||||
#ifndef UI_NO_HIBERNATE
|
#ifndef UI_NO_HIBERNATE
|
||||||
@@ -115,8 +115,10 @@ class HomeScreen : public UIScreen {
|
|||||||
uint8_t _page;
|
uint8_t _page;
|
||||||
bool _shutdown_init;
|
bool _shutdown_init;
|
||||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
#if UI_DISCOVER_SCREEN
|
||||||
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
|
DiscoveredNode discovered[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
|
||||||
|
uint32_t disc_node_req_tag = 0;
|
||||||
|
uint32_t disc_nodes_count = 0;
|
||||||
uint32_t discovery_req_time = 0;
|
uint32_t discovery_req_time = 0;
|
||||||
bool discovery_disp_names = true; // by default desplay names if available (removes SNR_O)
|
bool discovery_disp_names = true; // by default desplay names if available (removes SNR_O)
|
||||||
#endif
|
#endif
|
||||||
@@ -206,6 +208,40 @@ public:
|
|||||||
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
|
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
|
||||||
_shutdown_init(false), sensors_lpp(200) { }
|
_shutdown_init(false), sensors_lpp(200) { }
|
||||||
|
|
||||||
|
#if UI_DISCOVER_SCREEN
|
||||||
|
bool sendDiscoverRequest() {
|
||||||
|
uint8_t cmd_bytes[6];
|
||||||
|
cmd_bytes[0] = CTL_TYPE_NODE_DISCOVER_REQ | 1; // DISCOVER_REQ | prefix only
|
||||||
|
cmd_bytes[1] = 0xFF; // Repeaters
|
||||||
|
the_mesh.getRNG()->random((uint8_t *) &disc_node_req_tag, 4); // generate random tag
|
||||||
|
memcpy(&cmd_bytes[2], &disc_node_req_tag, 4);
|
||||||
|
disc_nodes_count = 0;
|
||||||
|
mesh::Packet* req = the_mesh.createControlData(cmd_bytes, sizeof(cmd_bytes));
|
||||||
|
if (req) {
|
||||||
|
the_mesh.sendZeroHop(req);
|
||||||
|
discovery_req_time = millis();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDiscoverResponse(const mesh::Packet* packet) {
|
||||||
|
if (disc_nodes_count < DISCOVERED_NODES_TABLE_SIZE && memcmp(&packet->payload[2], &disc_node_req_tag, 4) == 0) {
|
||||||
|
auto d = &discovered[disc_nodes_count++];
|
||||||
|
memcpy(d->pubkey_prefix, &packet->payload[6], 8);
|
||||||
|
d->type = packet->payload[0] & 0xF;
|
||||||
|
d->snr_out = ((int8_t)packet->payload[1]) / 4.0;
|
||||||
|
d->snr_in = radio_driver.getLastSNR();
|
||||||
|
ContactInfo* c = the_mesh.lookupContactByPubKey(&packet->payload[6], 8);
|
||||||
|
if (c != NULL) {
|
||||||
|
strncpy(d->name, c->name, 32);
|
||||||
|
} else {
|
||||||
|
d->name[0] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void poll() override {
|
void poll() override {
|
||||||
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
|
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
|
||||||
_task->shutdown();
|
_task->shutdown();
|
||||||
@@ -464,9 +500,9 @@ public:
|
|||||||
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
|
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
|
||||||
else sensors_scroll_offset = 0;
|
else sensors_scroll_offset = 0;
|
||||||
#endif
|
#endif
|
||||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
#if UI_DISCOVER_SCREEN
|
||||||
} else if (_page == HomePage::DISCOVERY) {
|
} else if (_page == HomePage::DISCOVERY) {
|
||||||
int count = the_mesh.getDiscoveredNodes(discovered, UI_RECENT_LIST_SIZE);
|
int count = disc_nodes_count;
|
||||||
display.setColor(UIColor::primary_txt);
|
display.setColor(UIColor::primary_txt);
|
||||||
int y = 20;
|
int y = 20;
|
||||||
for (int i = 0; i < count; i++, y += 11) {
|
for (int i = 0; i < count; i++, y += 11) {
|
||||||
@@ -493,8 +529,8 @@ public:
|
|||||||
}
|
}
|
||||||
if (millis() < discovery_req_time + 5000) {
|
if (millis() < discovery_req_time + 5000) {
|
||||||
return 1000; // more frequent updates just after req
|
return 1000; // more frequent updates just after req
|
||||||
} else if (count < UI_RECENT_LIST_SIZE -1) { // show only 5 sec after last disc
|
} else if (count < DISCOVERED_NODES_TABLE_SIZE -1) { // show only 5 sec after last disc
|
||||||
y = 10 + 11 * UI_RECENT_LIST_SIZE;
|
y = 10 + 11 * DISCOVERED_NODES_TABLE_SIZE;
|
||||||
display.drawTextCentered(display.width() / 2, y, "discover: " PRESS_LABEL);
|
display.drawTextCentered(display.width() / 2, y, "discover: " PRESS_LABEL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -525,7 +561,7 @@ public:
|
|||||||
if (_page == HomePage::RECENT) {
|
if (_page == HomePage::RECENT) {
|
||||||
_task->showAlert("Recent adverts", 800);
|
_task->showAlert("Recent adverts", 800);
|
||||||
}
|
}
|
||||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
#if UI_DISCOVER_SCREEN
|
||||||
if (_page == HomePage::DISCOVERY) {
|
if (_page == HomePage::DISCOVERY) {
|
||||||
_task->showAlert("Repeater disc", 800);
|
_task->showAlert("Repeater disc", 800);
|
||||||
}
|
}
|
||||||
@@ -562,11 +598,10 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
#if UI_DISCOVER_SCREEN
|
||||||
if (c == KEY_ENTER && _page == HomePage::DISCOVERY) {
|
if (c == KEY_ENTER && _page == HomePage::DISCOVERY) {
|
||||||
if (millis() > discovery_req_time + 5000) { // rate limiter
|
if (millis() > discovery_req_time + 5000) { // rate limiter
|
||||||
the_mesh.requestRepeatersDiscovery();
|
sendDiscoverRequest();
|
||||||
discovery_req_time = millis();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -751,8 +786,11 @@ switch(t){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::onMessageRecv(uint8_t path_len, const char* from_name, const char* text) {
|
void UITask::onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) {
|
||||||
((MsgPreviewScreen *) msg_preview)->addPreview(path_len, from_name, text);
|
// we only want to show text messages on display, not cli data
|
||||||
|
if (!(txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN)) return;
|
||||||
|
|
||||||
|
((MsgPreviewScreen *) msg_preview)->addPreview(path_len, from.name, text);
|
||||||
setCurrScreen(msg_preview);
|
setCurrScreen(msg_preview);
|
||||||
|
|
||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
@@ -802,6 +840,14 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITask::onControlDataRecv(const mesh::Packet* packet) {
|
||||||
|
#if UI_DISCOVER_SCREEN
|
||||||
|
if (packet->payload_len >= 12 && (packet->payload[0] & 0xF0) == CTL_TYPE_NODE_DISCOVER_RESP) {
|
||||||
|
((HomeScreen *) home)->handleDiscoverResponse(packet);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void UITask::userLedHandler() {
|
void UITask::userLedHandler() {
|
||||||
#ifdef PIN_STATUS_LED
|
#ifdef PIN_STATUS_LED
|
||||||
int cur_time = millis();
|
int cur_time = millis();
|
||||||
|
|||||||
@@ -22,6 +22,26 @@
|
|||||||
#include "../AbstractUITask.h"
|
#include "../AbstractUITask.h"
|
||||||
#include "../NodePrefs.h"
|
#include "../NodePrefs.h"
|
||||||
|
|
||||||
|
#ifndef UI_DISCOVER_SCREEN
|
||||||
|
#define UI_DISCOVER_SCREEN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UI_DISCOVER_SCREEN
|
||||||
|
#ifdef UI_RECENT_LIST_SIZE
|
||||||
|
#define DISCOVERED_NODES_TABLE_SIZE UI_RECENT_LIST_SIZE
|
||||||
|
#else
|
||||||
|
#define DISCOVERED_NODES_TABLE_SIZE 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct DiscoveredNode {
|
||||||
|
float snr_in;
|
||||||
|
float snr_out;
|
||||||
|
uint8_t pubkey_prefix[9];
|
||||||
|
uint8_t type;
|
||||||
|
char name[32];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class UITask : public AbstractUITask {
|
class UITask : public AbstractUITask {
|
||||||
DisplayDriver* _display;
|
DisplayDriver* _display;
|
||||||
SensorManager* _sensors;
|
SensorManager* _sensors;
|
||||||
@@ -91,10 +111,11 @@ public:
|
|||||||
void toggleGPS();
|
void toggleGPS();
|
||||||
|
|
||||||
// MyMesh::Listener
|
// MyMesh::Listener
|
||||||
void onMessageRecv(uint8_t path_len, const char* from_name, const char* text) override;
|
void onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) override;
|
||||||
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
||||||
void onQueueSizeChanged(int offline_queue_size) override;
|
void onQueueSizeChanged(int offline_queue_size) override;
|
||||||
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
||||||
|
void onControlDataRecv(const mesh::Packet* packet) override;
|
||||||
|
|
||||||
// from AbstractUITask
|
// from AbstractUITask
|
||||||
void notify(UIEventType t = UIEventType::none) override;
|
void notify(UIEventType t = UIEventType::none) override;
|
||||||
|
|||||||
@@ -139,15 +139,18 @@ void UITask::clearMsgPreview() {
|
|||||||
_need_refresh = true;
|
_need_refresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::onMessageRecv(uint8_t path_len, const char* from_name, const char* text) {
|
void UITask::onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) {
|
||||||
|
// we only want to show text messages on display, not cli data
|
||||||
|
if (!(txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN)) return;
|
||||||
|
|
||||||
#ifdef HAS_DRV2605
|
#ifdef HAS_DRV2605
|
||||||
vibration.trigger(); // vibrate even while the app is connected (honors quiet + cooldown)
|
vibration.trigger(); // vibrate even while the app is connected (honors quiet + cooldown)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (path_len == 0xFF) {
|
if (path_len == 0xFF) {
|
||||||
sprintf(_origin, "(F) %s", from_name);
|
sprintf(_origin, "(F) %s", from.name);
|
||||||
} else {
|
} else {
|
||||||
sprintf(_origin, "(%d) %s", (uint32_t) path_len, from_name);
|
sprintf(_origin, "(%d) %s", (uint32_t) path_len, from.name);
|
||||||
}
|
}
|
||||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||||
|
|
||||||
@@ -197,6 +200,9 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITask::onControlDataRecv(const mesh::Packet* packet) {
|
||||||
|
}
|
||||||
|
|
||||||
void UITask::renderBatteryIndicator(uint16_t batteryMilliVolts) {
|
void UITask::renderBatteryIndicator(uint16_t batteryMilliVolts) {
|
||||||
// Convert millivolts to percentage
|
// Convert millivolts to percentage
|
||||||
#ifndef BATT_MIN_MILLIVOLTS
|
#ifndef BATT_MIN_MILLIVOLTS
|
||||||
|
|||||||
@@ -71,10 +71,11 @@ public:
|
|||||||
void clearMsgPreview();
|
void clearMsgPreview();
|
||||||
|
|
||||||
// MyMesh::Listener
|
// MyMesh::Listener
|
||||||
void onMessageRecv(uint8_t path_len, const char* from_name, const char* text) override;
|
void onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) override;
|
||||||
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
||||||
void onQueueSizeChanged(int offline_queue_size) override;
|
void onQueueSizeChanged(int offline_queue_size) override;
|
||||||
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
||||||
|
void onControlDataRecv(const mesh::Packet* packet) override;
|
||||||
|
|
||||||
// from AbstractUITask
|
// from AbstractUITask
|
||||||
void notify(UIEventType t = UIEventType::none) override;
|
void notify(UIEventType t = UIEventType::none) override;
|
||||||
|
|||||||
@@ -510,7 +510,10 @@ void UITask::onQueueSizeChanged(int msgcount) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::onMessageRecv(uint8_t path_len, const char* from_name, const char* text) {
|
void UITask::onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) {
|
||||||
|
// we only want to show text messages on display, not cli data
|
||||||
|
if (!(txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN)) return;
|
||||||
|
|
||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
if (!_display->isOn() && !hasConnection()) {
|
if (!_display->isOn() && !hasConnection()) {
|
||||||
_display->turnOn();
|
_display->turnOn();
|
||||||
@@ -546,6 +549,9 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITask::onControlDataRecv(const mesh::Packet* packet) {
|
||||||
|
}
|
||||||
|
|
||||||
void UITask::userLedHandler() {
|
void UITask::userLedHandler() {
|
||||||
#ifdef PIN_STATUS_LED
|
#ifdef PIN_STATUS_LED
|
||||||
int cur_time = millis();
|
int cur_time = millis();
|
||||||
|
|||||||
@@ -99,10 +99,11 @@ public:
|
|||||||
void toggleGPS();
|
void toggleGPS();
|
||||||
|
|
||||||
// MyMesh::Listener
|
// MyMesh::Listener
|
||||||
void onMessageRecv(uint8_t path_len, const char* from_name, const char* text) override;
|
void onMessageRecv(const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, uint8_t path_len, const char* text) override;
|
||||||
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
void onChannelMsgRecv(ChannelDetails& channel_details, uint8_t path_len, const char* text) override;
|
||||||
void onQueueSizeChanged(int offline_queue_size) override;
|
void onQueueSizeChanged(int offline_queue_size) override;
|
||||||
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
||||||
|
void onControlDataRecv(const mesh::Packet* packet) override;
|
||||||
|
|
||||||
// from AbstractUITask
|
// from AbstractUITask
|
||||||
void notify(UIEventType t = UIEventType::none) override;
|
void notify(UIEventType t = UIEventType::none) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user