21#include "os_io_seproxyhal.h"
27#define KEY_WIDTH (SCREEN_WIDTH / 3)
28#if defined(TARGET_STAX)
29#define DIGIT_OFFSET_Y (((KEYPAD_KEY_HEIGHT - 48) / 2) & 0xFFC)
30#elif defined(TARGET_FLEX)
31#define DIGIT_OFFSET_Y (((KEYPAD_KEY_HEIGHT - 48) / 2) & 0xFFC)
34#define BACKSPACE_KEY_IDX 10
35#define VALIDATE_KEY_IDX 11
38#define GET_DIGIT_INDEX(_keypad, _digit) \
39 ((_digit & 1) ? (_keypad->digitIndexes[_digit >> 1] >> 4) \
40 : (_keypad->digitIndexes[_digit >> 1] & 0xF))
41#define SET_DIGIT_INDEX(_keypad, _digit, _index) \
42 (_keypad->digitIndexes[_digit >> 1] |= (_digit & 1) ? (_index << 4) : _index)
66 if (y < KEYPAD_KEY_HEIGHT) {
70 else if (y < (2 * KEYPAD_KEY_HEIGHT)) {
74 else if (y < (3 * KEYPAD_KEY_HEIGHT)) {
78 else if (y < (4 * KEYPAD_KEY_HEIGHT)) {
98 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
99 rectArea.x0 = keypad->obj.area.x0;
100 rectArea.y0 = keypad->obj.area.y0;
101 rectArea.width = keypad->obj.area.width;
102 rectArea.height = keypad->obj.area.height;
106 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
107 rectArea.x0 = keypad->obj.area.x0;
108 rectArea.y0 = keypad->obj.area.y0;
109 rectArea.width = keypad->obj.area.width;
110 rectArea.height = VERTICAL_ALIGNMENT;
112 rectArea.y0 += KEYPAD_KEY_HEIGHT;
114 rectArea.y0 += KEYPAD_KEY_HEIGHT;
116 rectArea.y0 += KEYPAD_KEY_HEIGHT;
120 rectArea.backgroundColor = keypad->borderColor;
121 rectArea.x0 = keypad->obj.area.x0;
122 rectArea.y0 = keypad->obj.area.y0;
124 rectArea.height = KEYPAD_KEY_HEIGHT * 4;
138 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
140 if (!keypad->partial) {
141 rectArea.y0 = keypad->obj.area.y0 + DIGIT_OFFSET_Y;
144 for (i = 0; i < 3; i++) {
147 rectArea.x0 = keypad->obj.area.x0 + i *
KEY_WIDTH;
150 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
153 rectArea.y0 += KEYPAD_KEY_HEIGHT;
156 rectArea.x0 = keypad->obj.area.x0 + (i - 3) *
KEY_WIDTH;
159 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
162 rectArea.y0 += KEYPAD_KEY_HEIGHT;
165 rectArea.x0 = keypad->obj.area.x0 + (i - 6) *
KEY_WIDTH;
168 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
173 rectArea.width = BACKSPACE_ICON.width;
174 rectArea.height = BACKSPACE_ICON.height;
176 rectArea.x0 = keypad->obj.area.x0 + (
KEY_WIDTH - rectArea.width) / 2;
178 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
179 if (BACKSPACE_ICON.isFile) {
181 (
uint8_t *) BACKSPACE_ICON.bitmap,
187 (
uint8_t *) BACKSPACE_ICON.bitmap,
193 if (!keypad->partial) {
196 rectArea.x0 = keypad->obj.area.x0 +
KEY_WIDTH;
198 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + DIGIT_OFFSET_Y;
200 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
204 if (!keypad->enableValidate) {
206 rectArea.height = KEYPAD_KEY_HEIGHT - 4;
208 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH + 1;
209 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + 4;
210 rectArea.backgroundColor =
WHITE;
213 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
214 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
215 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
217 rectArea.height = VERTICAL_ALIGNMENT;
220 rectArea.backgroundColor = keypad->borderColor;
221 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
222 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
224 rectArea.height = KEYPAD_KEY_HEIGHT;
230 if (keypad->softValidation) {
231 icon = &RIGHT_ARROW_ICON;
234 icon = &VALIDATE_ICON;
237 rectArea.backgroundColor =
BLACK;
238 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
239 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
241 rectArea.height = KEYPAD_KEY_HEIGHT;
243 rectArea.width = icon->width;
244 rectArea.height = icon->height;
247 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3
248 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
260 if (!keypad->partial) {
262 keypadDrawGrid(keypad);
266 keypadDrawDigits(keypad);
267 keypad->partial =
false;
296 firstIndex = getKeypadIndex(firstPosition->
x - obj->area.x0, firstPosition->
y - obj->area.y0);
300 lastIndex = getKeypadIndex(lastPosition->
x - obj->area.x0, lastPosition->
y - obj->area.y0);
306 if (lastIndex != firstIndex) {
310 if ((firstIndex < 10) && (keypad->enableDigits)) {
317 io_seproxyhal_play_tune(TUNE_TAP_CASUAL);
327 io_seproxyhal_play_tune(TUNE_TAP_CASUAL);
351 if ((index >=
'1') && (index <=
'3')) {
352 *x = kpd->obj.area.x0 + (index -
'1') *
KEY_WIDTH;
353 *y = kpd->obj.area.y0;
355 else if ((index >=
'4') && (index <=
'6')) {
356 *x = kpd->obj.area.x0 + (index -
'4') *
KEY_WIDTH;
357 *y = kpd->obj.area.y0 + KEYPAD_KEY_HEIGHT;
359 else if ((index >=
'7') && (index <=
'9')) {
360 *x = kpd->obj.area.x0 + (index -
'7') *
KEY_WIDTH;
361 *y = kpd->obj.area.y0 + (2 * KEYPAD_KEY_HEIGHT);
364 *x = kpd->obj.area.x0;
365 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
367 else if (index ==
'0') {
369 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
373 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
393 if (kpd->digitIndexes[0] == 0) {
396 uint8_t shuffledDigits[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
399 for (i = 0; i < 9; i++) {
401 uint32_t j = cx_rng_u32_range(i, 10);
402 uint8_t tmp = shuffledDigits[j];
405 shuffledDigits[j] = shuffledDigits[i];
406 shuffledDigits[i] = tmp;
408 for (i = 0; i < 10; i++) {
415 for (i = 0; i < 10; i++) {
Random Number Generation.
#define LOG_DEBUG(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area, const char *text, uint16_t textLen, nbgl_font_id_e fontId, color_t fontColor)
This function draws the given single-line text, with the given parameters.
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
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_frontDrawImageFile(const nbgl_area_t *area, const uint8_t *buffer, nbgl_color_map_t colorMap, const uint8_t *uzlib_chunk_buffer)
void nbgl_frontDrawHorizontalLine(const nbgl_area_t *area, uint8_t mask, color_t lineColor)
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)
struct PACKED__ nbgl_obj_s nbgl_obj_t
Common structure for all graphical objects.
#define GET_DIGIT_INDEX(_keypad, _digit)
void nbgl_objDrawKeypad(nbgl_keypad_t *kpd)
This function draws a keypad object.
#define BACKSPACE_KEY_IDX
#define SET_DIGIT_INDEX(_keypad, _digit, _index)
void nbgl_keypadTouchCallback(nbgl_obj_t *obj, nbgl_touchType_t eventType)
function to be called when the keypad object is touched
bool nbgl_keypadGetPosition(nbgl_keypad_t *kpd, char index, uint16_t *x, uint16_t *y)
This function gets the position (top-left corner) of the key at the given index. (to be used for Test...
uint8_t ramBuffer[GZLIB_UNCOMPRESSED_CHUNK]
bool nbgl_touchGetTouchedPosition(nbgl_obj_t *obj, nbgl_touchStatePosition_t **firstPos, nbgl_touchStatePosition_t **lastPos)
nbgl_touchType_t
The different types of Touchscreen events.
struct PACKED__ nbgl_icon_details_s nbgl_icon_details_t
Represents all information about an icon.
#define GZLIB_UNCOMPRESSED_CHUNK
size of gzlib uncompression buffer in bytes
#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.
The low level Touchscreen event, coming from driver.
int16_t y
vertical position of the touch (or for a RELEASED the last touched point)
int16_t x
horizontal position of the touch (or for a RELEASED the last touched point)