CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
T9InputView.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_ui/IView.h"
4#include <cstdint>
5
6namespace cdc::ui {
7
20class T9InputView : public ViewBase {
21public:
22 static constexpr uint16_t MAX_TEXT_LEN = 320;
23 static constexpr uint32_t TIMEOUT_MS = 2000; // Time before character is committed
24
29 using SaveCallback = void(*)(const char* text);
30
35 using CancelCallback = void(*)();
36
43 void init(const char* title, const char* initialText = nullptr, uint16_t maxLen = MAX_TEXT_LEN);
44
48 void setOnSave(SaveCallback callback) { onSave_ = callback; }
49
53 void setOnCancel(CancelCallback callback) { onCancel_ = callback; }
54
58 const char* getText() const { return text_; }
59
63 uint16_t getLength() const { return len_; }
64
68 void setPlaceholder(const char* placeholder) { placeholder_ = placeholder; }
69
73 void setHint(const char* hint) { hintOverride_ = hint; }
74
78 void forceDigit(char key);
79
84 uint16_t appendRaw(const char* text);
85
86 // IView implementation
87 void render(bool partial) override;
88 InputResult onKey(char key) override;
89 InputResult onLongPress(char key) override;
90 void onTick(uint32_t nowMs) override;
91 const char* getName() const override { return "T9InputView"; }
92 const char* getFooterHint() const override;
93
94protected:
95 static constexpr uint16_t TITLE_MAX_LEN = 48;
96 char titleBuf_[TITLE_MAX_LEN + 1] = {0};
97 const char* title_ = nullptr;
98 const char* placeholder_ = nullptr;
99 const char* hintOverride_ = nullptr;
100 char text_[MAX_TEXT_LEN + 1] = {0};
101 uint16_t len_ = 0;
105
106 // T9 state
107 char lastKey_ = 0;
108 uint8_t charIndex_ = 0;
109 uint32_t lastPressMs_ = 0;
110 bool cursorActive_ = false;
111
112 bool processKey(char key);
113 void backspace();
114 void commitCharacter();
115
116 // T9 helpers
117 static char getChar(char key, uint8_t index);
118 static uint8_t getCharCount(char key);
119};
120
121// ============================================================================
122// Convenience Functions
123// ============================================================================
124
139T9InputView* showT9Input(const char* title, const char* initialText,
140 T9InputView::SaveCallback onSave, uint16_t maxLen = 128);
141
142} // namespace cdc::ui
const char * placeholder_
Definition T9InputView.h:98
uint16_t getLength() const
Definition T9InputView.h:63
void backspace()
Removes the last character from the input buffer.
const char * getText() const
Definition T9InputView.h:58
void setOnCancel(CancelCallback callback)
Definition T9InputView.h:53
void commitCharacter()
Commits the currently active multi-tap character.
void(*)(const char *text) SaveCallback
Definition T9InputView.h:29
const char * getName() const override
Definition T9InputView.h:91
char text_[MAX_TEXT_LEN+1]
InputResult onLongPress(char key) override
Handles long-press actions for clear and forced digit insertion.
char titleBuf_[TITLE_MAX_LEN+1]
Definition T9InputView.h:96
void(*)() CancelCallback
Definition T9InputView.h:35
SaveCallback onSave_
void setOnSave(SaveCallback callback)
Definition T9InputView.h:48
const char * getFooterHint() const override
Returns localized footer hint text.
void init(const char *title, const char *initialText=nullptr, uint16_t maxLen=MAX_TEXT_LEN)
Initializes T9 input state and optional initial text.
static constexpr uint32_t TIMEOUT_MS
Definition T9InputView.h:23
static constexpr uint16_t MAX_TEXT_LEN
Definition T9InputView.h:22
void setHint(const char *hint)
Definition T9InputView.h:73
bool processKey(char key)
Processes a numeric key press using multi-tap logic.
CancelCallback onCancel_
const char * hintOverride_
Definition T9InputView.h:99
uint16_t appendRaw(const char *text)
void setPlaceholder(const char *placeholder)
Definition T9InputView.h:68
void forceDigit(char key)
Inserts a numeric digit literally, bypassing multi-tap mapping.
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.
void onTick(uint32_t nowMs) override
Handles timeout-based commit for active multi-tap input.
const char * title_
Definition T9InputView.h:97
InputResult onKey(char key) override
Handles key input for save, backspace, and digit entry.
static constexpr uint16_t TITLE_MAX_LEN
Definition T9InputView.h:95
Centralized key-code constants for cdc_views.
Definition IModule.h:8
InputResult
Definition IView.h:10
T9InputView * showT9Input(const char *title, const char *initialText, T9InputView::SaveCallback onSave, uint16_t maxLen=128)
Shows a shared T9 input view instance.