we now show correct usernames in the nodeinfo screens

1.2-legacy
geeksville 2020-02-11 10:51:45 -08:00
rodzic 3e773526b7
commit 6dc17bdfde
2 zmienionych plików z 75 dodań i 16 usunięć

Wyświetl plik

@ -43,6 +43,8 @@ public:
NodeNum getNodeNum() { return myNodeInfo.my_node_num; }
size_t getNumNodes() { return *numNodes; }
/// if returns false, that means our node should send a DenyNodeNum response. If true, we think the number is okay for use
// bool handleWantNodeNum(NodeNum n);
@ -65,6 +67,8 @@ public:
/// Find a node in our DB, return null for missing
NodeInfo *getNode(NodeNum n);
NodeInfo *getNodeByIndex(size_t x) { assert(x < *numNodes); return &nodes[x]; }
private:
/// Find a node in our DB, create an empty NodeInfo if missing

Wyświetl plik

@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "GPS.h"
#include "OLEDDisplayUi.h"
#include "screen.h"
#include "mesh-pb-constants.h"
#include "NodeDB.h"
#define FONT_HEIGHT 14 // actually 13 for "ariel 10" but want a little extra space
@ -44,6 +46,10 @@ bool disp; // true if we are using display
OLEDDisplayUi ui(&dispdev);
#define NUM_EXTRA_FRAMES 2 // text message and debug frame
// A text message frame + debug frame + all the node infos
FrameCallback nonBootFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState *state)
{
display->setTextAlignment(TEXT_ALIGN_RIGHT);
@ -202,32 +208,57 @@ public:
y = ry;
}
void translate(int16_t dx, int dy) {
void translate(int16_t dx, int dy)
{
x += dx;
y += dy;
}
void scale(float f) {
void scale(float f)
{
x *= f;
y *= f;
}
};
void drawLine(OLEDDisplay *d, const Point &p1, const Point &p2) {
void drawLine(OLEDDisplay *d, const Point &p1, const Point &p2)
{
d->drawLine(p1.x, p1.y, p2.x, p2.y);
}
#define COMPASS_DIAM 44
/// We will skip one node - the one for us, so we just blindly loop over all nodes
static size_t nodeIndex;
static uint8_t prevFrame = 0;
void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
// We only advance our nodeIndex if the frame # has changed - because drawNodeInfo will be called repeatedly while the frame is shown
if (state->currentFrame != prevFrame)
{
prevFrame = state->currentFrame;
nodeIndex = (nodeIndex + 1) % nodeDB.getNumNodes();
NodeInfo *n = nodeDB.getNodeByIndex(nodeIndex);
if (n->num == nodeDB.getNodeNum())
{
// Don't show our node, just skip to next
nodeIndex = (nodeIndex + 1) % nodeDB.getNumNodes();
}
}
NodeInfo *node = nodeDB.getNodeByIndex(nodeIndex);
display->setFont(ArialMT_Plain_10);
// The coordinates define the left starting point of the text
display->setTextAlignment(TEXT_ALIGN_LEFT);
const char *username = node->has_user ? node->user.long_name : "Unknown Name";
const char *fields[] = {
"Kevin Hester (KH)",
username,
"2.1 mi",
"Signal: good",
"12 minutes ago",
@ -247,7 +278,8 @@ void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, in
Point *points[] = {&tip, &tail, &leftArrow, &rightArrow};
for(int i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++)
{
points[i]->rotate(headingRadian);
points[i]->scale(COMPASS_DIAM * 0.6);
points[i]->translate(compassX, compassY);
@ -278,14 +310,13 @@ void drawDebugInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, i
// This array keeps function pointers to all frames
// frames are the single views that slide in
FrameCallback frames[] = {drawBootScreen, drawTextMessageFrame, drawNodeInfo, drawDebugInfo};
FrameCallback *nonBootFrames = frames + 1;
FrameCallback bootFrames[] = {drawBootScreen, drawTextMessageFrame, drawDebugInfo};
// Overlays are statically drawn on top of a frame eg. a clock
OverlayCallback overlays[] = {/* msOverlay */};
// how many frames are there?
const int frameCount = sizeof(frames) / sizeof(frames[0]);
const int bootFrameCount = sizeof(bootFrames) / sizeof(bootFrames[0]);
const int overlaysCount = sizeof(overlays) / sizeof(overlays[0]);
#if 0
@ -376,7 +407,7 @@ void screen_setup()
ui.setFrameAnimation(SLIDE_LEFT);
// Add frames - we subtract one from the framecount so there won't be a visual glitch when we take the boot screen out of the sequence.
ui.setFrames(frames, frameCount - 1);
ui.setFrames(bootFrames, bootFrameCount);
// Add overlays
ui.setOverlays(overlays, overlaysCount);
@ -416,11 +447,23 @@ uint32_t screen_loop()
ui.update();
// Once we finish showing the bootscreen, remove it from the loop
if (showingBootScreen && !showingBluetooth && ui.getUiState()->currentFrame == 1)
if (showingBootScreen && !showingBluetooth)
{
if (ui.getUiState()->currentFrame == 1)
{
showingBootScreen = false;
screen_set_frames();
}
}
static size_t oldnumnodes = 0;
size_t numnodes = nodeDB.getNumNodes();
if (numnodes != oldnumnodes)
{
// If the # nodes changes, we need to regen our list of screens
oldnumnodes = numnodes;
screen_set_frames();
}
// If we are scrolling do 30fps, otherwise just 1 fps (to save CPU)
return (ui.getUiState()->frameState == IN_TRANSITION ? 10 : 500);
@ -447,7 +490,19 @@ void screen_start_bluetooth(uint32_t pin)
void screen_set_frames()
{
DEBUG_MSG("showing standard frames\n");
ui.setFrames(nonBootFrames, frameCount - 1);
nonBootFrames[0] = drawTextMessageFrame;
nonBootFrames[1] = drawDebugInfo;
size_t numnodes = nodeDB.getNumNodes();
// We don't show the node info our our node (if we have it yet - we should)
if (numnodes > 0)
numnodes--;
for (size_t i = 0; i < numnodes; i++)
nonBootFrames[NUM_EXTRA_FRAMES + i] = drawNodeInfo;
ui.setFrames(nonBootFrames, NUM_EXTRA_FRAMES + numnodes);
showingBluetooth = false;
}