Add InkHUD driver for WeAct Studio 4.2" display module ()

* chore: todo.txt

* chore: InkHUD documentation
Word salad for maintainers

* refactor: don't init system applets using onActivate
System applets cannot be deactivated, so we will avoid using onActivate / onDeactivate methods entirely.

* chore: update the example applets

* fix: SSD16XX reset pulse
Allow time for controller IC to wake. Aligns with manufacturer's suggestions.
T-Echo button timing adjusted to prevent bouncing as a result(?) of slightly faster refreshes.

* fix: allow timeout if display update fails
Result is not graceful, but avoids total display lockup requiring power cycle.
Typical cause of failure is poor wiring / power supply.

* fix: improve display health on shutdown
Two extra full refreshes, masquerading as a "shutting down" screen. One is drawn white-on-black, to really shake the pixels up.

* feat: driver for display HINK_E042A87
As of Feb. 2025, these panels are used for "WeActStudio 4.2in B&W" display modules.

* fix: inkhud rotation should default to 0

* Revert "chore: todo.txt"

This reverts commit bea7df44a7.

* fix: more generous timeout for display updates
Previously this was tied to the expected duration of the update, but this didn't account for any delay if our polling thread got held up by an unrelated firmware task.

* fix: don't use the full shutdown screen during reboot

* fix: cooldown period during the display shutdown display sequence
Observed to prevent border pixels from being locked in place with some residual charge?
moar-nxp^2
todd-herbert 2025-03-31 20:17:24 +13:00 zatwierdzone przez GitHub
rodzic da26ff5b95
commit bd2d2981c9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
30 zmienionych plików z 945 dodań i 88 usunięć

Wyświetl plik

@ -6,7 +6,7 @@ using namespace NicheGraphics::Drivers;
// Separate from EInk::begin method, as derived class constructors can probably supply these parameters as constants
EInk::EInk(uint16_t width, uint16_t height, UpdateTypes supported)
: concurrency::OSThread("E-Ink Driver"), width(width), height(height), supportedUpdateTypes(supported)
: concurrency::OSThread("EInkDriver"), width(width), height(height), supportedUpdateTypes(supported)
{
OSThread::disable();
}
@ -31,8 +31,8 @@ bool EInk::supports(UpdateTypes type)
void EInk::beginPolling(uint32_t interval, uint32_t expectedDuration)
{
updateRunning = true;
updateBegunAt = millis();
pollingInterval = interval;
pollingBegunAt = millis();
// To minimize load, we can choose to delay polling for a few seconds, if we know roughly how long the update will take
// By default, expectedDuration is 0, and we'll start polling immediately
@ -45,10 +45,26 @@ void EInk::beginPolling(uint32_t interval, uint32_t expectedDuration)
// This is what allows us to update the display asynchronously
int32_t EInk::runOnce()
{
// Check for polling timeout
// Manually set at 10 seconds, in case some big task holds up the firmware's cooperative multitasking
if (millis() - pollingBegunAt > 10000)
failed = true;
// Handle failure
// - polling timeout
// - other error (derived classes)
if (failed) {
LOG_WARN("Display update failed. Check wiring & power supply.");
updateRunning = false;
failed = false;
return disable();
}
// If update not yet done
if (!isUpdateDone())
return pollingInterval; // Poll again in a few ms
// If update done:
// If update done
finalizeUpdate(); // Any post-update code: power down panel hardware, hibernate, etc
updateRunning = false; // Change what we report via EInk::busy()
return disable(); // Stop polling

Wyświetl plik

@ -24,7 +24,7 @@ class EInk : private concurrency::OSThread
enum UpdateTypes : uint8_t {
UNSPECIFIED = 0,
FULL = 1 << 0,
FAST = 1 << 1,
FAST = 1 << 1, // "Partial Refresh"
};
EInk(uint16_t width, uint16_t height, UpdateTypes supported);
@ -41,14 +41,15 @@ class EInk : private concurrency::OSThread
void beginPolling(uint32_t interval, uint32_t expectedDuration); // Begin checking repeatedly if update finished
virtual bool isUpdateDone() = 0; // Check once if update finished
virtual void finalizeUpdate() {} // Run any post-update code
bool failed = false; // If an error occurred during update
private:
int32_t runOnce() override; // Repeated checking if update finished
const UpdateTypes supportedUpdateTypes; // Capabilities of a derived display class
bool updateRunning = false; // see EInk::busy()
uint32_t updateBegunAt = 0; // For initial pause before polling for update completion
uint32_t pollingInterval = 0; // How often to check if update complete (ms)
uint32_t pollingBegunAt = 0; // To timeout during polling
};
} // namespace NicheGraphics::Drivers

Wyświetl plik

@ -0,0 +1,58 @@
#include "./HINK_E042A87.h"
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
using namespace NicheGraphics::Drivers;
// Load settings about how the pixels are moved from old state to new state during a refresh
// - manually specified,
// - or with stored values from displays OTP memory
void HINK_E042A87::configWaveform()
{
sendCommand(0x3C); // Border waveform:
sendData(0x01); // Follow LUT for VSH1
sendCommand(0x18); // Temperature sensor:
sendData(0x80); // Use internal temperature sensor to select an appropriate refresh waveform
}
// Describes the sequence of events performed by the displays controller IC during a refresh
// Includes "power up", "load settings from memory", "update the pixels", etc
void HINK_E042A87::configUpdateSequence()
{
switch (updateType) {
case FAST:
sendCommand(0x21); // Use both "old" and "new" image memory (differential)
sendData(0x00);
sendData(0x00);
sendCommand(0x22); // Set "update sequence"
sendData(0xFF); // Differential, load waveform from OTP
break;
case FULL:
default:
sendCommand(0x21); // Bypass "old" image memory (non-differential)
sendData(0x40);
sendData(0x00);
sendCommand(0x22); // Set "update sequence":
sendData(0xF7); // Non-differential, load waveform from OTP
break;
}
}
// Once the refresh operation has been started,
// begin periodically polling the display to check for completion, using the normal Meshtastic threading code
// Only used when refresh is "async"
void HINK_E042A87::detachFromUpdate()
{
switch (updateType) {
case FAST:
return beginPolling(50, 1000); // At least 1 second, then check every 50ms
case FULL:
default:
return beginPolling(100, 3500); // At least 3.5 seconds, then check every 100ms
}
}
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS

Wyświetl plik

