InkHUD refactoring (#6216)

* chore: todo.txt
* chore: comments
* fix: no fast refresh on VME290
Reverts a line of code which was accidentally committed
* refactor: god class
Divide the behavior from the old WindowManager class into several subclasses which each have a clear role.
* refactor: cppcheck medium warnings
Enough to pass github CI for now
* refactor: updateType selection
* refactor: don't use a setter for the shared AppletFonts
* fix: update prioritization
forceUpdate calls weren't being prioritized
* refactor: remove unhelpful logging
getTimeString is used for parsing our own time, but also the timestamps of messages. The "one time only" log printing will likely fire in unhelpful situations.
* fix: " "
* refactor: get rid of types.h file for enums
* Keep that sneaky todo file out of commits
This commit is contained in:
todd-herbert
2025-03-06 23:25:41 +13:00
committed by GitHub
parent b2ef92a328
commit e6a98b1d6b
70 changed files with 2381 additions and 1955 deletions

View File

@@ -6,7 +6,7 @@
// InkHUD-specific components
// ---------------------------
#include "graphics/niche/InkHUD/WindowManager.h"
#include "graphics/niche/InkHUD/InkHUD.h"
// Applets
#include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h"
@@ -50,31 +50,30 @@ void setupNicheGraphics()
// InkHUD
// ----------------------------
InkHUD::WindowManager *windowManager = InkHUD::WindowManager::getInstance();
InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance();
// Set the driver
windowManager->setDriver(driver);
inkhud->setDriver(driver);
// Set how many FAST updates per FULL update
// Set how unhealthy additional FAST updates beyond this number are
windowManager->setDisplayResilience(20, 1.5);
inkhud->setDisplayResilience(20, 1.5);
// Prepare fonts
InkHUD::AppletFont largeFont(FreeSans9pt7b);
InkHUD::AppletFont smallFont(FreeSans6pt7b);
InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b);
InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b);
/*
// Font localization demo: Cyrillic
InkHUD::AppletFont smallFont(FreeSans6pt8bCyrillic);
smallFont.addSubstitutionsWin1251();
InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic);
InkHUD::Applet::fontSmall.addSubstitutionsWin1251();
*/
InkHUD::Applet::setDefaultFonts(largeFont, smallFont);
// Init settings, and customize defaults
// Values ignored individually if found saved to flash
InkHUD::settings.userTiles.maxCount = 2; // Two applets side-by-side
InkHUD::settings.rotation = 3; // 270 degrees clockwise
InkHUD::settings.optionalFeatures.batteryIcon = true; // Device definitely has a battery
InkHUD::settings.optionalMenuItems.backlight = true; // Until proven (by touch) that user still has the capacitive button
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
inkhud->persistence->settings.optionalMenuItems.backlight = true; // Until proves capacitive button works by touching it
// Setup backlight
// Note: AUX button behavior configured further down
@@ -83,30 +82,32 @@ void setupNicheGraphics()
// Pick applets
// Note: order of applets determines priority of "auto-show" feature
windowManager->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown
windowManager->addApplet("DMs", new InkHUD::DMApplet);
windowManager->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0));
windowManager->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1));
windowManager->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated
windowManager->addApplet("Recents List", new InkHUD::RecentsListApplet);
windowManager->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, no autoshow, default on tile 0
// windowManager->addApplet("Basic", new InkHUD::BasicExampleApplet);
// windowManager->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);
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, no autoshow, default on tile 0
// inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet);
// inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet);
// Start running window manager
windowManager->begin();
// Start running InkHUD
inkhud->begin();
// Buttons
// --------------------------
Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // Shared NicheGraphics component
// (To improve code readability only)
constexpr uint8_t MAIN_BUTTON = 0;
constexpr uint8_t TOUCH_BUTTON = 1;
// Setup the main user button
buttons->setWiring(MAIN_BUTTON, BUTTON_PIN, LOW);
buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonShort(); });
buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonLong(); });
buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); });
buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); });
// Setup the capacitive touch button
// - short: momentary backlight
@@ -115,7 +116,8 @@ void setupNicheGraphics()
buttons->setTiming(TOUCH_BUTTON, 50, 5000); // 5 seconds before latch - limited by T-Echo's capacitive touch IC
buttons->setHandlerDown(TOUCH_BUTTON, [backlight]() {
backlight->peek();
InkHUD::settings.optionalMenuItems.backlight = false; // We've proved user still has the button. No need for menu entry.
InkHUD::InkHUD::getInstance()->persistence->settings.optionalMenuItems.backlight =
false; // We've proved user still has the button. No need to make backlight togglable via the menu.
});
buttons->setHandlerLongPress(TOUCH_BUTTON, [backlight]() { backlight->latch(); });
buttons->setHandlerShortPress(TOUCH_BUTTON, [backlight]() { backlight->off(); });

View File

@@ -39,6 +39,6 @@ build_src_filter =
${inkhud.build_src_filter}
+<../variants/t-echo>
lib_deps =
${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot intead of AdafruitGFX
${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX
${nrf52840_base.lib_deps}
lewisxhe/PCF8563_Library@^1.0.1