Could this be the end of all touch screen calibration issues?

I refer the honourable gentleman to the post I made some hours ago…

I have fixed my faux pas and pushed to github. (In my enthusiasm I had removed the code that cleared calibration before aquiring new data so each calibration was being calculated from previous offsets and accumulating.)

The current code still writes to /etc/X11 files. I need to understand what you intend to do with the config files so that I know where to write what. I will look at your changes today.

2 Likes

Hi @riban!

Sorry, i didn’t explain it correctly. It’s like that:

You should save a 2 copies of the the calibration file:

  • to the config dir like this:

    $ZYNTHIAN_CONFIG_DIR/touchscreen/$DISPLAY_NAME

  • to the X11 config directory:

    /etc/X11/xorg.conf.d/99-calibration.conf

In such a way, the update_sys script can set defaults when needed and restore generated calibrations for different displays when changing the display from webconf.

Regards,

The configuration file is a single, monolithic configuration for all and any touch interfaces. For example one of mine looks like this:

Section "InputClass" # Created 2021-01-03 01:34:00.998969
        Identifier "calibration"
        MatchProduct "Fondar Fondar USB Touch"
        Option "TransformationMatrix" "1.012429 0.000000 -0.004237 0.000000 0.985915 0.010329 0.000000 0.000000 1.000000" # updated 2021-01-03 09:58:09.274197
EndSection

Section "InputClass" # Created 2021-01-03 10:36:05.087244
        Identifier "calibration"
        MatchProduct "Wacom Intuos PT S Pen stylus"
        Option "TransformationMatrix" "0.823908 0.000000 0.026897 0.000000 -0.935412 0.946659 0.000000 0.000000 1.000000" # updated 2021-01-03 10:37:50.895213
EndSection

It has two entries, one for each of the absolute x-y controllers that I have configured on that device. (The USB touch screen and a wacom tablet I used to test device detection.)

I suggest we have a master copy of the configuration that holds the default settings we know about. This would be held in version control and can be used to restore to defaults by overwriting the live copy. We then have the live copy in /etc/X11/xorg.conf.d which the calibration code updates.

We would not need device specific configuration files and calibration would not need to be updated when changing display from webconf. All displays’ configurations are held in one file.

I could upload a default config with the default settings we already know if you tell me where to stick it. I would have guessed https://github.com/zynthian/zynthian-sys/tree/master/etc/X11/xorg.conf.d but that has a file that does not actually exist on my system.

[Edit] We don’t need to add any configurations that use their defaults, e.g. my USB Fondar does not need a configuration because it will work out of the box with its defaults. If a user installs a screen upside down then they can simply calibrate to override such default.

I have looked at the existing configurations in github and believe we only have these:

# Zynthian xserver touchscreen calibration configuration

Section "InputClass"
        Identifier "calibration"
        MatchProduct "ADS7846 Touchscreen"
        Option "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"
EndSection

Section "InputClass"
        Identifier "calibration"
        MatchProduct "stmpe-ts"
        Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"
EndSection

Although there are several different screen configurations, most use the same ADS7846 Touchscreen.

If anyone else has other screen configs then tell us here.

Hi @riban!

Using several touch devices simultaneously on zynthian is a really rare case, my friend. I would say “OK” if it didn’t add extra complexity, but …

… different displays can use the same TouchDevice, while having different default TransformationMatrix. This is specially true for the ubiquitous ADS7846, that is used for several WaveShare displays and also Piscreen & Zynscreen.

I would suggest to go the way i paved, that solves the problem of having a single touch device. For more bizarre multi-touchdevice configurations, a secondary “custom” calibration file should solve the problem.

Please, remember zynthian is a synthesizer … not a PC!!

Thanks!

1 Like

I don’t anticipate more than one touch interface but it seems the ADS7846 driver is enabled by default hence a device appears in the list even when not installed which is why I have to detect which interface is actually being calibrated on first press.

All the ADS7846 customisation scripts I have found in Zynthian codebase use the same transformation. There is the chance that someone puts the screen in a different orientation than expected (like Zynscreen, upside down :stuck_out_tongue:) but that just requires one calibration.

Using a (fully) populated xorg configuration file allows out-of-the-box correct operation of touchscreen without requiring webconf.

I continue to think my suggestion is the right way but you are the boss, so…

I don’t understand why you suggest updating two files. Surely updating the live file is what we want with the ability to reset that via webconf if the display is changed, in which case my code will work (and remains compatible with my alternative scheme :wink:).

We don’t want people configuring a Waveshare have axis swaped by default …

Webconf is needed for configuring the display itself. Zynthian SD images comes with a pre-configured display and touchscreen. If you are using a different one, you must use the webconf.

My proposal is that Zynthian (can) have a default calibration matrix for every display model and it remembers the generated calibration for every display model too. When the display model is changed from webconf, the saved calibration config is loaded, if it doesn’t exist, the default calibration is loaded instead.

The limitation is that only one touchdevice is configured in the 99-calibration.conf.

You proposal has 2 problems:

  • Adding new display calibration defaults or modifying existing defaults is not easy.
  • Managing displays that use the same TouchDevice but different calibration matrix (ADS7846).

And 1 advantage:

  • It supports multi-touchdevice configurations

Calibration can be modified from UI using the new tool. You write the X11 config file and it works. But next time update_sys script is executed (almost every time you click “save” button on webconf), it will regenerate all config files based on configured values (envars), overwriting existing ones. Saving a copy of the calibration config on the config directory, per-display, is a simple solution that works. :wink:

Regars,

I have done as you ask (even though you are wrong :wink:). I must once more voice my unease at this method. It is quite ridiculous to me to write the same file twice twice. Imagine I have a display that is kinda working but needs calibration. I calibrate and all is good. I then go to webconf and realise I had the wrong screen selected. My previous calibration has written my desired configuration to the live xserver file and the default copy of the wrong screen. I have now corrupted the default data.

