Embedded SDK
Embedded SDK
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 
61  keyboardCallback_t callback,
62  const char *text,
63  bool shuffled)
64 {
65  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
66  nbgl_keypad_t *keypad;
67  nbgl_text_area_t *textArea;
68 
69  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddKeypad():\n");
70  if (layout == NULL) {
71  return -1;
72  }
73 
74  textArea = (nbgl_text_area_t *) nbgl_objPoolGet(TEXT_AREA, layoutInt->layer);
75  textArea->textColor = WHITE;
76  textArea->text = PIC(text);
77  textArea->textAlignment = CENTER;
78  textArea->fontId = BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp;
79  textArea->obj.area.width = AVAILABLE_WIDTH;
80  textArea->obj.area.height = 12;
81  textArea->wrapping = false;
82  textArea->obj.alignment = TOP_MIDDLE;
83  textArea->obj.alignmentMarginY = 3;
84  // set this new obj as child of main container
85  layoutAddObject(layoutInt, (nbgl_obj_t *) textArea);
86 
87  // create keypad
88  keypad = (nbgl_keypad_t *) nbgl_objPoolGet(KEYPAD, layoutInt->layer);
89  keypad->obj.alignment = BOTTOM_MIDDLE;
90  keypad->obj.alignmentMarginY = 6;
91  keypad->obj.alignTo = NULL;
92  keypad->callback = PIC(callback);
93  keypad->enableBackspace = false;
94  keypad->enableValidate = false;
95  keypad->selectedKey = 0xFF; // to be picked
96  keypad->shuffled = shuffled;
97  // set this new keypad as child of the container
98  layoutAddObject(layoutInt, (nbgl_obj_t *) keypad);
99 
100  // return index of keypad to be modified later on
101  return (layoutInt->nbChildren - 1);
102 }
103 
114  uint8_t index,
115  bool enableValidate,
116  bool enableBackspace)
117 {
118  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
119  nbgl_keypad_t *keypad;
120 
122  "nbgl_layoutUpdateKeypad(): enableValidate = %d, enableBackspace = %d\n",
123  enableValidate,
124  enableBackspace);
125  if (layout == NULL) {
126  return -1;
127  }
128 
129  // get existing keypad
130  keypad = (nbgl_keypad_t *) layoutInt->children[index];
131  if ((keypad == NULL) || (keypad->obj.type != KEYPAD)) {
132  LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutUpdateKeypad(): keypad not found\n");
133  return -1;
134  }
135  if (enableValidate && !keypad->enableValidate) {
136  // if validate key is enabled and was not, select it directly
137  keypad->selectedKey = 11;
138  }
139  else {
140  // otherwise let the draw function pick a new selected
141  keypad->selectedKey = 0xFF;
142  }
143  keypad->enableValidate = enableValidate;
144  keypad->enableBackspace = enableBackspace;
145 
146  nbgl_objDraw((nbgl_obj_t *) keypad);
147 
148  return 0;
149 }
150 
162 int nbgl_layoutAddHiddenDigits(nbgl_layout_t *layout, uint8_t nbDigits)
163 {
164  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
165  nbgl_container_t *container;
166 
167  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddHiddenDigits():\n");
168  if (layout == NULL) {
169  return -1;
170  }
171 
172  // create a container, invisible or bordered
173  container = (nbgl_container_t *) nbgl_objPoolGet(CONTAINER, layoutInt->layer);
174  container->nbChildren = nbDigits;
175  container->children = nbgl_containerPoolGet(container->nbChildren, layoutInt->layer);
176  // 1 pixel between each icon (knowing that the effective bullets are 8px large)
177  container->obj.area.width = nbDigits * C_pin_bullet_empty.width + (nbDigits - 1);
178  container->obj.area.height = C_pin_bullet_empty.height;
179  // distance from top to digits is fixed to 24 px
180  container->obj.alignmentMarginY = 24;
181  container->obj.alignTo = NULL;
182  container->obj.alignment = TOP_MIDDLE;
183 
184  // set this new container as child of the main container
185  layoutAddObject(layoutInt, (nbgl_obj_t *) container);
186 
187  // create children of the container, as images (empty circles)
188  nbgl_objPoolGetArray(IMAGE, nbDigits, layoutInt->layer, (nbgl_obj_t **) container->children);
189  for (int i = 0; i < nbDigits; i++) {
190  nbgl_image_t *image = (nbgl_image_t *) container->children[i];
191  image->buffer = &C_pin_bullet_empty;
192  image->foregroundColor = WHITE;
193  if (i > 0) {
194  image->obj.alignment = MID_RIGHT;
195  image->obj.alignTo = (nbgl_obj_t *) container->children[i - 1];
196  image->obj.alignmentMarginX = 1;
197  }
198  else {
199  image->obj.alignment = NO_ALIGNMENT;
200  }
201  }
202  // return index of container to be modified later on
203  return (layoutInt->nbChildren - 1);
204 }
205 
214 int nbgl_layoutUpdateHiddenDigits(nbgl_layout_t *layout, uint8_t index, uint8_t nbActive)
215 {
216  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
217  nbgl_container_t *container;
218  nbgl_image_t *image;
219 
220  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateHiddenDigits(): nbActive = %d\n", nbActive);
221  if (layout == NULL) {
222  return -1;
223  }
224 
225  // get container
226  container = (nbgl_container_t *) layoutInt->children[index];
227  // sanity check
228  if ((container == NULL) || (container->obj.type != CONTAINER)) {
229  return -1;
230  }
231  if (nbActive > container->nbChildren) {
232  return -1;
233  }
234  if (nbActive == 0) {
235  // deactivate the first digit
236  image = (nbgl_image_t *) container->children[0];
237  if ((image == NULL) || (image->obj.type != IMAGE)) {
238  return -1;
239  }
240  image->buffer = &C_pin_bullet_empty;
241  }
242  else {
243  image = (nbgl_image_t *) container->children[nbActive - 1];
244  if ((image == NULL) || (image->obj.type != IMAGE)) {
245  return -1;
246  }
247  // if the last "active" is already active, it means that we are decreasing the number of
248  // active otherwise we are increasing it
249  if (image->buffer == &C_pin_bullet_filled) {
250  // all digits are already active
251  if (nbActive == container->nbChildren) {
252  return 0;
253  }
254  // deactivate the next digit
255  image = (nbgl_image_t *) container->children[nbActive];
256  image->buffer = &C_pin_bullet_empty;
257  }
258  else {
259  image->buffer = &C_pin_bullet_filled;
260  }
261  }
262 
263  nbgl_objDraw((nbgl_obj_t *) image);
264 
265  return 0;
266 }
267 #endif // NBGL_KEYPAD
268 #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:149
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
Definition: nbgl_layout.c:519
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:66
void * nbgl_layout_t
type shared externally
Definition: nbgl_layout.h:96
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_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:1521
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)
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)....
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.
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:466
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:105
@ TOP_MIDDLE
Definition: nbgl_types.h:143
@ CENTER
Definition: nbgl_types.h:146
@ NO_ALIGNMENT
used when parent container layout is used
Definition: nbgl_types.h:141
@ MID_RIGHT
Definition: nbgl_types.h:147
@ BOTTOM_MIDDLE
Definition: nbgl_types.h:149
@ KEYPAD
Keypad.
Definition: nbgl_types.h:128
@ IMAGE
Bitmap (y and height must be multiple of 4 on Stax)
Definition: nbgl_types.h:118
@ CONTAINER
Empty container.
Definition: nbgl_types.h:117
@ TEXT_AREA
Area to contain text line(s)
Definition: nbgl_types.h:120
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