Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/graphics/niche/InkHUD/Applet.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class Applet : public GFX
virtual void onShutdown() {}
virtual void onButtonShortPress() {} // (System Applets only)
virtual void onButtonLongPress() {} // (System Applets only)
virtual void onStickCenterShort() {} // (System Applets only)
virtual void onStickCenterLong() {} // (System Applets only)
virtual void onStickUp() {} // (System Applets only)
virtual void onStickDown() {} // (System Applets only)
virtual void onStickLeft() {} // (System Applets only)
virtual void onStickRight() {} // (System Applets only)

virtual bool approveNotification(Notification &n); // Allow an applet to veto a notification

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD

#include "./AlignStickApplet.h"

using namespace NicheGraphics;

InkHUD::AlignStickApplet::AlignStickApplet()
{
if (!settings->joystick.aligned)
bringToForeground();
}

void InkHUD::AlignStickApplet::onRender()
{
setFont(fontMedium);
printAt(0, 0, "Align Joystick:");
setFont(fontSmall);
std::string instructions = "Move joystick in the direction indicated";
printWrapped(0, fontMedium.lineHeight() * 1.5, width(), instructions);

// Size of the region in which the joystick graphic should fit
uint16_t joyXLimit = X(0.8);
uint16_t contentH = fontMedium.lineHeight() * 1.5 + fontSmall.lineHeight() * 1;
if (getTextWidth(instructions) > width())
contentH += fontSmall.lineHeight();
uint16_t freeY = height() - contentH - fontSmall.lineHeight() * 1.2;
uint16_t joyYLimit = freeY * 0.8;

// Use the shorter of the two
uint16_t joyWidth = joyXLimit < joyYLimit ? joyXLimit : joyYLimit;

// Center the joystick graphic
uint16_t centerX = X(0.5);
uint16_t centerY = contentH + freeY * 0.5;

// Draw joystick graphic
drawStick(centerX, centerY, joyWidth);

setFont(fontSmall);
printAt(X(0.5), Y(1.0) - fontSmall.lineHeight() * 0.2, "Long press to skip", CENTER, BOTTOM);
}

// Draw a scalable joystick graphic
void InkHUD::AlignStickApplet::drawStick(uint16_t centerX, uint16_t centerY, uint16_t width)
{
if (width < 9) // too small to draw
return;

else if (width < 40) { // only draw up arrow
uint16_t chamfer = width < 20 ? 1 : 2;

// Draw filled up arrow
drawDirection(centerX, centerY - width / 4, Direction::UP, width, chamfer, BLACK);

} else { // large enough to draw the full thing
uint16_t chamfer = width < 80 ? 1 : 2;
uint16_t stroke = 3; // pixels
uint16_t arrowW = width * 0.22;
uint16_t hollowW = arrowW - stroke * 2;

// Draw center circle
fillCircle((int16_t)centerX, (int16_t)centerY, (int16_t)(width * 0.2), BLACK);
fillCircle((int16_t)centerX, (int16_t)centerY, (int16_t)(width * 0.2) - stroke, WHITE);

// Draw filled up arrow
drawDirection(centerX, centerY - width / 2, Direction::UP, arrowW, chamfer, BLACK);

// Draw down arrow
drawDirection(centerX, centerY + width / 2, Direction::DOWN, arrowW, chamfer, BLACK);
drawDirection(centerX, centerY + width / 2 - stroke, Direction::DOWN, hollowW, 0, WHITE);

// Draw left arrow
drawDirection(centerX - width / 2, centerY, Direction::LEFT, arrowW, chamfer, BLACK);
drawDirection(centerX - width / 2 + stroke, centerY, Direction::LEFT, hollowW, 0, WHITE);

// Draw right arrow
drawDirection(centerX + width / 2, centerY, Direction::RIGHT, arrowW, chamfer, BLACK);
drawDirection(centerX + width / 2 - stroke, centerY, Direction::RIGHT, hollowW, 0, WHITE);
}
}

