Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
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
51int 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 keyboard->obfuscated = kbdInfo->obfuscated;
68
69 if (kbdInfo->lettersOnly) {
70#ifdef KEYBOARD_NOT_SHUFFLED
71 keyboard->selectedCharIndex = 0;
72#else
73 keyboard->selectedCharIndex = cx_rng_u32() % 26;
74#endif
75 keyboard->mode = MODE_LOWER_LETTERS;
76 }
77 else {
78 keyboard->mode = kbdInfo->mode;
79 }
80 keyboard->callback = PIC(kbdInfo->callback);
81 keyboard->lettersOnly = kbdInfo->lettersOnly;
82 keyboard->keyMask = kbdInfo->keyMask;
83 // set this new keyboard as child of the container
84 layoutAddObject(layoutInt, (nbgl_obj_t *) keyboard);
85
86 // return index of keyboard to be modified later on
87 return (layoutInt->nbChildren - 1);
88}
89
98int nbgl_layoutUpdateKeyboard(nbgl_layout_t *layout, uint8_t index, uint32_t keyMask)
99{
100 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
101 nbgl_keyboard_t *keyboard;
102
103 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateKeyboard(): keyMask = 0x%X\n", keyMask);
104 if (layout == NULL) {
105 return -1;
106 }
107
108 // get keyboard at given index
109 keyboard = (nbgl_keyboard_t *) layoutInt->children[index];
110 if ((keyboard == NULL) || (keyboard->obj.type != KEYBOARD)) {
111 LOG_WARN(
112 LAYOUT_LOGGER, "nbgl_layoutUpdateKeyboard(): keyboard not found at index %d\n", index);
113 return -1;
114 }
115 if (keyboard->lettersOnly) {
116#ifdef KEYBOARD_NOT_SHUFFLED
117 keyboard->selectedCharIndex = 0;
118#else
119 if (keyMask & (1 << 26)) {
120 keyboard->selectedCharIndex = cx_rng_u32() % 26;
121 }
122 else {
123 keyboard->selectedCharIndex = 0;
124 }
125#endif
126 }
127 else {
128 // if current keyMask was O and new one filters all keys,
129 // we should select Validate by default
130 if ((keyboard->keyMask == 0) && ((keyMask & 0x3FFFFFF) == 0x3FFFFFF)) {
131 keyboard->selectedCharIndex = 27;
132 }
133 }
134 keyboard->keyMask = keyMask;
135
136 nbgl_objDraw((nbgl_obj_t *) keyboard);
137
138 return 0;
139}
140
153int nbgl_layoutAddEnteredTextAdvanced(nbgl_layout_t *layout,
154 const char *text,
155 bool lettersOnly,
156 bool obfuscated)
157{
158 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
159 nbgl_text_entry_t *textEntry = NULL;
160
161 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutAddEnteredText():\n");
162 if (layout == NULL) {
163 return -1;
164 }
165
167 if (obfuscated) {
169 }
170
171 // create text area
172 textEntry = (nbgl_text_entry_t *) nbgl_objPoolGet(TEXT_ENTRY, layoutInt->layer);
173 textEntry->text = text;
174 textEntry->fontId = fontId;
175 textEntry->nbChars = lettersOnly ? 8 : 9;
176 textEntry->obj.alignmentMarginY = 5;
177 textEntry->obj.alignment = BOTTOM_MIDDLE;
178 textEntry->obj.area.width = 98;
179 textEntry->obj.area.height = 16;
180
181 // set this new text area as child of the container
182 layoutAddObject(layoutInt, (nbgl_obj_t *) textEntry);
183
184 // return index of text area to be modified later on
185 return (layoutInt->nbChildren - 1);
186}
187
199int nbgl_layoutAddEnteredText(nbgl_layout_t *layout, const char *text, bool lettersOnly)
200{
201 return nbgl_layoutAddEnteredTextAdvanced(layout, text, lettersOnly, false);
202}
203
213int nbgl_layoutUpdateEnteredText(nbgl_layout_t *layout, uint8_t index, const char *text)
214{
215 nbgl_layoutInternal_t *layoutInt = (nbgl_layoutInternal_t *) layout;
216 nbgl_text_entry_t *textEntry;
217
218 LOG_DEBUG(LAYOUT_LOGGER, "nbgl_layoutUpdateEnteredText():\n");
219 if (layout == NULL) {
220 return -1;
221 }
222
223 // update main text area
224 textEntry = (nbgl_text_entry_t *) layoutInt->children[index];
225 if ((textEntry == NULL) || (textEntry->obj.type != TEXT_ENTRY)) {
226 LOG_WARN(LAYOUT_LOGGER, "nbgl_layoutUpdateEnteredText(): text entry not found\n");
227 return -1;
228 }
229 textEntry->text = text;
230 nbgl_objDraw((nbgl_obj_t *) textEntry);
231
232 return 0;
233}
234
235#endif // NBGL_KEYBOARD
236#endif // HAVE_SE_TOUCH
Random Number Generation.
debug traces management
#define LOG_WARN(__logger,...)
Definition nbgl_debug.h:87
@ LAYOUT_LOGGER
Definition nbgl_debug.h:33
#define LOG_DEBUG(__logger,...)
Definition nbgl_debug.h:86
nbgl_font_id_e
Definition nbgl_fonts.h:141
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:148
@ BAGL_FONT_OBFUSCATED_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:168
void layoutAddObject(nbgl_layoutInternal_t *layout, nbgl_obj_t *obj)
adds the given obj to the main container
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
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)
nbgl_obj_t * nbgl_objPoolGet(nbgl_obj_type_t type, uint8_t layer)
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)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
@ CENTER
Definition nbgl_types.h:197
@ BOTTOM_MIDDLE
Definition nbgl_types.h:200
@ TEXT_ENTRY
area for entered text, only for Nanos
Definition nbgl_types.h:182
@ KEYBOARD
Keyboard.
Definition nbgl_types.h:178
Structure containing all information about the current layout.
uint8_t layer
layer in screen stack
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()
bool lettersOnly
if true, only display letter keys and Backspace
keyboardCallback_t callback
function called when an active key is pressed
keyboardMode_t mode
keyboard mode to start with