CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
PinChangeView.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
23class PinChangeView : public ViewBase {
24public:
25 static constexpr uint8_t MAX_PIN_LENGTH = 16;
26 static constexpr uint32_t MESSAGE_DISPLAY_MS = 2000;
27
28 enum class Step : uint8_t {
29 CURRENT_PIN, // Enter current PIN
30 NEW_PIN, // Enter new PIN
31 CONFIRM_PIN // Confirm new PIN
32 };
33
38 using CompleteCallback = void(*)(bool success);
39 using VerifyCallback = bool(*)(const char* pin);
40 using ChangeCallback = bool(*)(const char* currentPin, const char* newPin);
41 using RetriesCallback = uint8_t(*)();
42 using BlockedCallback = bool(*)();
43
49 void init(uint8_t minLength = 4, uint8_t maxLength = 16);
50
54 void setOnComplete(CompleteCallback callback) { onComplete_ = callback; }
55 void setVerifyCallback(VerifyCallback callback) { onVerify_ = callback; }
56 void setChangeCallback(ChangeCallback callback) { onChange_ = callback; }
57 void setRetriesCallback(RetriesCallback callback) { onRetries_ = callback; }
58 void setBlockedCallback(BlockedCallback callback) { onBlocked_ = callback; }
59 void setTitle(const char* title) { title_ = title; }
60
64 Step getStep() const { return step_; }
65
69 uint8_t getRetriesRemaining() const;
70
71 // IView implementation
72 void onEnter(void* context) override;
73 void render(bool partial) override;
74 InputResult onKey(char key) override;
75 void onTick(uint32_t nowMs) override;
76 const char* getName() const override { return "PinChangeView"; }
77 const char* getFooterHint() const override;
78
79private:
80 Step step_ = Step::CURRENT_PIN;
81 char currentPin_[MAX_PIN_LENGTH + 1] = {};
82 char newPin_[MAX_PIN_LENGTH + 1] = {};
83 char confirmPin_[MAX_PIN_LENGTH + 1] = {};
84 uint8_t length_ = 0;
85 uint8_t minLength_ = 4;
86 uint8_t maxLength_ = 16;
87 const char* message_ = nullptr;
88 uint32_t messageShownMs_ = 0;
89 bool pinChanged_ = false;
90
91 CompleteCallback onComplete_ = nullptr;
92 VerifyCallback onVerify_ = nullptr;
93 ChangeCallback onChange_ = nullptr;
94 RetriesCallback onRetries_ = nullptr;
95 BlockedCallback onBlocked_ = nullptr;
96 const char* title_ = nullptr;
97
98 void addDigit(char digit);
99 void backspace();
100 void confirmStep();
101 void showMessage(const char* msg);
102 void clearBuffer();
103 char* getCurrentBuffer();
104 const char* getStepTitle() const;
105};
106
107} // namespace cdc::ui
void setOnComplete(CompleteCallback callback)
void setBlockedCallback(BlockedCallback callback)
InputResult onKey(char key) override
Handles key input for PIN-change flow.
void setVerifyCallback(VerifyCallback callback)
const char * getFooterHint() const override
Returns localized footer hint text.
void setRetriesCallback(RetriesCallback callback)
const char * getName() const override
void setChangeCallback(ChangeCallback callback)
uint8_t(*)() RetriesCallback
void init(uint8_t minLength=4, uint8_t maxLength=16)
Initializes PIN-change wizard state.
void(*)(bool success) CompleteCallback
void setTitle(const char *title)
bool(*)(const char *pin) VerifyCallback
static constexpr uint8_t MAX_PIN_LENGTH
static constexpr uint32_t MESSAGE_DISPLAY_MS
void onEnter(void *context) override
Resets wizard state when entering the view.
uint8_t getRetriesRemaining() const
Returns remaining retry count for current PIN verification.
bool(*)(const char *currentPin, const char *newPin) ChangeCallback
void onTick(uint32_t nowMs) override
Handles message timeout and completion callbacks.
Centralized key-code constants for cdc_views.
Definition IModule.h:8
InputResult
Definition IView.h:10