12-OBD-Speed: settings page with screen rotation (0/90/180/270)

- third tile (swipe left from the menu): rotation buttons, saved in NVS,
  applied at boot
- shared lib: setRotation() rotates only the panel and redraws; touch
  points are converted in touchpad_read() for the current rotation;
  getRotation() added

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patriandClaude Opus 5.5 committed 2026-10-23 18:20:35 +02:00
1 parent 733306a9c0
commit 4fc70f13d0
5 files changed
+107 -21

No files matched your search

+36 -17
View File
@@ -272,11 +272,15 @@ IRAM_ATTR bool onRefreshFinishCallback(void *user_data)
return false;
}
static uint8_t rotation = 0; // 0..3, clockwise in 90° steps
// The panel rotates the image itself (MADCTL swap/mirror, same combinations as the vendor code);
// touch points are converted in touchpad_read() so they always match what is shown.
void setRotation(uint8_t rot)
{
if (rot > 3)
return;
if (lcd == NULL || touch == NULL)
if (lcd == NULL)
return;
switch (rot)
@@ -285,35 +289,31 @@ void setRotation(uint8_t rot)
lcd->swapXY(true);
lcd->mirrorX(true);
lcd->mirrorY(false);
touch->swapXY(true);
touch->mirrorX(true);
touch->mirrorY(false);
break;
case 2:
case 2: // 180°
lcd->swapXY(false);
lcd->mirrorX(true);
lcd->mirrorY(true);
touch->swapXY(false);
touch->mirrorX(true);
touch->mirrorY(true);
break;
case 3:
case 3: // 270° clockwise
lcd->swapXY(true);
lcd->mirrorX(false);
lcd->mirrorY(true);
touch->swapXY(true);
touch->mirrorX(false);
touch->mirrorY(true);
break;
default:
lcd->swapXY(false);
lcd->mirrorX(false);
lcd->mirrorY(false);
touch->swapXY(false);
touch->mirrorX(false);
touch->mirrorY(false);
break;
}
rotation = rot;
if (disp)
lv_obj_invalidate(lv_display_get_screen_active(disp)); // redraw everything in the new orientation
}
uint8_t getRotation()
{
return rotation;
}
void screen_switch(bool on)
@@ -341,8 +341,27 @@ static void touchpad_read(lv_indev_t *indev, lv_indev_data_t *data)
int read_touch_result = tp->readPoints(&point, 1);
if (read_touch_result > 0)
{
data->point.x = point.x;
data->point.y = point.y;
// physical panel coordinates -> coordinates of the rotated image
const int max = SCREEN_RES_HOR - 1; // square display
switch (rotation)
{
case 1:
data->point.x = point.y;
data->point.y = max - point.x;
break;
case 2:
data->point.x = max - point.x;
data->point.y = max - point.y;
break;
case 3:
data->point.x = max - point.y;
data->point.y = point.x;
break;
default:
data->point.x = point.x;
data->point.y = point.y;
break;
}
data->state = LV_INDEV_STATE_PRESSED;
}
else
+2 -1
View File
@@ -17,8 +17,9 @@
// Initializes backlight, touch, LCD and LVGL (lv_init, tick, display, touch input). Returns the display.
lv_display_t *scr_lvgl_init();
// 0 = normal, 1 = 90° clockwise, 2 = 180°, 3 = 270° (LCD and touch together)
// 0 = normal, 1 = 90° clockwise, 2 = 180°, 3 = 270° (LCD and touch together; call after scr_lvgl_init)
void setRotation(uint8_t rot);
uint8_t getRotation();
void screen_switch(bool on);