mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-20 02:11:28 +10:00
* 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
177 lines
7.8 KiB
C++
177 lines
7.8 KiB
C++
#ifdef MESHTASTIC_INCLUDE_INKHUD
|
|
|
|
/*
|
|
|
|
Singleton class, which manages the broadest InkHUD behaviors
|
|
|
|
Tasks include:
|
|
- containing instances of Tiles and Applets
|
|
- co-ordinating display updates
|
|
- interacting with other NicheGraphics componets, such as the driver, and input sources
|
|
- handling system-wide events (e.g. shutdown)
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "configuration.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "main.h"
|
|
#include "modules/TextMessageModule.h"
|
|
#include "power.h"
|
|
#include "sleep.h"
|
|
|
|
#include "./Applet.h"
|
|
#include "./Applets/System/Notification/Notification.h"
|
|
#include "./Persistence.h"
|
|
#include "./Tile.h"
|
|
#include "./Types.h"
|
|
#include "./UpdateMediator.h"
|
|
#include "graphics/niche/Drivers/EInk/EInk.h"
|
|
|
|
namespace NicheGraphics::InkHUD
|
|
{
|
|
|
|
class Applet;
|
|
class Tile;
|
|
|
|
class LogoApplet;
|
|
class MenuApplet;
|
|
class NotificationApplet;
|
|
|
|
class WindowManager : protected concurrency::OSThread
|
|
{
|
|
public:
|
|
static WindowManager *getInstance(); // Get or create singleton instance
|
|
|
|
void setDriver(NicheGraphics::Drivers::EInk *driver); // Assign a driver class
|
|
void setDisplayResilience(uint8_t fastPerFull, float stressMultiplier); // How many FAST updates before FULL
|
|
void addApplet(const char *name, Applet *a, bool defaultActive = false, bool defaultAutoshow = false,
|
|
uint8_t onTile = -1); // Select which applets are used with InkHUD
|
|
void begin(); // Start running the window manager (provisioning done)
|
|
|
|
void createSystemApplets(); // Instantiate and activate system applets
|
|
void createSystemTiles(); // Instantiate tiles which host system applets
|
|
void assignSystemAppletsToTiles();
|
|
void placeSystemTiles(); // Set position and size
|
|
void claimFullscreen(Applet *sa); // Assign a system applet to the fullscreen tile
|
|
void releaseFullscreen(); // Remove any system applet from the fullscreen tile
|
|
|
|
void createUserApplets(); // Activate user's selected applets
|
|
void createUserTiles(); // Instantiate enough tiles for user's selected layout
|
|
void assignUserAppletsToTiles();
|
|
void placeUserTiles(); // Automatically place tiles, according to user's layout
|
|
void refocusTile(); // Ensure focused tile has a valid applet
|
|
|
|
int beforeDeepSleep(void *unused); // Prepare for shutdown
|
|
int beforeReboot(void *unused); // Prepare for reboot
|
|
int onReceiveTextMessage(const meshtastic_MeshPacket *packet); // Store most recent text message
|
|
#ifdef ARCH_ESP32
|
|
int beforeLightSleep(void *unused); // Prepare for light sleep
|
|
#endif
|
|
|
|
void handleButtonShort(); // User button: short press
|
|
void handleButtonLong(); // User button: long press
|
|
|
|
void nextApplet(); // Cycle through user applets
|
|
void nextTile(); // Focus the next tile (when showing multiple applets at once)
|
|
|
|
void changeLayout(); // Change tile layout or count
|
|
void changeActivatedApplets(); // Change which applets are activated
|
|
void toggleBatteryIcon(); // Change whether the battery icon is shown
|
|
bool approveNotification(Notification &n); // Ask applets if a notification is worth showing
|
|
|
|
void handleTilePixel(int16_t x, int16_t y, Color c); // Apply rotation, then store the pixel in framebuffer
|
|
void requestUpdate(); // Update display, if a foreground applet has info it wants to show
|
|
void forceUpdate(Drivers::EInk::UpdateTypes type = Drivers::EInk::UpdateTypes::UNSPECIFIED,
|
|
bool async = true); // Update display, regardless of whether any applets requested this
|
|
|
|
uint16_t getWidth(); // Display width, relative to rotation
|
|
uint16_t getHeight(); // Display height, relative to rotation
|
|
uint8_t getAppletCount(); // How many user applets are available, including inactivated
|
|
const char *getAppletName(uint8_t index); // By order in userApplets
|
|
|
|
void lock(Applet *owner); // Allows system applets to prevent other applets triggering a refresh
|
|
void unlock(Applet *owner); // Allows normal updating of user applets to continue
|
|
bool canRequestUpdate(Applet *a = nullptr); // Checks if allowed to request an update (not locked by other applet)
|
|
Applet *whoLocked(); // Find which applet is blocking update requests, if any
|
|
|
|
protected:
|
|
WindowManager(); // Private constructor for singleton
|
|
|
|
int32_t runOnce() override;
|
|
|
|
void clearBuffer(); // Empty the framebuffer
|
|
void autoshow(); // Show a different applet, to display new info
|
|
bool shouldUpdate(); // Check if reason to change display image
|
|
Drivers::EInk::UpdateTypes selectUpdateType(); // Determine how the display hardware will perform the image update
|
|
void renderUserApplets(); // Draw all currently displayed user applets to the frame buffer
|
|
void renderSystemApplets(); // Draw all currently displayed system applets to the frame buffer
|
|
void renderPlaceholders(); // Draw diagonal lines on user tiles which have no assigned applet
|
|
void render(bool async = true); // Attempt to update the display
|
|
|
|
void setBufferPixel(int16_t x, int16_t y, Color c); // Place pixels into the frame buffer. All translation / rotation done.
|
|
void rotatePixelCoords(int16_t *x, int16_t *y); // Apply the display rotation
|
|
|
|
void findOrphanApplets(); // Find any applets left-behind when layout changes
|
|
|
|
// Get notified when the system is shutting down
|
|
CallbackObserver<WindowManager, void *> deepSleepObserver =
|
|
CallbackObserver<WindowManager, void *>(this, &WindowManager::beforeDeepSleep);
|
|
|
|
// Get notified when the system is rebooting
|
|
CallbackObserver<WindowManager, void *> rebootObserver =
|
|
CallbackObserver<WindowManager, void *>(this, &WindowManager::beforeReboot);
|
|
|
|
// Cache *incoming* text messages, for use by applets
|
|
CallbackObserver<WindowManager, const meshtastic_MeshPacket *> textMessageObserver =
|
|
CallbackObserver<WindowManager, const meshtastic_MeshPacket *>(this, &WindowManager::onReceiveTextMessage);
|
|
|
|
#ifdef ARCH_ESP32
|
|
// Get notified when the system is entering light sleep
|
|
CallbackObserver<WindowManager, void *> lightSleepObserver =
|
|
CallbackObserver<WindowManager, void *>(this, &WindowManager::beforeLightSleep);
|
|
#endif
|
|
|
|
NicheGraphics::Drivers::EInk *driver = nullptr;
|
|
uint8_t *imageBuffer; // Fed into driver
|
|
uint16_t imageBufferHeight;
|
|
uint16_t imageBufferWidth;
|
|
uint32_t imageBufferSize; // Bytes
|
|
|
|
// Encapsulates decision making about E-Ink update types
|
|
// Responsible for display health
|
|
UpdateMediator mediator;
|
|
|
|
// User Applets
|
|
std::vector<Applet *> userApplets;
|
|
std::vector<Tile *> userTiles;
|
|
|
|
// System Applets
|
|
std::vector<Applet *> systemApplets;
|
|
Tile *fullscreenTile = nullptr;
|
|
Tile *notificationTile = nullptr;
|
|
Tile *batteryIconTile = nullptr;
|
|
LogoApplet *logoApplet;
|
|
Applet *pairingApplet;
|
|
Applet *tipsApplet;
|
|
NotificationApplet *notificationApplet;
|
|
Applet *batteryIconApplet;
|
|
MenuApplet *menuApplet;
|
|
Applet *placeholderApplet;
|
|
|
|
// requestUpdate
|
|
bool requestingUpdate = false; // WindowManager::render run pending
|
|
|
|
// forceUpdate
|
|
bool forcingUpdate = false; // WindowManager::render run pending, guaranteed no skip of update
|
|
Drivers::EInk::UpdateTypes forcedUpdateType = Drivers::EInk::UpdateTypes::UNSPECIFIED; // guaranteed update using this type
|
|
|
|
Applet *lockOwner = nullptr; // Which system applet (if any) is preventing other applets from requesting update
|
|
};
|
|
|
|
}; // namespace NicheGraphics::InkHUD
|
|
|
|
#endif |