2.6 changes (#5806)

* 2.6 protos

* [create-pull-request] automated change (#5789)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Hello world support for UDP broadcasts over the LAN on ESP32 (#5779)

* UDP local area network meshing on ESP32

* Logs

* Comment

* Update UdpMulticastThread.h

* Changes

* Only use router->send

* Make NodeDatabase (and file) independent of DeviceState (#5813)

* Make NodeDatabase (and file) independent of DeviceState

* 70

* Remove logging statement no longer needed

* Explicitly set CAD symbols, improve slot time calculation and adjust CW size accordingly (#5772)

* File system persistence fixes

* [create-pull-request] automated change (#6000)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Update ref

* Back to 80

* [create-pull-request] automated change (#6002)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* 2.6 <- Next hop router (#6005)

* Initial version of NextHopRouter

* Set original hop limit in header flags

* Short-circuit to FloodingRouter for broadcasts

* If packet traveled 1 hop, set `relay_node` as `next_hop` for the original transmitter

* Set last byte to 0xFF if it ended at 0x00
As per an idea of @S5NC

* Also update next-hop based on received DM for us

* temp

* Add 1 retransmission for intermediate hops when using NextHopRouter

* Add next_hop and relayed_by in PacketHistory for setting next-hop and handle flooding fallback

* Update protos, store multiple relayers

* Remove next-hop update logic from NeighborInfoModule

* Fix retransmissions

* Improve ACKs for repeated packets and responses

* Stop retransmission even if there's not relay node

* Revert perhapsRebroadcast()

* Remove relayer if we cancel a transmission

* Better checking for fallback to flooding

* Fix newlines in traceroute print logs

* Stop retransmission for original packet

* Use relayID

* Also when want_ack is set, we should try to retransmit

* Fix cppcheck error

* Fix 'router' not in scope error

* Fix another cppcheck error

* Check for hop_limit and also update next hop when `hop_start == hop_limit` on ACK
Also check for broadcast in `getNextHop()`

* Formatting and correct NUM_RETRANSMISSIONS

* Update protos

* Start retransmissions in NextHopRouter if ReliableRouter didn't do it

* Handle repeated/fallback to flooding packets properly
First check if it's not still in the TxQueue

* Guard against clients setting `next_hop`/`relay_node`

* Don't cancel relay if we were the assigned next-hop

* Replies (e.g. tapback emoji) are also a valid confirmation of receipt

---------

Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>

* fix "native" compiler errors/warnings NodeDB.h

* fancy T-Deck / SenseCAP Indicator / unPhone / PICOmputer-S3 TFT screen (#3259)

* lib update: light theme

* fix merge issue

* lib update: home buttons + button try-fix

* lib update: icon color fix

* lib update: fix instability/crash on notification

* update lib: timezone

* timezone label

* lib update: fix set owner

* fix spiLock in RadioLibInterface

* add picomputer tft build

* picomputer build

* fix compiler error std::find()

* fix merge

* lib update: theme runtime config

* lib update: packet logger + T-Deck Plus

* lib update: mesh detector

* lib update: fix brightness & trackball crash

* try-fix less paranoia

* sensecap indicator updates

* lib update: indicator fix

* lib update: statistic & some fixes

* lib-update: other T-Deck touch driver

* use custom touch driver for Indicator

* lower tft task prio

* prepare LVGL ST7789 driver

* lib update: try-fix audio

* Drop received packets from self

* Additional decoded packet ignores

* Honor flip & color for Heltec T114 and T190 (#4786)

* Honor TFT_MESH color if defined for Heltec T114 or T190

* Temporary: point lib_deps at fork of Heltec's ST7789 library
For demo only, until ST7789 is merged

* Update lib_deps; tidy preprocessor logic

* Download debian files after firmware zip

* set title for protobufs bump PR (#4792)

* set title for version bump PR (#4791)

* Enable Dependabot

* chore: trunk fmt

* fix dependabot syntax (#4795)

* fix dependabot syntax

* Update dependabot.yml

* Update dependabot.yml

* Bump peter-evans/create-pull-request from 6 to 7 in /.github/workflows (#4797)

* Bump docker/build-push-action from 5 to 6 in /.github/workflows (#4800)

* Actions: Semgrep Images have moved from returntocorp to semgrep (#4774)

https://hub.docker.com/r/returntocorp/semgrep notes: "We've moved!
 Official Docker images for Semgrep now available at semgrep/semgrep."

Patch updates our CI workflow for these images.

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>

* Bump meshtestic from `31ee3d9` to `37245b3` (#4799)

Bumps [meshtestic](https://github.com/meshtastic/meshTestic) from `31ee3d9` to `37245b3`.
- [Commits](31ee3d90c8...37245b3d61)

---
updated-dependencies:
- dependency-name: meshtestic
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [create-pull-request] automated change (#4789)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Bump pnpm/action-setup from 2 to 4 in /.github/workflows (#4798)

Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 2 to 4.
- [Release notes](https://github.com/pnpm/action-setup/releases)
- [Commits](https://github.com/pnpm/action-setup/compare/v2...v4)

---
updated-dependencies:
- dependency-name: pnpm/action-setup
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Raspberry Pico2 - needs protos

* Re-order doDeepSleep (#4802)

Make sure PMU sleep takes place before I2C ends

* [create-pull-request] automated change

* heltec-wireless-bridge
requires Proto PR first

* feat: trigger class update when protobufs are changed

* meshtastic/ is a test suite; protobufs/ contains protobufs;

* Update platform-native to pick up portduino crash fix (#4807)

* Hopefully extract and commit to meshtastic.github.io

* CI fixes

* [Board] DIY "t-energy-s3_e22" (#4782)

* New variant "t-energy-s3_e22"

- Lilygo T-Energy-S3
- NanoVHF "Mesh-v1.06-TTGO-T18" board
- Ebyte E22 Series

* add board_level = extra

* Update variant.h

---------

Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>

* Consolidate variant build steps (#4806)

* poc: consolidate variant build steps

* use build-variant action

* only checkout once and clean up after run

* Revert "Consolidate variant build steps (#4806)" (#4816)

This reverts commit 9f8d86cb25.

* Make Ublox code more readable (#4727)

* Simplify Ublox code

Ublox comes in a myriad of versions and settings. Presently our
configuration code does a lot of branching based on versions being
or not being present.

This patch adds version detection earlier in the piece and branches
on the set gnssModel instead to create separate setup methods for Ublox 6,
Ublox 7/8/9, and Ublox10.

Additionally, adds a macro to make the code much shorter and more
readable.

* Make trunk happy

* Make trunk happy

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>

* Consider the LoRa header when checking packet length

* Minor fix (#4666)

* Minor fixes

It turns out setting a map value with the index notation causes
an lookup that can be avoided with emplace. Apply this to one line in
the StoreForward module.

Fix also Cppcheck-determined highly minor performance increase by
passing gpiochipname as a const reference :)

The amount of cycles used on this laptop while learning about these
callouts from cppcheck is unlikely to ever be more than the cycles
saved by the fixes ;)

* Update PortduinoGlue.cpp

* Revert "Update classes on protobufs update" (#4824)

* Revert "Update classes on protobufs update"

* remove quotes to fix trunk.

---------

Co-authored-by: Tom Fifield <tom@tomfifield.net>

* Implement optional second I2C bus for NRF52840
Enabled at compile-time if WIRE_INFERFACES_COUNT defined as 2

* Add I2C bus to Heltec T114 header pins
SDA: P0.13
SCL: P0.16

Uses bus 1, leaving bus 0 routed to the unpopulated footprint for the RTC (general future-proofing)

* Tidier macros

* Swap SDA and SCL
SDA=P0.16, SCL=P0.13

* Refactor and consolidate time window logic (#4826)

* Refactor and consolidate windowing logic

* Trunk

* Fixes

* More

* Fix braces and remove unused now variables.

There was a brace in src/mesh/RadioLibInterface.cpp that was breaking
compile on some architectures.

Additionally, there were some brace errors in
src/modules/Telemetry/AirQualityTelemetry.cpp
src/modules/Telemetry/EnvironmentTelemetry.cpp
src/mesh/wifi/WiFiAPClient.cpp

Move throttle include in WifiAPClient.cpp to top.

Add Default.h to sleep.cpp

rest of files just remove unused now variables.

* Remove a couple more meows

---------

Co-authored-by: Tom Fifield <tom@tomfifield.net>

* Rename message length headers and set payload max to 255 (#4827)

* Rename message length headers and set payload max to 255

* Add MESHTASTIC_PKC_OVERHEAD

* compare to MESHTASTIC_HEADER_LENGTH

---------

Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>

* Check for null before printing debug (#4835)

* fix merge

* try-fix crash

* lib update: fix neighbors

* fix GPIO0 mode after I2S audio

* lib update: audio fix

* lib update: fixes and improvements

* extra

* added ILI9342 (from master)

* device-ui persistency

* review update

* fix request, add handled

* fix merge issue

* fix merge issue

* remove newline

* remove newlines from debug log

* playing with locks; but needs more testing

* diy mesh-tab initial files

* board definition for mesh-tab (not yet used)

* use DISPLAY_SET_RESOLUTION to avoid hw dependency in code

* no telemetry for Indicator

* 16MB partition for Indicator

* 8MB partition for Indicator

* stability: add SPI lock before saving via littleFS

* dummy for config transfer (#5154)

* update indicator (due to compile and linker errors)

* remove faulty partition line

* fix missing include

* update indicator board

* update mesh-tab ILI9143 TFT

* fix naming

* mesh-tab targets

* try: disable duplicate locks

* fix nodeDB erase loop when free mem returns invalid value (0, -1).

* upgrade toolchain for nrf52 to gcc 9.3.1

* try-fix (workaround) T-Deck audio crash

* update mesh-tab tft configs

* set T-Deck audio to unused 48 (mem mclk)

* swap mclk to gpio 21

* update meshtab voltage divider

* update mesh-tab ini

* Fixed the issue that indicator device uploads via rp2040 serial port in some cases.

* Fixed the issue that the touch I2C address definition was not effective.

* Fixed the issue that the wifi configuration saved to RAM did not take effect.

* rotation fix; added ST7789 3.2" display

* dreamcatcher: assign GPIO44 to audio mclk

* mesh-tab touch updates

* add mesh-tab powersave as default

* fix DIO1 wakeup

* mesh-tab: enable alert message menu

* Streamline board definitions for first tech preview. (#5390)

* Streamline board definitions for first tech preview. TBD: Indicator Support

* add point-of-checkin

* use board/unphone.json

---------

Co-authored-by: mverch67 <manuel.verch@gmx.de>

* fix native targets

* add RadioLib debugging options for (T-Deck)

* fix T-Deck build

* fix native tft targets for rpi

* remove wrong debug defines

* t-deck-tft button is handled in device-ui

* disable default lightsleep for indicator

* Windows Support - Trunk and Platformio (#5397)

* Add support for GPG

* Add usb device support

* Add trunk.io to devcontainer

* Trunk things

* trunk fmt

* formatting

* fix trivy/DS002, checkov/CKV_DOCKER_3

* hide docker extension popup

* fix trivy/DS026, checkov/CKV_DOCKER_2

* fix radioLib warnings for T-Deck target

* wake screen with button only

* use custom touch driver

* define wake button for unphone

* use board definition for mesh-tab

* mesh-tab rotation upside-down

* update platform native

* use MESH_TAB hardware model definition

* radioLib update (fix crash/assert)

* reference seeed indicator fix commit arduino-esp32

* Remove unneeded file change :)

* disable serial module and tcp socket api for standalone devices (#5591)

* disable serial module and tcp socket api for standalone devices
* just disable webserver, leave wifi available
* disable socket api

* mesh-tab: lower I2C touch frequency

* log error when packet queue is full

* add more locking for shared SPI devices (#5595)

* add more locking for shared SPI devices
* call initSPI before the lock is used
* remove old one
* don't double lock
* Add missing unlock
* More missing unlocks
* Add locks to SafeFile, remove from `readcb`, introduce some LockGuards
* fix lock in setupSDCard()
* pull radiolib trunk with SPI-CS fixes
* change ContentHandler to Constructor type locks, where applicable

---------

Co-authored-by: mverch67 <manuel.verch@gmx.de>
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>

* T-Deck: revert back to lovyanGFX touch driver

* T-Deck: increase allocated PSRAM by 50%

* mesh-tab: streamline target definitions

* update RadioLib 7.1.2

* mesh-tab: fix touch rotation 4.0 inch display

* Mesh-Tab platformio: 4.0inch: increase SPI frequency to max

* mesh-tab: fix rotation for 3.5 IPS capacitive display

* mesh-tab: fix rotation for 3.2 IPS capacitive display

* restructure device-ui library into sub-directories

* preparations for generic DisplayDriverFactory

* T-Deck: increase LVGL memory size

* update lib

* trunk fmt

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Jason Murray <15822260+scruplelesswizard@users.noreply.github.com>
Co-authored-by: Jason Murray <jason@chaosaffe.io>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Austin <vidplace7@gmail.com>
Co-authored-by: virgil <virgil.wang.cj@gmail.com>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Kalle Lilja <15094562+ThatKalle@users.noreply.github.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>

* Version this

* Update platformio.ini (#6006)

* tested higher speed and it works

* Un-extra

* Add -tft environments to the ci matrix

* Exclude unphone tft for now. Something is wonky

* fixed Indicator touch issue (causing IO expander issues), added more RAM

* update lib

* fixed Indicator touch issue (causing IO expander issues), added more RAM (#6013)

* increase T-Deck PSRAM to avoid too early out-of-memory when messages fill up the storage

* update device-ui lib

* Fix T-Deck SD card detection (#6023)

* increase T-Deck PSRAM to avoid too early out-of-memory when messages fill up the storage

* fix SDCard for T-Deck; allow SPI frequency config

* meshtasticd: Add X11 480x480 preset (#6020)

* Littlefs per device

* 2.6 update

* [create-pull-request] automated change (#6037)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* InkHUD UI for E-Ink (#6034)

* Decouple ButtonThread from sleep.cpp
Reorganize sleep observables. Don't call ButtonThread methods inside doLightSleep. Instead, handle in class with new lightsleep Observables.

* InkHUD: initial commit (WIP)
Publicly discloses the current work in progress. Not ready for use.

* feat: battery icon

* chore: implement meshtastic/firmware #5454
Clean up some inline functions

* feat: menu & settings for "jump to applet"

* Remove the beforeRender pattern
It hugely complicates things. If we can achieve acceptable performance without it, so much the better.

* Remove previous Map Applet
Needs re-implementation to work without the beforeRender pattern

* refactor: reimplement map applet
Doesn't require own position
Doesn't require the beforeRender pattern to precalculate; now all-at-once in render
Lays groundwork for fixed-size map with custom background image

* feat: autoshow
Allow user to select which applets (if any) should be automatically brought to foreground when they have new data to display

* refactor: tidy-up applet constructors
misc. jobs including:
- consistent naming
- move initializer-list-only constructors to header
- give derived applets unique identifiers for MeshModule and OSThread logging

* hotfix: autoshow always uses FAST update
In future, it *will* often use FAST, but this will be controlled by a WindowManager component which has not yet been written.
Hotfixed, in case anybody is attempting to use this development version on their deployed devices.

* refactor: bringToForeground no longer requests FAST update
In situations where an applet has moved to foreground because of user input, requestUpdate can be manually called, to upgrade to FAST refresh.
More permanent solution for #23e1dfc

* refactor: extract string storage from ThreadedMessageApplet
Separates the code responsible for storing the limited message history, which was previously part of the ThreadedMessageApplet.
We're now also using this code to store the "most recent message". Previously, this was stored in the `InkHUD::settings` struct, which was much less space-efficient.
We're also now storing the latest DM, laying the foundation for an applet to display only DMs, which will complement the threaded message applet.

* fix: text wrapping
Attempts to fix a disparity between `Applet::printWrapped` and `Applet::getWrappedTextHeight`, which would occasionally cause a ThreadedMessageApplet message to render "too short", overlapping other text.

* fix: purge old constructor
This one slipped through the last commit..

* feat: DM Applet
Useful in combination with the ThreadedMessageApplets, which don't show DMs

* fix: applets shouldn't handle events while deactivated
Only one or two applets were actually doing this, but I'm making a habit of having all applets return early from their event handling methods (as good practice), even if those methods are disabled elsewhere (e.g. not observing observable, return false from wantPacket)

* refactor: allow requesting update without requesting autoshow
Some applets may want to redraw, if they are displayed, but not feel the information is worth being brought to foreground for. Example: ActiveNodesApplet, when purging old nodes from list.

* feat: custom "Recently Active" duration
Allows users to tailor how long nodes will appear in the "Recents" applets, to suit the activity level of their mesh.

* refactor: rename some applets

* fix: autoshow

* fix: getWrappedTextHeight
Remove the "simulate" option from printWrapped; too hard to keep inline with genuine printing (because of AdafruitGFX Fonts' xAdvance, mabye?). Instead of simulating, we printWrapped as normal, and discard pixel output by setting crop. Both methods are similarly inefficient, apparently.

* fix: text wrapping in ThreadedMessageApplet
Wrong arguments were passed to Applet::printWrapped

* feat: notifications for text messages
Only shown if current applet does not already display the same info. Autoshow takes priority over notifications, if both would be used to display the same info.

* feat: optimize FAST vs FULL updates
New UpdateMediator class counts the number of each update type, and suggets which one to use, if the code doesn't already have an explicit prefence. Also performs "maintenance refreshes" unprovoked if display is not given an opportunity to before a FULL refresh through organic use.

* chore: update todo list

* fix: rare lock-up of buttons

* refactor: backlight
Replaces the initial proof-of-concept frontlight code for T-Echo
Presses less than 5 seconds momentarily illuminate the display
Presses longer than 5 seconds latch the light, requiring another tap to disable
If user has previously removed the T-Echo's capacitive touch button (some DIY projects), the light is controlled by the on-screen menu. This fallback is used by all T-Echo devices, until a press of the capacitive touch button is detected.

* feat: change tile with aux button
Applied to VM-E290.
Working as is, but a refactor of WindowManager::render is expected shortly, which will also tidy code from this push.

* fix: specify out-of-the-box tile assignments
Prevents placeholder applet showing on initial boot, for devices which use a mult-tile layout by default (VM-E290)

* fix: verify settings version when loading

* fix: wrong settings version

* refactor: remove unimplemented argument from requestUpdate
Specified whether or not to update "async", however the implementation was slightly broken, Applet::requestUpdate is only handled next time WindowManager::runOnce is called. This didn't allow code to actually await an update, which was misleading.

* refactor: renaming
Applet::render becomes Applet::onRender.
Tile::displayedApplet becomes Tile::assignedApplet.
New onRender method name allows us to move some of the pre and post render code from WindowManager into new Applet::render method, which will call onRender for us.

* refactor: rendering
Bit of a tidy-up. No intended change in behavior.

* fix: optimize refresh times
Shorter wait between retrying update if display was previously busy.
Set anticipated update durations closer to observed values. No signifacant performance increase, but does decrease the amount of polling required.

* feat: blocking update for E-Ink
Option to wait for display update to complete before proceeding. Important when shutting down the device.

* refactor: allow system applets to lock rendering
Temporarily prevents other applets from rendering.

* feat: boot and shutdown screens

* feat: BluetoothStatus
Adds a meshtastic::Status object which exposes the state of the Bluetooth connection. Intends to allow decoupling of UI code.

* feat: Bluetooth pairing screen

* fix: InkHUD defaults not honored

* fix: random Bluetooth pin for NicheGraphics UIs

* chore: button interrupts tested

* fix: emoji reactions show as blank messages

* fix: autoshow and notification triggered by outgoing message

* feat: save InkHUD data before reboot
Implemented with a new Observable. Previously, config and a few recent messages were saved on shutdown. These were lost if the device rebooted, for example when firmware settings were changed by a client. Now, the InkHUD config and recent messages saved on reboot, the same as during an intentional shutdown.

* feat: imperial distances
Controlled by the config.display.units setting

* fix: hide features which are not yet implemented

* refactor: faster rendering
Previously, only tiles which requested update were re-rendered. Affected tiles had their region blanked before render, pixel by pixel. Benchmarking revealed that it is significantly faster to memset the framebuffer and redraw all tiles.

* refactor: tile ownership
Tiles and Applets now maintain a reciprocal link, which is enforced by asserts. Less confusing than the old situation, where an applet and a tile may disagree on their relationship. Empty tiles are now identified by a nullptr *Applet, instead of by having the placeholderApplet assigned.

* fix: notifications and battery when menu open
Do render notifications in front of menu; don't render battery icon in front of menu.

* fix: simpler defaults
Don't expose new users to multiplexed applets straight away: make them enable the feature for themselves.

* fix: Inputs::TwoButton interrupts, when only one button in use

* fix: ensure display update is complete when ESP32 enters light sleep
Many panels power down automatically, but some require active intervention from us. If light sleep (ESP32) occurs during a display update, these panels could potentially remain powered on, applying voltage the pixels for an extended period of time, and potentially damaging the display.

* fix: honor per-variant user tile limit
Set as the default value for InkHUD::settings.userTiles.maxCount in nicheGraphics.h

* feat: initial InkHUD support for Wireless Paper v1.1 and VM-E213

* refactor: Heard and Recents Applets
Tidier code, significant speed boost. Possibly no noticable change in responsiveness, but rendering now spends much less time blocking execution, which is important for correction functioning of the other firmware components.

* refactor: use a common pio base config
Easier to make any future PlatformIO config changes

* feat: tips
Show information that we think the user might find helpful. Some info shown first boot only. Other info shown when / if relevant.

* fix: text wrapping for '\n'
Previously, the newline was honored, but the adojining word was not printed.

* Decouple ButtonThread from sleep.cpp
Reorganize sleep observables. Don't call ButtonThread methods inside doLightSleep. Instead, handle in class with new lightsleep Observables.

* feat: BluetoothStatus
Adds a meshtastic::Status object which exposes the state of the Bluetooth connection. Intends to allow decoupling of UI code.

* feat: observable for reboot

* refactor: Heltec VM-E290 installDefaultConfig

* fix: random Bluetooth pin for NicheGraphics UIs

* update device-ui: fix touch/crash issue while light sleep

* Collect inkhud

* fix: InkHUD shouldn't nag about timezone (#6040)

* Guard eink drivers w/ MESHTASTIC_INCLUDE_NICHE_GRAPHICS

* Case sensitive perhaps?

* More case-sensitivity instances

* Moar

* RTC

* Yet another case issue!

* Sigh...

* MUI: BT programming mode (#6046)

* allow BT connection with disabled MUI

* Update device-ui

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>

* MUI: fix nag timeout, disable BT programming mode for native (#6052)

* allow BT connection with disabled MUI

* Update device-ui

* MUI: fix nag timeout default and remove programming mode for native

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>

* remove debuglog leftover

* Wireless Paper: remove stray board_level = extra (#6060)

Makes sure the InkHUD version gets build into the release zip

* Fixed persistence stragglers from NodeDB / Device State divorce (#6059)

* Increase `MAX_THREADS` for InkHUD variants with WiFi (#6064)

* Licensed usage compliance (#6047)

* Prevent psk and legacy admin channel on licensed mode

* Move it

* Consolidate warning strings

* More holes

* Device UI submodule bump

* Prevent licensed users from rebroadcasting unlicensed traffic (#6068)

* Prevent licensed users from rebroadcasting unlicensed traffic

* Added method and enum to make user license status more clear

* MUI: move UI initialization out of main.cpp and adding lightsleep observer + mutex (#6078)

* added device-ui to lightSleep observers for handling graceful sleep; refactoring main.cpp

* bump lib version

* Update device-ui

* unPhone TFT: include into build, enable SD card, increase PSRAM (#6082)

* unPhone-tft: include into build, enable SD card, increase assigned PSRAM

* lib update

* Backup / migrate pub private keys when upgrading to new files in 2.6 (#6096)

* Save a backup of pub/private keys before factory reset

* Fix licensed mode warning

* Unlock spi on else file doesn't exist

* Update device-ui

* Update protos and device-ui

* [create-pull-request] automated change (#6129)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Proto

* [create-pull-request] automated change (#6131)

* Proto update for backup

* [create-pull-request] automated change (#6133)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Update protobufs

* Space

* [create-pull-request] automated change (#6144)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Protos

* [create-pull-request] automated change (#6152)

Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>

* Updeet

* device-ui lib update

* fix channel OK button

* device-lib update: fix settings panel -> no scrolling

* device-ui lib: last minute update

* defined(SENSECAP_INDICATOR)

* MUI hot-fix pub/priv keys

* MUI hot-fix username dialog

* MUI: BT programming mode button

* Update protobufs

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: mverch67 <manuel.verch@gmx.de>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Jason Murray <15822260+scruplelesswizard@users.noreply.github.com>
Co-authored-by: Jason Murray <jason@chaosaffe.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Austin <vidplace7@gmail.com>
Co-authored-by: virgil <virgil.wang.cj@gmail.com>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Kalle Lilja <15094562+ThatKalle@users.noreply.github.com>
Co-authored-by: rcarteraz <robert.l.carter2@gmail.com>
This commit is contained in:
Ben Meadors
2025-03-01 06:18:33 -06:00
committed by GitHub
parent 088fce7d11
commit 99d3e5eb70
159 changed files with 12449 additions and 427 deletions

View File

@@ -0,0 +1,133 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./AllMessageApplet.h"
using namespace NicheGraphics;
void InkHUD::AllMessageApplet::onActivate()
{
textMessageObserver.observe(textMessageModule);
}
void InkHUD::AllMessageApplet::onDeactivate()
{
textMessageObserver.unobserve(textMessageModule);
}
// We're not consuming the data passed to this method;
// we're just just using it to trigger a render
int InkHUD::AllMessageApplet::onReceiveTextMessage(const meshtastic_MeshPacket *p)
{
// Abort if applet fully deactivated
// Already handled by onActivate and onDeactivate, but good practice for all applets
if (!isActive())
return 0;
// Abort if this is an outgoing message
if (getFrom(p) == nodeDB->getNodeNum())
return 0;
// Abort if message was only an "emoji reaction"
// Possibly some implemetation of this in future?
if (p->decoded.emoji)
return 0;
requestAutoshow(); // Want to become foreground, if permitted
requestUpdate(); // Want to update display, if applet is foreground
// Return zero: no issues here, carry on notifying other observers!
return 0;
}
void InkHUD::AllMessageApplet::onRender()
{
setFont(fontSmall);
// Find newest message, regardless of whether DM or broadcast
MessageStore::Message *message;
if (latestMessage.wasBroadcast)
message = &latestMessage.broadcast;
else
message = &latestMessage.dm;
// Short circuit: no text message
if (!message->sender) {
printAt(X(0.5), Y(0.5), "No Message", CENTER, MIDDLE);
return;
}
// ===========================
// Header (sender, timestamp)
// ===========================
// Y position for divider
// - between header text and messages
std::string header;
// RX Time
// - if valid
std::string timeString = getTimeString(message->timestamp);
if (timeString.length() > 0) {
header += timeString;
header += ": ";
}
// Sender's id
// - shortname, if available, or
// - node id
meshtastic_NodeInfoLite *sender = nodeDB->getMeshNode(message->sender);
if (sender && sender->has_user) {
header += sender->user.short_name;
header += " (";
header += sender->user.long_name;
header += ")";
} else
header += hexifyNodeNum(message->sender);
// Draw a "standard" applet header
drawHeader(header);
// Fade the right edge of the header, if text spills over edge
uint8_t wF = getFont().lineHeight() / 2; // Width of fade effect
uint8_t hF = getHeaderHeight(); // Height of fade effect
if (getCursorX() > width())
hatchRegion(width() - wF - 1, 1, wF, hF, 2, WHITE);
// Dimensions of the header
constexpr int16_t padDivH = 2;
const int16_t headerDivY = Applet::getHeaderHeight() - 1;
// ===================
// Print message text
// ===================
// Extra gap below the header
int16_t textTop = headerDivY + padDivH;
// Determine size if printed large
setFont(fontLarge);
uint32_t textHeight = getWrappedTextHeight(0, width(), message->text);
// If too large, swap to small font
if (textHeight + textTop > (uint32_t)height()) // (compare signed and unsigned)
setFont(fontSmall);
// Print text
printWrapped(0, textTop, width(), message->text);
}
// Don't show notifications for text messages when our applet is displayed
bool InkHUD::AllMessageApplet::approveNotification(Notification &n)
{
if (n.type == Notification::Type::NOTIFICATION_MESSAGE_BROADCAST)
return false;
else if (n.type == Notification::Type::NOTIFICATION_MESSAGE_DIRECT)
return false;
else
return true;
}
#endif

View File

@@ -0,0 +1,49 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Shows the latest incoming text message, as well as sender.
Both broadcast and direct messages will be shown here, from all channels.
This module doesn't doesn't use the devicestate.rx_text_message,' as this is overwritten to contain outgoing messages
This module doesn't collect its own text message. Instead, the WindowManager stores the most recent incoming text message.
This is available to any interested modules (SingeMessageApplet, NotificationApplet etc.) via InkHUD::latestMessage
We do still receive notifications from the text message module though,
to know when a new message has arrived, and trigger the update.
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applet.h"
#include "modules/TextMessageModule.h"
namespace NicheGraphics::InkHUD
{
class Applet;
class AllMessageApplet : public Applet
{
public:
void onRender() override;
void onActivate() override;
void onDeactivate() override;
int onReceiveTextMessage(const meshtastic_MeshPacket *p);
bool approveNotification(Notification &n) override; // Which notifications to suppress
protected:
// Used to register our text message callback
CallbackObserver<AllMessageApplet, const meshtastic_MeshPacket *> textMessageObserver =
CallbackObserver<AllMessageApplet, const meshtastic_MeshPacket *>(this, &AllMessageApplet::onReceiveTextMessage);
};
} // namespace NicheGraphics::InkHUD
#endif

View File

@@ -0,0 +1,126 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./DMApplet.h"
using namespace NicheGraphics;
void InkHUD::DMApplet::onActivate()
{
textMessageObserver.observe(textMessageModule);
}
void InkHUD::DMApplet::onDeactivate()
{
textMessageObserver.unobserve(textMessageModule);
}
// We're not consuming the data passed to this method;
// we're just just using it to trigger a render
int InkHUD::DMApplet::onReceiveTextMessage(const meshtastic_MeshPacket *p)
{
// Abort if applet fully deactivated
// Already handled by onActivate and onDeactivate, but good practice for all applets
if (!isActive())
return 0;
// Abort if only an "emoji reactions"
// Possibly some implemetation of this in future?
if (p->decoded.emoji)
return 0;
// If DM (not broadcast)
if (!isBroadcast(p->to)) {
// Want to update display, if applet is foreground
requestUpdate();
// If this was an incoming message, suggest that our applet becomes foreground, if permitted
if (getFrom(p) != nodeDB->getNodeNum())
requestAutoshow();
}
// Return zero: no issues here, carry on notifying other observers!
return 0;
}
void InkHUD::DMApplet::onRender()
{
setFont(fontSmall);
// Abort if no text message
if (!latestMessage.dm.sender) {
printAt(X(0.5), Y(0.5), "No DMs", CENTER, MIDDLE);
return;
}
// ===========================
// Header (sender, timestamp)
// ===========================
// Y position for divider
// - between header text and messages
std::string header;
// RX Time
// - if valid
std::string timeString = getTimeString(latestMessage.dm.timestamp);
if (timeString.length() > 0) {
header += timeString;
header += ": ";
}
// Sender's id
// - shortname, if available, or
// - node id
meshtastic_NodeInfoLite *sender = nodeDB->getMeshNode(latestMessage.dm.sender);
if (sender && sender->has_user) {
header += sender->user.short_name;
header += " (";
header += sender->user.long_name;
header += ")";
} else
header += hexifyNodeNum(latestMessage.dm.sender);
// Draw a "standard" applet header
drawHeader(header);
// Fade the right edge of the header, if text spills over edge
uint8_t wF = getFont().lineHeight() / 2; // Width of fade effect
uint8_t hF = getHeaderHeight(); // Height of fade effect
if (getCursorX() > width())
hatchRegion(width() - wF - 1, 1, wF, hF, 2, WHITE);
// Dimensions of the header
constexpr int16_t padDivH = 2;
const int16_t headerDivY = Applet::getHeaderHeight() - 1;
// ===================
// Print message text
// ===================
// Extra gap below the header
int16_t textTop = headerDivY + padDivH;
// Determine size if printed large
setFont(fontLarge);
uint32_t textHeight = getWrappedTextHeight(0, width(), latestMessage.dm.text);
// If too large, swap to small font
if (textHeight + textTop > (uint32_t)height()) // (compare signed and unsigned)
setFont(fontSmall);
// Print text
printWrapped(0, textTop, width(), latestMessage.dm.text);
}
// Don't show notifications for direct messages when our applet is displayed
bool InkHUD::DMApplet::approveNotification(Notification &n)
{
if (n.type == Notification::Type::NOTIFICATION_MESSAGE_DIRECT)
return false;
else
return true;
}
#endif

View File

@@ -0,0 +1,49 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Shows the latest incoming *Direct Message* (DM), as well as sender.
This compliments the threaded message applets
This module doesn't doesn't use the devicestate.rx_text_message,' as this is overwritten to contain outgoing messages
This module doesn't collect its own text message. Instead, the WindowManager stores the most recent incoming text message.
This is available to any interested modules (SingeMessageApplet, NotificationApplet etc.) via InkHUD::latestMessage
We do still receive notifications from the text message module though,
to know when a new message has arrived, and trigger the update.
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applet.h"
#include "modules/TextMessageModule.h"
namespace NicheGraphics::InkHUD
{
class Applet;
class DMApplet : public Applet
{
public:
void onRender() override;
void onActivate() override;
void onDeactivate() override;
int onReceiveTextMessage(const meshtastic_MeshPacket *p);
bool approveNotification(Notification &n) override; // Which notifications to suppress
protected:
// Used to register our text message callback
CallbackObserver<DMApplet, const meshtastic_MeshPacket *> textMessageObserver =
CallbackObserver<DMApplet, const meshtastic_MeshPacket *>(this, &DMApplet::onReceiveTextMessage);
};
} // namespace NicheGraphics::InkHUD
#endif

View File

@@ -0,0 +1,123 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "RTC.h"
#include "gps/GeoCoord.h"
#include "./HeardApplet.h"
using namespace NicheGraphics;
void InkHUD::HeardApplet::onActivate()
{
// When applet begins, pre-fill with stale info from NodeDB
populateFromNodeDB();
}
void InkHUD::HeardApplet::onDeactivate()
{
// Avoid an unlikely situation where frquent activation / deactivation populated duplicate info from node DB
cards.clear();
}
// When base applet hears a new packet, it extracts the info and passes it to us as CardInfo
// We need to store it (at front to sort recent), and request display update if our list has visibly changed as a result
void InkHUD::HeardApplet::handleParsed(CardInfo c)
{
// Grab the previous entry.
// To check if the new data is different enough to justify re-render
// Need to cache now, before we manipulate the deque
CardInfo previous;
if (!cards.empty())
previous = cards.at(0);
// If we're updating an existing entry, remove the old one. Will reinsert at front
for (auto it = cards.begin(); it != cards.end(); ++it) {
if (it->nodeNum == c.nodeNum) {
cards.erase(it);
break;
}
}
cards.push_front(c); // Insert into base class' card collection
cards.resize(min(maxCards(), (uint8_t)cards.size())); // Don't keep more cards than we could *ever* fit on screen
// Our rendered image needs to change if:
if (previous.nodeNum != c.nodeNum // Different node
|| previous.signal != c.signal // or different signal strength
|| previous.distanceMeters != c.distanceMeters // or different position
|| previous.hopsAway != c.hopsAway) // or different hops away
{
requestAutoshow();
requestUpdate();
}
}
// When applet is activated, pre-fill with stale data from NodeDB
// We're sorting using the last_heard value. Succeptible to weirdness if node's RTC changes.
// No SNR is available in node db, so we can't calculate signal either
// These initial cards from node db will be gradually pushed out by new packets which originate from out base applet instead
void InkHUD::HeardApplet::populateFromNodeDB()
{
// Fill a collection with pointers to each node in db
std::vector<meshtastic_NodeInfoLite *> ordered;
for (auto mn = nodeDB->meshNodes->begin(); mn != nodeDB->meshNodes->end(); ++mn) {
// Only copy if valid, and not our own node
if (mn->num != 0 && mn->num != nodeDB->getNodeNum())
ordered.push_back(&*mn);
}
// Sort the collection by age
std::sort(ordered.begin(), ordered.end(), [](meshtastic_NodeInfoLite *top, meshtastic_NodeInfoLite *bottom) -> bool {
return (top->last_heard > bottom->last_heard);
});
// Keep the most recent entries onlyt
// Just enough to fill the screen
if (ordered.size() > maxCards())
ordered.resize(maxCards());
// Create card info for these (stale) node observations
meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
for (meshtastic_NodeInfoLite *node : ordered) {
CardInfo c;
c.nodeNum = node->num;
if (node->has_hops_away)
c.hopsAway = node->hops_away;
if (nodeDB->hasValidPosition(node) && nodeDB->hasValidPosition(ourNode)) {
// Get lat and long as float
// Meshtastic stores these as integers internally
float ourLat = ourNode->position.latitude_i * 1e-7;
float ourLong = ourNode->position.longitude_i * 1e-7;
float theirLat = node->position.latitude_i * 1e-7;
float theirLong = node->position.longitude_i * 1e-7;
c.distanceMeters = (int32_t)GeoCoord::latLongToMeter(theirLat, theirLong, ourLat, ourLong);
}
// Insert into the card collection (member of base class)
cards.push_back(c);
}
}
// Text drawn in the usual applet header
// Handled by base class: ChronoListApplet
std::string InkHUD::HeardApplet::getHeaderText()
{
uint16_t nodeCount = nodeDB->getNumMeshNodes() - 1; // Don't count our own node
std::string text = "Heard: ";
// Print node count, if nodeDB not yet nearing full
if (nodeCount < MAX_NUM_NODES) {
text += to_string(nodeCount); // Max nodes
text += " ";
text += (nodeCount == 1) ? "node" : "nodes";
}
return text;
}
#endif

View File

@@ -0,0 +1,35 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Shows a list of all nodes (recently heard or not), sorted by time last heard.
Most of the work is done by the InkHUD::NodeListApplet base class
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h"
namespace NicheGraphics::InkHUD
{
class HeardApplet : public NodeListApplet
{
public:
HeardApplet() : NodeListApplet("HeardApplet") {}
void onActivate() override;
void onDeactivate() override;
protected:
void handleParsed(CardInfo c) override; // Store new info, and update display if needed
std::string getHeaderText() override; // Set title for this applet
void populateFromNodeDB(); // Pre-fill the CardInfo collection from NodeDB
};
} // namespace NicheGraphics::InkHUD
#endif

View File

@@ -0,0 +1,110 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./PositionsApplet.h"
using namespace NicheGraphics;
void InkHUD::PositionsApplet::onRender()
{
// Draw the usual map applet first
MapApplet::onRender();
// Draw our latest "node of interest" as a special marker
// -------------------------------------------------------
// We might be rendering because we got a position packet from them
// We might be rendering because our own position updated
// Either way, we still highlight which node most recently sent us a position packet
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(lastFrom);
if (node && nodeDB->hasValidPosition(node) && enoughMarkers())
drawLabeledMarker(node);
}
// Determine if we need to redraw the map, when we receive a new position packet
ProcessMessage InkHUD::PositionsApplet::handleReceived(const meshtastic_MeshPacket &mp)
{
// If applet is not active, we shouldn't be handling any data
// It's good practice for all applets to implement an early return like this
// for PositionsApplet, this is **required** - it's where we're handling active vs deactive
if (!isActive())
return ProcessMessage::CONTINUE;
// Try decode a position from the packet
bool hasPosition = false;
float lat;
float lng;
if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == meshtastic_PortNum_POSITION_APP) {
meshtastic_Position position = meshtastic_Position_init_default;
if (pb_decode_from_bytes(mp.decoded.payload.bytes, mp.decoded.payload.size, &meshtastic_Position_msg, &position)) {
if (position.has_latitude_i && position.has_longitude_i // Actually has position
&& (position.latitude_i != 0 || position.longitude_i != 0)) // Position isn't "null island"
{
hasPosition = true;
lat = position.latitude_i * 1e-7; // Convert from Meshtastic's internal int32_t format
lng = position.longitude_i * 1e-7;
}
}
}
// Skip if we didn't get a valid position
if (!hasPosition)
return ProcessMessage::CONTINUE;
bool hasHopsAway = (mp.hop_start != 0 && mp.hop_limit <= mp.hop_start); // From NodeDB::updateFrom
uint8_t hopsAway = mp.hop_start - mp.hop_limit;
// Determine if the position packet would change anything on-screen
// -----------------------------------------------------------------
bool somethingChanged = false;
// If our own position
if (isFromUs(&mp)) {
// We get frequent position updates from connected phone
// Only update if we're travelled some distance, for rate limiting
// Todo: smarter detection of position changes
if (GeoCoord::latLongToMeter(ourLastLat, ourLastLng, lat, lng) > 50) {
somethingChanged = true;
ourLastLat = lat;
ourLastLng = lng;
}
}
// If someone else's position
else {
// Check if this position is from someone different than our previous position packet
if (mp.from != lastFrom) {
somethingChanged = true;
lastFrom = mp.from;
lastLat = lat;
lastLng = lng;
lastHopsAway = hopsAway;
}
// Same sender: check if position changed
// Todo: smarter detection of position changes
else if (GeoCoord::latLongToMeter(lastLat, lastLng, lat, lng) > 10) {
somethingChanged = true;
lastLat = lat;
lastLng = lng;
}
// Same sender, same position: check if hops changed
// Only pay attention if the hopsAway value is valid
else if (hasHopsAway && (hopsAway != lastHopsAway)) {
somethingChanged = true;
lastHopsAway = hopsAway;
}
}
// Decision reached
// -----------------
if (somethingChanged) {
requestAutoshow(); // Todo: only request this in some situations?
requestUpdate();
}
return ProcessMessage::CONTINUE;
}
#endif

View File

@@ -0,0 +1,43 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Plots position of all nodes from DB, with North facing up.
Scaled to fit the most distant node.
Size of cross represents hops away.
The node which has most recently sent a position will be labeled.
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.h"
#include "SinglePortModule.h"
namespace NicheGraphics::InkHUD
{
class PositionsApplet : public MapApplet, public SinglePortModule
{
public:
PositionsApplet() : SinglePortModule("PositionsApplet", meshtastic_PortNum_POSITION_APP) {}
void onRender() override;
protected:
ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
NodeNum lastFrom; // Sender of most recent (non-local) position packet
float lastLat;
float lastLng;
float lastHopsAway;
float ourLastLat; // Info about the most recent (non-local) position packet
float ourLastLng; // Info about most recent *local* position
};
} // namespace NicheGraphics::InkHUD
#endif

View File

@@ -0,0 +1,150 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./RecentsListApplet.h"
#include "RTC.h"
using namespace NicheGraphics;
InkHUD::RecentsListApplet::RecentsListApplet() : NodeListApplet("RecentsListApplet"), concurrency::OSThread("RecentsListApplet")
{
// No scheduled tasks initially
OSThread::disable();
}
void InkHUD::RecentsListApplet::onActivate()
{
// When the applet is activated, begin scheduled purging of any nodes which are no longer "active"
OSThread::enabled = true;
OSThread::setIntervalFromNow(60 * 1000UL); // Every minute
}
void InkHUD::RecentsListApplet::onDeactivate()
{
// Halt scheduled purging
OSThread::disable();
}
int32_t InkHUD::RecentsListApplet::runOnce()
{
prune(); // Remove CardInfo and Age record for nodes which we haven't heard recently
return OSThread::interval;
}
// When base applet hears a new packet, it extracts the info and passes it to us as CardInfo
// We need to store it (at front to sort recent), and request display update if our list has visibly changed as a result
// We also need to record the current time against the nodenum, so we know when it becomes inactive
void InkHUD::RecentsListApplet::handleParsed(CardInfo c)
{
// Grab the previous entry.
// To check if the new data is different enough to justify re-render
// Need to cache now, before we manipulate the deque
CardInfo previous;
if (!cards.empty())
previous = cards.at(0);
// If we're updating an existing entry, remove the old one. Will reinsert at front
for (auto it = cards.begin(); it != cards.end(); ++it) {
if (it->nodeNum == c.nodeNum) {
cards.erase(it);
break;
}
}
cards.push_front(c); // Store this CardInfo
cards.resize(min(maxCards(), (uint8_t)cards.size())); // Don't keep more cards than we could *ever* fit on screen
// Record the time of this observation
// Used to count active nodes, and to know when to prune inactive nodes
seenNow(c.nodeNum);
// Our rendered image needs to change if:
if (previous.nodeNum != c.nodeNum // Different node
|| previous.signal != c.signal // or different signal strength
|| previous.distanceMeters != c.distanceMeters // or different position
|| previous.hopsAway != c.hopsAway) // or different hops away
{
prune(); // Take the opportunity now to remove inactive nodes
requestAutoshow();
requestUpdate();
}
}
// Record the time (millis, right now) that we hear a node
// If we do not hear from a node for a while, its card and age info will be removed by the purge method, which runs regularly
void InkHUD::RecentsListApplet::seenNow(NodeNum nodeNum)
{
// If we're updating an existing entry, remove the old one. Will reinsert at front
for (auto it = ages.begin(); it != ages.end(); ++it) {
if (it->nodeNum == nodeNum) {
ages.erase(it);
break;
}
}
Age a;
a.nodeNum = nodeNum;
a.seenAtMs = millis();
ages.push_front(a);
}
// Remove Card and Age info for any nodes which are now inactive
// Determined by when a node was last heard, in our internal record (not from nodeDB)
void InkHUD::RecentsListApplet::prune()
{
// Iterate age records from newest to oldest
for (uint16_t i = 0; i < ages.size(); i++) {
// Found the first record which is too old
if (!isActive(ages.at(i).seenAtMs)) {
// Drop this item, and all others behind it
ages.resize(i);
cards.resize(i);
// Request an update, if pruning did modify our data
// Required if pruning was scheduled. Redundent if pruning was prior to rendering.
requestAutoshow();
requestUpdate();
break;
}
}
// Push next scheduled pruning back
// Pruning may be called from by handleParsed, immediately prior to rendering
// In that case, we can slightly delay our scheduled pruning
OSThread::setIntervalFromNow(60 * 1000UL);
}
// Is a timestamp old enough that it would make a node inactive, and in need of purging?
bool InkHUD::RecentsListApplet::isActive(uint32_t seenAtMs)
{
uint32_t now = millis();
uint32_t secsAgo = (now - seenAtMs) / 1000UL; // millis() overflow safe
return (secsAgo < settings.recentlyActiveSeconds);
}
// Text to be shown at top of applet
// ChronoListApplet base class allows us to set this dynamically
// Might want to adjust depending on node count, RTC status, etc
std::string InkHUD::RecentsListApplet::getHeaderText()
{
std::string text;
// Print the length of our "Recents" time-window
text += "Last ";
text += to_string(settings.recentlyActiveSeconds / 60);
text += " mins";
// Print the node count
const uint16_t nodeCount = ages.size();
text += ": ";
text += to_string(nodeCount);
text += " ";
text += (nodeCount == 1) ? "node" : "nodes";
return text;
}
#endif

View File

@@ -0,0 +1,52 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Shows a list of nodes which have been recently active
The length of this "recently active" window is configurable using the onscreen menu
Most of the work is done by the shared InkHUD::NodeListApplet base class
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h"
namespace NicheGraphics::InkHUD
{
class RecentsListApplet : public NodeListApplet, public concurrency::OSThread
{
protected:
// Used internally to count the number of active nodes
// We count for ourselves, instead of using the value provided by NodeDB,
// as the values occasionally differ, due to the timing of our Applet's purge method
struct Age {
uint32_t nodeNum;
uint32_t seenAtMs;
};
public:
RecentsListApplet();
void onActivate() override;
void onDeactivate() override;
protected:
int32_t runOnce() override;
void handleParsed(CardInfo c) override; // Store new info, update active count, update display if needed
std::string getHeaderText() override; // Set title for this applet
void seenNow(NodeNum nodeNum); // Record that we have just seen this node, for active node count
void prune(); // Remove cards for nodes which we haven't seen recently
bool isActive(uint32_t seenAtMillis); // Is a node still active, based on when we last heard it?
std::deque<Age> ages; // Information about when we last heard nodes. Independent of NodeDB
};
} // namespace NicheGraphics::InkHUD
#endif

View File

@@ -0,0 +1,270 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
#include "./ThreadedMessageApplet.h"
#include "RTC.h"
#include "mesh/NodeDB.h"
using namespace NicheGraphics;
// Hard limits on how much message data to write to flash
// Avoid filling the storage if something goes wrong
// Normal usage should be well below this size
constexpr uint8_t MAX_MESSAGES_SAVED = 10;
constexpr uint32_t MAX_MESSAGE_SIZE = 250;
InkHUD::ThreadedMessageApplet::ThreadedMessageApplet(uint8_t channelIndex) : channelIndex(channelIndex)
{
// Create the message store
// Will shortly attempt to load messages from RAM, if applet is active
// Label (filename in flash) is set from channel index
store = new MessageStore("ch" + to_string(channelIndex));
}
void InkHUD::ThreadedMessageApplet::onRender()
{
setFont(fontSmall);
// =============
// Draw a header
// =============
// Header text
std::string headerText;
headerText += "Channel ";
headerText += to_string(channelIndex);
headerText += ": ";
if (channels.isDefaultChannel(channelIndex))
headerText += "Public";
else
headerText += channels.getByIndex(channelIndex).settings.name;
// Draw a "standard" applet header
drawHeader(headerText);
// Y position for divider
const int16_t dividerY = Applet::getHeaderHeight() - 1;
// ==================
// Draw each message
// ==================
// Restrict drawing area
// - don't overdraw the header
// - small gap below divider
setCrop(0, dividerY + 2, width(), height() - (dividerY + 2));
// Set padding
// - separates text from the vertical line which marks its edge
constexpr uint16_t padW = 2;
constexpr int16_t msgL = padW;
const int16_t msgR = (width() - 1) - padW;
const uint16_t msgW = (msgR - msgL) + 1;
int16_t msgB = height() - 1; // Vertical cursor for drawing. Messages are bottom-aligned to this value.
uint8_t i = 0; // Index of stored message
// Loop over messages
// - until no messages left, or
// - until no part of message fits on screen
while (msgB >= (0 - fontSmall.lineHeight()) && i < store->messages.size()) {
// Grab data for message
MessageStore::Message &m = store->messages.at(i);
bool outgoing = (m.sender == 0);
meshtastic_NodeInfoLite *sender = nodeDB->getMeshNode(m.sender);
// Cache bottom Y of message text
// - Used when drawing vertical line alongside
const int16_t dotsB = msgB;
// Get dimensions for message text
uint16_t bodyH = getWrappedTextHeight(msgL, msgW, m.text);
int16_t bodyT = msgB - bodyH;
// Print message
// - if incoming
if (!outgoing)
printWrapped(msgL, bodyT, msgW, m.text);
// Print message
// - if outgoing
else {
if (getTextWidth(m.text) < width()) // If short,
printAt(msgR, bodyT, m.text, RIGHT); // print right align
else // If long,
printWrapped(msgL, bodyT, msgW, m.text); // need printWrapped(), which doesn't support right align
}
// Move cursor up
// - above message text
msgB -= bodyH;
msgB -= getFont().lineHeight() * 0.2; // Padding between message and header
// Compose info string
// - shortname, if possible, or "me"
// - time received, if possible
std::string info;
if (sender && sender->has_user)
info += sender->user.short_name;
else if (outgoing)
info += "Me";
else
info += hexifyNodeNum(m.sender);
std::string timeString = getTimeString(m.timestamp);
if (timeString.length() > 0) {
info += " - ";
info += timeString;
}
// Print the info string
// - Faux bold: printed twice, shifted horizontally by one px
printAt(outgoing ? msgR : msgL, msgB, info, outgoing ? RIGHT : LEFT, BOTTOM);
printAt(outgoing ? msgR - 1 : msgL + 1, msgB, info, outgoing ? RIGHT : LEFT, BOTTOM);
// Underline the info string
const int16_t divY = msgB;
int16_t divL;
int16_t divR;
if (!outgoing) {
// Left side - incoming
divL = msgL;
divR = getTextWidth(info) + getFont().lineHeight() / 2;
} else {
// Right side - outgoing
divR = msgR;
divL = divR - getTextWidth(info) - getFont().lineHeight() / 2;
}
for (int16_t x = divL; x <= divR; x += 2)
drawPixel(x, divY, BLACK);
// Move cursor up: above info string
msgB -= fontSmall.lineHeight();
// Vertical line alongside message
for (int16_t y = msgB; y < dotsB; y += 1)
drawPixel(outgoing ? width() - 1 : 0, y, BLACK);
// Move cursor up: padding before next message
msgB -= fontSmall.lineHeight() * 0.5;
i++;
} // End of loop: drawing each message
// Fade effect:
// Area immediately below the divider. Overdraw with sparse white lines.
// Make text appear to pass behind the header
hatchRegion(0, dividerY + 1, width(), fontSmall.lineHeight() / 3, 2, WHITE);
// If we've run out of screen to draw messages, we can drop any leftover data from the queue
// Those messages have been pushed off the screen-top by newer ones
while (i < store->messages.size())
store->messages.pop_back();
}
// Code which runs when the applet begins running
// This might happen at boot, or if user enables the applet at run-time, via the menu
void InkHUD::ThreadedMessageApplet::onActivate()
{
loadMessagesFromFlash();
textMessageObserver.observe(textMessageModule); // Begin handling any new text messages with onReceiveTextMessage
}
// Code which runs when the applet stop running
// This might be happen at shutdown, or if user disables the applet at run-time
void InkHUD::ThreadedMessageApplet::onDeactivate()
{
textMessageObserver.unobserve(textMessageModule); // Stop handling any new text messages with onReceiveTextMessage
}
// Handle new text messages
// These might be incoming, from the mesh, or outgoing from phone
// Each instance of the ThreadMessageApplet will only listen on one specific channel
// Method should return 0, to indicate general success to TextMessageModule
int InkHUD::ThreadedMessageApplet::onReceiveTextMessage(const meshtastic_MeshPacket *p)
{
// Abort if applet fully deactivated
// Already handled by onActivate and onDeactivate, but good practice for all applets
if (!isActive())
return 0;
// Abort if wrong channel
if (p->channel != this->channelIndex)
return 0;
// Abort if message was a DM
if (p->to != NODENUM_BROADCAST)
return 0;
// Abort if messages was an "emoji reaction"
// Possibly some implemetation of this in future?
if (p->decoded.emoji)
return 0;
// Extract info into our slimmed-down "StoredMessage" type
MessageStore::Message newMessage;
newMessage.timestamp = getValidTime(RTCQuality::RTCQualityDevice, true); // Current RTC time
newMessage.sender = p->from;
newMessage.channelIndex = p->channel;
newMessage.text = std::string(&p->decoded.payload.bytes[0], &p->decoded.payload.bytes[p->decoded.payload.size]);
// Store newest message at front
// These records are used when rendering, and also stored in flash at shutdown
store->messages.push_front(newMessage);
// If this was an incoming message, suggest that our applet becomes foreground, if permitted
if (getFrom(p) != nodeDB->getNodeNum())
requestAutoshow();
// Redraw the applet, perhaps.
requestUpdate(); // Want to update display, if applet is foreground
return 0;
}
// Don't show notifications for text messages broadcast to our channel, when the applet is displayed
bool InkHUD::ThreadedMessageApplet::approveNotification(Notification &n)
{
if (n.type == Notification::Type::NOTIFICATION_MESSAGE_BROADCAST && n.getChannel() == channelIndex)
return false;
// None of our business. Allow the notification.
else
return true;
}
// Save several recent messages to flash
// Stores the contents of ThreadedMessageApplet::messages
// Just enough messages to fill the display
// Messages are packed "back-to-back", to minimize blocks of flash used
void InkHUD::ThreadedMessageApplet::saveMessagesToFlash()
{
// Create a label (will become the filename in flash)
std::string label = "ch" + to_string(channelIndex);
store->saveToFlash();
}
// Load recent messages to flash
// Fills ThreadedMessageApplet::messages with previous messages
// Just enough messages have been stored to cover the display
void InkHUD::ThreadedMessageApplet::loadMessagesFromFlash()
{
// Create a label (will become the filename in flash)
std::string label = "ch" + to_string(channelIndex);
store->loadFromFlash();
}
// Code to run when device is shutting down
// This is in addition to any onDeactivate() code, which will also run
// Todo: implement before a reboot also
void InkHUD::ThreadedMessageApplet::onShutdown()
{
// Save our current set of messages to flash, provided the applet isn't disabled
if (isActive())
saveMessagesToFlash();
}
#endif

View File

@@ -0,0 +1,63 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD
/*
Displays a thread-view of incoming and outgoing message for a specific channel
The channel for this applet is set in the constructor,
when the applet is added to WindowManager in the setupNicheGraphics method.
Several messages are saved to flash at shutdown, to preseve applet between reboots.
This class has its own internal method for saving and loading to fs, which interacts directly with the FSCommon layer.
If the amount of flash usage is unacceptable, we could keep these in RAM only.
Multiple instances of this channel may be used. This must be done at buildtime.
Suggest a max of two channel, to minimize fs usage?
*/
#pragma once
#include "configuration.h"
#include "graphics/niche/InkHUD/Applet.h"
#include "graphics/niche/InkHUD/MessageStore.h"
#include "modules/TextMessageModule.h"
namespace NicheGraphics::InkHUD
{
class Applet;
class ThreadedMessageApplet : public Applet
{
public:
ThreadedMessageApplet(uint8_t channelIndex);
ThreadedMessageApplet() = delete;
void onRender() override;
void onActivate() override;
void onDeactivate() override;
void onShutdown() override;
int onReceiveTextMessage(const meshtastic_MeshPacket *p);
bool approveNotification(Notification &n) override; // Which notifications to suppress
protected:
// Used to register our text message callback
CallbackObserver<ThreadedMessageApplet, const meshtastic_MeshPacket *> textMessageObserver =
CallbackObserver<ThreadedMessageApplet, const meshtastic_MeshPacket *>(this,
&ThreadedMessageApplet::onReceiveTextMessage);
void saveMessagesToFlash();
void loadMessagesFromFlash();
MessageStore *store; // Messages, held in RAM for use, ready to save to flash on shutdown
uint8_t channelIndex = 0;
};
} // namespace NicheGraphics::InkHUD
#endif