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

#include <T9InputView.h>

Inheritance diagram for cdc::ui::T9InputView:
cdc::ui::ViewBase cdc::ui::IView cdc::ui::PasswordT9View

Public Types

using SaveCallback = void(*)(const char* text)
using CancelCallback = void(*)()

Public Member Functions

void init (const char *title, const char *initialText=nullptr, uint16_t maxLen=MAX_TEXT_LEN)
 Initializes T9 input state and optional initial text.
void setOnSave (SaveCallback callback)
void setOnCancel (CancelCallback callback)
const char * getText () const
uint16_t getLength () const
void setPlaceholder (const char *placeholder)
void setHint (const char *hint)
void forceDigit (char key)
 Inserts a numeric digit literally, bypassing multi-tap mapping.
uint16_t appendRaw (const char *text)
void render (bool partial) override
 Renders title, text entry box, cursor state, and footer.
InputResult onKey (char key) override
 Handles key input for save, backspace, and digit entry.
InputResult onLongPress (char key) override
 Handles long-press actions for clear and forced digit insertion.
void onTick (uint32_t nowMs) override
 Handles timeout-based commit for active multi-tap input.
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

Static Public Attributes

static constexpr uint16_t MAX_TEXT_LEN = 320
static constexpr uint32_t TIMEOUT_MS = 2000

Protected Member Functions

bool processKey (char key)
 Processes a numeric key press using multi-tap logic.
void backspace ()
 Removes the last character from the input buffer.
void commitCharacter ()
 Commits the currently active multi-tap character.
Protected Member Functions inherited from cdc::ui::ViewBase
void setTitle (const char *title)
const char * getTitle () const

Static Protected Member Functions

static char getChar (char key, uint8_t index)
 Returns the character for a key/index in the T9 mapping.
static uint8_t getCharCount (char key)
 Returns the number of mapped characters for a key.

Protected Attributes

char titleBuf_ [TITLE_MAX_LEN+1] = {0}
const char * title_ = nullptr
const char * placeholder_ = nullptr
const char * hintOverride_ = nullptr
char text_ [MAX_TEXT_LEN+1] = {0}
uint16_t len_ = 0
uint16_t maxLen_ = MAX_TEXT_LEN
SaveCallback onSave_ = nullptr
CancelCallback onCancel_ = nullptr
char lastKey_ = 0
uint8_t charIndex_ = 0
uint32_t lastPressMs_ = 0
bool cursorActive_ = false
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

Static Protected Attributes

static constexpr uint16_t TITLE_MAX_LEN = 48

Detailed Description

T9InputView - Multi-tap text input

Classic phone-style T9 text entry. Each number key cycles through characters on repeated press.

Keys: 0-9 = Character input (multi-tap) Long-press 0-9 = Insert digit directly N = Backspace (short) / Cancel (long) Y = Confirm (triggers callback)

Definition at line 20 of file T9InputView.h.

Member Typedef Documentation

◆ CancelCallback

Cancel callback (called when the user dismisses the view via long-press N). The view pops itself before this fires, so do not call pop() in the handler.

Definition at line 35 of file T9InputView.h.

◆ SaveCallback

using cdc::ui::T9InputView::SaveCallback = void(*)(const char* text)

Save callback (called when Y is pressed)

Parameters
textFinal text

Definition at line 29 of file T9InputView.h.

Member Function Documentation

◆ appendRaw()

uint16_t cdc::ui::T9InputView::appendRaw ( const char * text)

Append a raw string to the buffer (used by T9_PASTE serial command). Truncates at maxLen_. Returns number of bytes actually appended.

Definition at line 202 of file T9InputView.cpp.

References charIndex_, commitCharacter(), cdc::ui::ViewBase::dirty_, lastKey_, len_, maxLen_, and text_.

Referenced by cdc::serial::cmdPaste().

◆ backspace()

void cdc::ui::T9InputView::backspace ( )
protected

Removes the last character from the input buffer.

Returns
void

Definition at line 161 of file T9InputView.cpp.

References cursorActive_, cdc::ui::ViewBase::dirty_, lastKey_, len_, and text_.

Referenced by onKey().

◆ commitCharacter()

void cdc::ui::T9InputView::commitCharacter ( )
protected

Commits the currently active multi-tap character.

Returns
void

Definition at line 221 of file T9InputView.cpp.

References cursorActive_, cdc::ui::ViewBase::dirty_, and lastKey_.

Referenced by appendRaw(), forceDigit(), onKey(), and onTick().

◆ forceDigit()

void cdc::ui::T9InputView::forceDigit ( char key)

Inserts a numeric digit literally, bypassing multi-tap mapping.

