27#define DIGIT_HEIGHT 12
28#define DIGIT_OFFSET_X 13
29#define DIGIT_OFFSET_Y ((KEYPAD_HEIGHT - DIGIT_HEIGHT) / 2)
30#define INIT_DIGIT_VALUE 5
56static char positionToChar(uint8_t pos)
65 return 0x30 + (pos - 1);
75 rectArea.backgroundColor =
BLACK;
76 rectArea.x0 = keypad->obj.area.x0;
77 rectArea.y0 = keypad->obj.area.y0;
78 rectArea.width = keypad->obj.area.width;
79 rectArea.height = keypad->obj.area.height;
82 rectArea.backgroundColor =
BLACK;
83 rectArea.y0 = keypad->obj.area.y0 + DIGIT_OFFSET_Y;
86 for (i = 0; i < 10; i++) {
87 rectArea.width = digits_icons[i]->width;
88 rectArea.height = digits_icons[i]->height;
90 rectArea.x0 = keypad->obj.area.x0 + DIGIT_OFFSET_X + i *
KEY_WIDTH;
94 if (keypad->enableBackspace) {
95 rectArea.width = C_icon_backspace.width;
96 rectArea.height = C_icon_backspace.height;
97 rectArea.x0 = keypad->obj.area.x0;
98 rectArea.y0 = keypad->obj.area.y0 + ((KEYPAD_HEIGHT - C_icon_backspace.height) / 2);
103 if (keypad->enableValidate) {
104 rectArea.width = C_digit_validate_bold.width;
105 rectArea.height = C_digit_validate_bold.height;
106 rectArea.x0 = keypad->obj.area.x0 + KEYPAD_WIDTH - C_digit_validate_bold.width;
107 rectArea.y0 = keypad->obj.area.y0 + ((KEYPAD_HEIGHT - C_digit_validate_bold.height) / 2);
116 rectArea.backgroundColor =
WHITE;
118 if (keypad->selectedKey == 0) {
119 rectArea.x0 = keypad->obj.area.x0;
121 else if (keypad->selectedKey < 11) {
122 rectArea.x0 = keypad->obj.area.x0 + DIGIT_OFFSET_X + (keypad->selectedKey - 1) *
KEY_WIDTH;
124 else if (keypad->selectedKey == 11) {
125 rectArea.x0 = keypad->obj.area.x0 + KEYPAD_WIDTH - C_digit_validate_bold.width;
130 rectArea.y0 = keypad->obj.area.y0 + keypad->obj.area.height - 2;
140 rectArea.backgroundColor =
WHITE;
142 if (keypad->selectedKey == 0) {
143 rectArea.x0 = keypad->obj.area.x0;
145 else if (keypad->selectedKey < 11) {
146 rectArea.x0 = keypad->obj.area.x0 + DIGIT_OFFSET_X + (keypad->selectedKey - 1) *
KEY_WIDTH;
148 else if (keypad->selectedKey == 11) {
149 rectArea.x0 = keypad->obj.area.x0 + KEYPAD_WIDTH - C_digit_validate_bold.width;
154 rectArea.y0 = keypad->obj.area.y0;
163 if (!keypad->shuffled) {
164 keypad->selectedKey = 1 + INIT_DIGIT_VALUE;
168 keypad->selectedKey = cx_rng_u32_range(1, 11);
191 keypadDrawSelectedTouched(keypad);
194 keypad->callback(positionToChar(keypad->selectedKey));
198 switch (keypad->selectedKey) {
200 if (keypad->enableBackspace) {
201 keypad->selectedKey = 0;
204 keypad->selectedKey = 10;
208 if (keypad->enableValidate) {
209 keypad->selectedKey = 11;
212 keypad->selectedKey = 10;
216 keypad->selectedKey--;
223 switch (keypad->selectedKey) {
225 if (keypad->enableValidate) {
226 keypad->selectedKey = 11;
228 else if (keypad->enableBackspace) {
229 keypad->selectedKey = 0;
232 keypad->selectedKey = 1;
236 keypad->selectedKey = 0;
239 keypad->selectedKey++;
256 keypadDrawDigits(keypad);
257 if (keypad->selectedKey == 0xFF) {
258 keypadInitSelected(keypad);
260 keypadDrawSelected(keypad);
Random Number Generation.
#define LOG_DEBUG(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
Font screen low-Level driver API, to draw elementary forms.
void nbgl_frontDrawImage(const nbgl_area_t *area, const uint8_t *buffer, nbgl_transformation_t transformation, nbgl_color_map_t colorMap)
void nbgl_frontRefreshArea(const nbgl_area_t *area, nbgl_refresh_mode_t mode, nbgl_post_refresh_t post_refresh)
void nbgl_frontDrawRect(const nbgl_area_t *area)
API to draw all basic graphic objects.
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
@ BUTTON_BOTH_TOUCHED
Sent when both buttons are touched.
@ BUTTON_LEFT_CONTINUOUS_PRESSED
@ BUTTON_BOTH_PRESSED
Sent when both buttons are released.
@ BUTTON_RIGHT_CONTINUOUS_PRESSED
@ BUTTON_LEFT_PRESSED
Sent when Left button is released.
@ BUTTON_RIGHT_PRESSED
Send when Right button is released.
void nbgl_objDrawKeypad(nbgl_keypad_t *kbd)
This function draws a keypad object.
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
void nbgl_screenRedraw(void)
This function redraws the whole screen on top of stack and its children.
@ POST_REFRESH_KEEP_POWER_STATE
Keep state after refresh.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define NO_TRANSFORMATION
@ NBGL_BPP_1
1 bit per pixel
struct PACKED__ nbgl_area_s nbgl_area_t
Represents a rectangle area of the screen.
@ FULL_COLOR_CLEAN_REFRESH
to be used for lock screen display (cleaner but longer refresh)