Added the option for forced NodeStatus updates on user change or text message, tweaked compass (#256)

pull/258/head
Ellie Hussey 2020-07-05 17:03:12 -07:00 zatwierdzone przez GitHub
rodzic aba5b01fa0
commit 6f7f540c79
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 37 dodań i 14 usunięć

Wyświetl plik

@ -15,13 +15,17 @@ namespace meshtastic {
uint8_t numOnline = 0; uint8_t numOnline = 0;
uint8_t numTotal = 0; uint8_t numTotal = 0;
uint8_t lastNumTotal = 0;
public: public:
bool forceUpdate = false;
NodeStatus() { NodeStatus() {
statusType = STATUS_TYPE_NODE; 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->numOnline = numOnline;
this->numTotal = numTotal; this->numTotal = numTotal;
} }
@ -43,6 +47,11 @@ namespace meshtastic {
return numTotal; return numTotal;
} }
uint8_t getLastNumTotal() const
{
return lastNumTotal;
}
bool matches(const NodeStatus *newStatus) const bool matches(const NodeStatus *newStatus) const
{ {
return ( return (
@ -52,6 +61,7 @@ namespace meshtastic {
} }
int updateStatus(const NodeStatus *newStatus) { int updateStatus(const NodeStatus *newStatus) {
// Only update the status if values have actually changed // Only update the status if values have actually changed
lastNumTotal = numTotal;
bool isDirty; bool isDirty;
{ {
isDirty = matches(newStatus); isDirty = matches(newStatus);
@ -59,7 +69,7 @@ namespace meshtastic {
numOnline = newStatus->getNumOnline(); numOnline = newStatus->getNumOnline();
numTotal = newStatus->getNumTotal(); numTotal = newStatus->getNumTotal();
} }
if(isDirty) { if(isDirty || newStatus->forceUpdate) {
DEBUG_MSG("Node status update: %d online, %d total\n", numOnline, numTotal); DEBUG_MSG("Node status update: %d online, %d total\n", numOnline, numTotal);
onNewStatus.notifyObservers(this); onNewStatus.notifyObservers(this);
} }

Wyświetl plik

@ -339,11 +339,8 @@ void NodeDB::updateFrom(const MeshPacket &mp)
const SubPacket &p = mp.decoded; const SubPacket &p = mp.decoded;
DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time); DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time);
int oldNumNodes = *numNodes;
NodeInfo *info = getOrCreateNode(mp.from); NodeInfo *info = getOrCreateNode(mp.from);
notifyObservers();
if (mp.rx_time) { // if the packet has a valid timestamp use it to update our last_seen 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->has_position = true; // at least the time is valid
info->position.time = mp.rx_time; info->position.time = mp.rx_time;
@ -359,6 +356,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
info->position.time = oldtime; info->position.time = oldtime;
info->has_position = true; info->has_position = true;
updateGUIforNode = info; updateGUIforNode = info;
notifyObservers(true); //Force an update whether or not our node counts have changed
break; break;
} }
@ -373,6 +371,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
devicestate.has_rx_text_message = true; devicestate.has_rx_text_message = true;
updateTextMessage = true; updateTextMessage = true;
powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG); powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG);
notifyObservers(true); //Force an update whether or not our node counts have changed
} }
} }
break; break;
@ -391,6 +390,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
if (changed) { if (changed) {
updateGUIforNode = info; updateGUIforNode = info;
powerFSM.trigger(EVENT_NODEDB_UPDATED); 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 // Not really needed - we will save anyways when we go to sleep
// We just changed something important about the user, store our DB // We just changed something important about the user, store our DB
@ -398,6 +398,10 @@ void NodeDB::updateFrom(const MeshPacket &mp)
} }
break; break;
} }
default: {
notifyObservers(); //If the node counts have changed, notify observers
}
} }
} }
} }

Wyświetl plik

@ -95,9 +95,9 @@ class NodeDB
NodeInfo *getOrCreateNode(NodeNum n); NodeInfo *getOrCreateNode(NodeNum n);
/// Notify observers of changes to the DB /// Notify observers of changes to the DB
void notifyObservers() { void notifyObservers(bool forceUpdate = false) {
// Notify observers of the current node state // 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); newStatus.notifyObservers(&status);
} }

Wyświetl plik

@ -479,6 +479,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
// coordinates for the center of the compass/circle // coordinates for the center of the compass/circle
int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 5, compassY = y + SCREEN_HEIGHT / 2; int16_t compassX = x + SCREEN_WIDTH - COMPASS_DIAM / 2 - 5, compassY = y + SCREEN_HEIGHT / 2;
bool hasNodeHeading = false;
if(ourNode && hasPosition(ourNode)) 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)); float myHeading = estimatedHeading(DegD(op.latitude_i), DegD(op.longitude_i));
drawCompassHeading(display, compassX, compassY, myHeading); 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; Position &p = node->position;
float d = latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); float d = latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
if (d < 2000) 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)); float bearingToOther = bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
headingRadian = bearingToOther - myHeading; headingRadian = bearingToOther - myHeading;
drawNodeHeading(display, compassX, compassY, headingRadian); 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); display->drawCircle(compassX, compassY, COMPASS_DIAM / 2);
@ -819,7 +824,11 @@ int Screen::handleStatusUpdate(const Status *arg)
switch(arg->getStatusType()) switch(arg->getStatusType())
{ {
case STATUS_TYPE_NODE: case STATUS_TYPE_NODE:
setFrames(); if (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal())
setFrames();
prevFrame = -1;
nodeDB.updateGUI = false;
nodeDB.updateTextMessage = false;
break; break;
} }
setPeriod(1); // Update the screen right away setPeriod(1); // Update the screen right away