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)
33#elif defined(TARGET_APEX)
34#define DIGIT_OFFSET_Y (((KEYPAD_KEY_HEIGHT - 28) / 2) & 0xFFC)
37#define BACKSPACE_KEY_IDX 10
38#define VALIDATE_KEY_IDX 11
41#define GET_DIGIT_INDEX(_keypad, _digit) \
42 ((_digit & 1) ? (_keypad->digitIndexes[_digit >> 1] >> 4) \
43 : (_keypad->digitIndexes[_digit >> 1] & 0xF))
44#define SET_DIGIT_INDEX(_keypad, _digit, _index) \
45 (_keypad->digitIndexes[_digit >> 1] |= (_digit & 1) ? (_index << 4) : _index)
65static uint8_t getKeypadIndex(uint16_t x, uint16_t y)
69 if (y < KEYPAD_KEY_HEIGHT) {
73 else if (y < (2 * KEYPAD_KEY_HEIGHT)) {
77 else if (y < (3 * KEYPAD_KEY_HEIGHT)) {
81 else if (y < (4 * KEYPAD_KEY_HEIGHT)) {
101 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
102 rectArea.x0 = keypad->obj.area.x0;
103 rectArea.y0 = keypad->obj.area.y0;
104 rectArea.width = keypad->obj.area.width;
105 rectArea.height = keypad->obj.area.height;
109 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
110 rectArea.x0 = keypad->obj.area.x0;
111 rectArea.y0 = keypad->obj.area.y0;
112 rectArea.width = keypad->obj.area.width;
115 rectArea.y0 += KEYPAD_KEY_HEIGHT;
117 rectArea.y0 += KEYPAD_KEY_HEIGHT;
119 rectArea.y0 += KEYPAD_KEY_HEIGHT;
123 rectArea.x0 = keypad->obj.area.x0;
124 rectArea.y0 = keypad->obj.area.y0;
126 rectArea.height = KEYPAD_KEY_HEIGHT * 4;
127#ifdef HAVE_SIDE_SCREEN
142 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
144 if (keypad->digitsChanged) {
145 rectArea.y0 = keypad->obj.area.y0 + DIGIT_OFFSET_Y;
148 for (i = 0; i < 3; i++) {
151 rectArea.x0 = keypad->obj.area.x0 + i *
KEY_WIDTH;
154 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
157 rectArea.y0 += KEYPAD_KEY_HEIGHT;
160 rectArea.x0 = keypad->obj.area.x0 + (i - 3) *
KEY_WIDTH;
163 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
166 rectArea.y0 += KEYPAD_KEY_HEIGHT;
169 rectArea.x0 = keypad->obj.area.x0 + (i - 6) *
KEY_WIDTH;
172 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
177 rectArea.width = BACKSPACE_ICON.width;
178 rectArea.height = BACKSPACE_ICON.height;
180 rectArea.x0 = keypad->obj.area.x0 + (
KEY_WIDTH - rectArea.width) / 2;
182 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
183 if (BACKSPACE_ICON.isFile) {
185 (uint8_t *) BACKSPACE_ICON.bitmap,
191 (uint8_t *) BACKSPACE_ICON.bitmap,
197 if (keypad->digitsChanged) {
200 rectArea.x0 = keypad->obj.area.x0 +
KEY_WIDTH;
202 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 + DIGIT_OFFSET_Y;
204 &rectArea, &key_value, 1, LARGE_MEDIUM_FONT, keypad->enableDigits ?
BLACK :
WHITE);
208 if (!keypad->enableValidate && keypad->validateChanged) {
209 uint8_t dotStartIdx = 0;
212 rectArea.height = KEYPAD_KEY_HEIGHT;
214 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
215 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
216 rectArea.backgroundColor =
WHITE;
219 rectArea.backgroundColor = keypad->obj.area.backgroundColor;
220 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
221 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
226 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
227 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
229 rectArea.height = KEYPAD_KEY_HEIGHT;
233 rectArea.height += 4;
238 else if (keypad->validateChanged) {
241 if (keypad->softValidation) {
242 icon = &RIGHT_ARROW_ICON;
245 icon = &VALIDATE_ICON;
248 rectArea.backgroundColor =
BLACK;
249 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
250 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3;
252 rectArea.height = KEYPAD_KEY_HEIGHT;
254 rectArea.width = icon->width;
255 rectArea.height = icon->height;
258 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3
259 + (KEYPAD_KEY_HEIGHT - rectArea.height) / 2;
269 rectArea.backgroundColor =
WHITE;
270 rectArea.x0 = keypad->obj.area.x0 + 2 *
KEY_WIDTH;
271 rectArea.y0 = keypad->obj.area.y0 + KEYPAD_KEY_HEIGHT * 3 - 4;
281 if (keypad->digitsChanged) {
283 keypadDrawGrid(keypad);
287 keypadDrawDigits(keypad);
288 keypad->digitsChanged =
false;
304 uint8_t firstIndex, lastIndex;
317 firstIndex = getKeypadIndex(firstPosition->
x - obj->area.x0, firstPosition->
y - obj->area.y0);
321 lastIndex = getKeypadIndex(lastPosition->
x - obj->area.x0, lastPosition->
y - obj->area.y0);
327 if (lastIndex != firstIndex) {
331 if ((firstIndex < 10) && (keypad->enableDigits)) {
338 os_io_seph_cmd_piezo_play_tune(TUNE_TAP_CASUAL);
348 os_io_seph_cmd_piezo_play_tune(TUNE_TAP_CASUAL);
372 if ((index >=
'1') && (index <=
'3')) {
373 *x = kpd->obj.area.x0 + (index -
'1') *
KEY_WIDTH;
374 *y = kpd->obj.area.y0;
376 else if ((index >=
'4') && (index <=
'6')) {
377 *x = kpd->obj.area.x0 + (index -
'4') *
KEY_WIDTH;
378 *y = kpd->obj.area.y0 + KEYPAD_KEY_HEIGHT;
380 else if ((index >=
'7') && (index <=
'9')) {
381 *x = kpd->obj.area.x0 + (index -
'7') *
KEY_WIDTH;
382 *y = kpd->obj.area.y0 + (2 * KEYPAD_KEY_HEIGHT);
385 *x = kpd->obj.area.x0;
386 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
388 else if (index ==
'0') {
390 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
394 *y = kpd->obj.area.y0 + (3 * KEYPAD_KEY_HEIGHT);
414 if (kpd->digitIndexes[0] == 0) {
417 uint8_t shuffledDigits[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
420 for (i = 0; i < 9; i++) {
422 uint32_t j = cx_rng_u32_range(i, 10);
423 uint8_t tmp = shuffledDigits[j];
426 shuffledDigits[j] = shuffledDigits[i];
427 shuffledDigits[i] = tmp;
429 for (i = 0; i < 10; i++) {
436 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_frontDrawLine(const nbgl_area_t *area, uint8_t dotStartIdx, color_t lineColor)
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_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)