LCD touch/input scaling FIXED! (7" Waveshare DSI (C) 1024x600)

Tears of joy :smiling_face_with_tear:

From the moment I hooked this screen to Zynthian, it had a scaling input problem where touch alignment gets worse towards bottom right of the screen (e.g. notes in pattern editor don’t go anywhere near your press). I’ve attempted fixes in the past without success. I posted some of my misadventures in the threads below where others had similar issues. Frustratingly, the screen has always worked fine in Bookworm/Trixie OS. Something happens in Zynthian at startup, I just couldn’t figure out what. I’d resigned myself to buying a new screen eventually and got by with just encoders and midi controllers.

It turns out, after querying a chatbot for a while and testing a few things, I found the evtest for touch input shows the bottom corner registering as 800x480 (not 1024x600). If I understand correctly, multitouch.py disables Xinput and reads direct from evdev instead, so the mismatch causes drift the further you go from the corner.

The fix that worked was to divide the actual display height 1024 by the (wrong) value evdev reports to get the scale factor and update the lines below (along with resolution constants). Being able to finally use the screen with touch overlay working is so great!!!

Summary

It was the extra two lines for each axis that solved it:

self._current_touch.x_root = round(
    self._current_touch.x_root * TOUCH_DISPLAY_WIDTH / self.max_x)    

elif evdev_event.code == ecodes.ABS_MT_POSITION_X:
    if self._invert_x:
        self._current_touch.x_root = self.max_x - evdev_event.value
    else:
        self._current_touch.x_root = evdev_event.value
    self._current_touch.x_root = round(
        self._current_touch.x_root * TOUCH_DISPLAY_WIDTH / self.max_x)    
    if self._current_touch not in self.events:
        self.events.append(self._current_touch)
elif evdev_event.code == ecodes.ABS_MT_POSITION_Y:
    if self._invert_y:
        self._current_touch.y_root = self.max_y - evdev_event.value
    else:
        self._current_touch.y_root = evdev_event.value
    self._current_touch.y_root = round(
        self._current_touch.y_root * TOUCH_DISPLAY_HEIGHT / self.max_y)    
    if self._current_touch not in self.events:
        self.events.append(self._current_touch)

@jofemodo Do you think there might be a way to allow for screens like this where the touch resolution reports different to the screen resolution?

This thread too but not clear if OP’s LCD touch problem was specifically scaling issue.

1 Like

Hi @LFO !

Your fix include 2 variables called TOUCH_DISPLAY_WIDTH and TOUCH_DISPLAY_HEIGHT, but this 2 variables doesn’t exist in the current code base.

What is the value for these 2 variables? Is it the display size in pixels? Then we should use better:

  • zynthian_gui_config.display_width
  • zynthian_gui_config.display_height

Could you test if this works for you?

Regards,

Hi Jofe, yes you are right about the variables, it’s the display size WIDTH = 1024 & HEIGHT = 600.

I tried your method and it still works fine! :+1:

1 Like