Anyway - my concerns are a matter of record. You are the boss. You take responsibility. I guess it is time for a pull request…

1 Like

The default config is not overwrote. Remember that it’s on the zynthian-sys dir. We could easily add a “delete custom calibration” button on the webconf, and the default calibration will be loaded. Or you could simply re-calibrate.

We need a way of updating default calibrations, and having mixed in the same file default and custom calibrations makes things more difficult to manage. Of course, we could parse and replace the calibration file. If you implement a simple CLI tool for managing calibration file (add, update and delete calibrations), then i could use it from the update_sys script. In such a case, i would agree on implementing things as you propose :yum:

all the best!

The calibration file parsing is in the code. I have commented it out for your pleasure!

Yes, but we need this functionality available from the udpate_sys script. Let me merge the current PR, let the community to test the functionality, and we can make a second step like this:

  • Creating a little CLI script allowing to manage the calibration file.
  • Modifying update_sys script for using it.
  • Add the “Delete Custom Calibration” button to webconf

Sorry for not explaining myself very well in my reply above. I really love the calibration tool, but having multi-device configurations is not a priority. We go one step forward and after a second one :wink:

Really Big Thanks @riban !

Hi @zynthianers!

The new calibration tool developed by @riban is already merged on master.
Simply update and enjoy!

zynthian_ui_calibration_01

zynthian_ui_calibration_02

zynthian_ui_calibration_03

It only supports one touch device, but we will improve it for supporting N touch devices :yum: :zynlogo:

Huge Thanks, Mr. @riban! :smiling_face_with_three_hearts:

6 Likes

I have added a section to the wiki describing operation of the calibration screen. Here is a summary:

  • Screen shows target crosshairs that must be touched and released
  • First target does no calibration and only detects the touch interface
  • Display type shown after first touch
  • Consequent touches are measured on release, allowing drag to target for more accuracy
  • After second touch the calibration is written to two files (I disagree!)
  • Each target appears white and changes to red when screen touched
  • Touches too close together are ignored (half a screen)
  • A timeout of 15s after last touch or release will close screen without saving configuration
  • BACK button will close screen without saving configuration

I don’t think we need support for multiple simultaneous touchscreens, at least not until we provide extended (second / third) screen support. The robust discussion @jofemodo and I had about how to implement persistent storage was not about multiple screens but how best to storeand restore configuration. VHS won over Betamax but we know which was best :wink:.

2 Likes

The second screen support will arrive sooner than later :wink:

Regarding the Betamax, in its current status has some limitations:

Example 1.) You have a 2 zynthians, one official kit with the Zynscreen and a second one with a Waveshare. Both displays use the same touch device “ADS7846”. You want to move the SD card from one zynthian to the other one. The Betamax can’t manage (in its current status) this situation and you need to recalibrate the touchscreen every time you move the SD card . If you don’t recalibrate, axis will be swapped and touch interface will be completely unusable. In the other hand, the poor VHS will manage the situation smoothly.

Example 2.) We add a new touch display to the config list. The Betamax (in its current status) can’t manage this situation and users wanting to test the new display with a working SD-card will need to use the terminal for fixing the configuration. The poor VHS will manage the situation smoothly.

Anyway, i must say that Betamax is a better system, but we need to address these little issues before jumping to it. Step by step.

All the best!

Argh! VHS epic fail!!! I updated my official Zynthian V4.1 and touchscreen calibration is inverted.

VHS 0 - Betamax 1

This is the scenario that VHS is supposed to avoid! What is going on???

Even after calibration it is still wrong. Something is awry.

Reverting to feature branch resolves issue so something wrong with the merge to master>

It could be a trace from some development bug that have corrupted the calibration file. Try to run update_zynthian_sys.sh script. Or click “save” from webconf.

Regards,

BTW, are you sure the update is pulling correctly everything? When developing and copying files by hand to the zynthian, sometimes you have to delete some of the files added by hand for allowing “git pull” to work.

I did this on my production unit which is separate to my development machine. I mostly develop and test on one machine and now that I have a pucker V4.1 I test on that after committing to GitHub.

Could you check if this file:

$ZYNTHIAN_CONFIG_DIR/zynthian_custom_config.sh

does exist? It should be removed …

Regards,

That file does not exist.

I swapped back to feature branch, calibrated fine. I swapped back to master and it remembered the calibration and consequent calibration is working fine.

I am worried that I experienced the issue I was worried about, i.e. that overwritting the live xserver config file and also updating the backup file is prone to unexpected behaviour. I understand your approach of having configurations for each screen type but don’t think we should update the backup / default. We should avoid overwritting the xserver file unless we have specifically chosen a different screen.

I can’t really comment on how your update and save mechanism works as I don’t fully understand it. I do know it causes me (and others) occasional issues when we try to circumvent it (which is to be expected) but in some cases (including this one) I think it may be overly complicated and hence getting in the way of a simple task. But I will go away now and leave it to the wider community to update, test and comment.

I never had a Betamax! I do still have many VHS cassettes but my player died some time ago!

And we don’t. We only save the custom calibration for each display in a separated file.
The display’s default calibration is always on the zynthian-sys/custom dir.

The update_zynthian_sys.sh script always regenerate almost all the relevant system files, and it’s good because it allows to fix a lot of problems. Generating the X11 calibration file shouldn’t be a problem. It’s the way zynthian configuration script works normally.

BTW, i just updated with a “virgin” V4 and it worked nicely. I think you v4 was polluted with some trace of your development process.

Simply burn a SD with the lated RC3 and update.

Regards,