A slider in an ESP32 project that always snaps back to zero when moved

What do you want to achieve? I have a slider which I need to use to set a value. When I move the slider in SLS it works fine and stays where it was left upon press release. However, in the ESP32 Arduino project it snaps back to zero when the press is lifted. I have an press lost event which calls a function to store the value too but this gets the zero value as the slider snaps back on release. If I use value changed to fire my function in ui_events.c I get the correct value until the slider is released.

What have you tried so far? I have tried several settings on the slider .

Screenshot or video

autogenrated code from ui.c

void ui_SetTempAlarm_screen_init(void)
{
ui_SetTempAlarm = lv_obj_create(NULL);
lv_obj_clear_flag(ui_SetTempAlarm, LV_OBJ_FLAG_SCROLLABLE); /// Flags

ui_Panel3 = lv_obj_create(ui_SetTempAlarm);
lv_obj_set_width(ui_Panel3, 480);
lv_obj_set_height(ui_Panel3, 480);
lv_obj_set_align(ui_Panel3, LV_ALIGN_CENTER);
lv_obj_clear_flag(ui_Panel3, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
lv_obj_set_style_radius(ui_Panel3, 240, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(ui_Panel3, lv_color_hex(0x0D0C0C), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(ui_Panel3, 255, LV_PART_MAIN | LV_STATE_DEFAULT);

ui_ReturnHome1 = lv_btn_create(ui_Panel3);
lv_obj_set_width(ui_ReturnHome1, 100);
lv_obj_set_height(ui_ReturnHome1, 50);
lv_obj_set_x(ui_ReturnHome1, 0);
lv_obj_set_y(ui_ReturnHome1, 160);
lv_obj_set_align(ui_ReturnHome1, LV_ALIGN_CENTER);
lv_obj_add_state(ui_ReturnHome1, LV_STATE_PRESSED);       /// States
lv_obj_add_flag(ui_ReturnHome1, LV_OBJ_FLAG_SCROLL_ON_FOCUS);     /// Flags
lv_obj_clear_flag(ui_ReturnHome1, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
lv_obj_set_style_text_color(ui_ReturnHome1, lv_color_hex(0xADE0D6), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui_ReturnHome1, 255, LV_PART_MAIN | LV_STATE_DEFAULT);

ui_HomeLabel1 = lv_label_create(ui_ReturnHome1);
lv_obj_set_width(ui_HomeLabel1, LV_SIZE_CONTENT);   /// 1
lv_obj_set_height(ui_HomeLabel1, LV_SIZE_CONTENT);    /// 1
lv_obj_set_align(ui_HomeLabel1, LV_ALIGN_CENTER);
lv_label_set_text(ui_HomeLabel1, "Home");

ui_TempSetPanel = lv_obj_create(ui_SetTempAlarm);
lv_obj_set_width(ui_TempSetPanel, 400);
lv_obj_set_height(ui_TempSetPanel, 250);
lv_obj_set_align(ui_TempSetPanel, LV_ALIGN_CENTER);
lv_obj_clear_flag(ui_TempSetPanel, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
lv_obj_set_style_bg_color(ui_TempSetPanel, lv_color_hex(0x0A0000), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(ui_TempSetPanel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);

ui_tempAlarmSlider = lv_slider_create(ui_TempSetPanel);
lv_slider_set_range(ui_tempAlarmSlider, 0, 300);
lv_slider_set_value(ui_tempAlarmSlider, 220, LV_ANIM_OFF);
if(lv_slider_get_mode(ui_tempAlarmSlider) == LV_SLIDER_MODE_RANGE) lv_slider_set_left_value(ui_tempAlarmSlider, 0,
                                                                                                LV_ANIM_OFF);
lv_obj_set_width(ui_tempAlarmSlider, 325);
lv_obj_set_height(ui_tempAlarmSlider, 30);
lv_obj_set_align(ui_tempAlarmSlider, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_tempAlarmSlider, LV_OBJ_FLAG_CHECKABLE);     /// Flags

ui_TempAlarmSet1 = lv_label_create(ui_TempSetPanel);
lv_obj_set_width(ui_TempAlarmSet1, LV_SIZE_CONTENT);   /// 1
lv_obj_set_height(ui_TempAlarmSet1, LV_SIZE_CONTENT);    /// 1
lv_obj_set_x(ui_TempAlarmSet1, 0);
lv_obj_set_y(ui_TempAlarmSet1, -90);
lv_obj_set_align(ui_TempAlarmSet1, LV_ALIGN_CENTER);
lv_obj_set_style_text_color(ui_TempAlarmSet1, lv_color_hex(0xF1E8E8), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_opa(ui_TempAlarmSet1, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_TempAlarmSet1, &ui_font_DataFont28, LV_PART_MAIN | LV_STATE_DEFAULT);

lv_obj_add_event_cb(ui_ReturnHome1, ui_event_ReturnHome1, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_tempAlarmSlider, ui_event_tempAlarmSlider, LV_EVENT_ALL, NULL);

}

Others

  • SquareLine Studio version: 1.2.1
  • Operating system: Windows 11
  • Target hardware: ESP32S3 TTGO RGB

Hi,

Could you also show the ui_event_tempAlarmSlider event?

I suspect that it’s a touch pad related issue. Can you print the x, y and state variables from the touchpad’s read_cb? Do you see something suspicious in it?