Is there a way to make the encoder switch Screens


What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

Rotate the encoder and switch screens. Notably in each screen, I don’t need the encoder to scroll through any widgets, most screens are purely for visualization (one screen has a single button, which should be activated with the encoder button).

I have this configuration. and it appropriately detects encoder changes from the callback

        SerialPort.printf("init encoder\n");
        static lv_indev_drv_t indev_drv;
        indev_drv.type = LV_INDEV_TYPE_ENCODER;
        indev_drv.read_cb = read_encoder;
        encoder_indev = lv_indev_drv_register(&indev_drv);
        //Create Group for encoder
        SerialPort.printf("init encoder group\n");
        g = lv_group_create();
        SerialPort.printf("group created\n");
        lv_indev_set_group(encoder_indev, g);

        SerialPort.printf("UI init\n");
        SerialPort.printf("add scr to group\n");
        lv_group_add_obj(g, ui_Main_Menu);
        lv_group_add_obj(g, ui_Temperatures);
        lv_group_add_obj(g, ui_Calibration);
        lv_group_set_wrap(g, true);

However adding screens to the group has no effect.

So I’m doing something like

static int32_t last_diff = 0;
int32_t diff = 0;

enum encDir{
    STOPPED = 0,
    ROT_CW = 1,
    ROT_CCW = -1

enum encDir encoderDir = STOPPED;

void determineEncoderDir(){
    int32_t delta = diff - last_diff;
    last_diff = diff;
    else if (delta<0)encoderDir=ROT_CCW;
    else if (delta>0)encoderDir=ROT_CW;

int32_t currentScreen = 0;
lv_obj_t* screenPtrs[3] = {ui_Main_Menu,ui_Temperatures,ui_Calibration};
void switchScreen(){
    if(encoderDir == STOPPED) return;
    else if(encoderDir == ROT_CW) currentScreen++;
    else if (encoderDir == ROT_CCW) currentScreen--;

    if(currentScreen>2) currentScreen=0;
    else if (currentScreen<0) currentScreen=2;
    SerialPort.printf("currentScreen %d\n",currentScreen);
    encoderDir = STOPPED;

Does anybody have any suggestions for a more graceful integration, or is this the best that can be done? I’m not particularly married to the idea of having separate screens, but it seemed to be the best way to do it from Squareline studio. Is there any widget that would be functionally equivalent?