@ -0,0 +1,43 @@
/*
E-Ink display driver
- HINK-E042A87
- Manufacturer: Holitech
- Size: 4.2 inch
- Resolution: 400px x 300px
- Flex connector marking: HINK-E042A07-FPC-A1
- Silver sticker with QR code, marked: HE042A87
Note: as of Feb. 2025, these panels are used for "WeActStudio 4.2in B&W" display modules
*/
#pragma once
#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS
#include "configuration.h"
#include "./SSD16XX.h"
namespace NicheGraphics::Drivers
{
class HINK_E042A87 : public SSD16XX
{
// Display properties
private:
static constexpr uint32_t width = 400;
static constexpr uint32_t height = 300;
static constexpr UpdateTypes supported = (UpdateTypes)(FULL | FAST);
public:
HINK_E042A87() : SSD16XX(width, height, supported) {}
protected:
void configWaveform() override;
void configUpdateSequence() override;
void detachFromUpdate() override;
};
} // namespace NicheGraphics::Drivers
#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS

Wyświetl plik

@ -28,6 +28,17 @@ void setupNicheGraphics()
}
```
- [Methods](#methods)
- [`update(uint8_t *imageData, UpdateTypes type)`](#updateuint8_t-imagedata-updatetypes-type)
- [`await()`](#await)
- [`supports(UpdateTypes type)`](#supportsupdatetypes-type)
- [`busy()`](#busy)
- [`width()`](#width)
- [`height()`](#height)
- [Supporting New Displays](#supporting-new-displays)
- [Controller IC](#controller-ic)
- [Finding Information](#finding-information)
## Methods
### `update(uint8_t *imageData, UpdateTypes type)`
@ -37,7 +48,7 @@ Update the image on the display
- _`imageData`_ to draw to the display.
- _`type`_ which type of update to perform.
- `FULL`
- `FAST`
- `FAST` (partial refresh)
- (Other custom types may be possible)
The imageData is a 1-bit image. X-Pixels are 8-per byte, with the MSB being the leftmost pixel. This was not an InkHUD design decision; it is the raw format accepted by the E-Ink display controllers ICs.
@ -83,3 +94,39 @@ Width of the display, in pixels. Note: most displays are portrait. Your UI will
### `height()`
Height of the display, in pixels. Note: most displays are portrait. Your UI will need to implement rotation in software.
## Supporting New Displays
_This topic is not covered in depth, but these notes may be helpful._
The `InkHUD::Drivers::EInk` class contains only the mechanism for implementing an E-Ink driver on-top of Meshtastic's `OSThread`. A driver for a specific display needs to extend this class.
### Controller IC
If your display uses a controller IC from Solomon Systech, you can probably extend the existing `Drivers::SSD16XX` class, making only minor modifications.
At this stage, displays using controller ICS from other manufacturers (UltraChip, Fitipower, etc) need to manually implemented. See `Drivers::LCMEN2R13EFC1` for an example.
Generic base classes for manufacturers other than Solomon Systech might be added here in future.
### Finding Information
#### Flex-Connector Labels
The orange flex-connector attached to E-Ink displays is often printed with an identifying label. This is not a _totally_ unique identifier, but does give a very strong clue as to the true model of the display, which can be used to search out further information.
#### Datasheets
The manufacturer of a DIY display module may publish a datasheet. These are often incomplete, but might reveal the true model of the display, or the controller IC.
If you can determine the true model name of the display, you can likely find a more complete datasheet on the display manufacturer's website. This will often provide a "typical operating sequence"; a general overview of the code used to drive the display
#### Example Code
The manufacturer of a DIY module may publish example code. You may have more luck finding example code published by the display manufacturer themselves, if you can determine the true model of the panel. These examples are a very valuable reference.
#### Other E-Ink drivers
Libraries like ZinggJM's GxEPD2 can be valuable sources of information, although your panel may not be _specifically_ supported, and only _compatible_ with a driver there, so some caution is advised.
The display selection file in GxEPD2's Hello World example is also a useful resource for matching "flex connector labels" with display models, but the flex connector label is _not_ a unique identifier, so this is only another clue.

Wyświetl plik

@ -37,11 +37,26 @@ void SSD16XX::begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_b
reset();
}
void SSD16XX::wait()
// Poll the displays busy pin until an operation is complete
// Timeout and set fail flag if something went wrong and the display got stuck
void SSD16XX::wait(uint32_t timeout)
{
// Don't bother waiting if part of the update sequence failed
// In that situation, we're now just failing-through the process, until we can try again with next update.
if (failed)
return;
uint32_t startMs = millis();
// Busy when HIGH
while (digitalRead(pin_busy) == HIGH)
while (digitalRead(pin_busy) == HIGH) {
// Check for timeout
if (millis() - startMs > timeout) {
failed = true;
break;
}
yield();
}
}
void SSD16XX::reset()
@ -50,8 +65,9 @@ void SSD16XX::reset()
if (pin_rst != 0xFF) {
pinMode(pin_rst, OUTPUT);
digitalWrite(pin_rst, LOW);
delay(50);
pinMode(pin_rst, INPUT_PULLUP);
delay(10);
digitalWrite(pin_rst, HIGH);
delay(10);
wait();
}
@ -61,6 +77,11 @@ void SSD16XX::reset()
void SSD16XX::sendCommand(const uint8_t command)
{
// Abort if part of the update sequence failed
// This will unlock again once we have failed-through the entire process
if (failed)
return;
spi->beginTransaction(spiSettings);
digitalWrite(pin_dc, LOW); // DC pin low indicates command
digitalWrite(pin_cs, LOW);
@ -77,6 +98,11 @@ void SSD16XX::sendData(uint8_t data)
void SSD16XX::sendData(const uint8_t *data, uint32_t size)
{
// Abort if part of the update sequence failed
// This will unlock again once we have failed-through the entire process
if (failed)
return;
spi->beginTransaction(spiSettings);
digitalWrite(pin_dc, HIGH); // DC pin HIGH indicates data, instead of command
digitalWrite(pin_cs, LOW);

Wyświetl plik

@ -27,7 +27,7 @@ class SSD16XX : public EInk
virtual void update(uint8_t *imageData, UpdateTypes type) override;
protected:
virtual void wait();
virtual void wait(uint32_t timeout = 1000);
virtual void reset();
virtual void sendCommand(const uint8_t command);
virtual void sendData(const uint8_t data);

Wyświetl plik

@ -802,7 +802,7 @@ uint16_t InkHUD::Applet::getLogoHeight(uint16_t limitWidth, uint16_t limitHeight
// // \\
*/
void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height)
void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height, Color color)
{
struct Point {
int x;
@ -908,24 +908,24 @@ void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width,
Point aq2{a2.x - fromPath.x, a2.y - fromPath.y};
Point aq3{a2.x + fromPath.x, a2.y + fromPath.y};
Point aq4{a1.x + fromPath.x, a1.y + fromPath.y};
fillTriangle(aq1.x, aq1.y, aq2.x, aq2.y, aq3.x, aq3.y, BLACK);
fillTriangle(aq1.x, aq1.y, aq3.x, aq3.y, aq4.x, aq4.y, BLACK);
fillTriangle(aq1.x, aq1.y, aq2.x, aq2.y, aq3.x, aq3.y, color);
fillTriangle(aq1.x, aq1.y, aq3.x, aq3.y, aq4.x, aq4.y, color);
// Make the path thick: path b becomes quad b
Point bq1{b1.x - fromPath.x, b1.y - fromPath.y};
Point bq2{b2.x - fromPath.x, b2.y - fromPath.y};
Point bq3{b2.x + fromPath.x, b2.y + fromPath.y};
Point bq4{b1.x + fromPath.x, b1.y + fromPath.y};
fillTriangle(bq1.x, bq1.y, bq2.x, bq2.y, bq3.x, bq3.y, BLACK);
fillTriangle(bq1.x, bq1.y, bq3.x, bq3.y, bq4.x, bq4.y, BLACK);
fillTriangle(bq1.x, bq1.y, bq2.x, bq2.y, bq3.x, bq3.y, color);
fillTriangle(bq1.x, bq1.y, bq3.x, bq3.y, bq4.x, bq4.y, color);
// Make the path thick: path c becomes quad c
Point cq1{c1.x - fromPath.x, c1.y + fromPath.y};
Point cq2{c2.x - fromPath.x, c2.y + fromPath.y};
Point cq3{c2.x + fromPath.x, c2.y - fromPath.y};
Point cq4{c1.x + fromPath.x, c1.y - fromPath.y};
fillTriangle(cq1.x, cq1.y, cq2.x, cq2.y, cq3.x, cq3.y, BLACK);
fillTriangle(cq1.x, cq1.y, cq3.x, cq3.y, cq4.x, cq4.y, BLACK);
fillTriangle(cq1.x, cq1.y, cq2.x, cq2.y, cq3.x, cq3.y, color);
fillTriangle(cq1.x, cq1.y, cq3.x, cq3.y, cq4.x, cq4.y, color);
// Radius the intersection of quad b and quad c
/*
@ -944,7 +944,7 @@ void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width,
// The radius for the cap *should* be the same as logoTh, but it's not, due to accumulated rounding
// We get better results just re-deriving it
int16_t capRad = sqrt(pow(fromPath.x, 2) + pow(fromPath.y, 2));
fillCircle(b2.x, b2.y, capRad, BLACK);
fillCircle(b2.x, b2.y, capRad, color);
}
}

Wyświetl plik

@ -130,7 +130,8 @@ class Applet : public GFX
static constexpr float LOGO_ASPECT_RATIO = 1.9; // Width:Height for drawing the Meshtastic logo
uint16_t getLogoWidth(uint16_t limitWidth, uint16_t limitHeight); // Size Meshtastic logo to fit within region
uint16_t getLogoHeight(uint16_t limitWidth, uint16_t limitHeight); // Size Meshtastic logo to fit within region
void drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height); // Draw the meshtastic logo
void drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height,
Color color = BLACK); // Draw the Meshtastic logo
std::string hexifyNodeNum(NodeNum num); // Style as !0123abdc
SignalStrength getSignalStrength(float snr, float rssi); // Interpret SNR and RSSI, as an easy to understand value

Wyświetl plik

@ -8,7 +8,7 @@ using namespace NicheGraphics;
// Our basic example doesn't do anything useful. It just passively prints some text.
void InkHUD::BasicExampleApplet::onRender()
{
print("Hello, World!");
printAt(0, 0, "Hello, World!");
}
#endif

Wyświetl plik

@ -4,11 +4,12 @@
using namespace NicheGraphics;
// We configured MeshModule API to call this method when we receive a new text message
// We configured the Module API to call this method when we receive a new text message
ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_MeshPacket &mp)
{
// Abort if applet fully deactivated
// Don't waste time: we wouldn't be rendered anyway
if (!isActive())
return ProcessMessage::CONTINUE;
@ -25,7 +26,7 @@ ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_Mesh
requestUpdate();
}
// Tell MeshModule API to continue informing other firmware components about this message
// Tell Module API to continue informing other firmware components about this message
// We're not the only component which is interested in new text messages
return ProcessMessage::CONTINUE;
}

Wyświetl plik

@ -34,7 +34,15 @@ void InkHUD::LogoApplet::onRender()
int16_t logoCX = X(0.5);
int16_t logoCY = Y(0.5 - 0.05);
drawLogo(logoCX, logoCY, logoW, logoH);
// Invert colors if black-on-white
// Used during shutdown, to resport display health
// Todo: handle this in InkHUD::Renderer instead
if (inverted) {
fillScreen(BLACK);
setTextColor(WHITE);
}
drawLogo(logoCX, logoCY, logoW, logoH, inverted ? WHITE : BLACK);
if (!textLeft.empty()) {
setFont(fontSmall);
@ -74,13 +82,45 @@ void InkHUD::LogoApplet::onBackground()
// Begin displaying the screen which is shown at shutdown
void InkHUD::LogoApplet::onShutdown()
{
bringToForeground();
textLeft = "";
textRight = "";
textTitle = "Shutting Down...";
fontTitle = fontSmall;
// Draw a shutting down screen, twice.
// Once white on black, once black on white.
// Intention is to restore display health.
inverted = true;
inkhud->forceUpdate(Drivers::EInk::FULL, false);
delay(1000); // Cooldown. Back to back updates aren't great for health.
inverted = false;
inkhud->forceUpdate(Drivers::EInk::FULL, false);
delay(1000); // Cooldown
// Prepare for the powered-off screen now
// We can change these values because the initial "shutting down" screen has already rendered at this point
textLeft = "";
textRight = "";
textTitle = owner.short_name;
fontTitle = fontLarge;
// This is then drawn by InkHUD::Events::onShutdown, with a blocking FULL update, after InkHUD's flash write is complete
}
void InkHUD::LogoApplet::onReboot()
{
bringToForeground();
// This is then drawn by InkHUD::Events::onShutdown, with a blocking FULL update
textLeft = "";
textRight = "";
textTitle = "Rebooting...";
fontTitle = fontSmall;
inkhud->forceUpdate(Drivers::EInk::FULL, false);
// Perform the update right now, waiting here until complete
}
int32_t InkHUD::LogoApplet::runOnce()

Wyświetl plik

@ -25,6 +25,7 @@ class LogoApplet : public SystemApplet, public concurrency::OSThread
void onForeground() override;
void onBackground() override;
void onShutdown() override;
void onReboot() override;
protected:
int32_t runOnce() override;
@ -33,6 +34,7 @@ class LogoApplet : public SystemApplet, public concurrency::OSThread
std::string textRight;
std::string textTitle;
AppletFont fontTitle;
bool inverted = false; // Invert colors. Used during shutdown, to restore display health.
};
} // namespace NicheGraphics::InkHUD

Wyświetl plik

@ -32,8 +32,6 @@ InkHUD::MenuApplet::MenuApplet() : concurrency::OSThread("MenuApplet")
}
}
void InkHUD::MenuApplet::onActivate() {}
void InkHUD::MenuApplet::onForeground()
{
// We do need this before we render, but we can optimize by just calculating it once now

Wyświetl plik

@ -21,7 +21,6 @@ class MenuApplet : public SystemApplet, public concurrency::OSThread
{
public:
MenuApplet();
void onActivate() override;
void onForeground() override;
void onBackground() override;
void onButtonShortPress() override;

Wyświetl plik

@ -207,8 +207,6 @@ void InkHUD::TipsApplet::onBackground()
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}
void InkHUD::TipsApplet::onActivate() {}
// While our SystemApplet::handleInput flag is true
void InkHUD::TipsApplet::onButtonShortPress()
{

Wyświetl plik

@ -33,7 +33,6 @@ class TipsApplet : public SystemApplet
TipsApplet();
void onRender() override;
void onActivate() override;
void onForeground() override;
void onBackground() override;
void onButtonShortPress() override;

Wyświetl plik

@ -70,6 +70,9 @@ void InkHUD::Events::onButtonLong()
// Returns 0 to signal that we agree to sleep now
int InkHUD::Events::beforeDeepSleep(void *unused)
{
// If a previous display update is in progress, wait for it to complete.
inkhud->awaitUpdate();
// Notify all applets that we're shutting down
for (Applet *ua : inkhud->userApplets) {
ua->onDeactivate();
@ -87,9 +90,12 @@ int InkHUD::Events::beforeDeepSleep(void *unused)
inkhud->persistence->saveSettings();
inkhud->persistence->saveLatestMessage();
// LogoApplet::onShutdown will have requested an update, to draw the shutdown screen
// Draw that now, and wait here until the update is complete
// LogoApplet::onShutdown attempted to heal the display by drawing a "shutting down" screen twice,
// then prepared a final powered-off screen for us, which shows device shortname.
// We're updating to show that one now.
inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FULL, false);
delay(1000); // Cooldown, before potentially yanking display power
return 0; // We agree: deep sleep now
}
@ -106,16 +112,16 @@ int InkHUD::Events::beforeReboot(void *unused)
a->onDeactivate();
a->onShutdown();
}
for (Applet *sa : inkhud->systemApplets) {
for (SystemApplet *sa : inkhud->systemApplets) {
// Note: no onDeactivate. System applets are always active.
sa->onShutdown();
sa->onReboot();
}
inkhud->persistence->saveSettings();
inkhud->persistence->saveLatestMessage();
// Note: no forceUpdate call here
// Because OSThread will not be given another chance to run before reboot, this means that no display update will occur
// We don't have any final screen to draw, although LogoApplet::onReboot did already display a "rebooting" screen
return 0; // No special status to report. Ignored anyway by this Observable
}

Wyświetl plik

@ -99,7 +99,7 @@ class Persistence
// Rotation of the display
// Multiples of 90 degrees clockwise
// Most commonly: rotation is 0 when flex connector is oriented below display
uint8_t rotation = 1;
uint8_t rotation = 0;
// How long do we consider another node to be "active"?
// Used when applets want to filter for "active nodes" only

Wyświetl plik

@ -1,12 +0,0 @@
# InkHUD
A heads-up-display for E-Ink devices, intended to supplement a connected phone / client. Implemented as a "NicheGraphics" UI.
Supported devices (as of 1st Feb. 2025):
- Heltec Vision Master E213
- Heltec Vision Master E290
- Heltec Wireless Paper V1.1
- LILYGO T-Echo
More to follow

Wyświetl plik

@ -26,6 +26,8 @@ class SystemApplet : public Applet
bool lockRendering = false; // - prevent other applets from being rendered during an update
bool lockRequests = false; // - prevent other applets from triggering display updates
virtual void onReboot() { onShutdown(); } // - handle reboot specially
// Other system applets may take precedence over our own system applet though
// The order an applet is passed to WindowManager::addSystemApplet determines this hierarchy (added earlier = higher rank)

Wyświetl plik

@ -0,0 +1,640 @@
# InkHUD
This document is intended as a reference for maintainers. A haphazard collection of notes which _might_ be helpful.
<img src="disclaimer.jpg" width="250" alt="self deprecating meme" />
---
- [Purpose](#purpose)
- [Design Principles](#design-principles)
- [Self-Contained](#self-contained)
- [Static](#static)
- [Non-interactive](#non-interactive)
- [Customizable](#customizable)
- [Event-Driven Rendering](#event-driven-rendering)
- [No `#ifdef` spaghetti](#no-ifdef-spaghetti)
- [The Implementation](#the-implementation)
- [The Rendering Process](#the-rendering-process)
- [Concepts](#concepts)
- [NicheGraphics Framework](#nichegraphics-framework)
- [NicheGraphics E-Ink Drivers](#nichegraphics-e-ink-drivers)
- [InkHUD Applets](#inkhud-applets)
- [Adding a Variant](#adding-a-variant)
- [platformio.ini](#platformioini)
- [nicheGraphics.h](#nichegraphicsh)
- [Class Notes](#class-notes)
- [`InkHUD::InkHUD`](#inkhudinkhud)
- [`InkHUD::Persistence`](#inkhudpersistence)
- [`InkHUD::Persistence::Settings`](#inkhudpersistencesettings)
- [`InkHUD::Persistence::LatestMessage`](#inkhudpersistencelatestmessage)
- [`InkHUD::WindowManager`](#inkhudwindowmanager)
- [`InkHUD::Renderer`](#inkhudrenderer)
- [`InkHUD::Renderer::DisplayHealth`](#inkhudrendererdisplayhealth)
- [`InkHUD::Events`](#inkhudevents)
- [`InkHUD::Applet`](#inkhudapplet)
- [`InkHUD::SystemApplet`](#inkhudsystemapplet)
- [`InkHUD::Tile`](#inkhudtile)
- [`InkHUD::AppletFont`](#inkhudappletfont)
## Purpose
InkHUD is a minimal UI for E-Ink devices. It displays the user's choice of info, as statically as possible, to minimize the amount of display refreshing.
It is intended to supplement a connected client app.
## Design Principles
### Self-Contained
- Keep InkHUD code within `/src/graphics/niche/InkHUD`.
- Place reusable components within `/src/graphics/niche`, for other UIs to take advantage of.
- Interact with the firmware code using the **Module API**, **Observables**, and other similarly non-intrusive hooks.
### Static
Information should be displayed as statically as possible. Unnecessary updates should be avoided.
As as example, fixed timestamps are used instead of `X seconds ago` labels, as these need to be constantly updated to remain current.
### Non-interactive
InkHUD aims to be a "heads up display". The intention is for the user to glance at the display. The intention is _not_ for the user to frequently interact with the display.
Some interactivity is tolerated as a means to an end: the display _should_ be customizable, but this should be minimized as much as possible.
_Edit: there's significant demand for keyboard support, so some sort of free-text feature will need to be added eventually, although it does go against the original design principles._
### Customizable
The user should be given the choice to decide which information they would like to receive, and how they would like to receive it.
### Event-Driven Rendering
The display image does not update "automatically". Individual applets are responsible for deciding when they have new information to show, and then requesting a display update.
### No `#ifdef` spaghetti
**Don't** use preprocessor macros for device-specific configuration. This should be achieved with config methods, in [`nicheGraphics.h`](#nichegraphicsh).
**Do** use preprocessor macros to guard all files
- `#ifdef MESHTASTIC_INCLUDE_INKHUD` for InkHUD files
- `#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS` for reusable components (drivers, etc)
## The Implementation
- Variant's platformio.ini file extends `inkhud` (defined in InkHUD/PlatformioConfig.ini)
- original screen class suppressed: `MESHTASTIC_EXCLUDE_SCREEN`
- ButtonThread suppressed: `HAS_BUTTON=0`
- NicheGraphics components included: `MESHTASTIC_INCLUDE_NICHE_GRAPHICS`
- InkHUD components included: `MESHTASTIC_INCLUDE_INKHUD`
- `main.cpp`
- includes `nicheGraphics.h` (from variant folder)
- calls `setupNicheGraphics`, (from nicheGraphics.h)
- `nicheGraphics.h`
- includes InkHUD components
- includes shared NicheGraphics components
- `setupNicheGraphics`
- configures and connects components
- `inkhud->begin`
## The Rendering Process
(animated diagram)
<img src="rendering.gif" alt="animated process diagram of InkHUD rendering" height="480"/>
An overview:
- A component calls `requestUpdate` (applets only) or `InkHUD::forceUpdate`
- `Renderer` schedules a render cycle for the next loop(), using `Renderer::runOnce`
- `Renderer` determines whether the update request is valid
- `Renderer` asks relevant applets to render
- Applet dimensions are updated (by Applet's `Tile`)
- Applets generate pixel output, and pass this to their `Tile`
- Tiles shift these "relative" pixels to their true region, for multiplexing
- Tiles pass the pixels to `Renderer`
- `Renderer` applies any global display rotation to the pixels
- `Renderer` combines the pixels into the finished image
- The finished image is passed to the display driver, starting the physical update process
## Concepts
### NicheGraphics Framework
InkHUD is implemented as a _NicheGraphics_ UI.
Intended as a pattern / philosophy for implementing self-contained UIs, to suit various niche devices, which are best served by their own custom user interface.
Hypothetical examples: E-Ink, 1602 LCDs, tiny OLEDs, smart watches, etc
A NicheGraphics UI:
- Is self-contained
- Makes use of the loose collection of resources (drivers, input methods, etc) gathered in the `/src/graphics/niche` folder.
- Implements a `setupNicheGraphics()` method.
### NicheGraphics E-Ink Drivers
InkHUD uses a set of custom E-Ink drivers. These are not based on GxEPD2, or any other code base. They are written directly on-top of the Meshtastic firmware, to make use of the OSThread class for asynchronous display updates.
Interacting with the drivers is straightforward. InkHUD generates a frame of 1-bit image data. This image data is passed to the driver, along with the type of refresh to use (FULL or FAST).
`driver->update(uint8_t* buffer, EInk::UpdateTypes::FULL)`
For more information, see the documentation in `src/graphics/niche/Drivers/EInk`
### InkHUD Applets
An InkHUD applet is a class which generates a screen of info for the display.
Consider: `DMApplet.h` (displays most recent direct message) and `RecentsList.h` (displays a list of recently heard nodes)
- Applets are modular: they are easy to write, and easy to implement. Users select which applets they want, using the menu.
- Applets use responsive design. They should scale for different screens / layouts / fonts.
- Applets decide when to update. They use the Module API, Observers, etc, to retrieve information, and request a display update when they have something interesting to show.
See `src/graphics/niche/InkHUD/Applets/Examples` for example code.
#### Writing an Applet
Your new applet class will inherit `InkHUD::Applet`.
```cpp
class BasicExampleApplet : public Applet
{
public:
// You must have an onRender() method
// All drawing happens here
void onRender() override;
};
```
The `onRender` method is called when the display image is redrawn. This can happen at any time, so be ready!
```cpp
// All drawing happens here
// Our basic example doesn't do anything useful. It just passively prints some text.
void InkHUD::BasicExampleApplet::onRender()
{
printAt(0, 0, "Hello, world!");
}
```
Your applet will need to scale automatically, to suit a variety of screens / layouts / fonts. Make sure you draw relative to applet's size.
| edge | coordinate | shorthand |
| ------ | ---------- | --------- |
| left | 0 | `X(0.0)` |
| top | 0 | `Y(0.0)` |
| right | `width()` | `X(1.0)` |
| bottom | `height()` | `Y(1.0)` |
The same principles apply for drawing text. Methods like `AppletFont::lineHeight` and `getTextWidth` are useful here.
```cpp
std::string line1 = "Line 1";
printAt(0, Y(0.5), line1);
drawRect(0, Y(0.5), getTextWidth(line1), fontSmall.lineHeight(), BLACK);
```
Your applet will only be redrawn when _something_ requests a display update. Your applet is welcome to request a display update, when it determines that it has new info to display, by calling `requestUpdate`.
Exactly how you determine this, depends on what your applet actually does. Here's a code snippet from one of the example applets. The applet is requesting an update when a new message is received.
```cpp
// We configured the Module API to call this method when we receive a new text message
ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_MeshPacket &mp)
{
// Abort if applet fully deactivated
// Don't waste time: we wouldn't be rendered anyway
if (!isActive())
return ProcessMessage::CONTINUE;
// Check that this is an incoming message
// Outgoing messages (sent by us) will also call handleReceived
if (!isFromUs(&mp)) {
// Store the sender's nodenum
// We need to keep this information, so we can re-use it anytime render() is called
haveMessage = true;
fromWho = mp.from;
// Tell InkHUD that we have something new to show on the screen
requestUpdate();
}
// Tell Module API to continue informing other firmware components about this message
// We're not the only component which is interested in new text messages
return ProcessMessage::CONTINUE;
}
```
#### Implementing an Applet
Incorporating your new applet into InkHUD is easy.
In a variant's `nicheGraphics.h`:
- `#include` your applet
- `inkhud->addApplet("My Applet", new InkHUD::MyApplet);`
You will need to add these lines to any variants which will use your applet.
#### Applet Bases
If you need to create several similar applets, it might make sense to create a reusable base class. Several of these already exist in `src/graphics/niche/InkHUD/Applets/Bases`, but use these with caution, as they may be modified in future.
#### System Applets
So far, we have been talking about "user applets". We also recognize a separate category of "system applets". These handle things like the menu, and the boot screen. These often need special handling, and need to be implemented manually.
## Adding a Variant
In `/variants/<YOUR_VARIANT>/`:
### platformio.ini
Extend `inkhud`, then combine with any other platformio config your hardware variant requires.
_(Example shows only config required by InkHUD. This is not a complete `env` definition.)_
```ini
[env:YOUR_VARIANT-inkhud]
extends = esp32s3_base, inkhud ; or nrf52840_base, etc
build_src_filter =
${esp32_base.build_src_filter}
${inkhud.build_src_filter}
build_flags =
${esp32s3_base.build_flags}
${inkhud.build_flags}
lib_deps =
${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX
${esp32s3_base.lib_deps}
```
### nicheGraphics.h
⚠ Wrap this file in `#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS`
`nicheGraphics.h` should be placed in the same folder as your variant's `platformio.ini`. If this is not possible, modify `build_src_filter`.
`nicheGraphics.h` should contain a `setupNicheGraphics` method, which creates and configures the various components for InkHUD.
- Display
- Start SPI
- Create display driver
- InkHUD
- Create InkHUD instance
- Set E-Ink fast refresh limit (`setDisplayResilience`)
- Set fonts
- Set default user-settings
- Select applets to build (`addApplet`)
- Start InkHUD
- Buttons
- Setup `TwoButton` driver (user button, optional "auxiliary" button)
- Connect to InkHUD handlers (use lambdas)
For well commented examples, see:
- `variants/heltec_vision_master_e290/nicheGraphics.h` (ESP32)
- `variants/t-echo/nicheGraphics.h` (NRF52)
## Class Notes
### `InkHUD::InkHUD`
_`src/graphics/niche/InkHUD/InkHUD.h`_
- singleton
- mediator between other InkHUD components
#### `getInstance()`
Gets access to the class.
First `getInstance` call instantiates the class, and the subclasses:
- `InkHUD::Persistence`
- `InkHUD::WindowManager`
- `InkHUD::Renderer`
- `InkHUD::Events`
For convenience, many InkHUD components call this on `begin`, and store it as `InkHUD* inkhud`.
---
### `InkHUD::Persistence`
_`src/graphics/niche/InkHUD/Persistence.h`_
Stores InkHUD data in flash
- settings
- most recent text message received (both for broadcast and DM)
In rare cases, applets may store their own specific data separately (e.g. `ThreadedMessageApplet`)
Data saved only on shutdown / reboot. Not saved if power is removed unexpectedly.
---
### `InkHUD::Persistence::Settings`
_`src/graphics/niche/InkHUD/Persistence.h`_
Settings which relate to InkHUD. Mostly user's customization, but some values record the UI's state (e.g. `tips.safeShutdownSeen`)
- stored using `FlashData.h` (a shared Niche Graphics tool)
- not encoded as protobufs
- serialized directly as bytes of struct
#### Defaults
Global default values are set when the struct is defined (Persistence.h).
Per-variant defaults are set by modifying the values of the settings instance during `setupNicheGraphics()`, before `inkhud->begin` is called.
```cpp
inkhud->persistence->settings.userTiles.count = 2;
inkhud->persistence->settings.userTiles.maxCount = 4;
inkhud->persistence->settings.rotation = 3;
```
By modifying the values at this point, they will be used if we fail to load previous settings from flash (not yet saved, old version, etc)
---
### `InkHUD::Persistence::LatestMessage`
_`src/graphics/niche/InkHUD/Persistence.h`_
Most recently received text message
- most recent DM
- most recent broadcast
Collected here, so various user applets don't all have to store their own copy of this info.
We are unable to use `devicestate.rx_text_message` for this purpose, because:
- it is cleared by an outgoing text message
- we want to store both a recent broadcast and a recent DM
#### Saving / Loading
_A bit of a hack.._
Stored to flash using `InkHUD::MessageStore`, which is really intended for storing a thread of messages (see `ThreadedMessageApplet`). Used because it stores strings more efficiently than `FlashData.h`.
The hack is:
- If most recent message was a DM, we only store the DM.
- If most recent message was a broadcast, we store both a DM and a broadcast. The DM may be 0-length string.
---
### `InkHUD::WindowManager`
_`src/graphics/niche/InkHUD/WindowManager.h`_
Manages which applets are shown, and their size / position (by manipulating the "tiles")
- owns the `Tile` instances
- creates and destroys tiles; sets size and position:
- at startup
- at runtime, when config changes (layout, rotation, etc)
- activates (or deactivates) applets
- cycling through applets (e.g. on button press)
The window manager doesn't process pixels; that is handled by the `InkHUD::Tile` objects.
Note: Some of the methods (incl. `changeLayout`, `changeActivatedApplets`) don't trigger changes themselves. They should be called _after_ the relevant values in `inkhud->persistence->settings` have been modified.
---
### `InkHUD::Renderer`
_`src/graphics/niche/InkHUD/Renderer.h`_
Get pixel output from applets (via a tile), combine, and pass to the driver.
- triggered by `requestUpdate` or `forceUpdate`
- not run immediately: allows multiple applets to share one render cycle
- calls `Applet::onRender` for relevant applets
- applies global rotation
- passes finalized image to driver
`requestUpdate` is for applets (user or system). Renderer will honor the request if the applet is visible. `forceUpdate` can be used anywhere, but not from user applets, please.
#### Asynchronous updates
`requestUpdate` and `forceUpdate` do not block code execution. They schedule rendering for "ASAP", using `Renderer::runOnce`. Renderer then gets pixel output from relevant applets, and hands the assembled image to the driver. Driver's update process is also asynchronous. If the driver is busy when `requestUpdate` or `forceUpdate` is called, another rendering will run as soon as possible. This is handled by `Renderer::runOnce`
#### Blocking updates
If needed, call `forceUpdate` with the optional argument `async=false` to wait while an update runs (> 1 second). Additionally, the `awaitUpdate` method can be used to block until any previous update has completed. An example usage of this is waiting to draw the shutdown screen.
#### Global rotation
The exact size / position / rotation of InkHUD applets is configurable by the user. To achieve this, applets draw pixels between 0,0 and `Applet::width()`, `Applet::height()`
- **Scaling**: Applet's `width()` and `height()` are set by `Tile` before rendering starts
- **Translation**: `Tile` shifts applet pixels up/down/left/right
- **Rotation**: `Renderer` rotates all pixels it receives, before placing them into the final image buffer
---
### `InkHUD::Renderer::DisplayHealth`
_`src/graphics/niche/InkHUD/DisplayHealth.h`_
Responsible for maintaining display health, by optimizing the ratio of FAST vs FULL refreshes
- count number of FAST vs FULL refreshes (debt)
- suggest either FAST or FULL type
- periodically FULL refresh the display unprovoked, if needed
#### Background Info
When the image on an E-Ink display is updated, different procedures can be used to move the pixels to their new states. We have defined two procedures: `FAST` and `FULL`.
A `FAST` update moves pixels directly from their old position, to their new position. This is aesthetically pleasing, and quick, _but_ it is challenging for the display hardware. If used excessively, pixels can build up residual charge, which negatively impacts the display's lifespan and image quality.
A `FULL` update first moves all pixels between black and white, before letting them eventually settle at their final position. This causes an unpleasant flashing of the display image, but is best for the display health and image quality.
Most displays readily tolerate `FAST` updates, so long as a `FULL` update is occasionally performed. How often this `FULL` update is required depends on the display model.
#### Debt
`InkHUD::DisplayHealth` records how many `FAST` refreshes have occurred since the previous `FULL` refresh.
This is referred to as the "full refresh debt".
If an update of a specific type (`FULL` / `FAST`) is requested / forced, this will be granted.
If an update is requested / forced _without_ a specified type (`UpdateTypes::UNSPECIFIED`), `DisplayHealth` will select either `FAST` or `FULL`, in an attempt to maintain a target ratio of fast to full updates.
This target is set by `InkHUD::setDisplayResilience`, when setting up in `nichegraphics.h`
If an _excessive_ amount of `FAST` refreshes are performed back-to-back, `DisplayHealth` will begin artificially inflating the full refresh debt. This will cause the next few `UNSPECIFIED` updates to _all_ be performed as `FULL`, while the debt is paid down.
This system of "full refresh debt" allows us to increase perceived responsiveness by tolerating additional strain on the display during periods of user interaction, and attempting to "repair the damage" later, once user interaction ceases.
#### Maintenance
The system of "full refresh debt" assumes that the display will perform many updates of `UNSPECIFIED` type between periods of user interaction. Depending on the amount of mesh traffic / applet selection, this may not be the case.
If debt is particularly high, and no updates are taking place organically, `DisplayHealth` will begin infrequently performing `FULL` updates, purely to pay down the full refresh debt.
---
### `InkHUD::Events`
Handles events which impact the InkHUD system generally (e.g. shutdown, button press).
Applets themselves do also listen separately for various events, but for the purpose of gathering information which they would like to display.
#### Buttons
Button input is sometimes handled by a system applet. `InkHUD::Events` determines whether the button should be handled by a specific system applet, or should instead trigger a default behavior
---
### `InkHUD::Applet`
A base class for applets. An applet is one "program", which may show info on the display.
To oversimplify, all of the InkHUD code "under the hood" only exists to support applets. Applets are what actually shows useful information to the user. This base class exposes the functionality needed to write an applet.
#### Drawing Methods
`Applet` implements most AdafruitGFX drawing methods. Exception is the text handling. `printAt`, `printWrapped`, and `printThick` should be used instead. These are intended to be more convenient, but they also implement the character substitution system which powers the foreign alphabet support.
`Applet` also adds methods for drawing several design elements which are re-used commonly though-out InkHUD.
#### InkHUD Events
Applets undergo a number of state changes: activated / deactivated by user, brought to foreground / hidden to background by user button press, etc. The `Applet` class provides a set of virtual methods, which an applet can override to appropriately handle these events.
The `onRender` virtual method is one example. This is called when an applet is rendered, and should execute all drawing code. An applet _must_ implement this method.
#### Responsive Design
An applet's size will vary depending on the screen size, and the user's layout (multiplexing). Immediately before `onRender` is called, an applet's dimensions are updated, so that `width()` and `height()` will give the required size. The applet should draw its graphical elements relative to these values. The methods `X(float)` and `Y(float)` are also provided for convenience.
| edge | coordinate | shorthand |
| ------ | ---------- | --------- |
| left | 0 | `X(0.0)` |
| top | 0 | `Y(0.0)` |
| right | `width()` | `X(1.0)` |
| bottom | `height()` | `Y(1.0)` |
The same principles apply for drawing text. Methods like `AppletFont::lineHeight` and `getTextWidth` are useful here.
Applets should always draw relative to their top left corner, at _x=0, y=0._ The applet's pixels are automatically moved to the correct position on-screen by an InkHUD::Tile.
#### User Applets
User applets are the "normal" applets, each one displaying a specific set of information to the user. They can be activated / deactivated at run-time using the on-screen menu. Examples include `DMApplet.h` and `PositionsApplet.h`. User applets are not expected to interact with lower layers of the InkHUD code.
Users applets are instantiated in a variant's `setupNicheGraphics` method, and passed to `InkHUD::addApplet`. Their class should not be mentioned elsewhere, so that its code can be stripped away during compilation if a variant does not implement the specific applet. Internal processing of user applets treats them all as the generic `Applet` type only.
#### Activated / Deactivated
User applets can be activated or deactivated. This changes at run-time: the user selects which applets should be active using the on-screen menu. An applet should not process data while it is deactivated. It can unobserve any observables, ignore `handleReceived` calls, etc.
An applet can implement the virtual `onActivate` and `onDeactivate` methods to handle this change in state. It can check this state internally by calling `isActive`.
System applets cannot be deactivated.
#### Foreground / Background
An activated applet can either be _foreground_ or _background_. A foreground applet is one which will be rendered to a tile when the screen updates. A background applet will not be drawn. The applet cycling which takes place when the user button is pressed is implemented using foreground / background.
Regardless of whether it is foreground or background, an activated applet should continue to collect / process data, and request update when it has new info to display. This is because of the _autoshow_ mechanic, which might bring a background applet to foreground in order to display its data. If an applet remains background, its update requests will be safely ignored.
#### Autoshow
Autoshow is a feature which allows the user to select which applets (if any) they would like to be shown automatically. If autoshow is enabled for an applet, it will be brought to foreground when it has new information to display. The user grants this privilege on a per-applet basis, using the on-screen menu. If an event causes an applet to be autoshown, NotificationApplet should not be shown for the same event.
An applet needs to decide when it has information worthy of autoshowing. It signals this by calling `requestAutoshow`, in addition to the usual `requestUpdate` call.
---
### `InkHUD::SystemApplet`
_System applets_ are applets with special roles, which require special handling. Examples include `BatteryIconApplet.h` and `LogoApplet.h`. These are manually implemented, one-by-one, in `WindowManager.h`.
This class is a slight extension of `Applet`. It adds extra flags for some special features which are restricted to system applets: exclusive use of the display, and the handling of user input. Having a separate system applet class also allows us to make it clear within the code when system applets are being handled, rather than user applets
We store reference to these as a `vector<SystemApplets*>`. This parallels how we treat user applets, and makes rendering convenient.
Because system applets do have unique roles, there are times when we will need to interact with a specific applet. Rather than keeping an extra set of references, we access them from the `vector<SystemApplet*>`. Use `InkHUD::getSystemApplet` to access the applet by its `Applet::name` value, and then typecast.
---
### `InkHUD::Tile`
A tile represents a region of the display. A tile controls the size and position of an applet.
For an applet to render, it must be assigned to a tile. When an applet is assigned to a tile, the two become linked. The applet is aware of the tile; the tile is aware of the applet. Applets cannot share a tile; assigning a different applet will remove any existing link.
Before an applet renders, its width and height are set to the dimensions of the tile. During `onRender`, an applet's drawing methods generate pixels between _x=0, y=0_ and _x=Applet::width(), y=Applet::height()_. These pixels are passed to its tile's `Tile::handleAppletPixel` method. The tile then applies x and y offset, "translating" these pixels to the tile's region of the display. These translated pixels are then passed on to the `InkHUD::Renderer`.
![depiction of a tile translating applet pixels](./tile_translation.png)
#### User Tiles
_User applets_ are the "normal" applets. They can be activated / deactivated at run-time using the on-screen menu. User applets are rendered to one of the **user tiles**.
The user can customize the "layout", using the on-screen menu. Depending on their selected layout, a certain number of _user tiles_ are created. These tiles are automatically positioned and sized so that they fill the entire screen.
Often, a user will have enabled more applets than they have tiles. Pressing the user-button will cycle through these applets. The old applet is sent to _background_, the new applet is brought to _foreground_. When a user applet is brought to foreground, it becomes assigned to a user tile (the focused tile). When it renders, its size will be set by this tile, and its pixels will be translated to this tile's region. The user applet which was sent to background loses its assignment; it no longer has an assigned tile.
#### Focused Tile
The focused tile is one of the user tiles. This is tile whose applet will change when the user button is pressed. This also the tile where the menu will appear on longpress. The focused tile is identified by its index in `vector<Tile*> userTiles`.
#### Highlighting
In addition to the user button, some devices have a second "auxiliary button". The function of this button can vary from device to device, but it is sometimes used to focus a different tile. When this happens, the newly focused tile is temporarily "highlighted", by drawing it with a border. This border is automatically removed after several seconds. As drawing code may only be executed by applets, this highlighting is a collaborative effort between a `Tile` and an `Applet`: performed in `Applet::render`, after the virtual `onRender` method has already run.
Highlighting is only used when `nextTile` is fired by an aux button. It does not occur if performed via the on-screen menu.
#### System Tiles
_System applets_ are applets with special roles, which require special handling. Examples include `BatteryIconApplet.h` and `LogoApplet.h`. _Mostly_, these applets do not render to user tiles. Instead, they are given their own unique tile, which is positioned / dimensioned manually. The only reference we keep to these special tiles is stored within the linked system applet. They can be accessed with `Applet::getTile`.
---
### `InkHUD::AppletFont`
Wrapper which extends the functionality of an AdafruitGFX font.
#### Dimension Info
The AppletFont class pre-calculates some info about a font's dimensions, which is useful for design (`AppletFont::lineHeight`), and is used to power InkHUD's custom text handling.
The default AdafruitGFX text handling places characters "upon a line", as if hand-written on a sheet of ruled paper. `InkHUD::AppletFont` measures the character set of the font, so that we instead draw fixed-height lines of text, positioned by the bounding box, with optional horizontal and vertical alignment.
![text origins in InkHUD vs AdafruitGFX](./appletfont.png)
The height of this box is `AppletFont::lineHeight`, which is the height of the tallest character in the font. This gives us a fixed-height for text, which is much tighter than with AdafruitGFX's default line spacing.
#### UTF-8 Substitutions
To enable non-English text, the `AppletFont` class includes a mechanism to detect specific UTF-8 characters, and replace them with alternative glyphs from the AdafruitGFX font. This can be used to remap characters for a custom font, or to offer a suitable ASCII replacement.
```cpp
// With a custom font
// ї is ASCII 0xBF, in Windows-1251 encoding
addSubstitution("ї", "\xBF");
// Substitution (with a default font)
addSubstitution("ö", "oe");
```
These substitutions should be performed in a variant's `setupNicheGraphics` method. For convenience, some common ASCII encodings have ready-to-go sets of substitutions you can apply, for example `AppletFont::addSubstitutionsWin1251`

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 7.6 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 18 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 77 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 5.7 KiB

Wyświetl plik

@ -67,25 +67,20 @@ void setupNicheGraphics()
InkHUD::Applet::fontSmall.addSubstitutionsWin1251();
*/
// Init settings, and customize defaults
// Customize default settings
inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle?
inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise
inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users
inkhud->persistence->settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead
// Pick applets
// Note: order of applets determines priority of "auto-show" feature
// Optional arguments for defaults:
// - is activated?
// - is autoshown?
// - is foreground on a specific tile (index)?
inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown
inkhud->addApplet("DMs", new InkHUD::DMApplet);
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0));
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1));
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet);
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
// inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet);
// inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);

Wyświetl plik

@ -80,25 +80,27 @@ void setupNicheGraphics()
InkHUD::Applet::fontSmall.addSubstitutionsWin1251();
*/
// Init settings, and customize defaults
// Customize default settings
inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle?
inkhud->persistence->settings.rotation = 1; // 90 degrees clockwise
inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users
inkhud->persistence->settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead
// Pick applets
// Note: order of applets determines priority of "auto-show" feature
// Optional arguments for defaults:
// - is activated?
// - is autoshown?
// - is foreground on a specific tile (index)?
// Order of applets determines priority of "auto-show" feature.
// Optional arguments for default state:
// - is activated?
// - is autoshown?
// - is foreground on a specific tile (index)?
inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown
inkhud->addApplet("DMs", new InkHUD::DMApplet);
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0));
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1));
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet);
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
// inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet);
// inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);

Wyświetl plik

@ -67,26 +67,21 @@ void setupNicheGraphics()
InkHUD::Applet::fontSmall.addSubstitutionsWin1251();
*/
// Init settings, and customize defaults
// Customize default settings
inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle?
inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise
inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users
// Pick applets
// Note: order of applets determines priority of "auto-show" feature
// Optional arguments for defaults:
// - is activated?
// - is autoshown?
// - is foreground on a specific tile (index)?
inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown
inkhud->addApplet("DMs", new InkHUD::DMApplet);
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0));
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1));
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet);
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive
inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive
inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive
inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive
inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0
// inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet);
// inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);
// inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);
// Start running InkHUD
inkhud->begin();

Wyświetl plik

@ -68,8 +68,7 @@ void setupNicheGraphics()
InkHUD::Applet::fontSmall.addSubstitutionsWin1251();
*/
// Init settings, and customize defaults
// Values ignored individually if found saved to flash
// Customize default settings
inkhud->persistence->settings.userTiles.maxCount = 2; // Two applets side-by-side
inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise
inkhud->persistence->settings.optionalFeatures.batteryIcon = true; // Device definitely has a battery
@ -106,6 +105,7 @@ void setupNicheGraphics()
// Setup the main user button
buttons->setWiring(MAIN_BUTTON, BUTTON_PIN, LOW);
buttons->setTiming(MAIN_BUTTON, 75, 500);
buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); });
buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); });