Force insert a digit (for long-press handling)

Parameters
keyNumeric key ('0'..'9').
Returns
void

Definition at line 176 of file T9InputView.cpp.

References commitCharacter(), cdc::ui::ViewBase::dirty_, lastKey_, len_, LOG_D, maxLen_, cdc::ui::showToastError(), cdc::ui::TAG, text_, and cdc::ui::tr().

Referenced by onLongPress().

◆ getChar()

char cdc::ui::T9InputView::getChar ( char key,
uint8_t index )
staticprotected

Returns the character for a key/index in the T9 mapping.

Parameters
keyNumeric key ('0'..'9').
indexCharacter index within that key map.
Returns
Mapped character or \\0 if key is invalid.

Definition at line 99 of file T9InputView.cpp.

References t9_chars.

Referenced by processKey().

◆ getCharCount()

uint8_t cdc::ui::T9InputView::getCharCount ( char key)
staticprotected

Returns the number of mapped characters for a key.

Parameters
keyNumeric key ('0'..'9').
Returns
Number of mapped characters.

Definition at line 111 of file T9InputView.cpp.

References t9_chars.

Referenced by processKey().

◆ getFooterHint()

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

Returns localized footer hint text.

Returns
Footer hint string.

Reimplemented from cdc::ui::IView.

Definition at line 306 of file T9InputView.cpp.

References hintOverride_, and cdc::ui::tr().

Referenced by render().

◆ getLength()

uint16_t cdc::ui::T9InputView::getLength ( ) const
inline

Get current text length

Definition at line 63 of file T9InputView.h.

References len_.

◆ getName()

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

Get view name for debugging

Implements cdc::ui::IView.

Definition at line 91 of file T9InputView.h.

◆ getText()

const char * cdc::ui::T9InputView::getText ( ) const
inline

Get current text

Definition at line 58 of file T9InputView.h.

References text_.

◆ init()

void cdc::ui::T9InputView::init ( const char * title,
const char * initialText = nullptr,
uint16_t maxLen = MAX_TEXT_LEN )

Initializes T9 input state and optional initial text.

Initialize T9 input view

Parameters
titleView title
initialTextInitial text (optional)
maxLenMaximum text length (default MAX_TEXT_LEN)
titleView title text.
initialTextInitial text value.
maxLenMaximum input length.
Returns
void

Definition at line 58 of file T9InputView.cpp.

References charIndex_, cursorActive_, cdc::ui::ViewBase::dirty_, hintOverride_, lastKey_, lastPressMs_, len_, LOG_D, MAX_TEXT_LEN, maxLen_, onCancel_, onSave_, placeholder_, cdc::ui::TAG, text_, title_, TITLE_MAX_LEN, and titleBuf_.

◆ onKey()

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

Handles key input for save, backspace, and digit entry.

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

Implements cdc::ui::IView.

Definition at line 252 of file T9InputView.cpp.

References backspace(), commitCharacter(), cdc::ui::CONSUMED, cdc::ui::IGNORED, cdc::ui::ViewStack::instance(), cdc::ui::KEY_NO, cdc::ui::KEY_YES, onSave_, cdc::ui::ViewStack::pop(), processKey(), and text_.

◆ onLongPress()

InputResult cdc::ui::T9InputView::onLongPress ( char key)
overridevirtual

Handles long-press actions for clear and forced digit insertion.

Parameters
keyLong-pressed key code.
Returns
Input handling result for the view stack.

Reimplemented from cdc::ui::IView.

Definition at line 282 of file T9InputView.cpp.

References cdc::ui::CONSUMED, forceDigit(), cdc::ui::IGNORED, cdc::ui::ViewStack::instance(), cdc::ui::KEY_NO, onCancel_, and cdc::ui::ViewStack::pop().

Referenced by cdc::ui::PasswordT9View::onLongPress().

◆ onTick()

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

Handles timeout-based commit for active multi-tap input.

Parameters
nowMsCurrent monotonic time in milliseconds.
Returns
void

Reimplemented from cdc::ui::IView.

Definition at line 234 of file T9InputView.cpp.

References commitCharacter(), lastKey_, lastPressMs_, and TIMEOUT_MS.

◆ processKey()

bool cdc::ui::T9InputView::processKey ( char key)
protected

Processes a numeric key press using multi-tap logic.

Parameters
keyNumeric key ('0'..'9').
Returns
true if key was processed, otherwise false.

Definition at line 121 of file T9InputView.cpp.

References charIndex_, cursorActive_, cdc::ui::ViewBase::dirty_, getChar(), getCharCount(), lastKey_, lastPressMs_, len_, maxLen_, cdc::ui::showToastError(), text_, TIMEOUT_MS, and cdc::ui::tr().

