diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 09c0635a4..145a75c2d 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -95,6 +95,7 @@ jobs: - board: tlora-t3s3-v1 - board: t-watch-s3 - board: t-deck + - board: picomputer-s3 uses: ./.github/workflows/build_esp32_s3.yml with: board: ${{ matrix.board }} diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index cdf662e1f..8ab9166fb 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,6 +1,6 @@ version: 0.1 cli: - version: 1.9.1 + version: 1.10.0 plugins: sources: - id: trunk @@ -10,7 +10,7 @@ lint: enabled: - taplo@0.7.0 - ruff@0.0.265 - - yamllint@1.31.0 + - yamllint@1.32.0 - isort@5.12.0 - markdownlint@0.34.0 - oxipng@8.0.0 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4fc84fa78..783791f0b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,4 +6,4 @@ "platformio.platformio-ide", "trunk.io" ], -} +} \ No newline at end of file diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 9a3cd8630..046c8ac62 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -1,11 +1,13 @@ [nrf52_base] ; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files -platform = platformio/nordicnrf52@^10.0.0 +platform = platformio/nordicnrf52@^10.1.0 extends = arduino_base build_type = debug ; I'm debugging with ICE a lot now build_flags = - ${arduino_base.build_flags} -Wno-unused-variable + ${arduino_base.build_flags} + -DSERIAL_BUFFER_SIZE=1024 + -Wno-unused-variable -Isrc/platform/nrf52 build_src_filter = diff --git a/boards/bpi_picow_esp32_s3.json b/boards/bpi_picow_esp32_s3.json index 75983d845..9a20dd57f 100644 --- a/boards/bpi_picow_esp32_s3.json +++ b/boards/bpi_picow_esp32_s3.json @@ -28,8 +28,6 @@ "flash_size": "8MB", "maximum_ram_size": 327680, "maximum_size": 8388608, - "use_1200bps_touch": true, - "wait_for_upload_port": true, "require_upload_port": true, "speed": 921600 }, diff --git a/platformio.ini b/platformio.ini index 08b00fee3..0a5029f9d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -88,7 +88,7 @@ check_flags = framework = arduino lib_deps = ${env.lib_deps} - mprograms/QMC5883LCompass@^1.1.1 + mprograms/QMC5883LCompass@^1.2.0 end2endzone/NonBlockingRTTTL@^1.3.0 https://github.com/meshtastic/SparkFun_ATECCX08a_Arduino_Library.git#5cf62b36c6f30bc72a07bdb2c11fc9a22d1e31da @@ -107,8 +107,8 @@ lib_deps = [environmental_base] lib_deps = adafruit/Adafruit BusIO@^1.11.4 - adafruit/Adafruit Unified Sensor@^1.1.9 - adafruit/Adafruit BMP280 Library@^2.6.6 + adafruit/Adafruit Unified Sensor@^1.1.11 + adafruit/Adafruit BMP280 Library@^2.6.8 adafruit/Adafruit BME280 Library@^2.2.2 https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.5.2400 boschsensortec/BME68x Sensor Library@^1.1.40407 @@ -117,7 +117,7 @@ lib_deps = adafruit/Adafruit INA219@^1.2.0 adafruit/Adafruit SHTC3 Library@^1.0.0 adafruit/Adafruit LPS2X@^2.0.4 - adafruit/Adafruit SHT31 Library@^2.2.0 + adafruit/Adafruit SHT31 Library@^2.2.2 adafruit/Adafruit PM25 AQI Sensor@^1.0.6 adafruit/Adafruit MPU6050@^2.2.4 adafruit/Adafruit LIS3DH@^1.2.4 diff --git a/protobufs b/protobufs index 8e7500278..d47300965 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 8e7500278f32a0f8096961843aad9b431916dcb0 +Subproject commit d47300965904a8d55d109327568e19a2eb9a12c0 diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index dc98c8d7d..0139db0c0 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -1,3 +1,13 @@ +/** + * @file FSCommon.cpp + * @brief This file contains functions for common filesystem operations such as copying, renaming, listing and deleting files and + * directories. + * + * The functions in this file are used to perform common filesystem operations such as copying, renaming, listing and deleting + * files and directories. These functions are used in the Meshtastic-device project to manage files and directories on the + * device's filesystem. + * + */ #include "FSCommon.h" #include "configuration.h" @@ -14,6 +24,13 @@ SPIClass SPI1(HSPI); #endif // HAS_SDCARD +/** + * @brief Copies a file from one location to another. + * + * @param from The path of the source file. + * @param to The path of the destination file. + * @return true if the file was successfully copied, false otherwise. + */ bool copyFile(const char *from, const char *to) { #ifdef FSCom @@ -43,6 +60,14 @@ bool copyFile(const char *from, const char *to) return true; } +/** + * Renames a file from pathFrom to pathTo. + * + * @param pathFrom The original path of the file. + * @param pathTo The new path of the file. + * + * @return True if the file was successfully renamed, false otherwise. + */ bool renameFile(const char *pathFrom, const char *pathTo) { #ifdef FSCom @@ -60,6 +85,13 @@ bool renameFile(const char *pathFrom, const char *pathTo) return true; } +/** + * Lists the contents of a directory. + * + * @param dirname The name of the directory to list. + * @param levels The number of levels of subdirectories to list. + * @param del Whether or not to delete the contents of the directory after listing. + */ void listDir(const char *dirname, uint8_t levels, bool del = false) { #ifdef FSCom @@ -155,6 +187,13 @@ void listDir(const char *dirname, uint8_t levels, bool del = false) #endif } +/** + * @brief Removes a directory and all its contents. + * + * This function recursively removes a directory and all its contents, including subdirectories and files. + * + * @param dirname The name of the directory to remove. + */ void rmDir(const char *dirname) { #ifdef FSCom @@ -183,6 +222,9 @@ void fsInit() #endif } +/** + * Initializes the SD card and mounts the file system. + */ void setupSDCard() { #ifdef HAS_SDCARD @@ -213,4 +255,4 @@ void setupSDCard() LOG_DEBUG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024)); LOG_DEBUG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024)); #endif -} +} \ No newline at end of file diff --git a/src/OSTimer.cpp b/src/OSTimer.cpp index 21744615f..f6739d75e 100644 --- a/src/OSTimer.cpp +++ b/src/OSTimer.cpp @@ -29,6 +29,16 @@ static void IRAM_ATTR onTimer() (*tCallback)(tParam1, tParam2); } +/** + * Schedules a hardware callback function to be executed after a specified delay. + * + * @param callback The function to be executed. + * @param param1 The first parameter to be passed to the function. + * @param param2 The second parameter to be passed to the function. + * @param delayMsec The delay time in milliseconds before the function is executed. + * + * @return True if the function was successfully scheduled, false otherwise. + */ bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec) { if (!timer) { diff --git a/src/Power.cpp b/src/Power.cpp index 5288fb2a6..533286fe9 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -1,3 +1,15 @@ +/** + * @file Power.cpp + * @brief This file contains the implementation of the Power class, which is responsible for managing power-related functionality + * of the device. It includes battery level sensing, power management unit (PMU) control, and power state machine management. The + * Power class is used by the main device class to manage power-related functionality. + * + * The file also includes implementations of various battery level sensors, such as the AnalogBatteryLevel class, which assumes + * the battery voltage is attached via a voltage-divider to an analog input. + * + * This file is part of the Meshtastic project. + * For more information, see: https://meshtastic.org/ + */ #include "power.h" #include "NodeDB.h" #include "PowerFSM.h" @@ -366,6 +378,11 @@ bool Power::analogInit() #endif } +/** + * Initializes the Power class. + * + * @return true if the setup was successful, false otherwise. + */ bool Power::setup() { bool found = axpChipInit(); diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 2d42ef655..6c6069365 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -1,3 +1,12 @@ +/** + * @file PowerFSM.cpp + * @brief Implements the finite state machine for power management. + * + * This file contains the implementation of the finite state machine (FSM) for power management. + * The FSM controls the power states of the device, including SDS (shallow deep sleep), LS (light sleep), + * NB (normal mode), and POWER (powered mode). The FSM also handles transitions between states and + * actions to be taken upon entering or exiting each state. + */ #include "PowerFSM.h" #include "GPS.h" #include "MeshService.h" @@ -137,7 +146,10 @@ static void nbEnter() { LOG_DEBUG("Enter state: NB\n"); screen->setOn(false); +#ifdef ARCH_ESP32 + // Only ESP32 should turn off bluetooth setBluetoothEnable(false); +#endif // FIXME - check if we already have packets for phone and immediately trigger EVENT_PACKETS_FOR_PHONE } @@ -158,6 +170,8 @@ static void serialEnter() static void serialExit() { + // Turn bluetooth back on when we leave serial stream API + setBluetoothEnable(true); screen->print("Serial disconnected\n"); } @@ -242,7 +256,11 @@ void PowerFSM_setup() // wake timer expired or a packet arrived // if we are a router node, we go to NB (no need for bluetooth) otherwise we go to DARK (so we can send message to phone) +#ifdef ARCH_ESP32 powerFSM.add_transition(&stateLS, isRouter ? &stateNB : &stateDARK, EVENT_WAKE_TIMER, NULL, "Wake timer"); +#else // Don't go into a no-bluetooth state on low power platforms + powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, NULL, "Wake timer"); +#endif // We need this transition, because we might not transition if we were waiting to enter light-sleep, because when we wake from // light sleep we _always_ transition to NB or dark and diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 737ad71d2..62536505d 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -213,8 +213,8 @@ bool GPS::setupGPS() // _serial_gps->begin(9600); //The baud rate of 9600 has been initialized at the beginning of setupGPS, this line // is the redundant part delay(250); - // Initialize the L76K Chip, use GPS + GLONASS - _serial_gps->write("$PCAS04,5*1C\r\n"); + // Initialize the L76K Chip, use GPS + GLONASS + BEIDOU + _serial_gps->write("$PCAS04,7*1E\r\n"); delay(250); // only ask for RMC and GGA _serial_gps->write("$PCAS03,1,0,0,0,1,0,0,0,0,0,,,0,0*02\r\n"); diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 0632164e9..b2cbcfa81 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -107,6 +107,14 @@ bool NMEAGPS::lookForLocation() // At a minimum, use the fixQuality indicator in GPGGA (FIXME?) fixQual = reader.fixQuality(); +#ifndef TINYGPS_OPTION_NO_STATISTICS + if (reader.failedChecksum() > lastChecksumFailCount) { + LOG_WARN("Warning, %u new GPS checksum failures, for a total of %u.\n", reader.failedChecksum() - lastChecksumFailCount, + reader.failedChecksum()); + lastChecksumFailCount = reader.failedChecksum(); + } +#endif + #ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS fixType = atoi(gsafixtype.value()); // will set to zero if no data // LOG_DEBUG("FIX QUAL=%d, TYPE=%d\n", fixQual, fixType); @@ -174,8 +182,10 @@ bool NMEAGPS::lookForLocation() #endif // Discard incomplete or erroneous readings - if (reader.hdop.value() == 0) + if (reader.hdop.value() == 0) { + LOG_WARN("BOGUS hdop.value() REJECTED: %d\n", reader.hdop.value()); return false; + } p.latitude_i = toDegInt(loc.lat); p.longitude_i = toDegInt(loc.lng); @@ -243,7 +253,8 @@ bool NMEAGPS::hasFlow() bool NMEAGPS::whileIdle() { bool isValid = false; - + // if (_serial_gps->available() > 0) + // LOG_DEBUG("GPS Bytes Waiting: %u\n", _serial_gps->available()); // First consume any chars that have piled up at the receiver while (_serial_gps->available() > 0) { int c = _serial_gps->read(); diff --git a/src/gps/NMEAGPS.h b/src/gps/NMEAGPS.h index 82e691717..85521077a 100644 --- a/src/gps/NMEAGPS.h +++ b/src/gps/NMEAGPS.h @@ -13,6 +13,7 @@ class NMEAGPS : public GPS { TinyGPSPlus reader; uint8_t fixQual = 0; // fix quality from GPGGA + uint32_t lastChecksumFailCount = 0; #ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS // (20210908) TinyGps++ can only read the GPGSA "FIX TYPE" field @@ -53,4 +54,4 @@ class NMEAGPS : public GPS virtual bool hasLock() override; virtual bool hasFlow() override; -}; +}; \ No newline at end of file diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index b80fd04aa..2bfb66e12 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -17,6 +17,10 @@ static uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time static uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only updated once on initial lock +/** + * Reads the current date and time from the RTC module and updates the system time. + * @return True if the RTC was successfully read and the system time was updated, false otherwise. + */ void readFromRTC() { struct timeval tv; /* btw settimeofday() is helpful here too*/ @@ -83,7 +87,15 @@ void readFromRTC() #endif } -/// If we haven't yet set our RTC this boot, set it from a GPS derived time +/** + * Sets the RTC (Real-Time Clock) if the provided time is of higher quality than the current RTC time. + * + * @param q The quality of the provided time. + * @param tv A pointer to a timeval struct containing the time to potentially set the RTC to. + * @return True if the RTC was set, false otherwise. + * + * If we haven't yet set our RTC this boot, set it from a GPS derived time + */ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) { static uint32_t lastSetMsec = 0; @@ -151,6 +163,13 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) } } +/** + * Sets the RTC time if the provided time is of higher quality than the current RTC time. + * + * @param q The quality of the provided time. + * @param t The time to potentially set the RTC to. + * @return True if the RTC was set to the provided time, false otherwise. + */ bool perhapsSetRTC(RTCQuality q, struct tm &t) { /* Convert to unix time @@ -171,11 +190,22 @@ bool perhapsSetRTC(RTCQuality q, struct tm &t) } } +/** + * Returns the current time in seconds since the Unix epoch (January 1, 1970). + * + * @return The current time in seconds since the Unix epoch. + */ uint32_t getTime() { return (((uint32_t)millis() - timeStartMsec) / 1000) + zeroOffsetSecs; } +/** + * Returns the current time from the RTC if the quality of the time is at least minQuality. + * + * @param minQuality The minimum quality of the RTC time required for it to be considered valid. + * @return The current time from the RTC if it meets the minimum quality requirement, or 0 if the time is not valid. + */ uint32_t getValidTime(RTCQuality minQuality) { return (currentQuality >= minQuality) ? getTime() : 0; diff --git a/src/graphics/EInkDisplay2.h b/src/graphics/EInkDisplay2.h index c7ae6754b..2529b1f0e 100644 --- a/src/graphics/EInkDisplay2.h +++ b/src/graphics/EInkDisplay2.h @@ -3,7 +3,7 @@ #include /** - * An adapter class that allows using the TFT_eSPI library as if it was an OLEDDisplay implementation. + * An adapter class that allows using the GxEPD2 library as if it was an OLEDDisplay implementation. * * Remaining TODO: * optimize display() to only draw changed pixels (see other OLED subclasses for examples) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index fbd99d252..ce6b7d5dd 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -103,7 +103,8 @@ static uint16_t displayWidth, displayHeight; #define SCREEN_WIDTH displayWidth #define SCREEN_HEIGHT displayHeight -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) // The screen is bigger so use bigger fonts #define FONT_SMALL ArialMT_Plain_16 // Height: 19 #define FONT_MEDIUM ArialMT_Plain_24 // Height: 28 @@ -493,7 +494,8 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, NodeStatus *no { char usersString[20]; snprintf(usersString, sizeof(usersString), "%d/%d", nodeStatus->getNumOnline(), nodeStatus->getNumTotal()); -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x, y + 3, 8, 8, imgUser); #else display->drawFastImage(x, y, 8, 8, imgUser); @@ -1527,7 +1529,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #ifdef ARCH_ESP32 if (millis() - storeForwardModule->lastHeartbeat > (storeForwardModule->heartbeatInterval * 1200)) { // no heartbeat, overlap a bit -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1); display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8, @@ -1537,7 +1540,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 imgQuestion); #endif } else { -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1); display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 16, 8, @@ -1549,7 +1553,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } #endif } else { -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8, diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 4c9196b2f..b42936c44 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -108,10 +108,12 @@ class LGFX : public lgfx::LGFX_Device lgfx::Panel_ST7789 _panel_instance; lgfx::Bus_SPI _bus_instance; lgfx::Light_PWM _light_instance; +#if HAS_TOUCHSCREEN #ifdef T_WATCH_S3 lgfx::Touch_FT5x06 _touch_instance; #else lgfx::Touch_GT911 _touch_instance; +#endif #endif public: @@ -126,13 +128,14 @@ class LGFX : public lgfx::LGFX_Device cfg.freq_write = SPI_FREQUENCY; // SPI clock for transmission (up to 80MHz, rounded to the value obtained by dividing // 80MHz by an integer) cfg.freq_read = SPI_READ_FREQUENCY; // SPI clock when receiving - cfg.spi_3wire = false; // Set to true if reception is done on the MOSI pin - cfg.use_lock = true; // Set to true to use transaction locking - cfg.dma_channel = SPI_DMA_CH_AUTO; // SPI_DMA_CH_AUTO; // Set DMA channel to use (0=not use DMA / 1=1ch / 2=ch / - cfg.pin_sclk = ST7789_SCK; // Set SPI SCLK pin number - cfg.pin_mosi = ST7789_SDA; // Set SPI MOSI pin number - cfg.pin_miso = ST7789_MISO; // Set SPI MISO pin number (-1 = disable) - cfg.pin_dc = ST7789_RS; // Set SPI DC pin number (-1 = disable) + cfg.spi_3wire = false; + cfg.use_lock = true; // Set to true to use transaction locking + cfg.dma_channel = SPI_DMA_CH_AUTO; // SPI_DMA_CH_AUTO; // Set DMA channel to use (0=not use DMA / 1=1ch / 2=ch / + // SPI_DMA_CH_AUTO=auto setting) + cfg.pin_sclk = ST7789_SCK; // Set SPI SCLK pin number + cfg.pin_mosi = ST7789_SDA; // Set SPI MOSI pin number + cfg.pin_miso = ST7789_MISO; // Set SPI MISO pin number (-1 = disable) + cfg.pin_dc = ST7789_RS; // Set SPI DC pin number (-1 = disable) _bus_instance.config(cfg); // applies the set value to the bus. _panel_instance.setBus(&_bus_instance); // set the bus on the panel. @@ -181,6 +184,7 @@ class LGFX : public lgfx::LGFX_Device _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. } +#if HAS_TOUCHSCREEN // Configure settings for touch screen control. { auto cfg = _touch_instance.config(); @@ -210,6 +214,7 @@ class LGFX : public lgfx::LGFX_Device _touch_instance.config(cfg); _panel_instance.setTouch(&_touch_instance); } +#endif setPanel(&_panel_instance); // Sets the panel to use. } @@ -217,7 +222,96 @@ class LGFX : public lgfx::LGFX_Device static LGFX tft; -#elif defined(ST7735_CS) || defined(ILI9341_DRIVER) +#elif defined(ILI9341_DRIVER) + +#include // Graphics and font library for ILI9341 driver chip + +#if defined(ILI9341_BACKLIGHT_EN) && !defined(TFT_BL) +#define TFT_BL ILI9341_BACKLIGHT_EN +#endif + +class LGFX : public lgfx::LGFX_Device +{ + lgfx::Panel_ILI9341 _panel_instance; + lgfx::Bus_SPI _bus_instance; + lgfx::Light_PWM _light_instance; + + public: + LGFX(void) + { + { + auto cfg = _bus_instance.config(); + + // configure SPI + cfg.spi_host = ILI9341_SPI_HOST; // ESP32-S2,S3,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST + cfg.spi_mode = 0; + cfg.freq_write = SPI_FREQUENCY; // SPI clock for transmission (up to 80MHz, rounded to the value obtained by dividing + // 80MHz by an integer) + cfg.freq_read = SPI_READ_FREQUENCY; // SPI clock when receiving + cfg.spi_3wire = false; // Set to true if reception is done on the MOSI pin + cfg.use_lock = true; // Set to true to use transaction locking + cfg.dma_channel = SPI_DMA_CH_AUTO; // SPI_DMA_CH_AUTO; // Set DMA channel to use (0=not use DMA / 1=1ch / 2=ch / + // SPI_DMA_CH_AUTO=auto setting) + cfg.pin_sclk = TFT_SCLK; // Set SPI SCLK pin number + cfg.pin_mosi = TFT_MOSI; // Set SPI MOSI pin number + cfg.pin_miso = TFT_MISO; // Set SPI MISO pin number (-1 = disable) + cfg.pin_dc = TFT_DC; // Set SPI DC pin number (-1 = disable) + + _bus_instance.config(cfg); // applies the set value to the bus. + _panel_instance.setBus(&_bus_instance); // set the bus on the panel. + } + + { // Set the display panel control. + auto cfg = _panel_instance.config(); // Gets a structure for display panel settings. + + cfg.pin_cs = TFT_CS; // Pin number where CS is connected (-1 = disable) + cfg.pin_rst = TFT_RST; // Pin number where RST is connected (-1 = disable) + cfg.pin_busy = TFT_BUSY; // Pin number where BUSY is connected (-1 = disable) + + // The following setting values ​​are general initial values ​​for each panel, so please comment out any + // unknown items and try them. + + cfg.panel_width = TFT_WIDTH; // actual displayable width + cfg.panel_height = TFT_HEIGHT; // actual displayable height + cfg.offset_x = TFT_OFFSET_X; // Panel offset amount in X direction + cfg.offset_y = TFT_OFFSET_Y; // Panel offset amount in Y direction + cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is upside down) + cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout + cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read + cfg.readable = true; // Set to true if data can be read + cfg.invert = false; // Set to true if the light/darkness of the panel is reversed + cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped + cfg.dlen_16bit = + false; // Set to true for panels that transmit data length in 16-bit units with 16-bit parallel or SPI + cfg.bus_shared = true; // If the bus is shared with the SD card, set to true (bus control with drawJpgFile etc.) + + // Set the following only when the display is shifted with a driver with a variable number of pixels, such as the + // ST7735 or ILI9163. + cfg.memory_width = TFT_WIDTH; // Maximum width supported by the driver IC + cfg.memory_height = TFT_HEIGHT; // Maximum height supported by the driver IC + _panel_instance.config(cfg); + } + + // Set the backlight control + { + auto cfg = _light_instance.config(); // Gets a structure for backlight settings. + + cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected + cfg.invert = false; // true to invert the brightness of the backlight + // cfg.freq = 44100; // PWM frequency of backlight + // cfg.pwm_channel = 1; // PWM channel number to use + + _light_instance.config(cfg); + _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. + } + + setPanel(&_panel_instance); + } +}; + +static LGFX tft; + +#elif defined(ST7735_CS) #include // Graphics and font library for ILI9341 driver chip static TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h @@ -335,9 +429,9 @@ bool TFTDisplay::connect() #endif tft.init(); -#if defined(M5STACK) || defined(T_DECK) +#if defined(T_DECK) || defined(PICOMPUTER_S3) tft.setRotation(1); // M5Stack/T-Deck have the TFT in landscape -#elif defined(T_WATCH_S3) +#elif defined(M5STACK) || defined(T_WATCH_S3) tft.setRotation(0); // T-Watch S3 has the TFT in portrait #else tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index 325765b1f..dee31acf1 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -3,7 +3,7 @@ #include /** - * An adapter class that allows using the TFT_eSPI library as if it was an OLEDDisplay implementation. + * An adapter class that allows using the LovyanGFX library as if it was an OLEDDisplay implementation. * * Remaining TODO: * optimize display() to only draw changed pixels (see other OLED subclasses for examples) diff --git a/src/graphics/images.h b/src/graphics/images.h index 46c9118b1..a1191076b 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -14,7 +14,8 @@ const uint8_t imgUser[] PROGMEM = {0x3C, 0x42, 0x99, 0xA5, 0xA5, 0x99, 0x42, 0x3 const uint8_t imgPositionEmpty[] PROGMEM = {0x20, 0x30, 0x28, 0x24, 0x42, 0xFF}; const uint8_t imgPositionSolid[] PROGMEM = {0x20, 0x30, 0x38, 0x3C, 0x7E, 0xFF}; -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; const uint8_t imgInfoL1[] PROGMEM = {0xff, 0x01, 0x01, 0x01, 0x1e, 0x7f, 0x1e, 0x01, 0x01, 0x01, 0x01, 0xff}; diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index cdffbaf7e..f7fd62645 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -28,17 +28,6 @@ uint8_t read_from_14004(TwoWire *i2cBus, uint8_t reg, uint8_t *data, uint8_t len return readflag; } -// Unused for now - flagging it off -#if 0 -void write_to_14004(const TwoWire * i2cBus, uint8_t reg, uint8_t data) -{ - i2cBus->beginTransmission(CARDKB_ADDR); - i2cBus->write(reg); - i2cBus->write(data); - i2cBus->endTransmission(); // stop transmitting -} -#endif - int32_t KbI2cBase::runOnce() { if (cardkb_found.address != CARDKB_ADDR && cardkb_found.address != TDECK_KB_ADDR) { diff --git a/src/input/kbMatrixBase.cpp b/src/input/kbMatrixBase.cpp new file mode 100644 index 000000000..823bfb629 --- /dev/null +++ b/src/input/kbMatrixBase.cpp @@ -0,0 +1,131 @@ +#include "kbMatrixBase.h" +#include "configuration.h" + +#ifdef INPUTBROKER_MATRIX_TYPE + +const byte keys_cols[] = KEYS_COLS; +const byte keys_rows[] = KEYS_ROWS; + +#if INPUTBROKER_MATRIX_TYPE == 1 + +unsigned char KeyMap[3][sizeof(keys_rows)][sizeof(keys_cols)] = {{{' ', '.', 'm', 'n', 'b', 0xb6}, + {0x0d, 'l', 'k', 'j', 'h', 0xb4}, + {'p', 'o', 'i', 'u', 'y', 0xb5}, + {0x08, 'z', 'x', 'c', 'v', 0xb7}, + {'a', 's', 'd', 'f', 'g', 0x09}, + {'q', 'w', 'e', 'r', 't', 0x1a}}, + {// SHIFT + {':', ';', 'M', 'N', 'B', 0xb6}, + {0x0d, 'L', 'K', 'J', 'H', 0xb4}, + {'P', 'O', 'I', 'U', 'Y', 0xb5}, + {0x08, 'Z', 'X', 'C', 'V', 0xb7}, + {'A', 'S', 'D', 'F', 'G', 0x09}, + {'Q', 'W', 'E', 'R', 'T', 0x1a}}, + {// SHIFT-SHIFT + {'_', ',', '>', '<', '"', '{'}, + {'~', '-', '*', '&', '+', '['}, + {'0', '9', '8', '7', '6', '}'}, + {'=', '(', ')', '?', '/', ']'}, + {'!', '@', '#', '$', '%', '\\'}, + {'1', '2', '3', '4', '5', 0x1a}}}; +#endif + +KbMatrixBase::KbMatrixBase(const char *name) : concurrency::OSThread(name) +{ + this->_originName = name; +} + +int32_t KbMatrixBase::runOnce() +{ + if (!INPUTBROKER_MATRIX_TYPE) { + // Input device is not requested. + return disable(); + } + + if (firstTime) { + // This is the first time the OSThread library has called this function, so do port setup + firstTime = 0; + for (byte i = 0; i < sizeof(keys_rows); i++) { + pinMode(keys_rows[i], OUTPUT); + digitalWrite(keys_rows[i], HIGH); + } + for (byte i = 0; i < sizeof(keys_cols); i++) { + pinMode(keys_cols[i], INPUT_PULLUP); + } + } + + key = 0; + + if (INPUTBROKER_MATRIX_TYPE == 1) { + // scan for keypresses + for (byte i = 0; i < sizeof(keys_rows); i++) { + digitalWrite(keys_rows[i], LOW); + for (byte j = 0; j < sizeof(keys_cols); j++) { + if (digitalRead(keys_cols[j]) == LOW) { + key = KeyMap[shift][i][j]; + } + } + digitalWrite(keys_rows[i], HIGH); + } + // debounce + if (key != prevkey) { + if (key != 0) { + LOG_DEBUG("Key 0x%x pressed\n", key); + // reset shift now that we have a keypress + InputEvent e; + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.source = this->_originName; + switch (key) { + case 0x1b: // ESC + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; + break; + case 0x08: // Back + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; + e.kbchar = key; + break; + case 0xb5: // Up + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP; + break; + case 0xb6: // Down + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN; + break; + case 0xb4: // Left + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT; + e.kbchar = key; + break; + case 0xb7: // Right + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT; + e.kbchar = key; + break; + case 0x0d: // Enter + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT; + break; + case 0x00: // nopress + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + break; + case 0x1a: // Shift + shift++; + if (shift > 2) { + shift = 0; + } + break; + default: // all other keys + e.inputEvent = ANYKEY; + e.kbchar = key; + break; + } + if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { + this->notifyObservers(&e); + } + } + prevkey = key; + } + + } else { + LOG_WARN("Unknown kb_model 0x%02x\n", INPUTBROKER_MATRIX_TYPE); + return disable(); + } + return 50; // Keyscan every 50msec to avoid key bounce +} + +#endif // INPUTBROKER_MATRIX_TYPE \ No newline at end of file diff --git a/src/input/kbMatrixBase.h b/src/input/kbMatrixBase.h new file mode 100644 index 000000000..8259fc07c --- /dev/null +++ b/src/input/kbMatrixBase.h @@ -0,0 +1,20 @@ +#pragma once + +#include "InputBroker.h" +#include "concurrency/OSThread.h" + +class KbMatrixBase : public Observable, public concurrency::OSThread +{ + public: + explicit KbMatrixBase(const char *name); + + protected: + virtual int32_t runOnce() override; + + private: + const char *_originName; + bool firstTime = 1; + int shift = 0; + char key = 0; + char prevkey = 0; +}; \ No newline at end of file diff --git a/src/input/kbMatrixImpl.cpp b/src/input/kbMatrixImpl.cpp new file mode 100644 index 000000000..0561b16fe --- /dev/null +++ b/src/input/kbMatrixImpl.cpp @@ -0,0 +1,20 @@ +#include "kbMatrixImpl.h" +#include "InputBroker.h" + +#ifdef INPUTBROKER_MATRIX_TYPE + +KbMatrixImpl *kbMatrixImpl; + +KbMatrixImpl::KbMatrixImpl() : KbMatrixBase("matrixKB") {} + +void KbMatrixImpl::init() +{ + if (!INPUTBROKER_MATRIX_TYPE) { + disable(); + return; + } + + inputBroker->registerSource(this); +} + +#endif // INPUTBROKER_MATRIX_TYPE \ No newline at end of file diff --git a/src/input/kbMatrixImpl.h b/src/input/kbMatrixImpl.h new file mode 100644 index 000000000..ead4a2d57 --- /dev/null +++ b/src/input/kbMatrixImpl.h @@ -0,0 +1,19 @@ +#pragma once +#include "kbMatrixBase.h" +#include "main.h" + +/** + * @brief The idea behind this class to have static methods for the event handlers. + * Check attachInterrupt() at RotaryEncoderInteruptBase.cpp + * Technically you can have as many rotary encoders hardver attached + * to your device as you wish, but you always need to have separate event + * handlers, thus you need to have a RotaryEncoderInterrupt implementation. + */ +class KbMatrixImpl : public KbMatrixBase +{ + public: + KbMatrixImpl(); + void init(); +}; + +extern KbMatrixImpl *kbMatrixImpl; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9c0eb1837..8b86dfcdb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -480,7 +480,7 @@ void setup() #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 + // but we need to do this after main cpu init (esp32setup), because we need the random seed set nodeDB.init(); // If we're taking on the repeater role, use flood router @@ -548,6 +548,7 @@ void setup() #else // ESP32 SPI.begin(RF95_SCK, RF95_MISO, RF95_MOSI, RF95_NSS); + LOG_WARN("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, NSS=%d)\n", RF95_SCK, RF95_MISO, RF95_MOSI, RF95_NSS); SPI.setFrequency(4000000); #endif diff --git a/src/memGet.cpp b/src/memGet.cpp index 9f59d29ff..0575da279 100644 --- a/src/memGet.cpp +++ b/src/memGet.cpp @@ -1,8 +1,21 @@ +/** + * @file memGet.cpp + * @brief Implementation of MemGet class that provides functions to get memory information. + * + * This file contains the implementation of MemGet class that provides functions to get + * information about free heap, heap size, free psram and psram size. The functions are + * implemented for ESP32 and NRF52 architectures. If the platform does not have heap + * management function implemented, the functions return UINT32_MAX or 0. + */ #include "memGet.h" #include "configuration.h" MemGet memGet; +/** + * Returns the amount of free heap memory in bytes. + * @return uint32_t The amount of free heap memory in bytes. + */ uint32_t MemGet::getFreeHeap() { #ifdef ARCH_ESP32 @@ -15,6 +28,10 @@ uint32_t MemGet::getFreeHeap() #endif } +/** + * Returns the size of the heap memory in bytes. + * @return uint32_t The size of the heap memory in bytes. + */ uint32_t MemGet::getHeapSize() { #ifdef ARCH_ESP32 @@ -27,6 +44,11 @@ uint32_t MemGet::getHeapSize() #endif } +/** + * Returns the amount of free psram memory in bytes. + * + * @return The amount of free psram memory in bytes. + */ uint32_t MemGet::getFreePsram() { #ifdef ARCH_ESP32 @@ -36,6 +58,11 @@ uint32_t MemGet::getFreePsram() #endif } +/** + * @brief Returns the size of the PSRAM memory. + * + * @return uint32_t The size of the PSRAM memory. + */ uint32_t MemGet::getPsramSize() { #ifdef ARCH_ESP32 @@ -43,4 +70,4 @@ uint32_t MemGet::getPsramSize() #else return 0; #endif -} +} \ No newline at end of file diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 83bd0e325..d27d47e87 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -21,7 +21,7 @@ bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) { if (wasSeenRecently(p)) { // Note: this will also add a recent packet record printPacket("Ignoring incoming msg, because we've already seen it", p); - if (config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER && + if (!moduleConfig.mqtt.enabled && config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER && config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT && config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) { // cancel rebroadcast of this message *if* there was already one, unless we're a router/repeater! @@ -49,10 +49,13 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas tosend->hop_limit--; // bump down the hop count - // If it is a traceRoute request, update the route that it went via me - if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag && traceRouteModule && - traceRouteModule->wantPacket(p)) { - traceRouteModule->updateRoute(tosend); + if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + // If it is a traceRoute request, update the route that it went via me + if (traceRouteModule && traceRouteModule->wantPacket(p)) + traceRouteModule->updateRoute(tosend); + // If it is a neighborInfo packet, update last_sent_by_id + if (neighborInfoModule && neighborInfoModule->wantPacket(p)) + neighborInfoModule->updateLastSentById(tosend); } LOG_INFO("Rebroadcasting received floodmsg to neighbors\n"); diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index 563b850a5..309035cb3 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -2,6 +2,7 @@ #include "PacketHistory.h" #include "Router.h" +#include "modules/NeighborInfoModule.h" #include "modules/TraceRouteModule.h" /** @@ -57,4 +58,4 @@ class FloodingRouter : public Router, protected PacketHistory * Look for broadcasts we need to rebroadcast */ virtual void sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Routing *c) override; -}; +}; \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index ecca443e0..59fc09da3 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -82,8 +82,13 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) powerFSM.trigger(EVENT_PACKET_FOR_PHONE); // Possibly keep the node from sleeping nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio - if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getMeshNode(mp->from)->has_user && - nodeInfoModule) { + if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && + mp->decoded.portnum == meshtastic_PortNum_TELEMETRY_APP && mp->decoded.request_id > 0) { + LOG_DEBUG( + "Received telemetry response. Skip sending our NodeInfo because this potentially a Repeater which will ignore our " + "request for its NodeInfo.\n"); + } else if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getMeshNode(mp->from)->has_user && + nodeInfoModule) { LOG_INFO("Heard a node on channel %d we don't know, sending NodeInfo and asking for a response.\n", mp->channel); nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index e03ee2f7e..3b13daaad 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -15,6 +15,7 @@ #include "error.h" #include "main.h" #include "mesh-pb-constants.h" +#include "modules/NeighborInfoModule.h" #include #include #include @@ -63,11 +64,7 @@ uint32_t error_address = 0; static uint8_t ourMacAddr[6]; -NodeDB::NodeDB() - : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count), meshNodes(devicestate.node_db_lite), - numMeshNodes(&devicestate.node_db_lite_count) -{ -} +NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(&devicestate.node_db_lite_count) {} /** * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on @@ -109,7 +106,6 @@ bool NodeDB::resetRadioConfig(bool factory_reset) config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_TW; // Enter super deep sleep soon and stay there not very long - // radioConfig.preferences.mesh_sds_timeout_secs = 10; // radioConfig.preferences.sds_secs = 60; } @@ -211,7 +207,6 @@ void NodeDB::initConfigIntervals() config.position.position_broadcast_secs = default_broadcast_interval_secs; config.power.ls_secs = default_ls_secs; - config.power.mesh_sds_timeout_secs = default_mesh_sds_timeout_secs; config.power.min_wake_secs = default_min_wake_secs; config.power.sds_secs = default_sds_secs; config.power.wait_bluetooth_secs = default_wait_bluetooth_secs; @@ -250,6 +245,9 @@ void NodeDB::installDefaultModuleConfig() strncpy(moduleConfig.mqtt.username, default_mqtt_username, sizeof(moduleConfig.mqtt.username)); strncpy(moduleConfig.mqtt.password, default_mqtt_password, sizeof(moduleConfig.mqtt.password)); + moduleConfig.has_neighbor_info = true; + moduleConfig.neighbor_info.enabled = false; + initModuleConfigIntervals(); } @@ -273,6 +271,7 @@ void NodeDB::initModuleConfigIntervals() moduleConfig.telemetry.device_update_interval = default_broadcast_interval_secs; moduleConfig.telemetry.environment_update_interval = default_broadcast_interval_secs; moduleConfig.telemetry.air_quality_interval = default_broadcast_interval_secs; + moduleConfig.neighbor_info.update_interval = default_broadcast_interval_secs; } void NodeDB::installDefaultChannels() @@ -284,12 +283,11 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - devicestate.node_db_count = 0; - memset(devicestate.node_db, 0, sizeof(devicestate.node_db)); - devicestate.node_db_lite_count = 0; memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite)); saveDeviceStateToDisk(); + if (neighborInfoModule && moduleConfig.neighbor_info.enabled) + neighborInfoModule->resetNeighbors(); } void NodeDB::installDefaultDeviceState() @@ -297,12 +295,11 @@ void NodeDB::installDefaultDeviceState() LOG_INFO("Installing default DeviceState\n"); memset(&devicestate, 0, sizeof(meshtastic_DeviceState)); - *numNodes = 0; + *numMeshNodes = 0; // init our devicestate with valid flags so protobuf writing/reading will work devicestate.has_my_node = true; devicestate.has_owner = true; - devicestate.node_db_count = 0; devicestate.node_db_lite_count = 0; devicestate.version = DEVICESTATE_CUR_VER; devicestate.receive_queue_count = 0; // Not yet implemented FIXME @@ -330,11 +327,9 @@ void NodeDB::init() int saveWhat = 0; // likewise - we always want the app requirements to come from the running appload - myNodeInfo.min_app_version = 20300; // format is Mmmss (where M is 1+the numeric major number. i.e. 20120 means 1.1.20 - myNodeInfo.max_channels = MAX_NUM_CHANNELS; // tell others the max # of channels we can understand + myNodeInfo.min_app_version = 30200; // format is Mmmss (where M is 1+the numeric major number. i.e. 30200 means 2.2.00 // Note! We do this after loading saved settings, so that if somehow an invalid nodenum was stored in preferences we won't // keep using that nodenum forever. Crummy guess at our nodenum (but we will check against the nodedb to avoid conflicts) - strncpy(myNodeInfo.firmware_version, optstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); pickNewNodeNum(); // Set our board type so we can share it with others @@ -345,19 +340,6 @@ void NodeDB::init() info->user = owner; info->has_user = true; - if (*numNodes > 0) { - LOG_DEBUG("Legacy NodeDB detected... Migrating to NodeDBLite\n"); - uint32_t readIndex = 0; - const meshtastic_NodeInfo *oldNodeInfo = nodeDB.readNextNodeInfo(readIndex); - while (oldNodeInfo != NULL) { - migrateToNodeInfoLite(oldNodeInfo); - oldNodeInfo = nodeDB.readNextNodeInfo(readIndex); - } - LOG_DEBUG("Migration complete! Clearing out legacy NodeDB...\n"); - devicestate.node_db_count = 0; - memset(devicestate.node_db, 0, sizeof(devicestate.node_db)); - } - #ifdef ARCH_ESP32 Preferences preferences; preferences.begin("meshtastic", false); @@ -367,7 +349,7 @@ void NodeDB::init() #endif resetRadioConfig(); // If bogus settings got saved, then fix them - LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numNodes); + LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numMeshNodes); if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate))) saveWhat |= SEGMENT_DEVICESTATE; @@ -613,14 +595,6 @@ void NodeDB::saveToDisk(int saveWhat) } } -const meshtastic_NodeInfo *NodeDB::readNextNodeInfo(uint32_t &readIndex) -{ - if (readIndex < *numNodes) - return &nodes[readIndex++]; - else - return NULL; -} - const meshtastic_NodeInfoLite *NodeDB::readNextMeshNode(uint32_t &readIndex) { if (readIndex < *numMeshNodes) @@ -798,17 +772,6 @@ uint8_t NodeDB::getMeshNodeChannel(NodeNum n) return info->channel; } -/// Find a node in our DB, return null for missing -/// NOTE: This function might be called from an ISR -meshtastic_NodeInfo *NodeDB::getNodeInfo(NodeNum n) -{ - for (int i = 0; i < *numNodes; i++) - if (nodes[i].num == n) - return &nodes[i]; - - return NULL; -} - /// Find a node in our DB, return null for missing /// NOTE: This function might be called from an ISR meshtastic_NodeInfoLite *NodeDB::getMeshNode(NodeNum n) @@ -854,57 +817,6 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) return lite; } -void NodeDB::migrateToNodeInfoLite(const meshtastic_NodeInfo *node) -{ - meshtastic_NodeInfoLite *lite = getMeshNode(node->num); - - if (!lite) { - if ((*numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { - screen->print("warning: node_db_lite full! erasing oldest entry\n"); - // look for oldest node and erase it - uint32_t oldest = UINT32_MAX; - int oldestIndex = -1; - for (int i = 0; i < *numMeshNodes; i++) { - if (meshNodes[i].last_heard < oldest) { - oldest = meshNodes[i].last_heard; - oldestIndex = i; - } - } - // Shove the remaining nodes down the chain - for (int i = oldestIndex; i < *numMeshNodes - 1; i++) { - meshNodes[i] = meshNodes[i + 1]; - } - (*numMeshNodes)--; - } - // add the node at the end - lite = &meshNodes[(*numMeshNodes)++]; - - // everything is missing except the nodenum - memset(lite, 0, sizeof(*lite)); - lite->num = node->num; - lite->snr = node->snr; - lite->last_heard = node->last_heard; - lite->channel = node->channel; - - if (node->has_position) { - lite->has_position = true; - lite->position.latitude_i = node->position.latitude_i; - lite->position.longitude_i = node->position.longitude_i; - lite->position.altitude = node->position.altitude; - lite->position.location_source = node->position.location_source; - lite->position.time = node->position.time; - } - if (node->has_user) { - lite->has_user = true; - lite->user = node->user; - } - if (node->has_device_metrics) { - lite->has_device_metrics = true; - lite->device_metrics = node->device_metrics; - } - } -} - /// Record an error that should be reported via analytics void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, const char *filename) { diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 9b0249dcd..ab0ec8288 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -19,7 +19,7 @@ DeviceState versions used to be defined in the .proto file but really only this #define SEGMENT_DEVICESTATE 4 #define SEGMENT_CHANNELS 8 -#define DEVICESTATE_CUR_VER 20 +#define DEVICESTATE_CUR_VER 22 #define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER extern meshtastic_DeviceState devicestate; @@ -45,9 +45,6 @@ class NodeDB // Eventually use a smarter datastructure // HashMap nodes; // Note: these two references just point into our static array we serialize to/from disk - meshtastic_NodeInfo *nodes; - pb_size_t *numNodes; - meshtastic_NodeInfoLite *meshNodes; pb_size_t *numMeshNodes; @@ -137,18 +134,6 @@ class NodeDB private: /// Find a node in our DB, create an empty NodeInfoLite if missing meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n); - void migrateToNodeInfoLite(const meshtastic_NodeInfo *node); - /// Find a node in our DB, return null for missing - meshtastic_NodeInfo *getNodeInfo(NodeNum n); - /// Allow the bluetooth layer to read our next nodeinfo record, or NULL if done reading - const meshtastic_NodeInfo *readNextNodeInfo(uint32_t &readIndex); - size_t getNumNodes() { return *numNodes; } - - meshtastic_NodeInfo *getNodeByIndex(size_t x) - { - assert(x < *numNodes); - return &nodes[x]; - } /// Notify observers of changes to the DB void notifyObservers(bool forceUpdate = false) @@ -174,7 +159,6 @@ extern NodeDB nodeDB; # prefs.position_broadcast_secs = FIXME possibly broadcast only once an hr prefs.wait_bluetooth_secs = 1 # Don't stay in bluetooth mode - prefs.mesh_sds_timeout_secs = never # try to stay in light sleep one full day, then briefly wake and sleep again prefs.ls_secs = oneday @@ -202,7 +186,6 @@ extern NodeDB nodeDB; #define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60) #define default_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 15 * 60) #define default_wait_bluetooth_secs IF_ROUTER(1, 60) -#define default_mesh_sds_timeout_secs IF_ROUTER(NODE_DELAY_FOREVER, 2 * 60 * 60) #define default_sds_secs IF_ROUTER(ONE_DAY, UINT32_MAX) // Default to forever super deep sleep #define default_ls_secs IF_ROUTER(ONE_DAY, 5 * 60) #define default_min_wake_secs 10 @@ -228,10 +211,6 @@ inline uint32_t getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t d /// Sometimes we will have Position objects that only have a time, so check for /// valid lat/lon -static inline bool hasValidPosition(const meshtastic_NodeInfo *n) -{ - return n->has_position && (n->position.latitude_i != 0 || n->position.longitude_i != 0); -} static inline bool hasValidPosition(const meshtastic_NodeInfoLite *n) { return n->has_position && (n->position.latitude_i != 0 || n->position.longitude_i != 0); diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 6c6c70165..cd230cb1c 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -279,6 +279,10 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_remote_hardware_tag; fromRadioScratch.moduleConfig.payload_variant.remote_hardware = moduleConfig.remote_hardware; break; + case meshtastic_ModuleConfig_neighbor_info_tag: + fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_neighbor_info_tag; + fromRadioScratch.moduleConfig.payload_variant.neighbor_info = moduleConfig.neighbor_info; + break; default: LOG_ERROR("Unknown module config type %d\n", config_state); } diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index e605cfc94..03aa57351 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -153,7 +153,12 @@ void Router::setReceivedMessage() meshtastic_QueueStatus Router::getQueueStatus() { - return iface->getQueueStatus(); + if (!iface) { + meshtastic_QueueStatus qs; + qs.res = qs.mesh_packet_id = qs.free = qs.maxlen = 0; + return qs; + } else + return iface->getQueueStatus(); } ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index aa39244ff..89e1fde0c 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -55,6 +55,8 @@ typedef enum _meshtastic_AdminMessage_ModuleConfigType { /* TODO: REPLACE */ meshtastic_AdminMessage_ModuleConfigType_REMOTEHARDWARE_CONFIG = 8, /* TODO: REPLACE */ + meshtastic_AdminMessage_ModuleConfigType_NEIGHBORINFO_CONFIG = 9, + /* TODO: REPLACE */ meshtastic_AdminMessage_ModuleConfigType_AMBIENTLIGHTING_CONFIG = 10 } meshtastic_AdminMessage_ModuleConfigType; diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 99314aef5..2bd1a177b 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -292,7 +292,8 @@ typedef struct _meshtastic_Config_PowerConfig { The number of seconds for to wait before turning off BLE in No Bluetooth states 0 for default of 1 minute */ uint32_t wait_bluetooth_secs; - /* Mesh Super Deep Sleep Timeout Seconds + /* Deprecated in 2.1.X + Mesh Super Deep Sleep Timeout Seconds While in Light Sleep if this value is exceeded we will lower into super deep sleep for sds_secs (default 1 year) or a button press 0 for default of two hours, MAXUINT for disabled */ diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index a093c9fe2..0c4b94c86 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -124,10 +124,6 @@ typedef struct _meshtastic_DeviceState { /* My owner info */ bool has_owner; meshtastic_User owner; - /* Deprecated in 2.1.x - Old node_db. See NodeInfoLite node_db_lite */ - pb_size_t node_db_count; - meshtastic_NodeInfo node_db[80]; /* Received packets saved for delivery to the phone */ pb_size_t receive_queue_count; meshtastic_MeshPacket receive_queue[1]; @@ -178,13 +174,13 @@ extern "C" { /* Initializer values for message structs */ -#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default, meshtastic_NodeInfo_init_default}, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, 0, {meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default}} +#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, 0, {meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default}} #define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_User_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0} #define meshtastic_PositionLite_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} #define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} #define meshtastic_NodeRemoteHardwarePin_init_default {0, false, meshtastic_RemoteHardwarePin_init_default} -#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero, meshtastic_NodeInfo_init_zero}, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, 0, {meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero}} +#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, 0, {meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero}} #define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0} #define meshtastic_PositionLite_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} @@ -218,7 +214,6 @@ extern "C" { #define meshtastic_NodeRemoteHardwarePin_pin_tag 2 #define meshtastic_DeviceState_my_node_tag 2 #define meshtastic_DeviceState_owner_tag 3 -#define meshtastic_DeviceState_node_db_tag 4 #define meshtastic_DeviceState_receive_queue_tag 5 #define meshtastic_DeviceState_rx_text_message_tag 7 #define meshtastic_DeviceState_version_tag 8 @@ -232,7 +227,6 @@ extern "C" { #define meshtastic_DeviceState_FIELDLIST(X, a) \ X(a, STATIC, OPTIONAL, MESSAGE, my_node, 2) \ X(a, STATIC, OPTIONAL, MESSAGE, owner, 3) \ -X(a, STATIC, REPEATED, MESSAGE, node_db, 4) \ X(a, STATIC, REPEATED, MESSAGE, receive_queue, 5) \ X(a, STATIC, OPTIONAL, MESSAGE, rx_text_message, 7) \ X(a, STATIC, SINGULAR, UINT32, version, 8) \ @@ -245,7 +239,6 @@ X(a, STATIC, REPEATED, MESSAGE, node_db_lite, 14) #define meshtastic_DeviceState_DEFAULT NULL #define meshtastic_DeviceState_my_node_MSGTYPE meshtastic_MyNodeInfo #define meshtastic_DeviceState_owner_MSGTYPE meshtastic_User -#define meshtastic_DeviceState_node_db_MSGTYPE meshtastic_NodeInfo #define meshtastic_DeviceState_receive_queue_MSGTYPE meshtastic_MeshPacket #define meshtastic_DeviceState_rx_text_message_MSGTYPE meshtastic_MeshPacket #define meshtastic_DeviceState_rx_waypoint_MSGTYPE meshtastic_MeshPacket @@ -320,7 +313,7 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; /* Maximum encoded size of messages (where known) */ #define meshtastic_ChannelFile_size 638 -#define meshtastic_DeviceState_size 35056 +#define meshtastic_DeviceState_size 13774 #define meshtastic_NodeInfoLite_size 151 #define meshtastic_NodeRemoteHardwarePin_size 29 #define meshtastic_OEMStore_size 3154 diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 7fffe9ea7..79800f3c8 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -103,10 +103,12 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_HELTEC_WIRELESS_TRACKER = 48, /* Heltec Wireless Paper with ESP32-S3 CPU and E-Ink display */ meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER = 49, - /* LilyGo T-Deck with ESP32-S3 CPU, Keyboard, and IPS display */ + /* LilyGo T-Deck with ESP32-S3 CPU, Keyboard and IPS display */ meshtastic_HardwareModel_T_DECK = 50, /* LilyGo T-Watch S3 with ESP32-S3 CPU and IPS display */ meshtastic_HardwareModel_T_WATCH_S3 = 51, + /* Bobricius Picomputer with ESP32-S3 CPU, Keyboard and IPS display */ + meshtastic_HardwareModel_PICOMPUTER_S3 = 52, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ @@ -605,60 +607,12 @@ typedef struct _meshtastic_MyNodeInfo { /* Tells the phone what our node number is, default starting value is lowbyte of macaddr, but it will be fixed if that is already in use */ uint32_t my_node_num; - /* Deprecated in 2.1.x (Source from device_metadata) - Note: This flag merely means we detected a hardware GPS in our node. - Not the same as UserPreferences.location_sharing */ - bool has_gps; - /* Deprecated in 2.1.x - The maximum number of 'software' channels that can be set on this node. */ - uint32_t max_channels; - /* Deprecated in 2.1.x (Source from device_metadata) - 0.0.5 etc... */ - char firmware_version[18]; - /* An error message we'd like to report back to the mothership through analytics. - It indicates a serious bug occurred on the device, the device coped with it, - but we still want to tell the devs about the bug. - This field will be cleared after the phone reads MyNodeInfo - (i.e. it will only be reported once) - a numeric error code to go with error message, zero means no error */ - meshtastic_CriticalErrorCode error_code; - /* A numeric error address (nonzero if available) */ - uint32_t error_address; - /* The total number of errors this node has ever encountered - (well - since the last time we discarded preferences) */ - uint32_t error_count; /* The total number of reboots this node has ever encountered (well - since the last time we discarded preferences) */ uint32_t reboot_count; - /* Deprecated in 2.1.x - Calculated bitrate of the current channel (in Bytes Per Second) */ - float bitrate; - /* Deprecated in 2.1.x - How long before we consider a message abandoned and we can clear our - caches of any messages in flight Normally quite large to handle the worst case - message delivery time, 5 minutes. - Formerly called FLOOD_EXPIRE_TIME in the device code */ - uint32_t message_timeout_msec; /* The minimum app version that can talk to this device. Phone/PC apps should compare this to their build number and if too low tell the user they must update their app */ uint32_t min_app_version; - /* Deprecated in 2.1.x (Only used on device to keep track of utilization) - 24 time windows of 1hr each with the airtime transmitted out of the device per hour. */ - pb_size_t air_period_tx_count; - uint32_t air_period_tx[8]; - /* Deprecated in 2.1.x (Only used on device to keep track of utilization) - 24 time windows of 1hr each with the airtime of valid packets for your mesh. */ - pb_size_t air_period_rx_count; - uint32_t air_period_rx[8]; - /* Deprecated in 2.1.x (Source from DeviceMetadata instead) - Is the device wifi capable? */ - bool has_wifi; - /* Deprecated in 2.1.x (Source from DeviceMetrics telemetry payloads) - Utilization for the current channel, including well formed TX, RX and malformed RX (aka noise). */ - float channel_utilization; - /* Deprecated in 2.1.x (Source from DeviceMetrics telemetry payloads) - Percent of airtime for transmission used within the last hour. */ - float air_util_tx; } meshtastic_MyNodeInfo; /* Debug output from the device. @@ -729,6 +683,12 @@ typedef struct _meshtastic_Neighbor { uint32_t node_id; /* SNR of last heard message */ float snr; + /* Reception time (in secs since 1970) of last message that was last sent by this ID. + Note: this is for local storage only and will not be sent out over the mesh. */ + uint32_t last_rx_time; + /* Broadcast interval of this neighbor (in seconds). + Note: this is for local storage only and will not be sent out over the mesh. */ + uint32_t node_broadcast_interval_secs; } meshtastic_Neighbor; /* Full info on edges for a single node */ @@ -737,6 +697,8 @@ typedef struct _meshtastic_NeighborInfo { uint32_t node_id; /* Field to pass neighbor info for the next sending cycle */ uint32_t last_sent_by_id; + /* Broadcast interval of the represented node (in seconds) */ + uint32_t node_broadcast_interval_secs; /* The list of out edges from this node */ pb_size_t neighbors_count; meshtastic_Neighbor neighbors[10]; @@ -871,7 +833,6 @@ extern "C" { #define meshtastic_MeshPacket_delayed_ENUMTYPE meshtastic_MeshPacket_Delayed -#define meshtastic_MyNodeInfo_error_code_ENUMTYPE meshtastic_CriticalErrorCode #define meshtastic_LogRecord_level_ENUMTYPE meshtastic_LogRecord_Level @@ -896,14 +857,14 @@ extern "C" { #define meshtastic_MqttClientProxyMessage_init_default {"", 0, {{0, {0}}}, 0} #define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN} #define meshtastic_NodeInfo_init_default {0, false, meshtastic_User_init_default, false, meshtastic_Position_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0} -#define meshtastic_MyNodeInfo_init_default {0, 0, 0, "", _meshtastic_CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0} +#define meshtastic_MyNodeInfo_init_default {0, 0, 0} #define meshtastic_LogRecord_init_default {"", 0, "", _meshtastic_LogRecord_Level_MIN} #define meshtastic_QueueStatus_init_default {0, 0, 0, 0} #define meshtastic_FromRadio_init_default {0, 0, {meshtastic_MeshPacket_init_default}} #define meshtastic_ToRadio_init_default {0, {meshtastic_MeshPacket_init_default}} #define meshtastic_Compressed_init_default {_meshtastic_PortNum_MIN, {0, {0}}} -#define meshtastic_NeighborInfo_init_default {0, 0, 0, {meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default}} -#define meshtastic_Neighbor_init_default {0, 0} +#define meshtastic_NeighborInfo_init_default {0, 0, 0, 0, {meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default}} +#define meshtastic_Neighbor_init_default {0, 0, 0, 0} #define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN, 0} #define meshtastic_Position_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_User_init_zero {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0} @@ -914,14 +875,14 @@ extern "C" { #define meshtastic_MqttClientProxyMessage_init_zero {"", 0, {{0, {0}}}, 0} #define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN} #define meshtastic_NodeInfo_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_Position_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0} -#define meshtastic_MyNodeInfo_init_zero {0, 0, 0, "", _meshtastic_CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0} +#define meshtastic_MyNodeInfo_init_zero {0, 0, 0} #define meshtastic_LogRecord_init_zero {"", 0, "", _meshtastic_LogRecord_Level_MIN} #define meshtastic_QueueStatus_init_zero {0, 0, 0, 0} #define meshtastic_FromRadio_init_zero {0, 0, {meshtastic_MeshPacket_init_zero}} #define meshtastic_ToRadio_init_zero {0, {meshtastic_MeshPacket_init_zero}} #define meshtastic_Compressed_init_zero {_meshtastic_PortNum_MIN, {0, {0}}} -#define meshtastic_NeighborInfo_init_zero {0, 0, 0, {meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero}} -#define meshtastic_Neighbor_init_zero {0, 0} +#define meshtastic_NeighborInfo_init_zero {0, 0, 0, 0, {meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero, meshtastic_Neighbor_init_zero}} +#define meshtastic_Neighbor_init_zero {0, 0, 0, 0} #define meshtastic_DeviceMetadata_init_zero {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN, 0} /* Field tags (for use in manual encoding/decoding) */ @@ -998,21 +959,8 @@ extern "C" { #define meshtastic_NodeInfo_device_metrics_tag 6 #define meshtastic_NodeInfo_channel_tag 7 #define meshtastic_MyNodeInfo_my_node_num_tag 1 -#define meshtastic_MyNodeInfo_has_gps_tag 2 -#define meshtastic_MyNodeInfo_max_channels_tag 3 -#define meshtastic_MyNodeInfo_firmware_version_tag 4 -#define meshtastic_MyNodeInfo_error_code_tag 5 -#define meshtastic_MyNodeInfo_error_address_tag 6 -#define meshtastic_MyNodeInfo_error_count_tag 7 #define meshtastic_MyNodeInfo_reboot_count_tag 8 -#define meshtastic_MyNodeInfo_bitrate_tag 9 -#define meshtastic_MyNodeInfo_message_timeout_msec_tag 10 #define meshtastic_MyNodeInfo_min_app_version_tag 11 -#define meshtastic_MyNodeInfo_air_period_tx_tag 12 -#define meshtastic_MyNodeInfo_air_period_rx_tag 13 -#define meshtastic_MyNodeInfo_has_wifi_tag 14 -#define meshtastic_MyNodeInfo_channel_utilization_tag 15 -#define meshtastic_MyNodeInfo_air_util_tx_tag 16 #define meshtastic_LogRecord_message_tag 1 #define meshtastic_LogRecord_time_tag 2 #define meshtastic_LogRecord_source_tag 3 @@ -1030,9 +978,12 @@ extern "C" { #define meshtastic_Compressed_data_tag 2 #define meshtastic_Neighbor_node_id_tag 1 #define meshtastic_Neighbor_snr_tag 2 +#define meshtastic_Neighbor_last_rx_time_tag 3 +#define meshtastic_Neighbor_node_broadcast_interval_secs_tag 4 #define meshtastic_NeighborInfo_node_id_tag 1 #define meshtastic_NeighborInfo_last_sent_by_id_tag 2 -#define meshtastic_NeighborInfo_neighbors_tag 3 +#define meshtastic_NeighborInfo_node_broadcast_interval_secs_tag 3 +#define meshtastic_NeighborInfo_neighbors_tag 4 #define meshtastic_DeviceMetadata_firmware_version_tag 1 #define meshtastic_DeviceMetadata_device_state_version_tag 2 #define meshtastic_DeviceMetadata_canShutdown_tag 3 @@ -1175,21 +1126,8 @@ X(a, STATIC, SINGULAR, UINT32, channel, 7) #define meshtastic_MyNodeInfo_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UINT32, my_node_num, 1) \ -X(a, STATIC, SINGULAR, BOOL, has_gps, 2) \ -X(a, STATIC, SINGULAR, UINT32, max_channels, 3) \ -X(a, STATIC, SINGULAR, STRING, firmware_version, 4) \ -X(a, STATIC, SINGULAR, UENUM, error_code, 5) \ -X(a, STATIC, SINGULAR, UINT32, error_address, 6) \ -X(a, STATIC, SINGULAR, UINT32, error_count, 7) \ X(a, STATIC, SINGULAR, UINT32, reboot_count, 8) \ -X(a, STATIC, SINGULAR, FLOAT, bitrate, 9) \ -X(a, STATIC, SINGULAR, UINT32, message_timeout_msec, 10) \ -X(a, STATIC, SINGULAR, UINT32, min_app_version, 11) \ -X(a, STATIC, REPEATED, UINT32, air_period_tx, 12) \ -X(a, STATIC, REPEATED, UINT32, air_period_rx, 13) \ -X(a, STATIC, SINGULAR, BOOL, has_wifi, 14) \ -X(a, STATIC, SINGULAR, FLOAT, channel_utilization, 15) \ -X(a, STATIC, SINGULAR, FLOAT, air_util_tx, 16) +X(a, STATIC, SINGULAR, UINT32, min_app_version, 11) #define meshtastic_MyNodeInfo_CALLBACK NULL #define meshtastic_MyNodeInfo_DEFAULT NULL @@ -1259,14 +1197,17 @@ X(a, STATIC, SINGULAR, BYTES, data, 2) #define meshtastic_NeighborInfo_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UINT32, node_id, 1) \ X(a, STATIC, SINGULAR, UINT32, last_sent_by_id, 2) \ -X(a, STATIC, REPEATED, MESSAGE, neighbors, 3) +X(a, STATIC, SINGULAR, UINT32, node_broadcast_interval_secs, 3) \ +X(a, STATIC, REPEATED, MESSAGE, neighbors, 4) #define meshtastic_NeighborInfo_CALLBACK NULL #define meshtastic_NeighborInfo_DEFAULT NULL #define meshtastic_NeighborInfo_neighbors_MSGTYPE meshtastic_Neighbor #define meshtastic_Neighbor_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UINT32, node_id, 1) \ -X(a, STATIC, SINGULAR, FLOAT, snr, 2) +X(a, STATIC, SINGULAR, FLOAT, snr, 2) \ +X(a, STATIC, SINGULAR, FIXED32, last_rx_time, 3) \ +X(a, STATIC, SINGULAR, UINT32, node_broadcast_interval_secs, 4) #define meshtastic_Neighbor_CALLBACK NULL #define meshtastic_Neighbor_DEFAULT NULL @@ -1331,9 +1272,9 @@ extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg; #define meshtastic_LogRecord_size 81 #define meshtastic_MeshPacket_size 321 #define meshtastic_MqttClientProxyMessage_size 501 -#define meshtastic_MyNodeInfo_size 179 -#define meshtastic_NeighborInfo_size 142 -#define meshtastic_Neighbor_size 11 +#define meshtastic_MyNodeInfo_size 18 +#define meshtastic_NeighborInfo_size 258 +#define meshtastic_Neighbor_size 22 #define meshtastic_NodeInfo_size 261 #define meshtastic_Position_size 137 #define meshtastic_QueueStatus_size 23 diff --git a/src/mesh/generated/meshtastic/portnums.pb.h b/src/mesh/generated/meshtastic/portnums.pb.h index 089d7b59f..44e9df70d 100644 --- a/src/mesh/generated/meshtastic/portnums.pb.h +++ b/src/mesh/generated/meshtastic/portnums.pb.h @@ -25,73 +25,99 @@ typedef enum _meshtastic_PortNum { /* Deprecated: do not use in new code (formerly called OPAQUE) A message sent from a device outside of the mesh, in a form the mesh does not understand - NOTE: This must be 0, because it is documented in IMeshService.aidl to be so */ + NOTE: This must be 0, because it is documented in IMeshService.aidl to be so + ENCODING: binary undefined */ meshtastic_PortNum_UNKNOWN_APP = 0, /* A simple UTF-8 text message, which even the little micros in the mesh can understand and show on their screen eventually in some circumstances - even signal might send messages in this form (see below) */ + even signal might send messages in this form (see below) + ENCODING: UTF-8 Plaintext (?) */ meshtastic_PortNum_TEXT_MESSAGE_APP = 1, /* Reserved for built-in GPIO/example app. - See remote_hardware.proto/HardwareMessage for details on the message sent/received to this port number */ + See remote_hardware.proto/HardwareMessage for details on the message sent/received to this port number + ENCODING: Protobuf */ meshtastic_PortNum_REMOTE_HARDWARE_APP = 2, /* The built-in position messaging app. - Payload is a [Position](/docs/developers/protobufs/api#position) message */ + Payload is a [Position](/docs/developers/protobufs/api#position) message + ENCODING: Protobuf */ meshtastic_PortNum_POSITION_APP = 3, /* The built-in user info app. - Payload is a [User](/docs/developers/protobufs/api#user) message */ + Payload is a [User](/docs/developers/protobufs/api#user) message + ENCODING: Protobuf */ meshtastic_PortNum_NODEINFO_APP = 4, /* Protocol control packets for mesh protocol use. - Payload is a [Routing](/docs/developers/protobufs/api#routing) message */ + Payload is a [Routing](/docs/developers/protobufs/api#routing) message + ENCODING: Protobuf */ meshtastic_PortNum_ROUTING_APP = 5, /* Admin control packets. - Payload is a [AdminMessage](/docs/developers/protobufs/api#adminmessage) message */ + Payload is a [AdminMessage](/docs/developers/protobufs/api#adminmessage) message + ENCODING: Protobuf */ meshtastic_PortNum_ADMIN_APP = 6, - /* Compressed TEXT_MESSAGE payloads. */ + /* Compressed TEXT_MESSAGE payloads. + ENCODING: UTF-8 Plaintext (?) with Unishox2 Compression + NOTE: The Device Firmware converts a TEXT_MESSAGE_APP to TEXT_MESSAGE_COMPRESSED_APP if the compressed + payload is shorter. There's no need for app developers to do this themselves. Also the firmware will decompress + any incoming TEXT_MESSAGE_COMPRESSED_APP payload and convert to TEXT_MESSAGE_APP. */ meshtastic_PortNum_TEXT_MESSAGE_COMPRESSED_APP = 7, /* Waypoint payloads. - Payload is a [Waypoint](/docs/developers/protobufs/api#waypoint) message */ + Payload is a [Waypoint](/docs/developers/protobufs/api#waypoint) message + ENCODING: Protobuf */ meshtastic_PortNum_WAYPOINT_APP = 8, /* Audio Payloads. - Encapsulated codec2 packets. On 2.4 GHZ Bandwidths only for now */ + Encapsulated codec2 packets. On 2.4 GHZ Bandwidths only for now + ENCODING: codec2 audio frames + NOTE: audio frames contain a 3 byte header (0xc0 0xde 0xc2) and a one byte marker for the decompressed bitrate. + This marker comes from the 'moduleConfig.audio.bitrate' enum minus one. */ meshtastic_PortNum_AUDIO_APP = 9, /* Provides a 'ping' service that replies to any packet it receives. - Also serves as a small example module. */ + Also serves as a small example module. + ENCODING: ASCII Plaintext */ meshtastic_PortNum_REPLY_APP = 32, - /* Used for the python IP tunnel feature */ + /* Used for the python IP tunnel feature + ENCODING: IP Packet. Handled by the python API, firmware ignores this one and pases on. */ meshtastic_PortNum_IP_TUNNEL_APP = 33, /* Provides a hardware serial interface to send and receive from the Meshtastic network. Connect to the RX/TX pins of a device with 38400 8N1. Packets received from the Meshtastic network is forwarded to the RX pin while sending a packet to TX will go out to the Mesh network. Maximum packet size of 240 bytes. - Module is disabled by default can be turned on by setting SERIAL_MODULE_ENABLED = 1 in SerialPlugh.cpp. */ + Module is disabled by default can be turned on by setting SERIAL_MODULE_ENABLED = 1 in SerialPlugh.cpp. + ENCODING: binary undefined */ meshtastic_PortNum_SERIAL_APP = 64, /* STORE_FORWARD_APP (Work in Progress) - Maintained by Jm Casler (MC Hamster) : jm@casler.org */ + Maintained by Jm Casler (MC Hamster) : jm@casler.org + ENCODING: Protobuf */ meshtastic_PortNum_STORE_FORWARD_APP = 65, - /* Optional port for messages for the range test module. */ + /* Optional port for messages for the range test module. + ENCODING: ASCII Plaintext */ meshtastic_PortNum_RANGE_TEST_APP = 66, /* Provides a format to send and receive telemetry data from the Meshtastic network. - Maintained by Charles Crossan (crossan007) : crossan007@gmail.com */ + Maintained by Charles Crossan (crossan007) : crossan007@gmail.com + ENCODING: Protobuf */ meshtastic_PortNum_TELEMETRY_APP = 67, /* Experimental tools for estimating node position without a GPS Maintained by Github user a-f-G-U-C (a Meshtastic contributor) - Project files at https://github.com/a-f-G-U-C/Meshtastic-ZPS */ + Project files at https://github.com/a-f-G-U-C/Meshtastic-ZPS + ENCODING: arrays of int64 fields */ meshtastic_PortNum_ZPS_APP = 68, /* Used to let multiple instances of Linux native applications communicate as if they did using their LoRa chip. Maintained by GitHub user GUVWAF. - Project files at https://github.com/GUVWAF/Meshtasticator */ + Project files at https://github.com/GUVWAF/Meshtasticator + ENCODING: Protobuf (?) */ meshtastic_PortNum_SIMULATOR_APP = 69, /* Provides a traceroute functionality to show the route a packet towards - a certain destination would take on the mesh. */ + a certain destination would take on the mesh. + ENCODING: Protobuf */ meshtastic_PortNum_TRACEROUTE_APP = 70, - /* Aggregates edge info for the network by sending out a list of each node's neighbors */ + /* Aggregates edge info for the network by sending out a list of each node's neighbors + ENCODING: Protobuf */ meshtastic_PortNum_NEIGHBORINFO_APP = 71, /* Private applications should use portnums >= 256. To simplify initial development and testing you can use "PRIVATE_APP" in your code without needing to rebuild protobuf files (via [regen-protos.sh](https://github.com/meshtastic/firmware/blob/master/bin/regen-protos.sh)) */ meshtastic_PortNum_PRIVATE_APP = 256, - /* ATAK Forwarder Module https://github.com/paulmandal/atak-forwarder */ + /* ATAK Forwarder Module https://github.com/paulmandal/atak-forwarder + ENCODING: libcotshrink */ meshtastic_PortNum_ATAK_FORWARDER = 257, /* Currently we limit port nums to no higher than this value */ meshtastic_PortNum_MAX = 511 diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index 8e22aa82b..22a80c8e3 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -16,7 +16,7 @@ #define MAX_RX_TOPHONE 32 /// max number of nodes allowed in the mesh -#define MAX_NUM_NODES (member_size(meshtastic_DeviceState, node_db) / member_size(meshtastic_DeviceState, node_db[0])) +#define MAX_NUM_NODES (member_size(meshtastic_DeviceState, node_db_lite) / member_size(meshtastic_DeviceState, node_db_lite[0])) /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index be76f62a5..283375b23 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -368,6 +368,11 @@ void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) moduleConfig.has_remote_hardware = true; moduleConfig.remote_hardware = c.payload_variant.remote_hardware; break; + case meshtastic_ModuleConfig_neighbor_info_tag: + LOG_INFO("Setting module config: Neighbor Info\n"); + moduleConfig.has_neighbor_info = true; + moduleConfig.neighbor_info = c.payload_variant.neighbor_info; + break; } saveChanges(SEGMENT_MODULECONFIG); @@ -503,6 +508,11 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_remote_hardware_tag; res.get_module_config_response.payload_variant.remote_hardware = moduleConfig.remote_hardware; break; + case meshtastic_AdminMessage_ModuleConfigType_NEIGHBORINFO_CONFIG: + LOG_INFO("Getting module config: Neighbor Info\n"); + res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_neighbor_info_tag; + res.get_module_config_response.payload_variant.neighbor_info = moduleConfig.neighbor_info; + break; } // NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior. @@ -663,4 +673,4 @@ AdminModule::AdminModule() : ProtobufModule("Admin", meshtastic_PortNum_ADMIN_AP { // restrict to the admin channel for rx boundChannel = Channels::adminChannel; -} +} \ No newline at end of file diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index b788d6a06..0f2921f36 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -10,6 +10,10 @@ #include "main.h" // for cardkb_found +#ifndef INPUTBROKER_MATRIX_TYPE +#define INPUTBROKER_MATRIX_TYPE 0 +#endif + #ifdef OLED_RU #include "graphics/fonts/OLEDDisplayFontsRU.h" #endif @@ -18,7 +22,9 @@ #include "graphics/fonts/OLEDDisplayFontsUA.h" #endif -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) + // The screen is bigger so use bigger fonts #define FONT_SMALL ArialMT_Plain_16 #define FONT_MEDIUM ArialMT_Plain_24 @@ -59,7 +65,8 @@ CannedMessageModule::CannedMessageModule() { if (moduleConfig.canned_message.enabled) { this->loadProtoForModule(); - if ((this->splitConfiguredMessages() <= 0) && (cardkb_found.address != CARDKB_ADDR)) { + if ((this->splitConfiguredMessages() <= 0) && (cardkb_found.address != CARDKB_ADDR) && + (cardkb_found.address != TDECK_KB_ADDR) && !INPUTBROKER_MATRIX_TYPE) { LOG_INFO("CannedMessageModule: No messages are configured. Module is disabled\n"); this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED; disable(); diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 7dd6dd1ce..cbcf4e452 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -1,3 +1,18 @@ +/** + * @file ExternalNotificationModule.cpp + * @brief Implementation of the ExternalNotificationModule class. + * + * This file contains the implementation of the ExternalNotificationModule class, which is responsible for handling external + * notifications such as vibration, buzzer, and LED lights. The class provides methods to turn on and off the external + * notification outputs and to play ringtones using PWM buzzer. It also includes default configurations and a runOnce() method to + * handle the module's behavior. + * + * Documentation: + * https://meshtastic.org/docs/settings/moduleconfig/external-notification + * + * @author Jm Casler & Meshtastic Team + * @date [Insert Date] + */ #include "ExternalNotificationModule.h" #include "MeshService.h" #include "NodeDB.h" @@ -113,6 +128,11 @@ int32_t ExternalNotificationModule::runOnce() } } +/** + * Sets the external notification on for the specified index. + * + * @param index The index of the external notification to turn on. + */ void ExternalNotificationModule::setExternalOn(uint8_t index) { externalCurrentState[index] = 1; diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 85cb169b3..9c216ff72 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -4,8 +4,10 @@ #include "input/TrackballInterruptImpl1.h" #include "input/UpDownInterruptImpl1.h" #include "input/cardKbI2cImpl.h" +#include "input/kbMatrixImpl.h" #include "modules/AdminModule.h" #include "modules/CannedMessageModule.h" +#include "modules/NeighborInfoModule.h" #include "modules/NodeInfoModule.h" #include "modules/PositionModule.h" #include "modules/RemoteHardwareModule.h" @@ -47,6 +49,7 @@ void setupModules() waypointModule = new WaypointModule(); textMessageModule = new TextMessageModule(); traceRouteModule = new TraceRouteModule(); + neighborInfoModule = new NeighborInfoModule(); // Note: if the rest of meshtastic doesn't need to explicitly use your module, you do not need to assign the instance // to a global variable. @@ -60,7 +63,11 @@ void setupModules() upDownInterruptImpl1->init(); cardKbI2cImpl = new CardKbI2cImpl(); cardKbI2cImpl->init(); -#endif +#ifdef INPUTBROKER_MATRIX_TYPE + kbMatrixImpl = new KbMatrixImpl(); + kbMatrixImpl->init(); +#endif // INPUTBROKER_MATRIX_TYPE +#endif // HAS_BUTTON #if HAS_TRACKBALL trackballInterruptImpl1 = new TrackballInterruptImpl1(); trackballInterruptImpl1->init(); @@ -92,6 +99,9 @@ void setupModules() #endif } else { adminModule = new AdminModule(); +#if HAS_TELEMETRY + new DeviceTelemetryModule(); +#endif traceRouteModule = new TraceRouteModule(); } // NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp new file mode 100644 index 000000000..578b41b29 --- /dev/null +++ b/src/modules/NeighborInfoModule.cpp @@ -0,0 +1,319 @@ +#include "NeighborInfoModule.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "RTC.h" + +#define MAX_NUM_NEIGHBORS 10 // also defined in NeighborInfo protobuf options +NeighborInfoModule *neighborInfoModule; + +static const char *neighborInfoConfigFile = "/prefs/neighbors.proto"; + +/* +Prints a single neighbor info packet and associated neighbors +Uses LOG_DEBUG, which equates to Console.log +NOTE: For debugging only +*/ +void NeighborInfoModule::printNeighborInfo(const char *header, const meshtastic_NeighborInfo *np) +{ + LOG_DEBUG("%s NEIGHBORINFO PACKET from Node %d to Node %d (last sent by %d)\n", header, np->node_id, nodeDB.getNodeNum(), + np->last_sent_by_id); + LOG_DEBUG("----------------\n"); + LOG_DEBUG("Packet contains %d neighbors\n", np->neighbors_count); + for (int i = 0; i < np->neighbors_count; i++) { + LOG_DEBUG("Neighbor %d: node_id=%d, snr=%.2f\n", i, np->neighbors[i].node_id, np->neighbors[i].snr); + } + LOG_DEBUG("----------------\n"); +} +/* +Prints the nodeDB nodes so we can see whose nodeInfo we have +NOTE: for debugging only +*/ +void NeighborInfoModule::printNodeDBNodes(const char *header) +{ + int num_nodes = nodeDB.getNumMeshNodes(); + LOG_DEBUG("%s NODEDB SELECTION from Node %d:\n", header, nodeDB.getNodeNum()); + LOG_DEBUG("----------------\n"); + LOG_DEBUG("DB contains %d nodes\n", num_nodes); + for (int i = 0; i < num_nodes; i++) { + meshtastic_NodeInfoLite *dbEntry = nodeDB.getMeshNodeByIndex(i); + LOG_DEBUG(" Node %d: node_id=%d, snr=%.2f\n", i, dbEntry->num, dbEntry->snr); + } + LOG_DEBUG("----------------\n"); +} + +/* +Prints the nodeDB neighbors +NOTE: for debugging only +*/ +void NeighborInfoModule::printNodeDBNeighbors(const char *header) +{ + int num_neighbors = getNumNeighbors(); + LOG_DEBUG("%s NODEDB SELECTION from Node %d:\n", header, nodeDB.getNodeNum()); + LOG_DEBUG("----------------\n"); + LOG_DEBUG("DB contains %d neighbors\n", num_neighbors); + for (int i = 0; i < num_neighbors; i++) { + meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + LOG_DEBUG(" Node %d: node_id=%d, snr=%.2f\n", i, dbEntry->node_id, dbEntry->snr); + } + LOG_DEBUG("----------------\n"); +} + +/* +Prints the nodeDB with selectors for the neighbors we've chosen to send (inefficiently) +Uses LOG_DEBUG, which equates to Console.log +NOTE: For debugging only +*/ +void NeighborInfoModule::printNodeDBSelection(const char *header, const meshtastic_NeighborInfo *np) +{ + int num_neighbors = getNumNeighbors(); + LOG_DEBUG("%s NODEDB SELECTION from Node %d:\n", header, nodeDB.getNodeNum()); + LOG_DEBUG("----------------\n"); + LOG_DEBUG("Selected %d neighbors of %d DB neighbors\n", np->neighbors_count, num_neighbors); + for (int i = 0; i < num_neighbors; i++) { + meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + bool chosen = false; + for (int j = 0; j < np->neighbors_count; j++) { + if (np->neighbors[j].node_id == dbEntry->node_id) { + chosen = true; + } + } + if (!chosen) { + LOG_DEBUG(" Node %d: neighbor=%d, snr=%.2f\n", i, dbEntry->node_id, dbEntry->snr); + } else { + LOG_DEBUG("---> Node %d: neighbor=%d, snr=%.2f\n", i, dbEntry->node_id, dbEntry->snr); + } + } + LOG_DEBUG("----------------\n"); +} + +/* Send our initial owner announcement 35 seconds after we start (to give network time to setup) */ +NeighborInfoModule::NeighborInfoModule() + : neighbors(neighborState.neighbors), numNeighbors(&neighborState.neighbors_count), + ProtobufModule("neighborinfo", meshtastic_PortNum_NEIGHBORINFO_APP, &meshtastic_NeighborInfo_msg), concurrency::OSThread( + "NeighborInfoModule") +{ + ourPortNum = meshtastic_PortNum_NEIGHBORINFO_APP; + + if (moduleConfig.neighbor_info.enabled) { + this->loadProtoForModule(); + setIntervalFromNow(35 * 1000); + } else { + LOG_DEBUG("NeighborInfoModule is disabled\n"); + disable(); + } +} + +/* +Allocate a zeroed neighbor info packet +*/ +meshtastic_NeighborInfo *NeighborInfoModule::allocateNeighborInfoPacket() +{ + meshtastic_NeighborInfo *neighborInfo = (meshtastic_NeighborInfo *)malloc(sizeof(meshtastic_NeighborInfo)); + memset(neighborInfo, 0, sizeof(meshtastic_NeighborInfo)); + return neighborInfo; +} + +/* +Collect neighbor info from the nodeDB's history, capping at a maximum number of entries and max time +Assumes that the neighborInfo packet has been allocated +@returns the number of entries collected +*/ +uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighborInfo) +{ + int my_node_id = nodeDB.getNodeNum(); + neighborInfo->node_id = my_node_id; + neighborInfo->last_sent_by_id = my_node_id; + neighborInfo->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval; + + int num_neighbors = cleanUpNeighbors(); + + for (int i = 0; i < num_neighbors; i++) { + meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + if ((neighborInfo->neighbors_count < MAX_NUM_NEIGHBORS) && (dbEntry->node_id != my_node_id)) { + neighborInfo->neighbors[neighborInfo->neighbors_count].node_id = dbEntry->node_id; + neighborInfo->neighbors[neighborInfo->neighbors_count].snr = dbEntry->snr; + // Note: we don't set the last_rx_time and node_broadcast_intervals_secs here, because we don't want to send this over + // the mesh + neighborInfo->neighbors_count++; + } + } + printNodeDBNodes("DBSTATE"); + printNodeDBNeighbors("NEIGHBORS"); + printNodeDBSelection("COLLECTED", neighborInfo); + return neighborInfo->neighbors_count; +} + +/* +Remove neighbors from the database that we haven't heard from in a while +@returns new number of neighbors +*/ +size_t NeighborInfoModule::cleanUpNeighbors() +{ + uint32_t now = getTime(); + int num_neighbors = getNumNeighbors(); + NodeNum my_node_id = nodeDB.getNodeNum(); + + // Find neighbors to remove + std::vector indices_to_remove; + for (int i = 0; i < num_neighbors; i++) { + meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + // We will remove a neighbor if we haven't heard from them in twice the broadcast interval + if ((now - dbEntry->last_rx_time > dbEntry->node_broadcast_interval_secs * 2) && (dbEntry->node_id != my_node_id)) { + indices_to_remove.push_back(i); + } + } + + // Update the neighbor list + for (int i = 0; i < indices_to_remove.size(); i++) { + int index = indices_to_remove[i]; + LOG_DEBUG("Removing neighbor with node ID 0x%x\n", neighbors[index].node_id); + for (int j = index; j < num_neighbors - 1; j++) { + neighbors[j] = neighbors[j + 1]; + } + (*numNeighbors)--; + } + + // Save the neighbor list if we removed any neighbors + if (indices_to_remove.size() > 0) { + saveProtoForModule(); + } + + return *numNeighbors; +} + +/* Send neighbor info to the mesh */ +void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies) +{ + meshtastic_NeighborInfo *neighborInfo = allocateNeighborInfoPacket(); + collectNeighborInfo(neighborInfo); + meshtastic_MeshPacket *p = allocDataProtobuf(*neighborInfo); + // send regardless of whether or not we have neighbors in our DB, + // because we want to get neighbors for the next cycle + p->to = dest; + p->decoded.want_response = wantReplies; + printNeighborInfo("SENDING", neighborInfo); + service.sendToMesh(p, RX_SRC_LOCAL, true); +} + +/* +Encompasses the full construction and sending packet to mesh +Will be used for broadcast. +*/ +int32_t NeighborInfoModule::runOnce() +{ + bool requestReplies = false; + sendNeighborInfo(NODENUM_BROADCAST, requestReplies); + return getConfiguredOrDefaultMs(moduleConfig.neighbor_info.update_interval, default_broadcast_interval_secs); +} + +/* +Collect a recieved neighbor info packet from another node +Pass it to an upper client; do not persist this data on the mesh +*/ +bool NeighborInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *np) +{ + printNeighborInfo("RECEIVED", np); + updateNeighbors(mp, np); + // Allow others to handle this packet + return false; +} + +/* +Copy the content of a current NeighborInfo packet into a new one and update the last_sent_by_id to our NodeNum +*/ +void NeighborInfoModule::updateLastSentById(meshtastic_MeshPacket *p) +{ + auto &incoming = p->decoded; + meshtastic_NeighborInfo scratch; + meshtastic_NeighborInfo *updated = NULL; + memset(&scratch, 0, sizeof(scratch)); + pb_decode_from_bytes(incoming.payload.bytes, incoming.payload.size, &meshtastic_NeighborInfo_msg, &scratch); + updated = &scratch; + + updated->last_sent_by_id = nodeDB.getNodeNum(); + + // Set updated last_sent_by_id to the payload of the to be flooded packet + p->decoded.payload.size = + pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_NeighborInfo_msg, updated); +} + +void NeighborInfoModule::resetNeighbors() +{ + *numNeighbors = 0; + neighborState.neighbors_count = 0; + memset(neighborState.neighbors, 0, sizeof(neighborState.neighbors)); + saveProtoForModule(); +} + +void NeighborInfoModule::updateNeighbors(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *np) +{ + // The last sent ID will be 0 if the packet is from the phone, which we don't count as + // an edge. So we assume that if it's zero, then this packet is from our node. + if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.from) { + getOrCreateNeighbor(mp.from, np->last_sent_by_id, np->node_broadcast_interval_secs, mp.rx_snr); + } +} + +meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSender, NodeNum n, + uint32_t node_broadcast_interval_secs, int snr) +{ + // our node and the phone are the same node (not neighbors) + if (n == 0) { + n = nodeDB.getNodeNum(); + } + // look for one in the existing list + for (int i = 0; i < (*numNeighbors); i++) { + meshtastic_Neighbor *nbr = &neighbors[i]; + if (nbr->node_id == n) { + // if found, update it + nbr->snr = snr; + nbr->last_rx_time = getTime(); + // Only if this is the original sender, the broadcast interval corresponds to it + if (originalSender == n) + nbr->node_broadcast_interval_secs = node_broadcast_interval_secs; + saveProtoForModule(); // Save the updated neighbor + return nbr; + } + } + // otherwise, allocate one and assign data to it + // TODO: max memory for the database should take neighbors into account, but currently doesn't + if (*numNeighbors < MAX_NUM_NODES) { + (*numNeighbors)++; + } + meshtastic_Neighbor *new_nbr = &neighbors[((*numNeighbors) - 1)]; + new_nbr->node_id = n; + new_nbr->snr = snr; + new_nbr->last_rx_time = getTime(); + // Only if this is the original sender, the broadcast interval corresponds to it + if (originalSender == n) + new_nbr->node_broadcast_interval_secs = node_broadcast_interval_secs; + saveProtoForModule(); // Save the new neighbor + return new_nbr; +} + +void NeighborInfoModule::loadProtoForModule() +{ + if (!nodeDB.loadProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, sizeof(meshtastic_NeighborInfo), + &meshtastic_NeighborInfo_msg, &neighborState)) { + neighborState = meshtastic_NeighborInfo_init_zero; + } +} + +/** + * @brief Save the module config to file. + * + * @return true On success. + * @return false On error. + */ +bool NeighborInfoModule::saveProtoForModule() +{ + bool okay = true; + +#ifdef FS + FS.mkdir("/prefs"); +#endif + + okay &= nodeDB.saveProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, &meshtastic_NeighborInfo_msg, &neighborState); + + return okay; +} \ No newline at end of file diff --git a/src/modules/NeighborInfoModule.h b/src/modules/NeighborInfoModule.h new file mode 100644 index 000000000..a2729f16e --- /dev/null +++ b/src/modules/NeighborInfoModule.h @@ -0,0 +1,84 @@ +#pragma once +#include "ProtobufModule.h" + +/* + * Neighborinfo module for sending info on each node's 0-hop neighbors to the mesh + */ +class NeighborInfoModule : public ProtobufModule, private concurrency::OSThread +{ + meshtastic_Neighbor *neighbors; + pb_size_t *numNeighbors; + + public: + /* + * Expose the constructor + */ + NeighborInfoModule(); + + /* Reset neighbor info after clearing nodeDB*/ + void resetNeighbors(); + + bool saveProtoForModule(); + + // Let FloodingRouter call updateLastSentById upon rebroadcasting a NeighborInfo packet + friend class FloodingRouter; + + protected: + // Note: this holds our local info. + meshtastic_NeighborInfo neighborState; + + /* + * Called to handle a particular incoming message + * @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *nb) override; + + /* + * Collect neighbor info from the nodeDB's history, capping at a maximum number of entries and max time + * @return the number of entries collected + */ + uint32_t collectNeighborInfo(meshtastic_NeighborInfo *neighborInfo); + + /* + Remove neighbors from the database that we haven't heard from in a while + @returns new number of neighbors + */ + size_t cleanUpNeighbors(); + + /* Allocate a new NeighborInfo packet */ + meshtastic_NeighborInfo *allocateNeighborInfoPacket(); + + // Find a neighbor in our DB, create an empty neighbor if missing + meshtastic_Neighbor *getOrCreateNeighbor(NodeNum originalSender, NodeNum n, uint32_t node_broadcast_interval_secs, int snr); + + /* + * Send info on our node's neighbors into the mesh + */ + void sendNeighborInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + + size_t getNumNeighbors() { return *numNeighbors; } + + meshtastic_Neighbor *getNeighborByIndex(size_t x) + { + assert(x < *numNeighbors); + return &neighbors[x]; + } + + /* update neighbors with subpacket sniffed from network */ + void updateNeighbors(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *np); + + /* update a NeighborInfo packet with our NodeNum as last_sent_by_id */ + void updateLastSentById(meshtastic_MeshPacket *p); + + void loadProtoForModule(); + + /* Does our periodic broadcast */ + int32_t runOnce() override; + + /* These are for debugging only */ + void printNeighborInfo(const char *header, const meshtastic_NeighborInfo *np); + void printNodeDBNodes(const char *header); + void printNodeDBNeighbors(const char *header); + void printNodeDBSelection(const char *header, const meshtastic_NeighborInfo *np); +}; +extern NeighborInfoModule *neighborInfoModule; \ No newline at end of file diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index 28835406d..ecf4b70c7 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -1,3 +1,13 @@ +/** + * @file RangeTestModule.cpp + * @brief Implementation of the RangeTestModule class and RangeTestModuleRadio class. + * + * As a sender, this module sends packets every n seconds with an incremented PacketID. + * As a receiver, this module receives packets from multiple senders and saves them to the Filesystem. + * + * The RangeTestModule class is an OSThread that runs the module. + * The RangeTestModuleRadio class handles sending and receiving packets. + */ #include "RangeTestModule.h" #include "FSCommon.h" #include "MeshService.h" @@ -10,11 +20,6 @@ #include "gps/GeoCoord.h" #include -/* - As a sender, I can send packets every n seconds. These packets include an incremented PacketID. - As a receiver, I can receive packets from multiple senders. These packets can be saved to the Filesystem. -*/ - RangeTestModule *rangeTestModule; RangeTestModuleRadio *rangeTestModuleRadio; @@ -97,6 +102,12 @@ int32_t RangeTestModule::runOnce() return disable(); } +/** + * Sends a payload to a specified destination node. + * + * @param dest The destination node number. + * @param wantReplies Whether or not to request replies from the destination node. + */ void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies) { meshtastic_MeshPacket *p = allocDataPacket(); diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 1caae69a3..4482aae90 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -86,7 +86,13 @@ SerialModuleRadio::SerialModuleRadio() : MeshModule("SerialModuleRadio") } } -// For the serial2 port we can't really detect if any client is on the other side, so instead just look for recent messages +/** + * @brief Checks if the serial connection is established. + * + * @return true if the serial connection is established, false otherwise. + * + * For the serial2 port we can't really detect if any client is on the other side, so instead just look for recent messages + */ bool SerialModule::checkIsConnected() { uint32_t now = millis(); @@ -191,6 +197,11 @@ int32_t SerialModule::runOnce() } } +/** + * Allocates a new mesh packet for use as a reply to a received packet. + * + * @return A pointer to the newly allocated mesh packet. + */ meshtastic_MeshPacket *SerialModuleRadio::allocReply() { auto reply = allocDataPacket(); // Allocate a packet for sending @@ -198,6 +209,12 @@ meshtastic_MeshPacket *SerialModuleRadio::allocReply() return reply; } +/** + * Sends a payload to a specified destination node. + * + * @param dest The destination node number. + * @param wantReplies Whether or not to request replies from the destination node. + */ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies) { meshtastic_Channel *ch = (boundChannel != NULL) ? &channels.getByName(boundChannel) : NULL; @@ -216,6 +233,12 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies) service.sendToMesh(p); } +/** + * Handle a received mesh packet. + * + * @param mp The received mesh packet. + * @return The processed message. + */ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp) { if (moduleConfig.serial.enabled) { @@ -277,6 +300,11 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp return ProcessMessage::CONTINUE; // Let others look at this message also if they want } +/** + * @brief Returns the baud rate of the serial module from the module configuration. + * + * @return uint32_t The baud rate of the serial module. + */ uint32_t SerialModule::getBaudRate() { if (moduleConfig.serial.baud == meshtastic_ModuleConfig_SerialConfig_Serial_Baud_BAUD_110) { diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 4ef5a9a13..bc6c03c52 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -17,7 +17,8 @@ int32_t DeviceTelemetryModule::runOnce() uint32_t now = millis(); if (((lastSentToMesh == 0) || ((now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))) && - airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil()) { + airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil() && + config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) { sendTelemetry(); lastSentToMesh = now; } else if (service.isToPhoneQueueEmpty()) { @@ -30,6 +31,10 @@ int32_t DeviceTelemetryModule::runOnce() bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { + // Don't worry about storing telemetry in NodeDB if we're a repeater + if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) + return false; + if (t->which_variant == meshtastic_Telemetry_device_metrics_tag) { #ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); @@ -43,7 +48,19 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket & return false; // Let others look at this message also if they want } -bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) +meshtastic_MeshPacket *DeviceTelemetryModule::allocReply() +{ + if (ignoreRequest) { + return NULL; + } + + LOG_INFO("Device telemetry replying to request\n"); + + meshtastic_Telemetry telemetry = getDeviceTelemetry(); + return allocDataProtobuf(telemetry); +} + +meshtastic_Telemetry DeviceTelemetryModule::getDeviceTelemetry() { meshtastic_Telemetry t; @@ -60,16 +77,22 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) t.variant.device_metrics.channel_utilization = airTime->channelUtilizationPercent(); t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0; - LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n", - t.variant.device_metrics.air_util_tx, t.variant.device_metrics.channel_utilization, - t.variant.device_metrics.battery_level, t.variant.device_metrics.voltage); + return t; +} - meshtastic_MeshPacket *p = allocDataProtobuf(t); +bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) +{ + meshtastic_Telemetry telemetry = getDeviceTelemetry(); + LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n", + telemetry.variant.device_metrics.air_util_tx, telemetry.variant.device_metrics.channel_utilization, + telemetry.variant.device_metrics.battery_level, telemetry.variant.device_metrics.voltage); + + meshtastic_MeshPacket *p = allocDataProtobuf(telemetry); p->to = dest; p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_MIN; - nodeDB.updateTelemetry(nodeDB.getNodeNum(), t, RX_SRC_LOCAL); + nodeDB.updateTelemetry(nodeDB.getNodeNum(), telemetry, RX_SRC_LOCAL); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); service.sendToPhone(p); diff --git a/src/modules/Telemetry/DeviceTelemetry.h b/src/modules/Telemetry/DeviceTelemetry.h index bd2a69da5..81f83ce0a 100644 --- a/src/modules/Telemetry/DeviceTelemetry.h +++ b/src/modules/Telemetry/DeviceTelemetry.h @@ -21,6 +21,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override; + virtual meshtastic_MeshPacket *allocReply() override; virtual int32_t runOnce() override; /** * Send our Telemetry into the mesh @@ -28,6 +29,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false); private: + meshtastic_Telemetry getDeviceTelemetry(); uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute uint32_t lastSentToMesh = 0; }; diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8a4747114..1f1a0cbf9 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -31,7 +31,9 @@ SHT31Sensor sht31Sensor; #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true -#ifdef USE_EINK +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) + // The screen is bigger so use bigger fonts #define FONT_SMALL ArialMT_Plain_16 #define FONT_MEDIUM ArialMT_Plain_24 diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index 4a154878d..a2e43347a 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -48,7 +48,9 @@ AudioModule *audioModule; #define YIELD_FROM_ISR(x) portYIELD_FROM_ISR(x) #endif -#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) + // The screen is bigger so use bigger fonts #define FONT_SMALL ArialMT_Plain_16 #define FONT_MEDIUM ArialMT_Plain_24 diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index fccbd7199..de4d4da3b 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -1,3 +1,17 @@ +/** + * @file StoreForwardModule.cpp + * @brief Implementation of the StoreForwardModule class. + * + * This file contains the implementation of the StoreForwardModule class, which is responsible for managing the store and forward + * functionality of the Meshtastic device. The class provides methods for sending and receiving messages, as well as managing the + * message history queue. It also initializes and manages the data structures used for storing the message history. + * + * The StoreForwardModule class is used by the MeshService class to provide store and forward functionality to the Meshtastic + * device. + * + * @author Jm Casler + * @date [Insert Date] + */ #include "StoreForwardModule.h" #include "MeshService.h" #include "NodeDB.h" @@ -52,9 +66,9 @@ int32_t StoreForwardModule::runOnce() return disable(); } -/* - Create our data structure in the PSRAM. -*/ +/** + * Populates the PSRAM with data to be sent later when a device is out of range. + */ void StoreForwardModule::populatePSRAM() { /* @@ -82,6 +96,12 @@ void StoreForwardModule::populatePSRAM() LOG_DEBUG("*** numberOfPackets for packetHistory - %u\n", numberOfPackets); } +/** + * Sends messages from the message history to the specified recipient. + * + * @param msAgo The number of milliseconds ago from which to start sending messages. + * @param to The recipient ID to send the messages to. + */ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to) { uint32_t queueSize = storeForwardModule->historyQueueCreate(msAgo, to); @@ -101,6 +121,13 @@ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to) storeForwardModule->sendMessage(to, sf); } +/** + * Creates a new history queue with messages that were received within the specified time frame. + * + * @param msAgo The number of milliseconds ago to start the history queue. + * @param to The maximum number of messages to include in the history queue. + * @return The ID of the newly created history queue. + */ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to) { @@ -141,6 +168,11 @@ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to) return this->packetHistoryTXQueue_size; } +/** + * Adds a mesh packet to the history buffer for store-and-forward functionality. + * + * @param mp The mesh packet to add to the history buffer. + */ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp) { const auto &p = mp.decoded; @@ -162,6 +194,12 @@ meshtastic_MeshPacket *StoreForwardModule::allocReply() return reply; } +/** + * Sends a payload to a specified destination node using the store and forward mechanism. + * + * @param dest The destination node number. + * @param packetHistory_index The index of the packet in the packet history buffer. + */ void StoreForwardModule::sendPayload(NodeNum dest, uint32_t packetHistory_index) { LOG_INFO("*** Sending S&F Payload\n"); @@ -183,6 +221,12 @@ void StoreForwardModule::sendPayload(NodeNum dest, uint32_t packetHistory_index) service.sendToMesh(p); } +/** + * Sends a message to a specified destination node using the store and forward protocol. + * + * @param dest The destination node number. + * @param payload The message payload to be sent. + */ void StoreForwardModule::sendMessage(NodeNum dest, meshtastic_StoreAndForward &payload) { meshtastic_MeshPacket *p = allocDataProtobuf(payload); @@ -203,6 +247,12 @@ void StoreForwardModule::sendMessage(NodeNum dest, meshtastic_StoreAndForward &p service.sendToMesh(p); } +/** + * Sends a store-and-forward message to the specified destination node. + * + * @param dest The destination node number. + * @param rr The store-and-forward request/response message to send. + */ void StoreForwardModule::sendMessage(NodeNum dest, meshtastic_StoreAndForward_RequestResponse rr) { // Craft an empty response, save some bytes in flash @@ -211,6 +261,11 @@ void StoreForwardModule::sendMessage(NodeNum dest, meshtastic_StoreAndForward_Re storeForwardModule->sendMessage(dest, sf); } +/** + * Sends statistics about the store and forward module to the specified node. + * + * @param to The node ID to send the statistics to. + */ void StoreForwardModule::statsSend(uint32_t to) { meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero; @@ -231,6 +286,12 @@ void StoreForwardModule::statsSend(uint32_t to) storeForwardModule->sendMessage(to, sf); } +/** + * Handles a received mesh packet, potentially storing it for later forwarding. + * + * @param mp The received mesh packet. + * @return A `ProcessMessage` indicating whether the packet was successfully handled. + */ ProcessMessage StoreForwardModule::handleReceived(const meshtastic_MeshPacket &mp) { #ifdef ARCH_ESP32 @@ -287,6 +348,13 @@ ProcessMessage StoreForwardModule::handleReceived(const meshtastic_MeshPacket &m return ProcessMessage::CONTINUE; // Let others look at this message also if they want } +/** + * Handles a received protobuf message for the Store and Forward module. + * + * @param mp The received MeshPacket to handle. + * @param p A pointer to the StoreAndForward object. + * @return True if the message was successfully handled, false otherwise. + */ bool StoreForwardModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_StoreAndForward *p) { if (!moduleConfig.store_forward.enabled) { @@ -488,4 +556,4 @@ StoreForwardModule::StoreForwardModule() disable(); } #endif -} +} \ No newline at end of file diff --git a/src/mqtt/JSONValue.cpp b/src/mqtt/JSONValue.cpp index 1990a13b6..a229666a9 100644 --- a/src/mqtt/JSONValue.cpp +++ b/src/mqtt/JSONValue.cpp @@ -363,6 +363,19 @@ JSONValue::JSONValue(int m_integer_value) number_value = (double)m_integer_value; } +/** + * Basic constructor for creating a JSON Value of type Number + * + * @access public + * + * @param uint m_integer_value The number to use as the value + */ +JSONValue::JSONValue(uint m_integer_value) +{ + type = JSONType_Number; + number_value = (double)m_integer_value; +} + /** * Basic constructor for creating a JSON Value of type Array * @@ -874,4 +887,4 @@ std::string JSONValue::Indent(size_t depth) depth ? --depth : 0; std::string indentStr(depth * indent_step, ' '); return indentStr; -} +} \ No newline at end of file diff --git a/src/mqtt/JSONValue.h b/src/mqtt/JSONValue.h index 9b231e93f..3a50a831a 100644 --- a/src/mqtt/JSONValue.h +++ b/src/mqtt/JSONValue.h @@ -45,6 +45,7 @@ class JSONValue JSONValue(bool m_bool_value); JSONValue(double m_number_value); JSONValue(int m_integer_value); + JSONValue(uint m_integer_value); JSONValue(const JSONArray &m_array_value); JSONValue(const JSONObject &m_object_value); JSONValue(const JSONValue &m_source); @@ -91,4 +92,4 @@ class JSONValue }; }; -#endif +#endif \ No newline at end of file diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index a7a6b662b..4e5a84477 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -541,7 +541,7 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Telemetry_msg, &scratch)) { decoded = &scratch; if (decoded->which_variant == meshtastic_Telemetry_device_metrics_tag) { - msgPayload["battery_level"] = new JSONValue((int)decoded->variant.device_metrics.battery_level); + msgPayload["battery_level"] = new JSONValue((uint)decoded->variant.device_metrics.battery_level); msgPayload["voltage"] = new JSONValue(decoded->variant.device_metrics.voltage); msgPayload["channel_utilization"] = new JSONValue(decoded->variant.device_metrics.channel_utilization); msgPayload["air_util_tx"] = new JSONValue(decoded->variant.device_metrics.air_util_tx); @@ -588,10 +588,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Position_msg, &scratch)) { decoded = &scratch; if ((int)decoded->time) { - msgPayload["time"] = new JSONValue((int)decoded->time); + msgPayload["time"] = new JSONValue((uint)decoded->time); } if ((int)decoded->timestamp) { - msgPayload["timestamp"] = new JSONValue((int)decoded->timestamp); + msgPayload["timestamp"] = new JSONValue((uint)decoded->timestamp); } msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); @@ -599,13 +599,13 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) msgPayload["altitude"] = new JSONValue((int)decoded->altitude); } if ((int)decoded->ground_speed) { - msgPayload["ground_speed"] = new JSONValue((int)decoded->ground_speed); + msgPayload["ground_speed"] = new JSONValue((uint)decoded->ground_speed); } if (int(decoded->ground_track)) { - msgPayload["ground_track"] = new JSONValue((int)decoded->ground_track); + msgPayload["ground_track"] = new JSONValue((uint)decoded->ground_track); } if (int(decoded->sats_in_view)) { - msgPayload["sats_in_view"] = new JSONValue((int)decoded->sats_in_view); + msgPayload["sats_in_view"] = new JSONValue((uint)decoded->sats_in_view); } if ((int)decoded->PDOP) { msgPayload["PDOP"] = new JSONValue((int)decoded->PDOP); @@ -632,11 +632,11 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) memset(&scratch, 0, sizeof(scratch)); if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Waypoint_msg, &scratch)) { decoded = &scratch; - msgPayload["id"] = new JSONValue((int)decoded->id); + msgPayload["id"] = new JSONValue((uint)decoded->id); msgPayload["name"] = new JSONValue(decoded->name); msgPayload["description"] = new JSONValue(decoded->description); - msgPayload["expire"] = new JSONValue((int)decoded->expire); - msgPayload["locked_to"] = new JSONValue((int)decoded->locked_to); + msgPayload["expire"] = new JSONValue((uint)decoded->expire); + msgPayload["locked_to"] = new JSONValue((uint)decoded->locked_to); msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); jsonObj["payload"] = new JSONValue(msgPayload); @@ -646,16 +646,34 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) }; break; } + case meshtastic_PortNum_NEIGHBORINFO_APP: { + msgType = "neighborinfo"; + meshtastic_NeighborInfo scratch; + meshtastic_NeighborInfo *decoded = NULL; + if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_NeighborInfo_msg, + &scratch)) { + decoded = &scratch; + msgPayload["node_id"] = new JSONValue((uint)decoded->node_id); + msgPayload["neighbors_count"] = new JSONValue(decoded->neighbors_count); + msgPayload["neighbors"] = new JSONValue(decoded->neighbors); + } else { + LOG_ERROR("Error decoding protobuf for neighborinfo message!\n"); + } + }; + break; + } // add more packet types here if needed default: break; } - jsonObj["id"] = new JSONValue((int)mp->id); - jsonObj["timestamp"] = new JSONValue((int)mp->rx_time); - jsonObj["to"] = new JSONValue((int)mp->to); - jsonObj["from"] = new JSONValue((int)mp->from); - jsonObj["channel"] = new JSONValue((int)mp->channel); + jsonObj["id"] = new JSONValue((uint)mp->id); + jsonObj["timestamp"] = new JSONValue((uint)mp->rx_time); + jsonObj["to"] = new JSONValue((uint)mp->to); + jsonObj["from"] = new JSONValue((uint)mp->from); + jsonObj["channel"] = new JSONValue((uint)mp->channel); jsonObj["type"] = new JSONValue(msgType.c_str()); jsonObj["sender"] = new JSONValue(owner.id); diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 6e80b50e6..8f71bace6 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -117,6 +117,8 @@ #define HW_VENDOR meshtastic_HardwareModel_NANO_G1_EXPLORER #elif defined(BETAFPV_900_TX_NANO) #define HW_VENDOR meshtastic_HardwareModel_BETAFPV_900_NANO_TX +#elif defined(PICOMPUTER_S3) +#define HW_VENDOR meshtastic_HardwareModel_PICOMPUTER_S3 #endif // diff --git a/src/shutdown.h b/src/shutdown.h index d9077151c..90fb19d0c 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -16,7 +16,7 @@ void powerCommandsCheck() rp2040.reboot(); #else rebootAtMsec = -1; - LOG_WARN("FIXME implement reboot for this platform. Skipping for now.\n"); + LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied.\n"); #endif } diff --git a/src/xmodem.cpp b/src/xmodem.cpp index e8727c468..852ff3453 100644 --- a/src/xmodem.cpp +++ b/src/xmodem.cpp @@ -1,3 +1,21 @@ +/** + * @file xmodem.cpp + * @brief Implementation of XMODEM protocol for Meshtastic devices. + * + * This file contains the implementation of the XMODEM protocol for Meshtastic devices. It is based on the XMODEM implementation + * by Georges Menie (www.menie.org) and has been adapted for protobuf encapsulation. + * + * The XMODEM protocol is used for reliable transmission of binary data over a serial connection. This implementation supports + * both sending and receiving of data. + * + * The XModemAdapter class provides the main functionality for the protocol, including CRC calculation, packet handling, and + * control signal sending. + * + * @copyright Copyright (c) 2001-2019 Georges Menie + * @author + * @author + * @date + */ /*********************************************************************************************************************** * based on XMODEM implementation by Georges Menie (www.menie.org) *********************************************************************************************************************** @@ -36,6 +54,13 @@ XModemAdapter xModem; XModemAdapter::XModemAdapter() {} +/** + * Calculates the CRC-16 CCITT checksum of the given buffer. + * + * @param buffer The buffer to calculate the checksum for. + * @param length The length of the buffer. + * @return The calculated checksum. + */ unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length) { unsigned short crc16 = 0; @@ -52,6 +77,15 @@ unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length) return crc16; } +/** + * Calculates the checksum of the given buffer and compares it to the given + * expected checksum. Returns 1 if the checksums match, 0 otherwise. + * + * @param buf The buffer to calculate the checksum of. + * @param sz The size of the buffer. + * @param tcrc The expected checksum. + * @return 1 if the checksums match, 0 otherwise. + */ int XModemAdapter::check(const pb_byte_t *buf, int sz, unsigned short tcrc) { return crc16_ccitt(buf, sz) == tcrc; @@ -214,4 +248,4 @@ void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket) // Unknown control character break; } -} +} \ No newline at end of file diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index aedfbe677..cb26ba0a3 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -4,6 +4,10 @@ #define I2C_SDA SDA_OLED // I2C pins for this board #define I2C_SCL SCL_OLED +// Enable secondary bus for external periherals +#define I2C_SDA1 SDA +#define I2C_SCL1 SCL + #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index 84c16c884..eb67ea816 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -1,5 +1,9 @@ #define LED_PIN 18 +// Enable bus for external periherals +#define I2C_SDA SDA +#define I2C_SCL SCL + #define USE_EINK /* * eink display pins diff --git a/variants/heltec_wireless_tracker/platformio.ini b/variants/heltec_wireless_tracker/platformio.ini index 92e76a981..45be3bf98 100644 --- a/variants/heltec_wireless_tracker/platformio.ini +++ b/variants/heltec_wireless_tracker/platformio.ini @@ -8,4 +8,4 @@ build_flags = lib_deps = ${esp32s3_base.lib_deps} - lovyan03/LovyanGFX@^1.1.7 \ No newline at end of file + lovyan03/LovyanGFX@^1.1.8 \ No newline at end of file diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 318454522..83f41ecdf 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -21,6 +21,7 @@ #define TFT_OFFSET_Y 0 #define VTFT_CTRL 46 // Heltec Tracker needs this pulled low for TFT #define SCREEN_TRANSITION_FRAMERATE 1 // fps +#define DISPLAY_FORCE_SMALL_FONTS #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index ec5796313..40671e4fb 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -1,5 +1,5 @@ -#define I2C_SCL 47 -#define I2C_SDA 48 +#define I2C_SCL SCL +#define I2C_SDA SDA #define LED_PIN LED diff --git a/variants/m5stack_core/platformio.ini b/variants/m5stack_core/platformio.ini index a2330922e..84fb9f251 100644 --- a/variants/m5stack_core/platformio.ini +++ b/variants/m5stack_core/platformio.ini @@ -2,8 +2,6 @@ extends = esp32_base board = m5stack-core-esp32 board_level = extra -upload_port = COM8 -monitor_port = COM8 monitor_filters = esp32_exception_decoder build_src_filter = ${esp32_base.build_src_filter} @@ -28,4 +26,4 @@ lib_ignore = m5stack-core lib_deps = ${esp32_base.lib_deps} - bodmer/TFT_eSPI@^2.4.76 \ No newline at end of file + lovyan03/LovyanGFX@^1.1.8 diff --git a/variants/m5stack_core/variant.h b/variants/m5stack_core/variant.h index d9ef9ab28..22fa323d7 100644 --- a/variants/m5stack_core/variant.h +++ b/variants/m5stack_core/variant.h @@ -34,8 +34,13 @@ #define GPS_RX_PIN 16 #define GPS_TX_PIN 17 -// Define if screen should be mirrored left to right -#define SCREEN_ROTATE +#define TFT_HEIGHT 240 +#define TFT_WIDTH 320 +#define TFT_OFFSET_X 0 +#define TFT_OFFSET_Y 0 +#define TFT_BUSY -1 // LCD screens are slow, so slowdown the wipe so it looks better #define SCREEN_TRANSITION_FRAMERATE 1 // fps + +#define ILI9341_SPI_HOST VSPI_HOST // VSPI_HOST or HSPI_HOST diff --git a/variants/m5stack_coreink/variant.h b/variants/m5stack_coreink/variant.h index 3abf16be7..5ec1a81a3 100644 --- a/variants/m5stack_coreink/variant.h +++ b/variants/m5stack_coreink/variant.h @@ -39,7 +39,9 @@ #undef RF95_MOSI #undef RF95_NSS #define USE_RF95 +//#define USE_SX1280 +#ifdef USE_RF95 #define RF95_SCK 18 #define RF95_MISO 34 #define RF95_MOSI 23 @@ -48,6 +50,22 @@ #define LORA_RESET 26 #define LORA_DIO1 RADIOLIB_NC #define LORA_DIO2 RADIOLIB_NC +#endif + +#ifdef USE_SX1280 +#define RF95_SCK 18 +#define RF95_MISO 34 +#define RF95_MOSI 23 +#define RF95_NSS 14 +#define LORA_RESET 26 +#define LORA_DIO1 25 +#define LORA_DIO2 13 +#define SX128X_CS RF95_NSS +#define SX128X_DIO1 LORA_DIO1 +#define SX128X_BUSY LORA_DIO2 +#define SX128X_RESET LORA_RESET +#define SX128X_MAX_POWER 13 // 10 +#endif #define USE_EINK // https://docs.m5stack.com/en/core/coreink @@ -59,3 +77,18 @@ #define PIN_EINK_RES -1 // Connected but not needed #define PIN_EINK_SCLK 18 // EPD_SCLK #define PIN_EINK_MOSI 23 // EPD_MOSI + +#define BATTERY_PIN 35 +#define ADC_CHANNEL ADC1_GPIO35_CHANNEL +// https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/schematic/Core/m5paper/M5_PAPER_SCH.pdf +// https://github.com/m5stack/M5Core-Ink/blob/master/examples/Basics/FactoryTest/FactoryTest.ino#L58 +// VBAT +// | +// R83 (3K) +// + +// R86 (11K) +// | +// GND +// https://github.com/m5stack/M5Core-Ink/blob/master/examples/Basics/FactoryTest/FactoryTest.ino#L58 +#define ADC_MULTIPLIER 5 // Just a guess for now... more detailed getBatVoltage above +// https://embeddedexplorer.com/esp32-adc-esp-idf-tutorial/ diff --git a/variants/nano-g2-ultra/platformio.ini b/variants/nano-g2-ultra/platformio.ini index c00a9e5ac..d5e5a6137 100644 --- a/variants/nano-g2-ultra/platformio.ini +++ b/variants/nano-g2-ultra/platformio.ini @@ -4,10 +4,6 @@ extends = nrf52840_base board = nano-g2-ultra debug_tool = jlink -# add our variants files to the include and src paths -# define build flags for the TFT_eSPI library - NOTE: WE NOT LONGER USE TFT_eSPI, it was for an earlier version of the TTGO eink screens -# -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30 -# add -DCFG_SYSVIEW if you want to use the Segger systemview tool for OS profiling. build_flags = ${nrf52840_base.build_flags} -Ivariants/nano-g2-ultra -D NANO_G2_ULTRA -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m4/fpv4-sp-d16-hard" build_src_filter = ${nrf52_base.build_src_filter} +<../variants/nano-g2-ultra> diff --git a/variants/nano-g2-ultra/variant.h b/variants/nano-g2-ultra/variant.h index da46f311d..4c1720af8 100644 --- a/variants/nano-g2-ultra/variant.h +++ b/variants/nano-g2-ultra/variant.h @@ -114,9 +114,8 @@ External serial flash W25Q16JV_IQ #define SX126X_CS (32 + 13) // FIXME - we really should define LORA_CS instead #define SX126X_DIO1 (32 + 10) // Note DIO2 is attached internally to the module to an analog switch for TX/RX switching -//#define SX1262_DIO3 \ - (0 + 21) // This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the main -// CPU? +//#define SX1262_DIO3 (0 + 21) +// This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the main CPU? #define SX126X_BUSY (32 + 11) #define SX126X_RESET (32 + 15) #define SX126X_E22 // DIO2 controlls an antenna switch and the TCXO voltage is controlled by DIO3 diff --git a/variants/picomputer-s3/pins_arduino.h b/variants/picomputer-s3/pins_arduino.h new file mode 100644 index 000000000..c84601b1e --- /dev/null +++ b/variants/picomputer-s3/pins_arduino.h @@ -0,0 +1,30 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +// Default SPI +static const uint8_t MISO = 39; +static const uint8_t SCK = 21; +static const uint8_t MOSI = 38; +static const uint8_t SS = 40; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/picomputer-s3/platformio.ini b/variants/picomputer-s3/platformio.ini new file mode 100644 index 000000000..e7093697a --- /dev/null +++ b/variants/picomputer-s3/platformio.ini @@ -0,0 +1,17 @@ +[env:picomputer-s3] +extends = esp32s3_base +board = bpi_picow_esp32_s3 +board_level = extra +;OpenOCD flash method +;upload_protocol = esp-builtin +;Normal method +upload_protocol = esptool + +build_flags = + ${esp32s3_base.build_flags} + -DPICOMPUTER_S3 + -I variants/picomputer-s3 + +lib_deps = + ${esp32s3_base.lib_deps} + lovyan03/LovyanGFX@^1.1.8 diff --git a/variants/picomputer-s3/variant.h b/variants/picomputer-s3/variant.h new file mode 100644 index 000000000..0f416efe0 --- /dev/null +++ b/variants/picomputer-s3/variant.h @@ -0,0 +1,54 @@ +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define BUTTON_PIN 0 + +#define PIN_BUZZER 43 + +#define HAS_GPS 0 +#define HAS_WIRE 0 + +#define USE_RF95 // RFM95/SX127x + +#define RF95_SCK SCK // 21 +#define RF95_MISO MISO // 39 +#define RF95_MOSI MOSI // 38 +#define RF95_NSS SS // 40 +#define LORA_RESET RADIOLIB_NC + +// per SX1276_Receive_Interrupt/utilities.h +#define LORA_DIO0 10 +#define LORA_DIO1 RADIOLIB_NC +#define LORA_DIO2 RADIOLIB_NC + +// Default SPI1 will be mapped to the display +#define ST7789_SDA 4 +#define ST7789_SCK 3 +#define ST7789_CS 6 +#define ST7789_RS 1 +#define ST7789_BL 5 + +#define ST7789_RESET -1 +#define ST7789_MISO -1 +#define ST7789_BUSY -1 +#define ST7789_SPI_HOST SPI3_HOST +#define ST7789_BACKLIGHT_EN 5 +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 +#define TFT_HEIGHT 320 +#define TFT_WIDTH 240 +#define TFT_OFFSET_X 0 +#define TFT_OFFSET_Y 0 +#define SCREEN_ROTATE +#define SCREEN_TRANSITION_FRAMERATE 5 + +#define INPUTBROKER_MATRIX_TYPE 1 + +#define KEYS_COLS \ + { \ + 44, 47, 17, 15, 13, 41 \ + } +#define KEYS_ROWS \ + { \ + 12, 16, 42, 18, 14, 7 \ + } diff --git a/variants/t-deck/platformio.ini b/variants/t-deck/platformio.ini index 8344fb990..c3c508a0f 100644 --- a/variants/t-deck/platformio.ini +++ b/variants/t-deck/platformio.ini @@ -11,4 +11,4 @@ build_flags = ${esp32_base.build_flags} -Ivariants/t-deck lib_deps = ${esp32s3_base.lib_deps} - lovyan03/LovyanGFX@^1.1.7 \ No newline at end of file + lovyan03/LovyanGFX@^1.1.8 \ No newline at end of file diff --git a/variants/t-echo/platformio.ini b/variants/t-echo/platformio.ini index 2f043108c..2555032df 100644 --- a/variants/t-echo/platformio.ini +++ b/variants/t-echo/platformio.ini @@ -4,9 +4,6 @@ extends = nrf52840_base board = t-echo debug_tool = jlink -# add our variants files to the include and src paths -# define build flags for the TFT_eSPI library - NOTE: WE NOT LONGER USE TFT_eSPI, it was for an earlier version of the TTGO eink screens -# -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30 # add -DCFG_SYSVIEW if you want to use the Segger systemview tool for OS profiling. build_flags = ${nrf52840_base.build_flags} -Ivariants/t-echo -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m4/fpv4-sp-d16-hard" diff --git a/variants/t-watch-s3/platformio.ini b/variants/t-watch-s3/platformio.ini index 709ea89ee..08751d463 100644 --- a/variants/t-watch-s3/platformio.ini +++ b/variants/t-watch-s3/platformio.ini @@ -12,6 +12,6 @@ build_flags = ${esp32_base.build_flags} -DPCF8563_RTC=0x51 lib_deps = ${esp32s3_base.lib_deps} - lovyan03/LovyanGFX@^1.1.7 + lovyan03/LovyanGFX@^1.1.8 lewisxhe/PCF8563_Library@1.0.1 adafruit/Adafruit DRV2605 Library@^1.2.2 \ No newline at end of file diff --git a/version.properties b/version.properties index c00681305..1c45cbf4b 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 1 -build = 22 +build = 23