Embedded SDK
Embedded SDK
nbgl_layout_keyboard_nanos.c
Go to the documentation of this file.
1 
6 #ifndef HAVE_SE_TOUCH
7 #ifdef NBGL_KEYBOARD
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  * GLOBAL FUNCTIONS
42  **********************/
43 
51 int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
52 {
53  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
54  nbgl_keyboard_t *keyboard;
55 
56  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddKeyboard():\n");
57  if (layout == NULL) {
58  return -1;
59  }
60 
61  // create keyboard
62  keyboard = (nbgl_keyboard_t *) nbgl_objPoolGet(KEYBOARD, layoutInt->layer);
63  keyboard->obj.alignmentMarginY = 0;
64  keyboard->obj.alignment = CENTER;
65  keyboard->enableBackspace = kbdInfo->enableBackspace;
66  keyboard->enableValidate = kbdInfo->enableValidate;
67  if (kbdInfo->lettersOnly) {
68  keyboard->selectedCharIndex = cx_rng_u32() % 26;
69  keyboard->mode = MODE_LOWER_LETTERS;
70  }
71  else {
72  keyboard->mode = MODE_NONE;
73  }
74  keyboard->callback = PIC(kbdInfo->callback);
75  keyboard->lettersOnly = kbdInfo->lettersOnly;
76  keyboard->keyMask = kbdInfo->keyMask;
77  // set this new keyboard as child of the container
78  layoutAddObject(layoutInt, (nbgl_obj_t *) keyboard);
79 
80  // return index of keyboard to be modified later on
81  return (layoutInt->nbChildren - 1);
82 }
83 
92 int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask)
93 {
94  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
95  nbgl_keyboard_t *keyboard;
96 
97  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateKeyboard(): keyMask = 0x%X\n", keyMask);
98  if (layout == NULL) {
99  return -1;
100  }
101 
102  // get keyboard at given index
103  keyboard = (nbgl_keyboard_t *) layoutInt->children[index];
104  if ((keyboard == NULL) || (keyboard->obj.type != KEYBOARD)) {
105  return -1;
106  }
107  keyboard->keyMask = keyMask;
108  if (keyboard->lettersOnly) {
109  if (keyMask & (1 << 26)) {
110  keyboard->selectedCharIndex = cx_rng_u32() % 26;
111  }
112  else {
113  keyboard->selectedCharIndex = 0;
114  }
115  }
116 
117  nbgl_objDraw((nbgl_obj_t *) keyboard);
118 
119  return 0;
120 }
121 
133 int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, const char *text, bool lettersOnly)
134 {
135  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
136  nbgl_text_entry_t *textEntry;
137 
138  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddEnteredText():\n");
139  if (layout == NULL) {
140  return -1;
141  }
142 
143  // create text area
144  textEntry = (nbgl_text_entry_t *) nbgl_objPoolGet(TEXT_ENTRY, layoutInt->layer);
145  textEntry->text = text;
146  textEntry->fontId = BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp;
147  textEntry->nbChars = lettersOnly ? 8 : 9;
148  textEntry->obj.alignmentMarginY = 5;
149  textEntry->obj.alignment = BOTTOM_MIDDLE;
150  textEntry->obj.area.width = 98;
151  textEntry->obj.area.height = 16;
152 
153  // set this new text area as child of the container
154  layoutAddObject(layoutInt, (nbgl_obj_t *) textEntry);
155 
156  // return index of text area to be modified later on
157  return (layoutInt->nbChildren - 1);
158 }
159 
169 int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, const char *text)
170 {
171  nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
172  nbgl_text_entry_t *textEntry;
173 
174  LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateEnteredText():\n");
175  if (layout == NULL) {
176  return -1;
177  }
178 
179  // update main text area
180  textEntry = (nbgl_text_entry_t *) layoutInt->children[index];
181  if ((textEntry == NULL) || (textEntry->obj.type != TEXT_ENTRY)) {
182  return -1;
183  }
184  textEntry->text = text;
185  nbgl_objDraw((nbgl_obj_t *) textEntry);
186 
187  return 0;
188 }
189 
190 #endif // NBGL_KEYBOARD
191 #endif // HAVE_SE_TOUCH
Random Number Generation.
debug traces management
#define LOG_DEBUG(__logger,...)
Definition: nbgl_debug.h:86
@ LAYOUT_LOGGER
Definition: nbgl_debug.h:33
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition: nbgl_fonts.h:147
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
Definition: nbgl_layout.c:519
DEPRECATED int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, bool numbered, uint8_t number, const char *text, bool grayedOut, int offsetY, int token)
Adds a "text entry" area under the previously entered object. This area can be preceded (beginning of...
int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask, bool updateCasing, keyboardCase_t casing)
Updates an existing keyboard on bottom of the screen, with the given configuration.
int nbgl_layoutAddKeyboard(nbgl_layout_t *layout, const nbgl_layoutKbd_t *kbdInfo)
Creates a keyboard on bottom of the screen, with the given configuration.
void * nbgl_layout_t
type shared externally
Definition: nbgl_layout.h:96
DEPRECATED int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, bool numbered, uint8_t number, const char *text, bool grayedOut)
Updates an existing "text entry" area, created with nbgl_layoutAddEnteredText()
Internal functions/constants of NBGL layout layer.
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
struct PACKED__ nbgl_text_entry_s nbgl_text_entry_t
struct to represent a text entry area (TEXT_ENTRY type)
struct PACKED__ nbgl_keyboard_s nbgl_keyboard_t
struct to represent a keyboard (KEYBOARD 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_obj_s nbgl_obj_t
Common structure for all graphical objects.
@ CENTER
Definition: nbgl_types.h:146
@ BOTTOM_MIDDLE
Definition: nbgl_types.h:149
@ TEXT_ENTRY
area for entered text, only for Nanos
Definition: nbgl_types.h:131
@ KEYBOARD
Keyboard.
Definition: nbgl_types.h:127
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
This structure contains info to build a keyboard with nbgl_layoutAddKeyboard()
Definition: nbgl_layout.h:564
uint32_t keyMask
Definition: nbgl_layout.h:565
bool lettersOnly
if true, only display letter keys and Backspace
Definition: nbgl_layout.h:569
keyboardCallback_t callback
function called when an active key is pressed
Definition: nbgl_layout.h:568
keyboardMode_t mode
keyboard mode to start with
Definition: nbgl_layout.h:570
unsigned char uint8_t
Definition: usbd_conf.h:53