Referenced by onKey().

◆ render()

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

Renders title, text entry box, cursor state, and footer.

Parameters
partialIndicates partial/full redraw mode.
Returns
void

Implements cdc::ui::IView.

Definition at line 315 of file T9InputView.cpp.

References cursorActive_, cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::ui::render::drawFooterBar(), cdc::ui::render::drawHeaderLeft(), cdc::hal::getDisplayInstance(), getFooterHint(), len_, maxLen_, placeholder_, cdc::ui::render::printText(), text_, cdc::ui::TEXT_MARGIN, cdc::ui::TEXT_Y, title_, and cdc::ui::TITLE_Y.

◆ setHint()

void cdc::ui::T9InputView::setHint ( const char * hint)
inline

Override footer hint for this instance. Pass nullptr to fall back to default.

Definition at line 73 of file T9InputView.h.

References hintOverride_.

◆ setOnCancel()

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

Set cancel callback (called when the view is dismissed without confirming)

Definition at line 53 of file T9InputView.h.

References onCancel_.

◆ setOnSave()

void cdc::ui::T9InputView::setOnSave ( SaveCallback callback)
inline

Set save callback (called on Y key)

Definition at line 48 of file T9InputView.h.

References onSave_.

◆ setPlaceholder()

void cdc::ui::T9InputView::setPlaceholder ( const char * placeholder)
inline

Set placeholder text (shown when empty)

Definition at line 68 of file T9InputView.h.

References placeholder_.

Member Data Documentation

◆ charIndex_

uint8_t cdc::ui::T9InputView::charIndex_ = 0
protected

Definition at line 108 of file T9InputView.h.

Referenced by appendRaw(), init(), and processKey().

◆ cursorActive_

bool cdc::ui::T9InputView::cursorActive_ = false
protected

◆ hintOverride_

const char* cdc::ui::T9InputView::hintOverride_ = nullptr
protected

Definition at line 99 of file T9InputView.h.

Referenced by getFooterHint(), init(), and setHint().

◆ lastKey_

char cdc::ui::T9InputView::lastKey_ = 0
protected

Definition at line 107 of file T9InputView.h.

Referenced by appendRaw(), backspace(), commitCharacter(), forceDigit(), init(), onTick(), and processKey().

◆ lastPressMs_

uint32_t cdc::ui::T9InputView::lastPressMs_ = 0
protected

Definition at line 109 of file T9InputView.h.

Referenced by init(), onTick(), and processKey().

◆ len_

uint16_t cdc::ui::T9InputView::len_ = 0
protected

◆ MAX_TEXT_LEN

uint16_t cdc::ui::T9InputView::MAX_TEXT_LEN = 320
staticconstexpr

Definition at line 22 of file T9InputView.h.

Referenced by init(), and cdc::mod_vcard::pushCurrentStep().

◆ maxLen_

uint16_t cdc::ui::T9InputView::maxLen_ = MAX_TEXT_LEN
protected

◆ onCancel_

CancelCallback cdc::ui::T9InputView::onCancel_ = nullptr
protected

Definition at line 104 of file T9InputView.h.

Referenced by init(), onLongPress(), and setOnCancel().

◆ onSave_

SaveCallback cdc::ui::T9InputView::onSave_ = nullptr
protected

Definition at line 103 of file T9InputView.h.

Referenced by init(), onKey(), and setOnSave().

◆ placeholder_

const char* cdc::ui::T9InputView::placeholder_ = nullptr
protected

Definition at line 98 of file T9InputView.h.

Referenced by init(), cdc::ui::PasswordT9View::render(), render(), and setPlaceholder().

◆ text_

char cdc::ui::T9InputView::text_[MAX_TEXT_LEN+1] = {0}
protected

◆ TIMEOUT_MS

uint32_t cdc::ui::T9InputView::TIMEOUT_MS = 2000
staticconstexpr

Definition at line 23 of file T9InputView.h.

Referenced by onTick(), and processKey().

◆ title_

const char* cdc::ui::T9InputView::title_ = nullptr
protected

Definition at line 97 of file T9InputView.h.

Referenced by init(), cdc::ui::PasswordT9View::render(), and render().

◆ TITLE_MAX_LEN

uint16_t cdc::ui::T9InputView::TITLE_MAX_LEN = 48
staticconstexprprotected

Definition at line 95 of file T9InputView.h.

Referenced by init().

◆ titleBuf_

char cdc::ui::T9InputView::titleBuf_[TITLE_MAX_LEN+1] = {0}
protected

Definition at line 96 of file T9InputView.h.

Referenced by init().


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