Description
Hello, I have been trying to get my code from SquareLine Studio to work with 3 buttons as an input device, imitating an encoder. I want to navigate the menus with it, but it is doing nothing at all
What MCU/Processor/Board and compiler are you using?
I am using an ESP32, with the module M5Stack Core2.
What LVGL version are you using?
8.3.4
What do you want to achieve?
To get the buttons working, but nothing happens.
What have you tried so far?
Debugging using log function
Code to reproduce
/* Deceleration of the button driver */
void lv_three_button_read(lv_indev_drv_t * drv, lv_indev_data_t * data){
if(digitalRead(btn_left_pin) == LOW) { /* when digitalRead returns LOW, means the button is pressed */
log_i("btn_left_pin");
data->state = LV_INDEV_STATE_PRESSED;
data->key = LV_KEY_LEFT;
}
else if(digitalRead(btn_center_pin) == LOW) {
log_i("btn_center_pin");
data->state = LV_INDEV_STATE_PRESSED;
data->key = LV_KEY_ENTER;
}
else if(digitalRead(btn_right_pin) == LOW) {
log_i("btn_right_pin");
data->state = LV_INDEV_STATE_PRESSED;
data->key = LV_KEY_RIGHT;
}
else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
/* Deceleration of the touch driver (removed because it's unnecessary for this post) */
void lv_setup() {
/* Code to set up the display buffer and ect, removed since its unnecessary */
/* Initialise the touch display driver, again removed since its unnecessary */
/* Initialise the button encoder driver */
static lv_indev_drv_t three_button_indev_drv;
lv_indev_drv_init(&three_button_indev_drv);
three_button_indev_drv.type = LV_INDEV_TYPE_ENCODER;
three_button_indev_drv.read_cb = lv_three_button_read; /* Callback to touchscreen read function */
lv_indev_drv_register(&three_button_indev_drv);
}
Screenshot and/or video
Third party video hosting service “Streamable”