Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_layout_keypad_nanos.c
Go to the documentation of this file.
1
6#ifndef HAVE_SE_TOUCH
7#ifdef NBGL_KEYPAD
8/*********************
9 * INCLUDES
10 *********************/
11#include <string.h>
12#include <stdlib.h>
13#include "nbgl_debug.h"
15#include "glyphs.h"
16#include "os_pic.h"
17#include "os_helpers.h"
18#include "lcx_rng.h"
19
20/*********************
21 * DEFINES
22 *********************/
23
24/**********************
25 * MACROS
26 **********************/
27
28/**********************
29 * TYPEDEFS
30 **********************/
31
32/**********************
33 * VARIABLES
34 **********************/
35
36/**********************
37 * STATIC PROTOTYPES
38 **********************/
39
40/**********************
41 * PROTOTYPES
42 **********************/
43
44/**********************
45 * GLOBAL FUNCTIONS
46 **********************/
47
60 keyboardCallback_t callback,
61 const char *text,
62 bool shuffled)
63{
64 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
65 nbgl_keypad_t *keypad;
66 nbgl_text_area_t *textArea;
67
68 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddKeypad():\n");
69 if (layout == NULL) {
70 return -1;
71 }
72
73 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
74 textArea->textColor = WHITE;
75 textArea->text = PIC(text);
76 textArea->textAlignment = CENTER;
78 textArea->obj.area.width = AVAILABLE_WIDTH;
79 textArea->obj.area.height = 12;
80 textArea->wrapping = false;
81 textArea->obj.alignment = TOP_MIDDLE;
82 textArea->obj.alignmentMarginY = 3;
83 // set this new obj as child of main container
84 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
85
86 // create keypad
87 keypad = (nbgl_keypad_t *) nbgl_objPoolGet(KEYPAD, layoutInt->layer);
88 keypad->obj.alignment = BOTTOM_MIDDLE;
89 keypad->obj.alignmentMarginY = 6;
90 keypad->obj.alignTo = NULL;
91 keypad->callback = PIC(callback);
92 keypad->enableBackspace = false;
93 keypad->enableValidate = false;
94 keypad->selectedKey = 0xFF; // to be picked
95 keypad->shuffled = shuffled;
96 // set this new keypad as child of the container
97 layoutAddObject(layoutInt, (nbgl_obj_t *) keypad);
98
99 // return index of keypad to be modified later on
100 return (layoutInt->nbChildren - 1);
101}
102
113 uint8_t index,
114 bool enableValidate,
115 bool enableBackspace)
116{
117 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
118 nbgl_keypad_t *keypad;
119
121 "nbgl_layoutUpdateKeypad(): enableValidate = %d, enableBackspace = %d\n",
122 enableValidate,
123 enableBackspace);
124 if (layout == NULL) {
125 return -1;
126 }
127
128 // get existing keypad
129 keypad = (nbgl_keypad_t *) layoutInt->children[index];
130 if ((keypad == NULL) || (keypad->obj.type != KEYPAD)) {
131 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutUpdateKeypad(): keypad not found\n");
132 return -1;
133 }
134 if (enableValidate && !keypad->enableValidate) {
135 // if validate key is enabled and was not, select it directly
136 keypad->selectedKey = 11;
137 }
138 // Shuffle if selected key was not backspace or if the last pin entry has been deleted
139 else if ((keypad->selectedKey != 0) || (keypad->enableBackspace && !enableBackspace)) {
140 keypad->selectedKey = 0xFF;
141 }
142 keypad->enableValidate = enableValidate;
143 keypad->enableBackspace = enableBackspace;
144
145 nbgl_objDraw((nbgl_obj_t *) keypad);
146
147 return 0;
148}
149
162{
163 return nbgl_layoutAddKeypadContent(layout, true, nbDigits, NULL);
164}
165
175{
176 UNUSED(index);
177 if (nbgl_layoutUpdateKeypadContent(layout, true, nbActive, NULL) < 0) {
178 return -1;
179 }
180 return 0;
181}
182
197 bool hidden,
198 uint8_t nbDigits,
199 const char *text)
200{
201 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
202 nbgl_container_t *container;
203 nbgl_text_area_t *textArea;
204
205 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddKeypadContent():\n");
206 if (layout == NULL) {
207 return -1;
208 }
209
210 if (hidden) {
211 // create a container, invisible
212 container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
213 container->nbChildren = nbDigits;
214 container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
215 // 1 pixel between each icon (knowing that the effective bullets are 8px large)
216 container->obj.area.width = nbDigits * C_pin_bullet_empty.width + (nbDigits - 1);
217 container->obj.area.height = C_pin_bullet_empty.height;
218 // distance from top to digits is fixed to 24 px
219 container->obj.alignmentMarginY = 24;
220 container->obj.alignTo = NULL;
221 container->obj.alignment = TOP_MIDDLE;
222
223 // set this new container as child of the main container
224 layoutAddObject(layoutInt, (nbgl_obj_t *) container);
225
226 // create children of the container, as images (empty circles)
228 IMAGE, nbDigits, layoutInt->layer, (nbgl_obj_t **) container->children);
229 for (int i = 0; i < nbDigits; i++) {
230 nbgl_image_t *image = (nbgl_image_t *) container->children[i];
231 image->buffer = &C_pin_bullet_empty;
232 image->foregroundColor = WHITE;
233 if (i > 0) {
234 image->obj.alignment = MID_RIGHT;
235 image->obj.alignTo = (nbgl_obj_t *) container->children[i - 1];
236 image->obj.alignmentMarginX = 1;
237 }
238 else {
239 image->obj.alignment = NO_ALIGNMENT;
240 }
241 }
242 }
243 else {
244 // create text area
245 textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
246 textArea->textColor = WHITE;
247 textArea->text = text;
248 textArea->textAlignment = CENTER;
250 textArea->obj.area.width = AVAILABLE_WIDTH;
251 textArea->obj.area.height = nbgl_getFontLineHeight(textArea->fontId);
252 textArea->autoHideLongLine = true;
253 // distance from top to digits is fixed to 20 px
254 textArea->obj.alignmentMarginY = 20;
255 textArea->obj.alignTo = NULL;
256 textArea->obj.alignment = TOP_MIDDLE;
257 // set this new text area as child of the main container
258 layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
259 }
260
261 // return 0
262 return 0;
263}
264
278 bool hidden,
279 uint8_t nbActiveDigits,
280 const char *text)
281{
282 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
283 nbgl_container_t *container;
284 nbgl_image_t *image;
285
286 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateHiddenDigits(): nbActive = %d\n", nbActiveDigits);
287 if (layout == NULL) {
288 return -1;
289 }
290
291 if (hidden) {
292 // get container (3rd child of main container)
293 container = (nbgl_container_t *) layoutInt->children[2];
294 // sanity check
295 if ((container == NULL) || (container->obj.type != CONTAINER)) {
296 return -1;
297 }
298 if (nbActiveDigits > container->nbChildren) {
299 return -1;
300 }
301 if (nbActiveDigits == 0) {
302 // deactivate the first digit
303 image = (nbgl_image_t *) container->children[0];
304 if ((image == NULL) || (image->obj.type != IMAGE)) {
305 return -1;
306 }
307 image->buffer = &C_pin_bullet_empty;
308 }
309 else {
310 image = (nbgl_image_t *) container->children[nbActiveDigits - 1];
311 if ((image == NULL) || (image->obj.type != IMAGE)) {
312 return -1;
313 }
314 // if the last "active" is already active, it means that we are decreasing the number of
315 // active otherwise we are increasing it
316 if (image->buffer == &C_pin_bullet_filled) {
317 // all digits are already active
318 if (nbActiveDigits == container->nbChildren) {
319 return 0;
320 }
321 // deactivate the next digit
322 image = (nbgl_image_t *) container->children[nbActiveDigits];
323 image->buffer = &C_pin_bullet_empty;
324 }
325 else {
326 image->buffer = &C_pin_bullet_filled;
327 }
328 }
329
330 nbgl_objDraw((nbgl_obj_t *) image);
331 }
332 else {
333 // update main text area (second child of the main container)
334 nbgl_text_area_t *textArea = (nbgl_text_area_t *) layoutInt->children[2];
335 if ((textArea == NULL) || (textArea->obj.type != TEXT_AREA)) {
336 return -1;
337 }
338 textArea->text = text;
339 nbgl_objDraw((nbgl_obj_t *) textArea);
340 }
341
342 return 0;
343}
344
345#endif // NBGL_KEYPAD
346#endif // HAVE_SE_TOUCH
Random Number Generation.
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:87
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:86
@ LAYOUT_LOGGER
Definition nbgl_debug.h:33
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
Definition nbgl_fonts.h:145
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:143
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
Definition nbgl_fonts.c:400
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
int nbgl_layoutUpdateKeypad(nbgl_layout_t *layout, uint8_t index, bool enableValidate, bool enableBackspace, bool enableDigits)
Updates an existing keypad on bottom of the screen, with the given configuration.
DEPRECATED int nbgl_layoutAddHiddenDigits(nbgl_layout_t *layout, uint8_t nbDigits)
Adds a placeholder for hidden digits on top of a keypad, to represent the entered digits,...
#define AVAILABLE_WIDTH
Definition nbgl_layout.h:84
void * nbgl_layout_t
type shared externally
DEPRECATED int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout, uint8_t index, uint8_t nbActive)
Updates an existing set of hidden digits, with the given configuration.
int nbgl_layoutAddKeypadContent(nbgl_layout_t *layout, const char *title, bool hidden, uint8_t nbDigits, const char *text)
Adds an area with a title and a placeholder for hidden digits on top of a keypad, to represent the en...
int nbgl_layoutUpdateKeypadContent(nbgl_layout_t *layout, bool hidden, uint8_t nbActiveDigits, const char *text)
Updates an existing set of hidden digits, with the given configuration.
int nbgl_layoutAddKeypad(nbgl_layout_t *layout, keyboardCallback_t callback, bool shuffled)
Adds a keypad on bottom of the screen, with the associated callback.
Internal functions/constants of NBGL layout layer.
struct PACKED__ nbgl_text_area_s nbgl_text_area_t
struct to represent a text area (TEXT_AREA type)
void nbgl_objDraw(nbgl_obj_t *obj)
This function draws or redraws the given object and its children (recursive version)
Definition nbgl_obj.c:1520
nbgl_obj_t ** nbgl_containerPoolGet(uint8_t nbObjs, uint8_t layer)
Gets a new container from the pool, with the given number of obj pointers.
struct PACKED__ nbgl_keypad_s nbgl_keypad_t
struct to represent a keypad (KEYPAD type)
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
Gets a new graphic object from the pool, with the given type. The type field of the object is set.
struct PACKED__ nbgl_image_s nbgl_image_t
struct to represent an image (IMAGE type)
int nbgl_objPoolGetArray(nbgl_obj_type_t type, uint8_t nbObjs, uint8_t layer, nbgl_obj_t **objArray)
Gets nbObjects new graphic object from the pool, with the given type, for the given layer (screen)....
void(* keyboardCallback_t)(char touchedKey)
prototype of function to be called when a valid key is pressed on keyboard Backspace is equal to 0x8 ...
Definition nbgl_obj.h:487
struct PACKED__ nbgl_container_s nbgl_container_t
struct to represent a container (CONTAINER type)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
@ WHITE
Definition nbgl_types.h:124
@ TOP_MIDDLE
Definition nbgl_types.h:162
@ CENTER
Definition nbgl_types.h:165
@ NO_ALIGNMENT
used when parent container layout is used
Definition nbgl_types.h:160
@ MID_RIGHT
Definition nbgl_types.h:166
@ BOTTOM_MIDDLE
Definition nbgl_types.h:168
@ KEYPAD
Keypad.
Definition nbgl_types.h:147
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
Definition nbgl_types.h:137
@ CONTAINER
Empty container.
Definition nbgl_types.h:136
@ TEXT_AREA
Area to contain text line(s)
Definition nbgl_types.h:139
Structure containing all information about the current layout.
uint8_t nbChildren
number of children in above array
nbgl_obj_t ** children
children for main screen
unsigned char uint8_t
Definition usbd_conf.h:53