CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::ui::PinEntryView Class Reference

#include <PinEntryView.h>

Inheritance diagram for cdc::ui::PinEntryView:
cdc::ui::ViewBase cdc::ui::IView

Public Types

using VerifyCallback = bool(*)(const char* pin)
using SuccessCallback = void(*)()
using CancelCallback = void(*)()
using FailureCallback = void(*)(bool lockedOut)

Public Member Functions

void init (const char *title, uint8_t maxPinLength=6, uint8_t maxAttempts=3)
 Initializes PIN entry configuration and clears current input.
void setOnVerify (VerifyCallback callback)
void setOnSuccess (SuccessCallback callback)
void setOnCancel (CancelCallback callback)
void setOnFailure (FailureCallback callback)
void setShowMessages (bool enabled)
const char * getPin () const
uint8_t getAttempts () const
bool isLockedOut () const
void clear ()
 Clears the internal PIN buffer.
void resetAttempts ()
void setMinLength (uint8_t minLen)
uint32_t getLockoutRemaining () const
 Returns remaining lockout time.
void onEnter (void *context) override
 Resets entry state when the view is entered.
void onTick (uint32_t nowMs) override
 Updates lockout state and periodic countdown refresh.
void render (bool partial) override
 Renders PIN dots, status text, and footer hint.
InputResult onKey (char key) override
 Handles key input for PIN entry and actions.
const char * getName () const override
const char * getFooterHint () const override
 Returns localized footer hint text.
Public Member Functions inherited from cdc::ui::ViewBase
virtual ~ViewBase ()=default
void onEnter (void *context) override
void onExit () override
void onResume () override
void onPause () override
void setLifecycleHooks (void(*onHide)(void *), void(*onShow)(void *), void *userData) override
bool needsRender () const override
void markDirty () override
void clearDirty () override
void setFooterHint (const char *hint) override
const char * getFooterHint () const override
Public Member Functions inherited from cdc::ui::IView
virtual ~IView ()=default
virtual bool prefersLightRefresh () const
virtual InputResult onLongPress (char key)

Static Public Attributes

static constexpr uint8_t MAX_PIN_LENGTH = 8
static constexpr uint32_t LOCKOUT_DURATION_MS = 60000

Additional Inherited Members

Protected Member Functions inherited from cdc::ui::ViewBase
void setTitle (const char *title)
const char * getTitle () const
Protected Attributes inherited from cdc::ui::ViewBase
bool dirty_ = true
const char * title_ = nullptr
const char * customFooter_ = nullptr
void(* onHide_ )(void *) = nullptr
void(* onShow_ )(void *) = nullptr
void * lifecycleUserData_ = nullptr

Detailed Description

PinEntryView - Secure PIN code input

Displays PIN entry with masked digits. Supports configurable length and max attempts. Errors are shown via MessageBox overlay.

Keys: 0-9 = Add digit N = Backspace (short) / Cancel (empty) Y = Confirm and verify PIN

Definition at line 20 of file PinEntryView.h.

Member Typedef Documentation

◆ CancelCallback

Cancel callback (called when N is pressed with empty PIN)

Definition at line 40 of file PinEntryView.h.

◆ FailureCallback

using cdc::ui::PinEntryView::FailureCallback = void(*)(bool lockedOut)

Failure callback (called after invalid PIN)

Parameters
lockedOutTrue if device is now locked out

Definition at line 46 of file PinEntryView.h.

◆ SuccessCallback

PIN success callback

Definition at line 35 of file PinEntryView.h.

◆ VerifyCallback

using cdc::ui::PinEntryView::VerifyCallback = bool(*)(const char* pin)

PIN complete callback

Parameters
pinThe entered PIN
Returns
true if PIN is correct, false otherwise

Definition at line 30 of file PinEntryView.h.

Member Function Documentation

◆ clear()

void cdc::ui::PinEntryView::clear ( )

Clears the internal PIN buffer.

Clear PIN and reset state

Returns
void

Definition at line 71 of file PinEntryView.cpp.

Referenced by init(), and onEnter().

◆ getAttempts()

uint8_t cdc::ui::PinEntryView::getAttempts ( ) const
inline

Get current attempt count

Definition at line 89 of file PinEntryView.h.

◆ getFooterHint()

const char * cdc::ui::PinEntryView::getFooterHint ( ) const
overridevirtual

Returns localized footer hint text.

Returns
Footer hint string.

Reimplemented from cdc::ui::IView.

Definition at line 226 of file PinEntryView.cpp.

References cdc::ui::tr().

Referenced by render().

◆ getLockoutRemaining()

uint32_t cdc::ui::PinEntryView::getLockoutRemaining ( ) const

Returns remaining lockout time.

Get remaining lockout time in seconds (0 if not locked)

Returns
Remaining lockout duration in milliseconds.

