From 27c16ba185179470232fc6348cb1e598f68af273 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 26 Dec 2020 12:53:20 +0800 Subject: [PATCH 1/3] add ppr1 notes --- src/nrf52/BQ25713.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nrf52/BQ25713.cpp b/src/nrf52/BQ25713.cpp index 52f4381f..2018ea7d 100644 --- a/src/nrf52/BQ25713.cpp +++ b/src/nrf52/BQ25713.cpp @@ -18,10 +18,10 @@ bool BQ25713::setup() if (!writeReg(0x00, 0x0F0A)) return false; // Config Charge Option 0 - if (!writeReg(0x02, 0x0224)) + if (!writeReg(0x02, 0x0224)) // 512mA, FIXME, this seems to be setting a number of bits marked as reserved, why? return false; // Config Charge Current - if (!writeReg(0x04, 0x1070)) + if (!writeReg(0x04, 0x1070)) // about 4.29V return false; // Config Charge Voltage if (!writeReg(0x06, 0x099C)) @@ -32,7 +32,7 @@ bool BQ25713::setup() // if(!writeReg(0x0A,0x0100)) return false;//Config Input Voltage - if (!writeReg(0x0C, 0x1800)) + if (!writeReg(0x0C, 0x1800)) // 4.2Vish FIXME, we could lower this? return false; // Config Minimum System Voltage if (!writeReg(0x0E, 0x4900)) From 651bd714543996f6c16295ba224f6bf561dc244d Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 26 Dec 2020 13:36:21 +0800 Subject: [PATCH 2/3] show critical faults on the screen --- docs/software/TODO.md | 4 ++-- src/error.h | 20 ++++++++++++++++++-- src/gps/UBloxGPS.cpp | 2 +- src/graphics/Screen.cpp | 34 ++++++++++++++++++++++++++++++++-- src/graphics/configs.h | 12 ------------ src/main.cpp | 11 +++++++++++ src/mesh/MeshService.cpp | 3 ++- src/mesh/NodeDB.cpp | 3 +++ 8 files changed, 69 insertions(+), 20 deletions(-) delete mode 100644 src/graphics/configs.h diff --git a/docs/software/TODO.md b/docs/software/TODO.md index f96d2acb..6c338c81 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -34,8 +34,8 @@ For app cleanup: * DONE move user info into regular data packets (use new app framework) * DONE test that positions, text messages and user info still work * DONE test that position, text messages and user info work properly with new android app and old device code -* do UDP tunnel -* fix the RTC drift bug +* DONE do UDP tunnel +* DONE fix the RTC drift bug * move python ping functionality into device, reply with rxsnr info * use channels for gpio security https://github.com/meshtastic/Meshtastic-device/issues/104 * MeshPackets for sending should be reference counted so that API clients would have the option of checking sent status (would allow removing the nasty 30 sec timer in gpio watch sending) diff --git a/src/error.h b/src/error.h index 6a2bae24..9b50f670 100644 --- a/src/error.h +++ b/src/error.h @@ -2,8 +2,24 @@ #include -/// Error codes for critical error -enum CriticalErrorCode { NoError, ErrTxWatchdog, ErrSleepEnterWait, ErrNoRadio, ErrUnspecified, UBloxInitFailed }; +/** Error codes for critical errors + * + * The device might report these fault codes on the screen. If you encounter a fault code, please + * post on the meshtastic.discourse.group and we'll try to help. + */ +enum CriticalErrorCode { + NoError = 0, + ErrTxWatchdog = 1, + ErrSleepEnterWait = 2, + + // No Lora radio hardware could be found + ErrNoRadio = 3, + ErrUnspecified = 4, + ErrUBloxInitFailed = 5, + + // This board was expected to have a power management chip and it is missing or broken + ErrNoAXP192 = 6 + }; /// Record an error that should be reported via analytics void recordCriticalError(CriticalErrorCode code, uint32_t address = 0); diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 2db5d775..7aa29b01 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -43,7 +43,7 @@ bool UBloxGPS::setupGPS() DEBUG_MSG("Connected to UBLOX GPS successfully\n"); if (!setUBXMode()) - recordCriticalError(UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug + recordCriticalError(ErrUBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug return true; } else { diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index ecaa216f..6604b0d7 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -26,7 +26,6 @@ along with this program. If not, see . #include "MeshService.h" #include "NodeDB.h" #include "Screen.h" -#include "configs.h" #include "configuration.h" #include "graphics/images.h" #include "main.h" @@ -35,12 +34,22 @@ along with this program. If not, see . #include "plugins/TextMessagePlugin.h" #include "target_specific.h" #include "utils.h" +#include "fonts.h" using namespace meshtastic; /** @todo remove */ namespace graphics { +// This means the *visible* area (sh1106 can address 132, but shows 128 for example) +#define IDLE_FRAMERATE 1 // in fps +#define COMPASS_DIAM 44 + +// DEBUG +#define NUM_EXTRA_FRAMES 3 // text message and debug frame +// if defined a pixel will blink to show redraws +// #define SHOW_REDRAWS + // A text message frame + debug frame + all the node infos static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES]; static uint32_t targetFramerate = IDLE_FRAMERATE; @@ -152,6 +161,23 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state, display->drawString(64 + x, 48 + y, buf); } +/// Draw the last text message we received +static void drawCriticalFaultFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + displayedNodeNum = 0; // Not currently showing a node pane + + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(FONT_MEDIUM); + + char tempBuf[24]; + snprintf(tempBuf, sizeof(tempBuf), "Critical fault #%d", myNodeInfo.error_code); + display->drawString(0 + x, 0 + y, tempBuf); + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(FONT_SMALL); + display->drawString(0 + x, FONT_HEIGHT_MEDIUM + y, "For help, please post on\nmeshtastic.discourse.group"); +} + + /// Draw the last text message we received static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { @@ -849,7 +875,11 @@ void Screen::setFrames() size_t numframes = 0; - // If we have a text message - show it first + // If we have a critical fault, show it first + if (myNodeInfo.error_code) + normalFrames[numframes++] = drawCriticalFaultFrame; + + // If we have a text message - show it next if (devicestate.has_rx_text_message) normalFrames[numframes++] = drawTextMessageFrame; diff --git a/src/graphics/configs.h b/src/graphics/configs.h deleted file mode 100644 index 65077b9d..00000000 --- a/src/graphics/configs.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "fonts.h" - -// This means the *visible* area (sh1106 can address 132, but shows 128 for example) -#define IDLE_FRAMERATE 1 // in fps -#define COMPASS_DIAM 44 - -// DEBUG -#define NUM_EXTRA_FRAMES 2 // text message and debug frame -// if defined a pixel will blink to show redraws -// #define SHOW_REDRAWS \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3f028613..7d27ad63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,6 +92,7 @@ void scanI2Cdevice(void) DEBUG_MSG("Unknow error at address 0x%x\n", addr); } } + if (nDevices == 0) DEBUG_MSG("No I2C devices found\n"); else @@ -362,6 +363,10 @@ void setup() nrf52Setup(); #endif + // We do this as early as possible because this loads preferences from flash + // but we need to do this after main cpu iniot (esp32setup), because we need the random seed set + nodeDB.init(); + // Currently only the tbeam has a PMU power = new Power(); power->setStatusHandler(powerStatus); @@ -420,6 +425,12 @@ void setup() service.init(); + // Do this after service.init (because that clears error_code) +#ifdef AXP192_SLAVE_ADDRESS + if(!axp192_found) + recordCriticalError(ErrNoAXP192); // Record a hardware fault for missing hardware +#endif + // Don't call screen setup until after nodedb is setup (because we need // the current region name) #if defined(ST7735_CS) || defined(HAS_EINK) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 5ca841ef..b1d4e687 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -77,7 +77,8 @@ void MeshService::init() sendOwnerPeriod = new concurrency::Periodic("SendOwner", sendOwnerCb); sendOwnerPeriod->setIntervalFromNow(30 * 1000); // Send our initial owner announcement 30 seconds after we start (to give network time to setup) - nodeDB.init(); + // moved much earlier in boot (called from setup()) + // nodeDB.init(); if (gps) gpsObserver.observe(&gps->newStatus); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a003f20a..9f4c144d 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -271,6 +271,9 @@ void NodeDB::init() myNodeInfo.node_num_bits = sizeof(NodeNum) * 8; myNodeInfo.packet_id_bits = sizeof(PacketId) * 8; + myNodeInfo.error_code = NoError; // For the error code, only show values from this boot (discard value from flash) + myNodeInfo.error_address = 0; + // likewise - we always want the app requirements to come from the running appload myNodeInfo.min_app_version = 20120; // format is Mmmss (where M is 1+the numeric major number. i.e. 20120 means 1.1.20 From 4a653ab054d115a14c8e1ab37913224d3648f349 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 26 Dec 2020 13:47:02 +0800 Subject: [PATCH 3/3] fix nrf52 build --- src/graphics/TFTDisplay.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index f1258291..21534edd 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -3,7 +3,6 @@ #ifdef ST7735_CS #include "SPILock.h" #include "TFTDisplay.h" -#include "graphics/configs.h" #include #include // Graphics and font library for ST7735 driver chip