From a5d7bacdbf3523fb0f0c4286daf0bbe155c54302 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 21 Oct 2020 17:27:13 +0800 Subject: [PATCH] Show current region on the boot screen --- src/graphics/Screen.cpp | 17 ++++++++++------- src/main.cpp | 19 +++++++++++-------- src/mesh/MeshRadio.h | 5 ++++- src/mesh/NodeDB.cpp | 3 +++ src/mesh/RadioInterface.cpp | 29 ++++++++++++++++------------- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 350b27d47..b6e626fdf 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -92,21 +92,24 @@ static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int1 // needs to be drawn relative to x and y // draw centered left to right and centered above the one line of app text - display->drawXbm(x + (SCREEN_WIDTH - icon_width) / 2, y + (SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM - icon_height) / 2, icon_width, - icon_height, (const uint8_t *)icon_bits); + display->drawXbm(x + (SCREEN_WIDTH - icon_width) / 2, + y + (SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM - icon_height) / 2 + 2, + icon_width, icon_height, (const uint8_t *)icon_bits); display->setFont(FONT_MEDIUM); display->setTextAlignment(TEXT_ALIGN_LEFT); const char *title = "meshtastic.org"; display->drawString(x + getStringCenteredX(title), y + SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM, title); display->setFont(FONT_SMALL); - const char *region = xstr(HW_VERSION); - if (*region && region[3] == '-') // Skip past 1.0- in the 1.0-EU865 string - region += 4; + + const char *region = myRegion ? myRegion->name : NULL; + if (region) + display->drawString(x + 0, y + 0, region); + char buf[16]; snprintf(buf, sizeof(buf), "%s", xstr(APP_VERSION)); // Note: we don't bother printing region or now, it makes the string too long - display->drawString(SCREEN_WIDTH - 20, 0, buf); + display->drawString(x + SCREEN_WIDTH - display->getStringWidth(buf), y + 0, buf); screen->forceDisplay(); } @@ -1139,7 +1142,7 @@ int Screen::handleStatusUpdate(const meshtastic::Status *arg) // DEBUG_MSG("Screen got status update %d\n", arg->getStatusType()); switch (arg->getStatusType()) { case STATUS_TYPE_NODE: - if (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal()) { + if (showingNormalScreen && (nodeDB.updateTextMessage || nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal())) { setFrames(); // Regen the list of screens } nodeDB.updateGUI = false; diff --git a/src/main.cpp b/src/main.cpp index e258ec521..2781b7707 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -290,14 +290,6 @@ void setup() // Initialize the screen first so we can show the logo while we start up everything else. screen = new graphics::Screen(SSD1306_ADDRESS); -#if defined(ST7735_CS) || defined(HAS_EINK) - screen->setup(); -#else - if (ssd1306_found) - screen->setup(); -#endif - - screen->print("Started...\n"); readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) @@ -338,6 +330,17 @@ void setup() service.init(); + // Don't call screen setup until after nodedb is setup (because we need + // the current region name) +#if defined(ST7735_CS) || defined(HAS_EINK) + screen->setup(); +#else + if (ssd1306_found) + screen->setup(); +#endif + + screen->print("Started...\n"); + // We have now loaded our saved preferences from flash // ONCE we will factory reset the GPS for bug #327 diff --git a/src/mesh/MeshRadio.h b/src/mesh/MeshRadio.h index 2cee8f89a..be99032f2 100644 --- a/src/mesh/MeshRadio.h +++ b/src/mesh/MeshRadio.h @@ -16,4 +16,7 @@ struct RegionInfo { const char *name; // EU433 etc }; -extern const RegionInfo regions[]; \ No newline at end of file +extern const RegionInfo regions[]; +extern const RegionInfo *myRegion; + +extern void initRegion(); \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cf47cfd15..1febc0ae1 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -245,6 +245,9 @@ void NodeDB::init() } } + // Update the global myRegion + initRegion(); + strncpy(myNodeInfo.firmware_version, optstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 8fefd80f8..c35075c66 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -26,7 +26,20 @@ const RegionInfo regions[] = { RDEF(Unset, 903.08f, 2.16f, 13, 0) // Assume US freqs if unset, Must be last }; -static const RegionInfo *myRegion; +const RegionInfo *myRegion; + +void initRegion() +{ + if (!myRegion) { + const RegionInfo *r = regions; + for (; r->code != RegionCode_Unset && r->code != radioConfig.preferences.region; r++) + ; + myRegion = r; + DEBUG_MSG("Wanted region %d, using %s\n", radioConfig.preferences.region, r->name); + + myNodeInfo.num_channels = myRegion->numChannels; // Tell our android app how many channels we have + } +} /** * ## LoRaWAN for North America @@ -91,20 +104,10 @@ void printPacket(const char *prefix, const MeshPacket *p) DEBUG_MSG(")\n"); } -RadioInterface::RadioInterface() +RadioInterface::RadioInterface() { assert(sizeof(PacketHeader) == 4 || sizeof(PacketHeader) == 16); // make sure the compiler did what we expected - if (!myRegion) { - const RegionInfo *r = regions; - for (; r->code != RegionCode_Unset && r->code != radioConfig.preferences.region; r++) - ; - myRegion = r; - DEBUG_MSG("Wanted region %d, using %s\n", radioConfig.preferences.region, r->name); - - myNodeInfo.num_channels = myRegion->numChannels; // Tell our android app how many channels we have - } - // Can't print strings this early - serial not setup yet // DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name); } @@ -120,7 +123,7 @@ bool RadioInterface::init() // we now expect interfaces to operate in promiscous mode // radioIf.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor // time. - + return true; }