+19









Ben Meadors
Jonathan Bennett
Jason P
Eric Sesterhenn
Vortetty
Mattatat25
Copilot
Max
Colby Dillion
Austin
Tom
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Chloe Bethel
Thomas Göttgens
Quency-D
HarukiToreda
oscgonfer
nikl
Hannes Fuchs
Nashui-Yan
Tom Fifield
Mike Robbins
WillyJL
renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Wessel
Christian Walther
Jorropo
Eric Barch
Clive Blackledge
4c91beeda9
* Don't ever define PIN_LED or BLE_LED_INVERTED (#9494) * Don't ever define PIN_LED * Deprecate BLE_LED_INVERTED * Add StatusMessage module and config overrides (#9351) * Add StatusMessage module and config overrides * Trunk * Don't reboot node simply for a StatusMessage config update * Missed in reviews - fixing send bubble (#9505) * Prefer EXT_PWR_DETECT pin over chargingVolt to detect power unplugged (#9511) * Make sure we always return a value in NodeDB::restorePreferences() (#9516) In case FScom is not defined there is no return statement. This moves the return outside of the ifdef to make sure a defined value is returned. * Inkhud battery icon improvements. (#9513) * Inkhud battery icon improvements. Fixes the battery icon draining from the flat side towards the bump, which is backwards from general design language seen on most devices By request of kr0n05_ on discord, adds the ability to mirror the battery icon which fixes that issue in another way, and is also a common design seen on other devices. * Remove option for icon mirroring * Add border + dither to battery to prevent font overlap * Fix trunk format * Code cleanup, courtesy of Xaositek. * Add reply bot module with DM-only responses and rate limiting (#9456) * Implement Meshtastic reply bot module with ping and status features Adds a reply bot module that listens for /ping, /hello, and /test commands received via direct messages or broadcasts on the primary channel. The module always replies via direct message to the sender only, reporting hop count, RSSI, and SNR. Per-sender cooldowns are enforced to reduce network spam, and the module can be excluded at build time via a compile flag. Updates include the new module source files and required build configuration changes. * Update ReplyBotModule.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/ReplyBotModule.h Match the existing MESHTASTIC_EXCLUDE_* guard pattern so the module is excluded by default. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/ReplyBotModule.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Tidying up --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * HotFix for ReplyBot - Modules.cpp included and moved configuration.h (#9532) * Undefine LED_BUILTIN (#9531) Keep variant in sync with https://github.com/meshtastic/firmware/commit/df40085 Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Add agc reset attempt (#8163) * Add agc reset attempt * Add radioLibInterface include * Trunk * AGC reset don't crash, don't naively call * Update src/main.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use Throttle function --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove unused hmx variable (#9529) The variable is not used at all in the function, remove it to silence the compiler warning. Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Rename LED_PIN to LED_POWER, move handling out of main to dedicated module (#9512) * Rename LED_PIN to LED_POWER, move handling out of main to dedicated module * Misc * Remove errant endif * Fix hop_limit upgrade detection (#9550) Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * meshtasticd: Fix install on Fedora 43 (#9556) * RPM: Include meshtasticd-start.sh (#9561) * Add Slash Key to VirtualKeyboard (#9563) Addition of ? and / to the virtual Keyboard via short and long press * Add support for CW2015 LiPo battery fuel gauge (#9564) * Add support for CW2015 LiPo battery fuel gauge * Address Copilot's concerns, minor fixups * Make LED_POWER blip even in critical battery (#9545) * Enable FORTIFY and SP for native builds (#9537) * Enable FORITFY and NX for native builds meshtasticd does have an executable stack and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and a non-executable stack. This gives the following improvements on Debian Trixie: $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 13516 Symbols No 0 17 ./.pio/build/native/meshtasticd $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO Canary found NX enabled PIE enabled No RPATH No RUNPATH 13519 Symbols Yes 12 20 ./.pio/build/native/meshtasticd Tested with --sim mode I do not get any crashes or similar. * Enable FORTIFY and NX for native builds meshtasticd does have an executable stack and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and a non-executable stack. This gives the following improvements on Debian Trixie: $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 13516 Symbols No 0 17 ./.pio/build/native/meshtasticd $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO Canary found NX enabled PIE enabled No RPATH No RUNPATH 13519 Symbols Yes 12 20 ./.pio/build/native/meshtasticd Tested with --sim mode I do not get any crashes or similar. * Enable FORTIFY and SP for native builds meshtasticd does have a stack canaries and is not built with fortify, which makes exploitation of memory corruption bugs easier than it has to be. This enables fortify and stack canaries. This gives the following improvements on Debian Trixie: $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 13516 Symbols No 0 17 ./.pio/build/native/meshtasticd $ checksec --file=./.pio/build/native/meshtasticd RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO Canary found NX enabled PIE enabled No RPATH No RUNPATH 13519 Symbols Yes 12 20 ./.pio/build/native/meshtasticd Tested with --sim mode I do not get any crashes or similar. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Update built-in documentation for current method of implementation (#9592) * Refactor logging in ProtobufModule to ensure message details are logged after successful decoding (#9536) * Automated version bumps (#9604) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Add missing openocd_target to custom nrf52 boards (#9603) This stops platformio complaining about `Missing target configuration for me25ls01-4y10td` etc when trying to flash with nrfutil. * Add sdl libs for native builds (#9595) * Add sdl libs for native builds * Alpine try again * fix some random compiler warnings (#9596) * Modify the dependency library of v4-tft (#9507) * BaseUI: Favorite Screen Signal Quality improvement (#9566) * Favorite Signal Quality improvement * Show Voltage if node shares it. * Trunk Fix * Change Favorite tittle to encase name with Asterisks * Add Pluggin In condition for Battery Line * Adjust getUptimeStr Prefixes * Create isAPIConnected for SharedCommon usage * Correct leftSideSpacing to account for isAPIConnected --------- Co-authored-by: Jason P <applewiz@mac.com> * ExternalNotification and StatusLED now call AmbientLighting to update… (#9554) * ExternalNotification and StatusLED now call AmbientLighting to update RGB LEDs. Add optional heartbeat * Don't overwrite RGB state if heartbeat is disabled. * Use the right define * Remove another .h and make rgb static * move rgb objects into AmbientLighting class * Straighten out AmbientLighting Thread object * Use %f for floats * Fixes on SCD4X admin comands (#9607) * Fixes on SCD4X admin comands * Minor fix in logs for SEN5X --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * feat/add sfa30 (#9372) * Move PMSA003I to separate class and update AQ telemetry * AirQualityTelemetry module not depend on PM sensor presence * Remove commented line * Fixes on PMS class * Add missing warmup period to wakeUp function * Fixes on compilation for different variants * Add functions to check for I2C bus speed and set it * Initial implementation for SFA30Sensor * Move PMSA003I to separate class and update AQ telemetry * AirQualityTelemetry module not depend on PM sensor presence * Remove commented line * Fixes on PMS class * Add missing warmup period to wakeUp function * Fixes on compilation for different variants * Add functions to check for I2C bus speed and set it * Add ScreenFonts.h Co-authored-by: Hannes Fuchs <hannes.fuchs+git@0xef.de> * PMSA003I 1st round test * Fix I2C scan speed * Fix minor issues and bring back I2C SPEED def * Remove PMSA003I library as its no longer needed * Add functional SCD4X * Fix screen frame for CO2 * Add admin commands to SCD4X class * Add further admin commands and fixes. * Remove unused I2C speed functions and cleanup * Cleanup of SEN5X specific code added from switching branches * Remove SCAN_I2C_CLOCK_SPEED block as its not needed * Remove associated functions for setting I2C speed * Unify build epoch to add flag in platformio-custom.py (#7917) * Unify build_epoch replacement logic in platformio-custom * Missed one * Fix build error in rak_wismesh_tap_v2 (#7905) In the logs was: "No screen resolution defined in build_flags. Please define DISPLAY_SIZE." set according to similar devices. * Put guards in place around debug heap operations (#7955) * Put guards in place around debug heap operations * Add macros to clean up code * Add pointer as well * Cleanup * Fix memory leak in NextHopRouter: always free packet copy when removing from pending * Formatting * Only queue 2 client notification * Merge pull request #7965 from compumike/compumike/fix-nrf52-bluetooth-memory-leak Fix memory leak in `NRF52Bluetooth`: allocate `BluetoothStatus` on stack, not heap * Merge pull request #7964 from compumike/compumike/fix-nimble-bluetooth-memory-leak Fix memory leak in `NimbleBluetooth`: allocate `BluetoothStatus` on stack, not heap * Update protobufs (#7973) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * T-Lora Pager: Support LR1121 and SX1280 models (#7956) * T-Lora Pager: Support LR1121 and SX1280 models * Remove ifdefs * Trunk * Trunk * Static memory pool allocation (#7966) * Static memory pool * Initializer * T-Lora Pager: Support LR1121 and SX1280 models (#7956) * T-Lora Pager: Support LR1121 and SX1280 models * Remove ifdefs --------- Co-authored-by: WillyJL <me@willyjl.dev> * Portduino dynamic alloc * Missed * Drop the limit * Update meshtastic-esp8266-oled-ssd1306 digest to 0cbc26b (#7977) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Fix json report crashes on esp32 (#7978) * Tweak maximums * Fix DRAM overflow on old esp32 targets * Guard bad time warning logs using GPS_DEBUG (#7897) In 2.7.7 / 2.7.8 we introduced some new checks for time accuracy. In combination, these result in a spamming of the logs when a bad time is found When the GPS is active, we're calling the GPS thread every 0.2secs. So this log could be printed 4,500 times in a no-lock scenario :) Reserve this experience for developers using GPS_DEBUG. Fixes https://github.com/meshtastic/firmware/issues/7896 * Scale probe buffer size based on current baud rate (#7975) * Scale probe buffer size based on current baud rate * Throttle bad time validation logging and fix time comparison logic * Remove comment * Missed the other instances * Copy pasta * Fix GPS gm_mktime memory leak (#7981) * Fix overflow of time value (#7984) * Fix overflow of time value * Revert "Fix overflow of time value" This reverts commit 084796920179e80a7500d36c25fd4d82b3ef4214. * That got boogered up * Remove PMSA003 include from modules * Add flag to exclude air quality module * Rework PMSA003I to align with new I2C scanner * Reworks AQ telemetry to match new dynamic allocation method * Adds VBLE_I2C_CLOCK_SPEED build flag for sensors with different I2C speed requirements * Reworks PMSA003I * Move add sensor template to separate file * Split telemetry on screen options * Add variable I2C clock compile flag * Added to Seeed Xiao S3 as demo * Fix drawFrame in AQ module * Module settings override to i2cScan module function * Move to CAN_RECLOCK_I2C per architecture * Add reclock function in TelemetrySensor.cpp * Add flag in ESP32 common * Minor fix * Move I2C reclock function to src/detect * Fix uninitMemberVar errors and compile issue * Make sleep, wakeUp functions generic * Fix STM32 builds * Add exclude AQ sensor to builds that have environmental sensor excludes * Add includes to AddI2CSensorTemplate.h * SEN5X first pass * WIP Sen5X functions * Further (non-working) progress in SEN5X * WIP Sen5X functions * Changes on SEN5X library - removing pm_env as well * Small cleanup of SEN5X sensors * Minor change for SEN5X detection * Remove dup code * Enable PM sensor before sending telemetry. This enables the PM sensor for a predefined period to allow for warmup. Once telemetry is sent, the sensor shuts down again. * Small cleanups in SEN5X sensor * Add dynamic measurement interval for SEN5X * Only disable SEN5X if enough time after reading. * Idle for SEN5X on communication error * Cleanup of logs and remove unnecessary delays * Small TODO * Settle on uint16_t for SEN5X PM data * Make AQTelemetry sensors non-exclusive * Implementation of cleaning in FS prefs and cleanup * Remove unnecessary LOGS * Add cleaning date storage in FS * Report non-cumulative PN * Bring back detection code for SEN5X after branch rebase * Add placeholder for admin message * Add VOC measurements and persistence (WIP) * Adds VOC measurements and state * Still not working on VOC Index persistence * Should it stay in continuous mode? * Add one-shot mode config flag to SEN5X * Add nan checks on sensor data from SEN5X * Working implementation on VOCState * Adds initial timer for SEN55 to not sleep if VOCstate is not stable (1h) * Adds conditions for stability and sensor state * Fixes on VOC state and mode swtiching * Adds a new RHT/Gas only mode, with 3600s stabilization time * Fixes the VOCState buffer mismatch * Fixes SEN50/54/55 model mistake * Adapt SEN5X to new sensor list structure. Improve reclock. * Improve reClockI2C conditions for different variants * Add sleep, wakeUp, pendingForReady, hasSleep functions to PM sensors to save battery * Add SEN5X * Fix merge errors * Small reordering in PMS class for consistency * If one sensor fails, AQ telemetry still reports data * Small formatting fix * Add SEN5X to AQI in ScanI2C * SCD4X now part of AQ module with template list * Fixes difference between idle and sleep * In LowPower, sleep is disabled * Requires testing for I2C clock comms for commands * Remove unnecessary import * Add co2 to serialized AQ metrics * Add SFA30 with new sensor template in AQ module * Update library dependencies in platformio.ini * Fix unitialized variables in SEN5X constructor * Fix missing import * Fix uninitMemberVars * Fix import error for SCD4X * Fix I2CClock logic * Fix not reclocking back to 700000Hz * Fix multiple sensors being read simultaneously * The logic in AQ module is different to the one in EnvironmentTelemetryModule. In Env module, if any sensor fails to getMetrics, no valid flag for the module. This prevents other sensors to report data. * Fix pending clock change in PMSA003 * Cleanup of SEN5X class * Exclude AQ sensor from wio-e5 due to flash limitations * Fix I2C clock change logic * Make sure clock is always set to needed value * Fix returns * Fix trunk * Fix on condition in reclock * Fix trunk * Final SFA30 class implementation * Add HCHO to screen and improve logs * Add metrics to mesh packet serializer * Minor fixes in logs * OCD tidy up of logs * Fix sleep function * Remove old I2C_CLOCK_SPEED code --------- Co-authored-by: nikl <nikl174@mailbox.org> Co-authored-by: Hannes Fuchs <hannes.fuchs+git@0xef.de> Co-authored-by: Nashui-Yan <yannashui10@gmail.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Tom Fifield <tom@tomfifield.net> Co-authored-by: Mike Robbins <mrobbins@alum.mit.edu> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> Co-authored-by: WillyJL <me@willyjl.dev> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Log rxBad PacketHeaders with more info (id, relay_node) like printPacket, so we can try to match RX errors to other packets in the logs. (#9614) * Exclude status message module * fix: zero entire public key array instead of only first byte (#9619) * Update protobufs (#9621) * Xiao NRF - define suitable i2c pins for the sub-variants (#8866) Co-authored-by: Christian Walther <cwalther@gmx.ch> * Update src/detect/ScanI2C.cpp Co-authored-by: Wessel <wessel@weebl.me> * Update src/modules/Telemetry/Sensor/SFA30Sensor.cpp Co-authored-by: Wessel <wessel@weebl.me> * Update src/modules/Telemetry/Sensor/SFA30Sensor.cpp Co-authored-by: Wessel <wessel@weebl.me> * Update src/modules/Telemetry/Sensor/SFA30Sensor.cpp Co-authored-by: Wessel <wessel@weebl.me> * Update src/mesh/NodeDB.cpp Co-authored-by: Wessel <wessel@weebl.me> * convert GPS global and some new in gps.cpp to unique_ptr (#9628) Trying this to see if anything bad happen if I were to replace most raw pointers with unique_ptr. I didn't used std::make_unique since it is only supported in C++14 and onwards but until we update esp32 to arduino 3.x the ESP32 xtensa chips use a C++11 std. * replace delete in RedirectablePrint.cpp with std::unique_ptr (#9642) Is part of the unique_ptr modernization effort. * replace delete in EInkDynamicDisplay.{cpp,h} with std::unique_ptr (#9643) Is part of the unique_ptr modernization effort. * Undefine LED_BUILTIN for Heltec v2 variant (#9647) * Undefine LED_BUILTIN for Heltec v2 variant * Undefine LED_BUILTIN for Heltec v2.1 variant --------- Co-authored-by: Jorropo <jorropo.pgm@gmail.com> * replace delete in RadioInterface.cpp with std::unique_ptr (#9645) Is part of the unique_ptr modernization effort. * fix typo in PIN_GPS_SWITCH (#9648) Wasn't caught by CI. * replace delete in CryptoEngine.{cpp,h} with std::unique_ptr (#9649) Is part of the unique_ptr modernization effort. * workaround NCP5623 and LP5562 I2C builds (#9652) Theses two appear to be buggy on r1-neo and nomadstar meteor pro, they rely on Wire.h being included previously to their import. Idk why other platforms using the same smart LEDs are working while theses ones don't. This should make CI green on the dev branch. * replace delete in AudioThread.h with std::unique_ptr (#9651) Is part of the unique_ptr modernization effort. * Add USB_MODE=1 for Station G2 (#9660) * InkHUD: Favorite Map Applet (#9654) * fix a lot of low level cppcheck warnings (#9623) * simplify the observer pattern, since all the called functions are const getters. * use arduino macro over std: for numerical values and refactor local variables in drawScrollbar() * oh, so Cppcheck actually complained about const pointers not being const. * slowly getting out of ifdef hell * fix inkHUD warnings as well * last 2 check warnings * git checks should fail on low defects from now on * Feat/add scd30 (#9609) * Merge develop into SCD30 * Add SCD30 class * Fix logging and admin commands * Minor cleanup and logging improvements * Minor formatting issue Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improvements on setTemperature * Fix casting float-uint16_t * Pass 100 for resetting temperature offset * Fix issues pointed out by copilot * Add quick reboot to set interval quicker on scd30 * Change saveState to only happen after boot and minor log changes * Fix missing semicolon in one shot mode log --------- Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * fix: respect DontMqttMeBro flag regardless of channel PSK (#9626) The previous PSK check was broken from its introduction in #4643 — memcmp was used in boolean context without comparing to 0, inverting the condition. Since no one noticed for over a year, the PSK-based filtering provided no practical value. Simplifying to always respect the sender's preference is both more correct and easier to reason about. * our firmware action is too clever Update pio_target and add pio_opts for checks. * fix detection of SCD30 by checking if the size of the return from a 2 byte register read is correct (#9664) * fix detection of SCD30 by checking if thee size of the return from a 2 byte register read is correct fix signedness warning in PMSA003 sensor code. * Add alternate path for LPS22HB Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * check EndTransmission for errors and compare returned length to expected value Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * #9623 resolved a local shadow of next_key by converting it to int. (#9665) * zip a few gitrefs down (#9672) * InkHUD: Allow non-system applets to subscribe to input events (#9514) * Allow inkhud user applets to consume inputs with opt-in system Adds a way for applets to subscribe to input events while keeping it off by default to preserve compatibility and expected behaviours. Adds example for use as well. * Add check for nullptr on getActiveApplet uses * Remove redundant includes * Move subscribedInputs to protected * More consistent naming scheme * Fake IAQ values on Non-BSEC2 platforms like Platformio and the original ESP32 (#9663) * BSEC2 Replacement - add approximation for IAQ to non-BSEC2 platforms. - Re-add this sensor to ESP32 targets, and refactor env_extra includes. - Fix C++ 11 compatibility * Check for gas resistance 0 * ULED_BUILTIN for 9m2ibr_aprs_lora_tracker (#9685) --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Jason P <applewiz@mac.com> Co-authored-by: Eric Sesterhenn <eric.sesterhenn@x41-dsec.de> Co-authored-by: Vortetty <33466216+Vortetty@users.noreply.github.com> Co-authored-by: Mattatat25 <108779801+mattatat25@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max <rekin.m@gmail.com> Co-authored-by: Colby Dillion <colby.dillion@pacshealth.com> Co-authored-by: Austin <vidplace7@gmail.com> Co-authored-by: Tom <116762865+NomDeTom@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Chloe Bethel <chloe@9net.org> Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: Quency-D <55523105+Quency-D@users.noreply.github.com> Co-authored-by: HarukiToreda <116696711+HarukiToreda@users.noreply.github.com> Co-authored-by: oscgonfer <oscgonfer@users.noreply.github.com> Co-authored-by: nikl <nikl174@mailbox.org> Co-authored-by: Hannes Fuchs <hannes.fuchs+git@0xef.de> Co-authored-by: Nashui-Yan <yannashui10@gmail.com> Co-authored-by: Tom Fifield <tom@tomfifield.net> Co-authored-by: Mike Robbins <mrobbins@alum.mit.edu> Co-authored-by: WillyJL <me@willyjl.dev> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Wessel <wessel@weebl.me> Co-authored-by: Christian Walther <cwalther@gmx.ch> Co-authored-by: Jorropo <jorropo.pgm@gmail.com> Co-authored-by: Eric Barch <ericb@ericbarch.com> Co-authored-by: Clive Blackledge <clive@ansible.org>
564 lines
18 KiB
C++
564 lines
18 KiB
C++
#include "Throttle.h"
|
|
#include "configuration.h"
|
|
|
|
#if defined(USE_EINK) && defined(USE_EINK_DYNAMICDISPLAY)
|
|
#include "EInkDynamicDisplay.h"
|
|
|
|
// Constructor
|
|
EInkDynamicDisplay::EInkDynamicDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus)
|
|
: EInkDisplay(address, sda, scl, geometry, i2cBus), NotifiedWorkerThread("EInkDynamicDisplay")
|
|
{
|
|
// If tracking ghost pixels, grab memory
|
|
#ifdef EINK_LIMIT_GHOSTING_PX
|
|
dirtyPixels = std::unique_ptr<uint8_t[]>(new uint8_t[EInkDisplay::displayBufferSize]()); // Init with zeros
|
|
#endif
|
|
}
|
|
|
|
// Destructor
|
|
EInkDynamicDisplay::~EInkDynamicDisplay()
|
|
{
|
|
// If we were tracking ghost pixels, free the memory
|
|
#ifdef EINK_LIMIT_GHOSTING_PX
|
|
dirtyPixels = nullptr;
|
|
#endif
|
|
}
|
|
|
|
// Screen requests a BACKGROUND frame
|
|
void EInkDynamicDisplay::display()
|
|
{
|
|
addFrameFlag(BACKGROUND);
|
|
update();
|
|
}
|
|
|
|
// Screen requests a RESPONSIVE frame
|
|
bool EInkDynamicDisplay::forceDisplay(uint32_t msecLimit)
|
|
{
|
|
addFrameFlag(RESPONSIVE);
|
|
return update(); // (Unutilized) Base class promises to return true if update ran
|
|
}
|
|
|
|
// Add flag for the next frame
|
|
void EInkDynamicDisplay::addFrameFlag(frameFlagTypes flag)
|
|
{
|
|
// OR the new flag into the existing flags
|
|
this->frameFlags = (frameFlagTypes)(this->frameFlags | flag);
|
|
}
|
|
|
|
// GxEPD2 code to set fast refresh
|
|
void EInkDynamicDisplay::configForFastRefresh()
|
|
{
|
|
// Variant-specific code can go here
|
|
#if defined(PRIVATE_HW)
|
|
#else
|
|
// Otherwise:
|
|
adafruitDisplay->setPartialWindow(0, 0, adafruitDisplay->width(), adafruitDisplay->height());
|
|
#endif
|
|
}
|
|
|
|
// GxEPD2 code to set full refresh
|
|
void EInkDynamicDisplay::configForFullRefresh()
|
|
{
|
|
// Variant-specific code can go here
|
|
#if defined(PRIVATE_HW)
|
|
#else
|
|
// Otherwise:
|
|
adafruitDisplay->setFullWindow();
|
|
#endif
|
|
}
|
|
|
|
// Run any relevant GxEPD2 code, so next update will use correct refresh type
|
|
void EInkDynamicDisplay::applyRefreshMode()
|
|
{
|
|
// Change from FULL to FAST
|
|
if (currentConfig == FULL && refresh == FAST) {
|
|
configForFastRefresh();
|
|
currentConfig = FAST;
|
|
}
|
|
|
|
// Change from FAST back to FULL
|
|
else if (currentConfig == FAST && refresh == FULL) {
|
|
configForFullRefresh();
|
|
currentConfig = FULL;
|
|
}
|
|
}
|
|
|
|
// Update fastRefreshCount
|
|
void EInkDynamicDisplay::adjustRefreshCounters()
|
|
{
|
|
if (refresh == FAST)
|
|
fastRefreshCount++;
|
|
|
|
else if (refresh == FULL)
|
|
fastRefreshCount = 0;
|
|
}
|
|
|
|
// Trigger the display update by calling base class
|
|
bool EInkDynamicDisplay::update()
|
|
{
|
|
// Detemine the refresh mode to use, and start the update
|
|
bool refreshApproved = determineMode();
|
|
if (refreshApproved) {
|
|
EInkDisplay::forceDisplay(0); // Bypass base class' own rate-limiting system
|
|
storeAndReset(); // Store the result of this loop for next time. Note: call *before* endOrDetach()
|
|
endOrDetach(); // endUpdate() right now, or set the async refresh flag (if FULL and HAS_EINK_ASYNCFULL)
|
|
} else
|
|
storeAndReset(); // No update, no post-update code, just store the results
|
|
|
|
return refreshApproved; // (Unutilized) Base class promises to return true if update ran
|
|
}
|
|
|
|
// Figure out who runs the post-update code
|
|
void EInkDynamicDisplay::endOrDetach()
|
|
{
|
|
// If the GxEPD2 version reports that it has the async modifications
|
|
#ifdef HAS_EINK_ASYNCFULL
|
|
if (previousRefresh == FULL) {
|
|
asyncRefreshRunning = true; // Set the flag - checked in determineMode(); cleared by onNotify()
|
|
|
|
if (previousFrameFlags & BLOCKING)
|
|
awaitRefresh();
|
|
else {
|
|
// Async begins
|
|
LOG_DEBUG("Async full-refresh begins (drop frames)");
|
|
notifyLater(intervalPollAsyncRefresh, DUE_POLL_ASYNCREFRESH, true); // Hand-off to NotifiedWorkerThread
|
|
}
|
|
}
|
|
|
|
// Fast Refresh
|
|
else if (previousRefresh == FAST)
|
|
EInkDisplay::endUpdate(); // Still block while updating, but EInkDisplay needs us to call endUpdate() ourselves.
|
|
|
|
// Fallback - If using an unmodified version of GxEPD2 for some reason
|
|
#else
|
|
if (previousRefresh == FULL || previousRefresh == FAST) { // If refresh wasn't skipped (on unspecified..)
|
|
LOG_WARN(
|
|
"GxEPD2 version has not been modified to support async refresh; using fallback behavior. Please update lib_deps in "
|
|
"variant's platformio.ini file");
|
|
EInkDisplay::endUpdate();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
// Assess situation, pick a refresh type
|
|
bool EInkDynamicDisplay::determineMode()
|
|
{
|
|
checkInitialized();
|
|
checkForPromotion();
|
|
#if defined(HAS_EINK_ASYNCFULL)
|
|
checkBusyAsyncRefresh();
|
|
#endif
|
|
checkRateLimiting();
|
|
|
|
// If too soon for a new frame, or display busy, abort early
|
|
if (refresh == SKIPPED)
|
|
return false; // No refresh
|
|
|
|
// -- New frame is due --
|
|
|
|
resetRateLimiting(); // Once determineMode() ends, will have to wait again
|
|
hashImage(); // Generate here, so we can still copy it to previousImageHash, even if we skip the comparison check
|
|
LOG_DEBUG("determineMode(): "); // Begin log entry
|
|
|
|
// Once mode determined, any remaining checks will bypass
|
|
checkCosmetic();
|
|
checkDemandingFast();
|
|
checkFrameMatchesPrevious();
|
|
checkConsecutiveFastRefreshes();
|
|
#ifdef EINK_LIMIT_GHOSTING_PX
|
|
checkExcessiveGhosting();
|
|
#endif
|
|
checkFastRequested();
|
|
|
|
if (refresh == UNSPECIFIED)
|
|
LOG_WARN("There was a flaw in the determineMode() logic");
|
|
|
|
// -- Decision has been reached --
|
|
applyRefreshMode();
|
|
adjustRefreshCounters();
|
|
|
|
#ifdef EINK_LIMIT_GHOSTING_PX
|
|
// Full refresh clears any ghosting
|
|
if (refresh == FULL)
|
|
resetGhostPixelTracking();
|
|
#endif
|
|
|
|
// Return - call a refresh or not?
|
|
if (refresh == SKIPPED)
|
|
return false; // Don't trigger a refresh
|
|
else
|
|
return true; // Do trigger a refresh
|
|
}
|
|
|
|
// Is this the very first frame?
|
|
void EInkDynamicDisplay::checkInitialized()
|
|
{
|
|
if (!initialized) {
|
|
// Undo GxEPD2_BW::partialWindow(), if set by developer in EInkDisplay::connect()
|
|
configForFullRefresh();
|
|
|
|
// Clear any existing image, so we can draw logo with fast-refresh, but also to set GxEPD2_EPD::_initial_write
|
|
adafruitDisplay->clearScreen();
|
|
|
|
LOG_DEBUG("initialized, ");
|
|
initialized = true;
|
|
|
|
// Use a fast-refresh for the next frame; no skipping or else blank screen when waking from deep sleep
|
|
addFrameFlag(DEMAND_FAST);
|
|
}
|
|
}
|
|
|
|
// Was a frame skipped (rate, display busy) that should have been a FAST refresh?
|
|
void EInkDynamicDisplay::checkForPromotion()
|
|
{
|
|
// If a frame was skipped (rate, display busy), then promote a BACKGROUND frame
|
|
// Because we DID want a RESPONSIVE/COSMETIC/DEMAND_FULL frame last time, we just didn't get it
|
|
|
|
switch (previousReason) {
|
|
case ASYNC_REFRESH_BLOCKED_DEMANDFAST:
|
|
addFrameFlag(DEMAND_FAST);
|
|
break;
|
|
case ASYNC_REFRESH_BLOCKED_COSMETIC:
|
|
addFrameFlag(COSMETIC);
|
|
break;
|
|
case ASYNC_REFRESH_BLOCKED_RESPONSIVE:
|
|
case EXCEEDED_RATELIMIT_FAST:
|
|
addFrameFlag(RESPONSIVE);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Is it too soon for another frame of this type?
|
|
void EInkDynamicDisplay::checkRateLimiting()
|
|
{
|
|
// Sanity check: millis() overflow - just let the update run..
|
|
if (previousRunMs > millis())
|
|
return;
|
|
|
|
// Skip update: too soon for BACKGROUND
|
|
if (frameFlags == BACKGROUND) {
|
|
if (Throttle::isWithinTimespanMs(previousRunMs, 30000)) {
|
|
refresh = SKIPPED;
|
|
reason = EXCEEDED_RATELIMIT_FULL;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// No rate-limit for these special cases
|
|
if (frameFlags & COSMETIC || frameFlags & DEMAND_FAST)
|
|
return;
|
|
|
|
// Skip update: too soon for RESPONSIVE
|
|
if (frameFlags & RESPONSIVE) {
|
|
if (Throttle::isWithinTimespanMs(previousRunMs, 1000)) {
|
|
refresh = SKIPPED;
|
|
reason = EXCEEDED_RATELIMIT_FAST;
|
|
LOG_DEBUG("refresh=SKIPPED, reason=EXCEEDED_RATELIMIT_FAST, frameFlags=0x%x", frameFlags);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Is this frame COSMETIC (splash screens?)
|
|
void EInkDynamicDisplay::checkCosmetic()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
// A full refresh is requested for cosmetic purposes: we have a decision
|
|
if (frameFlags & COSMETIC) {
|
|
refresh = FULL;
|
|
reason = FLAGGED_COSMETIC;
|
|
LOG_DEBUG("refresh=FULL, reason=FLAGGED_COSMETIC, frameFlags=0x%x", frameFlags);
|
|
}
|
|
}
|
|
|
|
// Is this a one-off special circumstance, where we REALLY want a fast refresh?
|
|
void EInkDynamicDisplay::checkDemandingFast()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
// A fast refresh is demanded: we have a decision
|
|
if (frameFlags & DEMAND_FAST) {
|
|
refresh = FAST;
|
|
reason = FLAGGED_DEMAND_FAST;
|
|
LOG_DEBUG("refresh=FAST, reason=FLAGGED_DEMAND_FAST, frameFlags=0x%x", frameFlags);
|
|
}
|
|
}
|
|
|
|
// Does the new frame match the currently displayed image?
|
|
void EInkDynamicDisplay::checkFrameMatchesPrevious()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
// If frame is *not* a duplicate, abort the check
|
|
if (imageHash != previousImageHash)
|
|
return;
|
|
|
|
#if !defined(EINK_BACKGROUND_USES_FAST)
|
|
// If BACKGROUND, and last update was FAST: redraw the same image in FULL (for display health + image quality)
|
|
if (frameFlags == BACKGROUND && fastRefreshCount > 0) {
|
|
refresh = FULL;
|
|
reason = REDRAW_WITH_FULL;
|
|
LOG_DEBUG("refresh=FULL, reason=REDRAW_WITH_FULL, frameFlags=0x%x", frameFlags);
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
// Not redrawn, not COSMETIC, not DEMAND_FAST
|
|
refresh = SKIPPED;
|
|
reason = FRAME_MATCHED_PREVIOUS;
|
|
LOG_DEBUG("refresh=SKIPPED, reason=FRAME_MATCHED_PREVIOUS, frameFlags=0x%x", frameFlags);
|
|
}
|
|
|
|
// Have too many fast-refreshes occured consecutively, since last full refresh?
|
|
void EInkDynamicDisplay::checkConsecutiveFastRefreshes()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
// Bypass limit if UNLIMITED_FAST mode is active
|
|
if (frameFlags & UNLIMITED_FAST) {
|
|
refresh = FAST;
|
|
reason = NO_OBJECTIONS;
|
|
LOG_DEBUG("refresh=FAST, reason=UNLIMITED_FAST_MODE_ACTIVE, frameFlags=0x%x", frameFlags);
|
|
return;
|
|
}
|
|
|
|
// If too many FAST refreshes consecutively - force a FULL refresh
|
|
if (fastRefreshCount >= EINK_LIMIT_FASTREFRESH) {
|
|
refresh = FULL;
|
|
reason = EXCEEDED_LIMIT_FASTREFRESH;
|
|
LOG_DEBUG("refresh=FULL, reason=EXCEEDED_LIMIT_FASTREFRESH, frameFlags=0x%x", frameFlags);
|
|
}
|
|
}
|
|
|
|
// No objections, we can perform fast-refresh, if desired
|
|
void EInkDynamicDisplay::checkFastRequested()
|
|
{
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
if (frameFlags == BACKGROUND) {
|
|
#ifdef EINK_BACKGROUND_USES_FAST
|
|
// If we want BACKGROUND to use fast. (FULL only when a limit is hit)
|
|
refresh = FAST;
|
|
reason = BACKGROUND_USES_FAST;
|
|
LOG_DEBUG("refresh=FAST, reason=BACKGROUND_USES_FAST, fastRefreshCount=%lu, frameFlags=0x%x", fastRefreshCount,
|
|
frameFlags);
|
|
#else
|
|
// If we do want to use FULL for BACKGROUND updates
|
|
refresh = FULL;
|
|
reason = FLAGGED_BACKGROUND;
|
|
LOG_DEBUG("refresh=FULL, reason=FLAGGED_BACKGROUND");
|
|
#endif
|
|
}
|
|
|
|
// Sanity: confirm that we did ask for a RESPONSIVE frame.
|
|
if (frameFlags & RESPONSIVE) {
|
|
refresh = FAST;
|
|
reason = NO_OBJECTIONS;
|
|
LOG_DEBUG("refresh=FAST, reason=NO_OBJECTIONS, fastRefreshCount=%lu, frameFlags=0x%x", fastRefreshCount, frameFlags);
|
|
}
|
|
}
|
|
|
|
// Reset the timer used for rate-limiting
|
|
void EInkDynamicDisplay::resetRateLimiting()
|
|
{
|
|
previousRunMs = millis();
|
|
}
|
|
|
|
// Generate a hash of this frame, to compare against previous update
|
|
void EInkDynamicDisplay::hashImage()
|
|
{
|
|
imageHash = 0;
|
|
|
|
// Sum all bytes of the image buffer together
|
|
for (uint16_t b = 0; b < (displayWidth / 8) * displayHeight; b++) {
|
|
imageHash ^= buffer[b] << b;
|
|
}
|
|
}
|
|
|
|
// Store the results of determineMode() for future use, and reset for next call
|
|
void EInkDynamicDisplay::storeAndReset()
|
|
{
|
|
previousFrameFlags = frameFlags;
|
|
previousRefresh = refresh;
|
|
previousReason = reason;
|
|
|
|
// Only store image hash if the display will update
|
|
if (refresh != SKIPPED) {
|
|
previousImageHash = imageHash;
|
|
}
|
|
|
|
frameFlags = BACKGROUND;
|
|
refresh = UNSPECIFIED;
|
|
}
|
|
|
|
#ifdef EINK_LIMIT_GHOSTING_PX
|
|
// Count how many ghost pixels the new image will display
|
|
void EInkDynamicDisplay::countGhostPixels()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
// Start a new count
|
|
ghostPixelCount = 0;
|
|
|
|
// Check new image, bit by bit, for any white pixels at locations marked "dirty"
|
|
for (uint16_t i = 0; i < displayBufferSize; i++) {
|
|
for (uint8_t bit = 0; bit < 7; bit++) {
|
|
|
|
const bool dirty = (dirtyPixels[i] >> bit) & 1; // Has pixel location been drawn to since full-refresh?
|
|
const bool shouldBeBlank = !((buffer[i] >> bit) & 1); // Is pixel location white in the new image?
|
|
|
|
// If pixel is (or has been) black since last full-refresh, and now is white: ghosting
|
|
if (dirty && shouldBeBlank)
|
|
ghostPixelCount++;
|
|
|
|
// Update the dirty status for this pixel - will this location become a ghost if set white in future?
|
|
if (!dirty && !shouldBeBlank)
|
|
dirtyPixels[i] |= (1 << bit);
|
|
}
|
|
}
|
|
|
|
LOG_DEBUG("ghostPixels=%hu, ", ghostPixelCount);
|
|
}
|
|
|
|
// Check if ghost pixel count exceeds the defined limit
|
|
void EInkDynamicDisplay::checkExcessiveGhosting()
|
|
{
|
|
// If a decision was already reached, don't run the check
|
|
if (refresh != UNSPECIFIED)
|
|
return;
|
|
|
|
countGhostPixels();
|
|
|
|
// If too many ghost pixels, select full refresh
|
|
if (ghostPixelCount > EINK_LIMIT_GHOSTING_PX) {
|
|
refresh = FULL;
|
|
reason = EXCEEDED_GHOSTINGLIMIT;
|
|
LOG_DEBUG("refresh=FULL, reason=EXCEEDED_GHOSTINGLIMIT, frameFlags=0x%x", frameFlags);
|
|
}
|
|
}
|
|
|
|
// Clear the dirty pixels array. Call when full-refresh cleans the display.
|
|
void EInkDynamicDisplay::resetGhostPixelTracking()
|
|
{
|
|
// Copy the current frame into dirtyPixels[] from the display buffer
|
|
memcpy(dirtyPixels.get(), EInkDisplay::buffer, EInkDisplay::displayBufferSize);
|
|
}
|
|
#endif // EINK_LIMIT_GHOSTING_PX
|
|
|
|
// Handle any asyc tasks
|
|
void EInkDynamicDisplay::onNotify(uint32_t notification)
|
|
{
|
|
// Which task
|
|
switch (notification) {
|
|
case DUE_POLL_ASYNCREFRESH:
|
|
pollAsyncRefresh();
|
|
break;
|
|
}
|
|
}
|
|
|
|
#ifdef HAS_EINK_ASYNCFULL
|
|
// Public: wait for an refresh already in progress, then run the post-update code. See Screen::setScreensaverFrames()
|
|
void EInkDynamicDisplay::joinAsyncRefresh()
|
|
{
|
|
// If no async refresh running, nothing to do
|
|
if (!asyncRefreshRunning)
|
|
return;
|
|
|
|
LOG_DEBUG("Join an async refresh in progress");
|
|
|
|
// Continually poll the BUSY pin
|
|
while (adafruitDisplay->epd2.isBusy())
|
|
yield();
|
|
|
|
// If asyncRefreshRunning flag is still set, but display's BUSY pin reports the refresh is done
|
|
adafruitDisplay->endAsyncFull(); // Run the end of nextPage() code
|
|
EInkDisplay::endUpdate(); // Run base-class code to finish off update (NOT our derived class override)
|
|
asyncRefreshRunning = false; // Unset the flag
|
|
LOG_DEBUG("Refresh complete");
|
|
|
|
// Note: this code only works because of a modification to meshtastic/GxEPD2.
|
|
// It is only equipped to intercept calls to nextPage()
|
|
}
|
|
|
|
// Called from NotifiedWorkerThread. Run the post-update code if the hardware is ready
|
|
void EInkDynamicDisplay::pollAsyncRefresh()
|
|
{
|
|
// In theory, this condition should never be met
|
|
if (!asyncRefreshRunning)
|
|
return;
|
|
|
|
// Still running, check back later
|
|
if (adafruitDisplay->epd2.isBusy()) {
|
|
// Schedule next call of pollAsyncRefresh()
|
|
NotifiedWorkerThread::notifyLater(intervalPollAsyncRefresh, DUE_POLL_ASYNCREFRESH, true);
|
|
return;
|
|
}
|
|
|
|
// If asyncRefreshRunning flag is still set, but display's BUSY pin reports the refresh is done
|
|
adafruitDisplay->endAsyncFull(); // Run the end of nextPage() code
|
|
EInkDisplay::endUpdate(); // Run base-class code to finish off update (NOT our derived class override)
|
|
asyncRefreshRunning = false; // Unset the flag
|
|
LOG_DEBUG("Async full-refresh complete");
|
|
|
|
// Note: this code only works because of a modification to meshtastic/GxEPD2.
|
|
// It is only equipped to intercept calls to nextPage()
|
|
}
|
|
|
|
// Check the status of "async full-refresh"; skip if running
|
|
void EInkDynamicDisplay::checkBusyAsyncRefresh()
|
|
{
|
|
// No refresh taking place, continue with determineMode()
|
|
if (!asyncRefreshRunning)
|
|
return;
|
|
|
|
// Full refresh still running
|
|
if (adafruitDisplay->epd2.isBusy()) {
|
|
// No refresh
|
|
refresh = SKIPPED;
|
|
|
|
// Set the reason, marking what type of frame we're skipping
|
|
if (frameFlags & DEMAND_FAST)
|
|
reason = ASYNC_REFRESH_BLOCKED_DEMANDFAST;
|
|
else if (frameFlags & COSMETIC)
|
|
reason = ASYNC_REFRESH_BLOCKED_COSMETIC;
|
|
else if (frameFlags & RESPONSIVE)
|
|
reason = ASYNC_REFRESH_BLOCKED_RESPONSIVE;
|
|
else
|
|
reason = ASYNC_REFRESH_BLOCKED_BACKGROUND;
|
|
|
|
return;
|
|
}
|
|
|
|
// Async refresh appears to have stopped, but wasn't caught by onNotify()
|
|
else
|
|
pollAsyncRefresh(); // Check (and terminate) the async refresh manually
|
|
}
|
|
|
|
// Hold control while an async refresh runs
|
|
void EInkDynamicDisplay::awaitRefresh()
|
|
{
|
|
// Continually poll the BUSY pin
|
|
while (adafruitDisplay->epd2.isBusy())
|
|
yield();
|
|
|
|
// End the full-refresh process
|
|
adafruitDisplay->endAsyncFull(); // Run the end of nextPage() code
|
|
EInkDisplay::endUpdate(); // Run base-class code to finish off update (NOT our derived class override)
|
|
asyncRefreshRunning = false; // Unset the flag
|
|
}
|
|
#endif // HAS_EINK_ASYNCFULL
|
|
|
|
#endif // USE_EINK_DYNAMICDISPLAY
|