17#include <goodisplay/gdey029T94.h>
20static const char*
TAG =
"PinEntryView";
50 maxAttempts_ = maxAttempts;
72 memset(buffer_, 0,
sizeof(buffer_));
81void PinEntryView::addDigit(
char digit) {
82 if (length_ >= maxLength_ || lockedOut_)
return;
84 buffer_[length_++] = digit;
85 buffer_[length_] =
'\0';
93void PinEntryView::backspace() {
94 if (length_ > 0 && !lockedOut_) {
95 buffer_[--length_] =
'\0';
110 bool blocked =
pm.isBadgeBlocked();
111 if (blocked != lockedOut_) {
112 lockedOut_ = blocked;
118 static uint32_t lastUpdate = 0;
138void PinEntryView::verify() {
139 if (length_ < minLength_) {
154 bool valid = onVerify_(buffer_);
156 LOG_I(
TAG,
"PIN verified successfully");
162 LOG_W(
TAG,
"PIN verification failed, attempt %d", attempts_);
166 if (pm.isBadgeBlocked()) {
179 onFailure_(lockedOut_);
195 if (key >=
'0' && key <=
'9') {
227 return ui::tr(
"core.hint_pin_input");
242 auto* gfx =
static_cast<Gdey029T94*
>(
display->getNativeHandle());
248 const uint16_t width =
display->getWidth();
249 const uint16_t height =
display->getHeight();
252 gfx->fillScreen(EPD_WHITE);
255 gfx->setTextColor(EPD_BLACK);
265 int startX = (width - totalWidth) / 2;
267 for (uint8_t i = 0; i < maxLength_; i++) {
288 if (
pm.isBadgeBlocked()) {
289 uint32_t remainingMs =
pm.getLockoutRemainingMs();
290 uint32_t remainingSec = (remainingMs + 999) / 1000;
291 snprintf(statusStr,
sizeof(statusStr),
"%s: %lus",
ui::tr(
"core.locked_out"), remainingSec);
293 uint8_t retries =
pm.getBadgeRetries();
294 snprintf(statusStr,
sizeof(statusStr),
"%s: %d",
ui::tr(
"core.retries"), retries);
297 gfx->getTextBounds(statusStr, 0, 0, &x1, &y1, &w, &h);
298 gfx->setCursor((width - w) / 2,
RETRIES_Y);
330 uint8_t maxAttempts) {
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
static constexpr int PIN_DOT_SIZE
static constexpr int PIN_Y
static constexpr int PIN_DOT_SPACING
static constexpr int TITLE_Y
Display layout constants.
static constexpr uint32_t TOAST_DURATION_SHORT_MS
Toast message display durations in milliseconds.
static constexpr uint32_t LOCKOUT_REFRESH_MS
Refresh interval for the lockout countdown display.
static constexpr uint32_t TOAST_DURATION_LONG_MS
static constexpr int RETRIES_Y
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_W(tag, fmt,...)
#define LOG_I(tag, fmt,...)
#define LOG_E(tag, fmt,...)
static constexpr uint8_t BADGE_PIN_MIN
static PinManager & instance()
Returns singleton PIN manager instance.
uint32_t getLockoutRemainingMs() const
Returns remaining badge lockout duration.
void init(const char *title, uint8_t maxPinLength=6, uint8_t maxAttempts=3)
Initializes PIN entry configuration and clears current input.
static constexpr uint8_t MAX_PIN_LENGTH
InputResult onKey(char key) override
Handles key input for PIN entry and actions.
void onEnter(void *context) override
Resets entry state when the view is entered.
void render(bool partial) override
Renders PIN dots, status text, and footer hint.
void(*)() SuccessCallback
void onTick(uint32_t nowMs) override
Updates lockout state and periodic countdown refresh.
const char * getFooterHint() const override
Returns localized footer hint text.
void clear()
Clears the internal PIN buffer.
uint32_t getLockoutRemaining() const
Returns remaining lockout time.
bool(*)(const char *pin) VerifyCallback
static ViewStack & instance()
Returns singleton view-stack instance.
void push(IView *view, void *context=nullptr)
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
void printText(Gdey029T94 *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
static PinEntryView s_sharedPinEntry
Convenience factory/helper function.
static constexpr uint32_t TOAST_DURATION_LONG_MS
static constexpr char KEY_NO
Cancel / Back / Backspace.
static constexpr int TITLE_Y
Layout constants mirror the ones used by T9InputView.
PinEntryView * showPinEntry(const char *title, PinEntryView::VerifyCallback onVerify, PinEntryView::SuccessCallback onSuccess, uint8_t maxLength=6, uint8_t minLength=4, uint8_t maxAttempts=3)
Shows a shared PIN entry view instance.
static constexpr uint32_t TOAST_DURATION_SHORT_MS
static constexpr char KEY_YES
Confirm / OK / Save.
void showMessage(const char *message, MessageIcon icon=MessageIcon::NONE, uint32_t timeoutMs=0, MessageBox::CloseCallback onClose=nullptr)
Shows the shared modal message box.