|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <T9InputView.h>
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 |
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.
| using cdc::ui::T9InputView::CancelCallback = void(*)() |
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.
| using cdc::ui::T9InputView::SaveCallback = void(*)(const char* text) |
Save callback (called when Y is pressed)
| text | Final text |
Definition at line 29 of file T9InputView.h.
| 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().
|
protected |
Removes the last character from the input buffer.
Definition at line 161 of file T9InputView.cpp.
References cursorActive_, cdc::ui::ViewBase::dirty_, lastKey_, len_, and text_.
Referenced by onKey().
|
protected |
Commits the currently active multi-tap character.
Definition at line 221 of file T9InputView.cpp.
References cursorActive_, cdc::ui::ViewBase::dirty_, and lastKey_.
Referenced by appendRaw(), forceDigit(), onKey(), and onTick().
| void cdc::ui::T9InputView::forceDigit | ( | char | key | ) |
Inserts a numeric digit literally, bypassing multi-tap mapping.
Force insert a digit (for long-press handling)
| key | Numeric key ('0'..'9'). |
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().
|
staticprotected |
Returns the character for a key/index in the T9 mapping.
| key | Numeric key ('0'..'9'). |
| index | Character index within that key map. |
Definition at line 99 of file T9InputView.cpp.
References t9_chars.
Referenced by processKey().
|
staticprotected |
Returns the number of mapped characters for a key.
| key | Numeric key ('0'..'9'). |
Definition at line 111 of file T9InputView.cpp.
References t9_chars.
Referenced by processKey().
|
overridevirtual |
Returns localized footer hint text.
Reimplemented from cdc::ui::IView.
Definition at line 306 of file T9InputView.cpp.
References hintOverride_, and cdc::ui::tr().
Referenced by render().
|
inline |
|
inlineoverridevirtual |
|
inline |
| 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
| title | View title |
| initialText | Initial text (optional) |
| maxLen | Maximum text length (default MAX_TEXT_LEN) |
| title | View title text. |
| initialText | Initial text value. |
| maxLen | Maximum input length. |
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_.
|
overridevirtual |
Handles key input for save, backspace, and digit entry.
| key | Pressed key code. |
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_.
|
overridevirtual |
Handles long-press actions for clear and forced digit insertion.
| key | Long-pressed key code. |
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().
|
overridevirtual |
Handles timeout-based commit for active multi-tap input.
| nowMs | Current monotonic time in milliseconds. |
Reimplemented from cdc::ui::IView.
Definition at line 234 of file T9InputView.cpp.
References commitCharacter(), lastKey_, lastPressMs_, and TIMEOUT_MS.
|
protected |
Processes a numeric key press using multi-tap logic.
| key | Numeric key ('0'..'9'). |
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().
|
overridevirtual |
Renders title, text entry box, cursor state, and footer.
| partial | Indicates partial/full redraw mode. |
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.
|
inline |
Override footer hint for this instance. Pass nullptr to fall back to default.
Definition at line 73 of file T9InputView.h.
References hintOverride_.
|
inline |
Set cancel callback (called when the view is dismissed without confirming)
Definition at line 53 of file T9InputView.h.
References onCancel_.
|
inline |
Set save callback (called on Y key)
Definition at line 48 of file T9InputView.h.
References onSave_.
|
inline |
Set placeholder text (shown when empty)
Definition at line 68 of file T9InputView.h.
References placeholder_.
|
protected |
Definition at line 108 of file T9InputView.h.
Referenced by appendRaw(), init(), and processKey().
|
protected |
Definition at line 110 of file T9InputView.h.
Referenced by backspace(), commitCharacter(), init(), processKey(), cdc::ui::PasswordT9View::render(), and render().
|
protected |
Definition at line 99 of file T9InputView.h.
Referenced by getFooterHint(), init(), and setHint().
|
protected |
Definition at line 107 of file T9InputView.h.
Referenced by appendRaw(), backspace(), commitCharacter(), forceDigit(), init(), onTick(), and processKey().
|
protected |
Definition at line 109 of file T9InputView.h.
Referenced by init(), onTick(), and processKey().
|
protected |
Definition at line 101 of file T9InputView.h.
Referenced by appendRaw(), backspace(), forceDigit(), getLength(), init(), processKey(), cdc::ui::PasswordT9View::render(), and render().
|
staticconstexpr |
Definition at line 22 of file T9InputView.h.
Referenced by init(), and cdc::mod_vcard::pushCurrentStep().
|
protected |
Definition at line 102 of file T9InputView.h.
Referenced by appendRaw(), forceDigit(), init(), processKey(), cdc::ui::PasswordT9View::render(), and render().
|
protected |
Definition at line 104 of file T9InputView.h.
Referenced by init(), onLongPress(), and setOnCancel().
|
protected |
Definition at line 103 of file T9InputView.h.
Referenced by init(), onKey(), and setOnSave().
|
protected |
Definition at line 98 of file T9InputView.h.
Referenced by init(), cdc::ui::PasswordT9View::render(), render(), and setPlaceholder().
|
protected |
Definition at line 100 of file T9InputView.h.
Referenced by appendRaw(), backspace(), forceDigit(), getText(), init(), onKey(), processKey(), cdc::ui::PasswordT9View::render(), and render().
|
staticconstexpr |
Definition at line 23 of file T9InputView.h.
Referenced by onTick(), and processKey().
|
protected |
Definition at line 97 of file T9InputView.h.
Referenced by init(), cdc::ui::PasswordT9View::render(), and render().
|
staticconstexprprotected |
Definition at line 95 of file T9InputView.h.
Referenced by init().
|
protected |
Definition at line 96 of file T9InputView.h.
Referenced by init().