Definition at line 130 of file PinEntryView.cpp.

References cdc::core::PinManager::getLockoutRemainingMs(), and cdc::core::PinManager::instance().

◆ getName()

const char * cdc::ui::PinEntryView::getName ( ) const
inlineoverridevirtual

Get view name for debugging

Implements cdc::ui::IView.

Definition at line 122 of file PinEntryView.h.

◆ getPin()

const char * cdc::ui::PinEntryView::getPin ( ) const
inline

Get current PIN

Definition at line 84 of file PinEntryView.h.

◆ init()

void cdc::ui::PinEntryView::init ( const char * title,
uint8_t maxPinLength = 6,
uint8_t maxAttempts = 3 )

Initializes PIN entry configuration and clears current input.

Initialize PIN entry view

Parameters
titleTitle text
maxPinLengthMaximum PIN length (default 6)
maxAttemptsMaximum attempts before lockout (0 = unlimited)
titleTitle text shown in the view.
maxPinLengthMaximum accepted PIN length.
maxAttemptsMaximum allowed attempts before lockout handling.
Returns
void

Definition at line 47 of file PinEntryView.cpp.

References cdc::core::PinManager::BADGE_PIN_MIN, clear(), cdc::ui::ViewBase::dirty_, and MAX_PIN_LENGTH.

◆ isLockedOut()

bool cdc::ui::PinEntryView::isLockedOut ( ) const
inline

Check if locked out

Definition at line 94 of file PinEntryView.h.

◆ onEnter()

void cdc::ui::PinEntryView::onEnter ( void * context)
overridevirtual

Resets entry state when the view is entered.

Parameters
contextOptional view context (unused).
Returns
void

Implements cdc::ui::IView.

Definition at line 61 of file PinEntryView.cpp.

References clear(), and cdc::ui::ViewBase::dirty_.

◆ onKey()

InputResult cdc::ui::PinEntryView::onKey ( char key)
overridevirtual

Handles key input for PIN entry and actions.

Parameters
keyPressed key code.
Returns
Input handling result for the view stack.

Implements cdc::ui::IView.

Definition at line 189 of file PinEntryView.cpp.

References cdc::ui::CONSUMED, cdc::ui::IGNORED, cdc::ui::KEY_NO, cdc::ui::KEY_YES, and cdc::ui::REQUEST_POP.

◆ onTick()

void cdc::ui::PinEntryView::onTick ( uint32_t nowMs)
overridevirtual

Updates lockout state and periodic countdown refresh.

Parameters
nowMsCurrent monotonic time in milliseconds.
Returns
void

Reimplemented from cdc::ui::IView.

Definition at line 105 of file PinEntryView.cpp.

References cdc::ui::ViewBase::dirty_, cdc::core::PinManager::instance(), and LOCKOUT_REFRESH_MS.

◆ render()

void cdc::ui::PinEntryView::render ( bool partial)
overridevirtual

◆ resetAttempts()

void cdc::ui::PinEntryView::resetAttempts ( )
inline

Reset attempt counter

Definition at line 104 of file PinEntryView.h.

◆ setMinLength()

void cdc::ui::PinEntryView::setMinLength ( uint8_t minLen)
inline

Set minimum PIN length required (default 1) Y will only work if length >= minLength

Definition at line 110 of file PinEntryView.h.

◆ setOnCancel()

void cdc::ui::PinEntryView::setOnCancel ( CancelCallback callback)
inline

Set cancel callback (optional)

Definition at line 69 of file PinEntryView.h.

◆ setOnFailure()

void cdc::ui::PinEntryView::setOnFailure ( FailureCallback callback)
inline

Set failure callback (optional)

Definition at line 74 of file PinEntryView.h.

◆ setOnSuccess()

void cdc::ui::PinEntryView::setOnSuccess ( SuccessCallback callback)
inline

Set success callback (called after successful verify)

Definition at line 64 of file PinEntryView.h.

◆ setOnVerify()

void cdc::ui::PinEntryView::setOnVerify ( VerifyCallback callback)
inline

Set verify callback (called when Y is pressed)

Definition at line 59 of file PinEntryView.h.

◆ setShowMessages()

void cdc::ui::PinEntryView::setShowMessages ( bool enabled)
inline

Suppress internal error messages (caller handles feedback)

Definition at line 79 of file PinEntryView.h.

Member Data Documentation

◆ LOCKOUT_DURATION_MS

uint32_t cdc::ui::PinEntryView::LOCKOUT_DURATION_MS = 60000
staticconstexpr

Definition at line 23 of file PinEntryView.h.

◆ MAX_PIN_LENGTH

uint8_t cdc::ui::PinEntryView::MAX_PIN_LENGTH = 8
staticconstexpr

Definition at line 22 of file PinEntryView.h.

Referenced by init().


The documentation for this class was generated from the following files: