From 6f7f540c7923b5d9338a0c4841e81623c2002e22 Mon Sep 17 00:00:00 2001 From: Ellie Hussey Date: Sun, 5 Jul 2020 17:03:12 -0700 Subject: [PATCH] Added the option for forced NodeStatus updates on user change or text message, tweaked compass (#256) --- src/NodeStatus.h | 14 ++++++++++++-- src/mesh/NodeDB.cpp | 10 +++++++--- src/mesh/NodeDB.h | 4 ++-- src/screen.cpp | 23 ++++++++++++++++------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/NodeStatus.h b/src/NodeStatus.h index 275199467..dc567fd2f 100644 --- a/src/NodeStatus.h +++ b/src/NodeStatus.h @@ -15,13 +15,17 @@ namespace meshtastic { uint8_t numOnline = 0; uint8_t numTotal = 0; + uint8_t lastNumTotal = 0; + public: + bool forceUpdate = false; NodeStatus() { statusType = STATUS_TYPE_NODE; } - NodeStatus( uint8_t numOnline, uint8_t numTotal ) : Status() + NodeStatus( uint8_t numOnline, uint8_t numTotal, bool forceUpdate = false ) : Status() { + this->forceUpdate = forceUpdate; this->numOnline = numOnline; this->numTotal = numTotal; } @@ -43,6 +47,11 @@ namespace meshtastic { return numTotal; } + uint8_t getLastNumTotal() const + { + return lastNumTotal; + } + bool matches(const NodeStatus *newStatus) const { return ( @@ -52,6 +61,7 @@ namespace meshtastic { } int updateStatus(const NodeStatus *newStatus) { // Only update the status if values have actually changed + lastNumTotal = numTotal; bool isDirty; { isDirty = matches(newStatus); @@ -59,7 +69,7 @@ namespace meshtastic { numOnline = newStatus->getNumOnline(); numTotal = newStatus->getNumTotal(); } - if(isDirty) { + if(isDirty || newStatus->forceUpdate) { DEBUG_MSG("Node status update: %d online, %d total\n", numOnline, numTotal); onNewStatus.notifyObservers(this); } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 00d3f5699..fe816a202 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -339,11 +339,8 @@ void NodeDB::updateFrom(const MeshPacket &mp) const SubPacket &p = mp.decoded; DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time); - int oldNumNodes = *numNodes; NodeInfo *info = getOrCreateNode(mp.from); - notifyObservers(); - if (mp.rx_time) { // if the packet has a valid timestamp use it to update our last_seen info->has_position = true; // at least the time is valid info->position.time = mp.rx_time; @@ -359,6 +356,7 @@ void NodeDB::updateFrom(const MeshPacket &mp) info->position.time = oldtime; info->has_position = true; updateGUIforNode = info; + notifyObservers(true); //Force an update whether or not our node counts have changed break; } @@ -373,6 +371,7 @@ void NodeDB::updateFrom(const MeshPacket &mp) devicestate.has_rx_text_message = true; updateTextMessage = true; powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG); + notifyObservers(true); //Force an update whether or not our node counts have changed } } break; @@ -391,6 +390,7 @@ void NodeDB::updateFrom(const MeshPacket &mp) if (changed) { updateGUIforNode = info; powerFSM.trigger(EVENT_NODEDB_UPDATED); + notifyObservers(true); //Force an update whether or not our node counts have changed // Not really needed - we will save anyways when we go to sleep // We just changed something important about the user, store our DB @@ -398,6 +398,10 @@ void NodeDB::updateFrom(const MeshPacket &mp) } break; } + + default: { + notifyObservers(); //If the node counts have changed, notify observers + } } } } diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index ec967de31..2465c2021 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -95,9 +95,9 @@ class NodeDB NodeInfo *getOrCreateNode(NodeNum n); /// Notify observers of changes to the DB - void notifyObservers() { + void notifyObservers(bool forceUpdate = false) { // Notify observers of the current node state - const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineNodes(), getNumNodes()); + const meshtastic::NodeStatus status = meshtastic::NodeStatus(getNumOnlineNodes(), getNumNodes(), forceUpdate); newStatus.notifyObservers(&status); } diff --git a/src/screen.cpp b/src/screen.cpp index a0b78c027..71005288f 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -479,6 +479,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ // coordinates for the center of the compass/circle int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 5, compassY = y + SCREEN_HEIGHT / 2; + bool hasNodeHeading = false; if(ourNode && hasPosition(ourNode)) { @@ -486,7 +487,10 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i)); drawCompassHeading(display, compassX, compassY, myHeading); - if(hasPosition(node)) { // display direction toward node + if(hasPosition(node)) + { + // display direction toward node + hasNodeHeading = true; Position &p = node->position; float d = latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); if (d < 2000) @@ -499,12 +503,13 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ float bearingToOther = bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); headingRadian = bearingToOther - myHeading; drawNodeHeading(display, compassX, compassY, headingRadian); - } else { // direction to node is unknown so display question mark - // Debug info for gps lock errors - // DEBUG_MSG("ourNode %d, ourPos %d, theirPos %d\n", !!ourNode, ourNode && hasPosition(ourNode), hasPosition(node)); - display->drawString(compassX - FONT_HEIGHT / 4, compassY - FONT_HEIGHT / 2, "?"); - } + } } + if(!hasNodeHeading) + // direction to node is unknown so display question mark + // Debug info for gps lock errors + // DEBUG_MSG("ourNode %d, ourPos %d, theirPos %d\n", !!ourNode, ourNode && hasPosition(ourNode), hasPosition(node)); + display->drawString(compassX - FONT_HEIGHT / 4, compassY - FONT_HEIGHT / 2, "?"); display->drawCircle(compassX, compassY, COMPASS_DIAM / 2); @@ -819,7 +824,11 @@ int Screen::handleStatusUpdate(const Status *arg) switch(arg->getStatusType()) { case STATUS_TYPE_NODE: - setFrames(); + if (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal()) + setFrames(); + prevFrame = -1; + nodeDB.updateGUI = false; + nodeDB.updateTextMessage = false; break; } setPeriod(1); // Update the screen right away