21#include "os_io_seph_cmd.h"
22#include "os_io_seph_ux.h"
28#define KEY_WIDTH (SCREEN_WIDTH / 3)
29#if defined(TARGET_STAX)
30#define DIGIT_OFFSET_Y (((KEYPAD_KEY_HEIGHT - 48) / 2) & 0xFFC)
31#elif defined(TARGET_FLEX)
32#define DIGIT_OFFSET_Y (((KEYPAD_KEY_HEIGHT - 48) / 2) & 0xFFC)
35#define BACKSPACE_KEY_IDX 10
36#define VALIDATE_KEY_IDX 11
39#define GET_DIGIT_INDEX(_keypad, _digit) \
40 ((_digit & 1) ? (_keypad->digitIndexes[_digit >> 1] >> 4) \
41 : (_keypad->digitIndexes[_digit >> 1] & 0xF))
42#define SET_DIGIT_INDEX(_keypad, _digit, _index) \
43 (_keypad->digitIndexes[_digit >> 1] |= (_digit & 1) ? (_index << 4) : _index)
63static uint8_t getKeypadIndex(uint16_t x, uint16_t y)
67 if (y < KEYPAD_KEY_HEIGHT) {
71 else if (y < (2 * KEYPAD_KEY_HEIGHT)) {
75 else if (y < (3 * KEYPAD_KEY_HEIGHT)) {
79 else if (y < (4 * KEYPAD_KEY_HEIGHT)) {
99 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
100 rectArea.x0 = keypad->obj.area.x0;
101 rectArea.y0 = keypad->obj.area.y0;
102 rectArea.width = keypad->obj.area.width;
103 rectArea.height = keypad->obj.area.height;
107 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
108 rectArea.x0 = keypad->obj.area.x0;
109 rectArea.y0 = keypad->obj.area.y0;
110 rectArea.width = keypad->obj.area.width;
111 rectArea.height = VERTICAL_ALIGNMENT;
113 rectArea.y0 += KEYPAD_KEY_HEIGHT;
115 rectArea.y0 += KEYPAD_KEY_HEIGHT;
117 rectArea.y0 += KEYPAD_KEY_HEIGHT;
121 rectArea.backgroundColor = keypad->borderColor;
122 rectArea.x0 = keypad->obj.area.x0;
123 rectArea.y0 = keypad->obj.area.y0;
125 rectArea.height = KEYPAD_KEY_HEIGHT * 4;
139 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
141 if (!keypad->partial) {
142 rectArea.y0 = keypad->obj.area.y0 + DIGIT_OFFSET_Y;
145 for (i = 0; i < 3; i++) {
148 rectArea.x0 = keypad->obj.area.x0 + i *
KEY_WIDTH;
151 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
154 rectArea.y0 += KEYPAD_KEY_HEIGHT;
157 rectArea.x0 = keypad->obj.area.x0 + (i - 3) *
KEY_WIDTH;
160 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
163 rectArea.y0 += KEYPAD_KEY_HEIGHT;
166 rectArea.x0 = keypad->obj.area.x0 + (i - 6) *
KEY_WIDTH;
169 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
174 rectArea.width = BACKSPACE_ICON.width;
175 rectArea.height = BACKSPACE_ICON.height;
177 rectArea.x0 = keypad->obj.area.x0 + (
KEY_WIDTH - rectArea.width) / 2;
179 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
180 if (BACKSPACE_ICON.isFile) {
182 (uint8_t *) BACKSPACE_ICON.bitmap,
188 (uint8_t *) BACKSPACE_ICON.bitmap,
194 if (!keypad->partial) {
197 rectArea.x0 = keypad->obj.area.x0 +
KEY_WIDTH;
199 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + DIGIT_OFFSET_Y;
201 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
205 if (!keypad->enableValidate) {
207 rectArea.height = KEYPAD_KEY_HEIGHT - 4;
209 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH + 1;
210 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + 4;
211 rectArea.backgroundColor =
WHITE;
214 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
215 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
216 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
218 rectArea.height = VERTICAL_ALIGNMENT;
221 rectArea.backgroundColor = keypad->borderColor;
222 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
223 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
225 rectArea.height = KEYPAD_KEY_HEIGHT;
231 if (keypad->softValidation) {
232 icon = &RIGHT_ARROW_ICON;
235 icon = &VALIDATE_ICON;
238 rectArea.backgroundColor =
BLACK;
239 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
240 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
242 rectArea.height = KEYPAD_KEY_HEIGHT;
244 rectArea.width = icon->width;
245 rectArea.height = icon->height;
248 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3
249 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
261 if (!keypad->partial) {
263 keypadDrawGrid(keypad);
267 keypadDrawDigits(keypad);
268 keypad->partial =
false;
284 uint8_t firstIndex, lastIndex;
297 firstIndex = getKeypadIndex(firstPosition->
x - obj->area.x0, firstPosition->
y - obj->area.y0);
301 lastIndex = getKeypadIndex(lastPosition->
x - obj->area.x0, lastPosition->
y - obj->area.y0);
307 if (lastIndex != firstIndex) {
311 if ((firstIndex < 10) && (keypad->enableDigits)) {
318 os_io_seph_cmd_piezo_play_tune(TUNE_TAP_CASUAL);
328 os_io_seph_cmd_piezo_play_tune(TUNE_TAP_CASUAL);
352 if ((index >=
'1') && (index <=
'3')) {
353 *x = kpd->obj.area.x0 + (index -
'1') *
KEY_WIDTH;
354 *y = kpd->obj.area.y0;
356 else if ((index >=
'4') && (index <=
'6')) {
357 *x = kpd->obj.area.x0 + (index -
'4') *
KEY_WIDTH;
358 *y = kpd->obj.area.y0 + KEYPAD_KEY_HEIGHT;
360 else if ((index >=
'7') && (index <=
'9')) {
361 *x = kpd->obj.area.x0 + (index -
'7') *
KEY_WIDTH;
362 *y = kpd->obj.area.y0 + (2 * KEYPAD_KEY_HEIGHT);
365 *x = kpd->obj.area.x0;
366 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
368 else if (index ==
'0') {
370 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
374 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
394 if (kpd->digitIndexes[0] == 0) {
397 uint8_t shuffledDigits[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
400 for (i = 0; i < 9; i++) {
402 uint32_t j = cx_rng_u32_range(i, 10);
403 uint8_t tmp = shuffledDigits[j];
406 shuffledDigits[j] = shuffledDigits[i];
407 shuffledDigits[i] = tmp;
409 for (i = 0; i < 10; i++) {
416 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)