How to cycle through keyboard widget keys using an encoder?
Hi @Serg,
Thank you to open this topic. There are steps:
- Create a group and assigned the encoder.
- Add the keybord as widget to the group
- Configure the encode mode (Navegation and Edit mode).
Once in edit mode, LV_KEY_RIGHT/UP/LEFT/DOWN navigate among the keyboard buttons, and LV_KEY_ENTER (pressing the encoder) presses the selected button
lv_group_t * g = lv_group_create();
lv_indev_t * indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_ENCODER);
lv_indev_set_read_cb(indev, your_encoder_read);
lv_indev_set_group(indev, g);
lv_obj_t * kb = lv_keyboard_create(lv_screen_active());
lv_group_add_obj(g, kb);
Thank you, halyssonJr
Yes, these buttons work, but I thought rotating the encoder was equivalent to pressing these buttons.
I had to do it this way:
void encoder_read(lv_indev_t *indev, lv_indev_data_t *data)
{
data->enc_diff = (int16_t) EncoderSel_update();
tmp = data->enc_diff;
if (data->enc_diff < 0)
data->key = LV_KEY_LEFT;
else if (data->enc_diff > 0)
data->key = LV_KEY_RIGHT;
else
data->key = GetNumKey();
/*Get the last pressed or released key*/
if (data->key >= 0)
data->state = LV_INDEV_STATE_PRESSED;
else
data->state = LV_INDEV_STATE_RELEASED;
}