mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-22 17:57:32 +00:00
add a .clang-format file (#9154)
This commit is contained in:
@@ -13,222 +13,174 @@
|
||||
using namespace NicheGraphics;
|
||||
|
||||
// Get or create the singleton
|
||||
InkHUD::InkHUD *InkHUD::InkHUD::getInstance()
|
||||
{
|
||||
// Create the singleton instance of our class, if not yet done
|
||||
static InkHUD *instance = nullptr;
|
||||
if (!instance) {
|
||||
instance = new InkHUD;
|
||||
InkHUD::InkHUD *InkHUD::InkHUD::getInstance() {
|
||||
// Create the singleton instance of our class, if not yet done
|
||||
static InkHUD *instance = nullptr;
|
||||
if (!instance) {
|
||||
instance = new InkHUD;
|
||||
|
||||
instance->persistence = new Persistence;
|
||||
instance->windowManager = new WindowManager;
|
||||
instance->renderer = new Renderer;
|
||||
instance->events = new Events;
|
||||
}
|
||||
instance->persistence = new Persistence;
|
||||
instance->windowManager = new WindowManager;
|
||||
instance->renderer = new Renderer;
|
||||
instance->events = new Events;
|
||||
}
|
||||
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Connect the (fully set-up) E-Ink driver to InkHUD
|
||||
// Should happen in your variant's nicheGraphics.h file, before InkHUD::begin is called
|
||||
void InkHUD::InkHUD::setDriver(Drivers::EInk *driver)
|
||||
{
|
||||
renderer->setDriver(driver);
|
||||
}
|
||||
void InkHUD::InkHUD::setDriver(Drivers::EInk *driver) { renderer->setDriver(driver); }
|
||||
|
||||
// Set the target number of FAST display updates in a row, before a FULL update is used for display health
|
||||
// This value applies only to updates with an UNSPECIFIED update type
|
||||
// If explicitly requested FAST updates exceed this target, the stressMultiplier parameter determines how many
|
||||
// subsequent FULL updates will be performed, in an attempt to restore the display's health
|
||||
void InkHUD::InkHUD::setDisplayResilience(uint8_t fastPerFull, float stressMultiplier)
|
||||
{
|
||||
renderer->setDisplayResilience(fastPerFull, stressMultiplier);
|
||||
void InkHUD::InkHUD::setDisplayResilience(uint8_t fastPerFull, float stressMultiplier) {
|
||||
renderer->setDisplayResilience(fastPerFull, stressMultiplier);
|
||||
}
|
||||
|
||||
// Register a user applet with InkHUD
|
||||
// A variant's nicheGraphics.h file should instantiate your chosen applets, then pass them to this method
|
||||
// Passing an applet to this method is all that is required to make it available to the user in your InkHUD build
|
||||
void InkHUD::InkHUD::addApplet(const char *name, Applet *a, bool defaultActive, bool defaultAutoshow, uint8_t onTile)
|
||||
{
|
||||
windowManager->addApplet(name, a, defaultActive, defaultAutoshow, onTile);
|
||||
void InkHUD::InkHUD::addApplet(const char *name, Applet *a, bool defaultActive, bool defaultAutoshow, uint8_t onTile) {
|
||||
windowManager->addApplet(name, a, defaultActive, defaultAutoshow, onTile);
|
||||
}
|
||||
|
||||
// Start InkHUD!
|
||||
// Call this only after you have configured InkHUD
|
||||
void InkHUD::InkHUD::begin()
|
||||
{
|
||||
persistence->loadSettings();
|
||||
persistence->loadLatestMessage();
|
||||
void InkHUD::InkHUD::begin() {
|
||||
persistence->loadSettings();
|
||||
persistence->loadLatestMessage();
|
||||
|
||||
windowManager->begin();
|
||||
events->begin();
|
||||
renderer->begin();
|
||||
// LogoApplet shows boot screen here
|
||||
windowManager->begin();
|
||||
events->begin();
|
||||
renderer->begin();
|
||||
// LogoApplet shows boot screen here
|
||||
}
|
||||
|
||||
// Call this when your user button gets a short press
|
||||
// Should be connected to an input source in nicheGraphics.h (NicheGraphics::Inputs::TwoButton?)
|
||||
void InkHUD::InkHUD::shortpress()
|
||||
{
|
||||
events->onButtonShort();
|
||||
}
|
||||
void InkHUD::InkHUD::shortpress() { events->onButtonShort(); }
|
||||
|
||||
// Call this when your user button gets a long press
|
||||
// Should be connected to an input source in nicheGraphics.h (NicheGraphics::Inputs::TwoButton?)
|
||||
void InkHUD::InkHUD::longpress()
|
||||
{
|
||||
events->onButtonLong();
|
||||
}
|
||||
void InkHUD::InkHUD::longpress() { events->onButtonLong(); }
|
||||
|
||||
// Call this when your exit button gets a short press
|
||||
void InkHUD::InkHUD::exitShort()
|
||||
{
|
||||
events->onExitShort();
|
||||
}
|
||||
void InkHUD::InkHUD::exitShort() { events->onExitShort(); }
|
||||
|
||||
// Call this when your exit button gets a long press
|
||||
void InkHUD::InkHUD::exitLong()
|
||||
{
|
||||
events->onExitLong();
|
||||
}
|
||||
void InkHUD::InkHUD::exitLong() { events->onExitLong(); }
|
||||
|
||||
// Call this when your joystick gets an up input
|
||||
void InkHUD::InkHUD::navUp()
|
||||
{
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
}
|
||||
void InkHUD::InkHUD::navUp() {
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Call this when your joystick gets a down input
|
||||
void InkHUD::InkHUD::navDown()
|
||||
{
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
}
|
||||
void InkHUD::InkHUD::navDown() {
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Call this when your joystick gets a left input
|
||||
void InkHUD::InkHUD::navLeft()
|
||||
{
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
}
|
||||
void InkHUD::InkHUD::navLeft() {
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Call this when your joystick gets a right input
|
||||
void InkHUD::InkHUD::navRight()
|
||||
{
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
}
|
||||
void InkHUD::InkHUD::navRight() {
|
||||
switch ((persistence->settings.rotation + persistence->settings.joystick.alignment) % 4) {
|
||||
case 1: // 90 deg
|
||||
events->onNavUp();
|
||||
break;
|
||||
case 2: // 180 deg
|
||||
events->onNavLeft();
|
||||
break;
|
||||
case 3: // 270 deg
|
||||
events->onNavDown();
|
||||
break;
|
||||
default: // 0 deg
|
||||
events->onNavRight();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle the next user applet to the foreground
|
||||
// Only activated applets are cycled
|
||||
// If user has a multi-applet layout, the applets will cycle on the "focused tile"
|
||||
void InkHUD::InkHUD::nextApplet()
|
||||
{
|
||||
windowManager->nextApplet();
|
||||
}
|
||||
void InkHUD::InkHUD::nextApplet() { windowManager->nextApplet(); }
|
||||
|
||||
// Cycle the previous user applet to the foreground
|
||||
// Only activated applets are cycled
|
||||
// If user has a multi-applet layout, the applets will cycle on the "focused tile"
|
||||
void InkHUD::InkHUD::prevApplet()
|
||||
{
|
||||
windowManager->prevApplet();
|
||||
}
|
||||
void InkHUD::InkHUD::prevApplet() { windowManager->prevApplet(); }
|
||||
|
||||
// Show the menu (on the the focused tile)
|
||||
// The applet previously displayed there will be restored once the menu closes
|
||||
void InkHUD::InkHUD::openMenu()
|
||||
{
|
||||
windowManager->openMenu();
|
||||
}
|
||||
void InkHUD::InkHUD::openMenu() { windowManager->openMenu(); }
|
||||
|
||||
// Bring AlignStick applet to the foreground
|
||||
void InkHUD::InkHUD::openAlignStick()
|
||||
{
|
||||
windowManager->openAlignStick();
|
||||
}
|
||||
void InkHUD::InkHUD::openAlignStick() { windowManager->openAlignStick(); }
|
||||
|
||||
// In layouts where multiple applets are shown at once, change which tile is focused
|
||||
// The focused tile in the one which cycles applets on button short press, and displays menu on long press
|
||||
void InkHUD::InkHUD::nextTile()
|
||||
{
|
||||
windowManager->nextTile();
|
||||
}
|
||||
void InkHUD::InkHUD::nextTile() { windowManager->nextTile(); }
|
||||
|
||||
// In layouts where multiple applets are shown at once, change which tile is focused
|
||||
// The focused tile in the one which cycles applets on button short press, and displays menu on long press
|
||||
void InkHUD::InkHUD::prevTile()
|
||||
{
|
||||
windowManager->prevTile();
|
||||
}
|
||||
void InkHUD::InkHUD::prevTile() { windowManager->prevTile(); }
|
||||
|
||||
// Rotate the display image by 90 degrees
|
||||
void InkHUD::InkHUD::rotate()
|
||||
{
|
||||
windowManager->rotate();
|
||||
}
|
||||
void InkHUD::InkHUD::rotate() { windowManager->rotate(); }
|
||||
|
||||
// rotate the joystick in 90 degree increments
|
||||
void InkHUD::InkHUD::rotateJoystick(uint8_t angle)
|
||||
{
|
||||
persistence->settings.joystick.alignment += angle;
|
||||
persistence->settings.joystick.alignment %= 4;
|
||||
void InkHUD::InkHUD::rotateJoystick(uint8_t angle) {
|
||||
persistence->settings.joystick.alignment += angle;
|
||||
persistence->settings.joystick.alignment %= 4;
|
||||
}
|
||||
|
||||
// Show / hide the battery indicator in top-right
|
||||
void InkHUD::InkHUD::toggleBatteryIcon()
|
||||
{
|
||||
windowManager->toggleBatteryIcon();
|
||||
}
|
||||
void InkHUD::InkHUD::toggleBatteryIcon() { windowManager->toggleBatteryIcon(); }
|
||||
|
||||
// An applet asking for the display to be updated
|
||||
// This does not occur immediately
|
||||
@@ -236,64 +188,40 @@ void InkHUD::InkHUD::toggleBatteryIcon()
|
||||
// This allows multiple applets to observe the same event, and then share the same opportunity to update
|
||||
// Applets should requestUpdate, whether or not they are currently displayed ("foreground")
|
||||
// This is because they *might* be automatically brought to foreground by WindowManager::autoshow
|
||||
void InkHUD::InkHUD::requestUpdate()
|
||||
{
|
||||
renderer->requestUpdate();
|
||||
}
|
||||
void InkHUD::InkHUD::requestUpdate() { renderer->requestUpdate(); }
|
||||
|
||||
// Demand that the display be updated
|
||||
// Ignores all diplomacy:
|
||||
// - the display *will* update
|
||||
// - the specified update type *will* be used
|
||||
// If the async parameter is false, code flow is blocked while the update takes place
|
||||
void InkHUD::InkHUD::forceUpdate(EInk::UpdateTypes type, bool async)
|
||||
{
|
||||
renderer->forceUpdate(type, async);
|
||||
}
|
||||
void InkHUD::InkHUD::forceUpdate(EInk::UpdateTypes type, bool async) { renderer->forceUpdate(type, async); }
|
||||
|
||||
// Wait for any in-progress display update to complete before continuing
|
||||
void InkHUD::InkHUD::awaitUpdate()
|
||||
{
|
||||
renderer->awaitUpdate();
|
||||
}
|
||||
void InkHUD::InkHUD::awaitUpdate() { renderer->awaitUpdate(); }
|
||||
|
||||
// Ask the window manager to potentially bring a different user applet to foreground
|
||||
// An applet will be brought to foreground if it has just received new and relevant info
|
||||
// For Example: AllMessagesApplet has just received a new text message
|
||||
// Permission for this autoshow behavior is granted by the user, on an applet-by-applet basis
|
||||
// If autoshow brings an applet to foreground, an InkHUD notification will not be generated for the same event
|
||||
void InkHUD::InkHUD::autoshow()
|
||||
{
|
||||
windowManager->autoshow();
|
||||
}
|
||||
void InkHUD::InkHUD::autoshow() { windowManager->autoshow(); }
|
||||
|
||||
// Tell the window manager that the Persistence::Settings value for applet activation has changed,
|
||||
// and that it should reconfigure accordingly.
|
||||
// This is triggered at boot, or when the user enables / disabled applets via the on-screen menu
|
||||
void InkHUD::InkHUD::updateAppletSelection()
|
||||
{
|
||||
windowManager->changeActivatedApplets();
|
||||
}
|
||||
void InkHUD::InkHUD::updateAppletSelection() { windowManager->changeActivatedApplets(); }
|
||||
|
||||
// Tell the window manager that the Persistence::Settings value for layout or rotation has changed,
|
||||
// and that it should reconfigure accordingly.
|
||||
// This is triggered at boot, or by rotate / layout options in the on-screen menu
|
||||
void InkHUD::InkHUD::updateLayout()
|
||||
{
|
||||
windowManager->changeLayout();
|
||||
}
|
||||
void InkHUD::InkHUD::updateLayout() { windowManager->changeLayout(); }
|
||||
|
||||
// Width of the display, in the context of the current rotation
|
||||
uint16_t InkHUD::InkHUD::width()
|
||||
{
|
||||
return renderer->width();
|
||||
}
|
||||
uint16_t InkHUD::InkHUD::width() { return renderer->width(); }
|
||||
|
||||
// Height of the display, in the context of the current rotation
|
||||
uint16_t InkHUD::InkHUD::height()
|
||||
{
|
||||
return renderer->height();
|
||||
}
|
||||
uint16_t InkHUD::InkHUD::height() { return renderer->height(); }
|
||||
|
||||
// A collection of any user tiles which do not have a valid user applet
|
||||
// This can occur in various situations, such as when a user enables fewer applets than their layout has tiles
|
||||
@@ -301,23 +229,19 @@ uint16_t InkHUD::InkHUD::height()
|
||||
// The renderer needs to know which regions (if any) are empty,
|
||||
// in order to fill them with a "placeholder" pattern.
|
||||
// -- There may be a tidier way to accomplish this --
|
||||
std::vector<InkHUD::Tile *> InkHUD::InkHUD::getEmptyTiles()
|
||||
{
|
||||
return windowManager->getEmptyTiles();
|
||||
}
|
||||
std::vector<InkHUD::Tile *> InkHUD::InkHUD::getEmptyTiles() { return windowManager->getEmptyTiles(); }
|
||||
|
||||
// Get a system applet by its name
|
||||
// This isn't particularly elegant, but it does avoid:
|
||||
// - passing around a big set of references
|
||||
// - having two sets of references (systemApplet vector for iteration)
|
||||
InkHUD::SystemApplet *InkHUD::InkHUD::getSystemApplet(const char *name)
|
||||
{
|
||||
for (SystemApplet *sa : systemApplets) {
|
||||
if (strcmp(name, sa->name) == 0)
|
||||
return sa;
|
||||
}
|
||||
InkHUD::SystemApplet *InkHUD::InkHUD::getSystemApplet(const char *name) {
|
||||
for (SystemApplet *sa : systemApplets) {
|
||||
if (strcmp(name, sa->name) == 0)
|
||||
return sa;
|
||||
}
|
||||
|
||||
assert(false); // Invalid name
|
||||
assert(false); // Invalid name
|
||||
}
|
||||
|
||||
// Place a pixel into the image buffer
|
||||
@@ -326,9 +250,6 @@ InkHUD::SystemApplet *InkHUD::InkHUD::getSystemApplet(const char *name)
|
||||
// - Tiles pass translated pixels to this method
|
||||
// - this methods (Renderer) places rotated pixels into the image buffer
|
||||
// This method provides the final formatting step required. The image buffer is suitable for writing to display
|
||||
void InkHUD::InkHUD::drawPixel(int16_t x, int16_t y, Color c)
|
||||
{
|
||||
renderer->handlePixel(x, y, c);
|
||||
}
|
||||
void InkHUD::InkHUD::drawPixel(int16_t x, int16_t y, Color c) { renderer->handlePixel(x, y, c); }
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user