// Draw a scalable joystick direction arrow
// a right-triangle with blunted tips
/*
_ <--point
^ / \
| / \
size / \
| / \
v |_________|

*/
void InkHUD::AlignStickApplet::drawDirection(uint16_t pointX, uint16_t pointY, Direction direction, uint16_t size,
uint16_t chamfer, Color color)
{
uint16_t chamferW = chamfer * 2 + 1;
uint16_t triangleW = size - chamferW;

// Draw arrow
switch (direction) {
case Direction::UP:
fillRect(pointX - chamfer, pointY, chamferW, triangleW, color);
fillRect(pointX - chamfer - triangleW, pointY + triangleW, chamferW + triangleW * 2, chamferW, color);
fillTriangle(pointX - chamfer, pointY, pointX - chamfer - triangleW, pointY + triangleW, pointX - chamfer,
pointY + triangleW, color);
fillTriangle(pointX + chamfer, pointY, pointX + chamfer + triangleW, pointY + triangleW, pointX + chamfer,
pointY + triangleW, color);
break;
case Direction::DOWN:
fillRect(pointX - chamfer, pointY - triangleW + 1, chamferW, triangleW, color);
fillRect(pointX - chamfer - triangleW, pointY - size + 1, chamferW + triangleW * 2, chamferW, color);
fillTriangle(pointX - chamfer, pointY, pointX - chamfer - triangleW, pointY - triangleW, pointX - chamfer,
pointY - triangleW, color);
fillTriangle(pointX + chamfer, pointY, pointX + chamfer + triangleW, pointY - triangleW, pointX + chamfer,
pointY - triangleW, color);
break;
case Direction::LEFT:
fillRect(pointX, pointY - chamfer, triangleW, chamferW, color);
fillRect(pointX + triangleW, pointY - chamfer - triangleW, chamferW, chamferW + triangleW * 2, color);
fillTriangle(pointX, pointY - chamfer, pointX + triangleW, pointY - chamfer - triangleW, pointX + triangleW,
pointY - chamfer, color);
fillTriangle(pointX, pointY + chamfer, pointX + triangleW, pointY + chamfer + triangleW, pointX + triangleW,
pointY + chamfer, color);
break;
case Direction::RIGHT:
fillRect(pointX - triangleW + 1, pointY - chamfer, triangleW, chamferW, color);
fillRect(pointX - size + 1, pointY - chamfer - triangleW, chamferW, chamferW + triangleW * 2, color);
fillTriangle(pointX, pointY - chamfer, pointX - triangleW, pointY - chamfer - triangleW, pointX - triangleW,
pointY - chamfer, color);
fillTriangle(pointX, pointY + chamfer, pointX - triangleW, pointY + chamfer + triangleW, pointX - triangleW,
pointY + chamfer, color);
break;
}
}

void InkHUD::AlignStickApplet::onForeground()
{
// Prevent most other applets from requesting update, and skip their rendering entirely
// Another system applet with a higher precedence can potentially ignore this
SystemApplet::lockRendering = true;
SystemApplet::lockRequests = true;

handleInput = true; // Intercept the button input for our applet
}

void InkHUD::AlignStickApplet::onBackground()
{
// Allow normal update behavior to resume
SystemApplet::lockRendering = false;
SystemApplet::lockRequests = false;
SystemApplet::handleInput = false;

// Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background
// Usually, onBackground is followed by another applet's onForeground (which requests update), but not in this case
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onButtonLongPress()
{
sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onStickCenterLong()
{
sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onStickUp()
{
settings->joystick.aligned = true;

sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onStickDown()
{
inkhud->rotateJoystick(2); // 180 deg
settings->joystick.aligned = true;

sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onStickLeft()
{
inkhud->rotateJoystick(3); // 270 deg
settings->joystick.aligned = true;

sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

void InkHUD::AlignStickApplet::onStickRight()
{
inkhud->rotateJoystick(1); // 90 deg
settings->joystick.aligned = true;

sendToBackground();
inkhud->forceUpdate(EInk::UpdateTypes::FULL);
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifdef MESHTASTIC_INCLUDE_INKHUD

/*

System Applet for manually aligning the joystick with the screen

should be run at startup if the joystick is enabled
and not aligned to the screen

*/

#pragma once

#include "configuration.h"

#include "graphics/niche/InkHUD/SystemApplet.h"

namespace NicheGraphics::InkHUD
{

class AlignStickApplet : public SystemApplet
{
public:
AlignStickApplet();

void onRender() override;
void onForeground() override;
void onBackground() override;
void onButtonLongPress() override;
void onStickCenterLong() override;
void onStickUp() override;
void onStickDown() override;
void onStickLeft() override;
void onStickRight() override;

protected:
enum Direction {
UP,
DOWN,
LEFT,
RIGHT,
};

void drawStick(uint16_t centerX, uint16_t centerY, uint16_t width);
void drawDirection(uint16_t pointX, uint16_t pointY, Direction direction, uint16_t size, uint16_t chamfer, Color color);
};

} // namespace NicheGraphics::InkHUD

#endif
1 change: 1 addition & 0 deletions src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum MenuAction {
TOGGLE_AUTOSHOW_APPLET,
SET_RECENTS,
ROTATE,
ALIGN_JOYSTICK,
LAYOUT,
TOGGLE_BATTERY_ICON,
TOGGLE_NOTIFICATIONS,
Expand Down
Loading
Loading