Skip to content

Commit

Permalink
Add a pressurecurve debugging tool
Browse files Browse the repository at this point in the history
This tool takes (one or multiple) sets of 4 coordinate that represent
the second and third point for our pressure curve (first and fourth
points are hardcoded to 0/0 and 1/1 like the driver does)

It spits out gnuplot-compatible lines that can be printed for visual
debugging. Usage to print the GNOME default curves:

./build/pressurecurve \
    0 .75 .25 1 \
    0 .5 .5 1  \
    0 .25 .75 1 \
    0 0 1 1 \
    .25 0 1 .75 \
    .5 0 1 .5 \
    .75 0 1 .25 > gnuplot.data

And that gnuplot data can then be printed with:

 #!/usr/bin/gnuplot
 set terminal qt persist
 set style data lines
 set xrange [0:1]
 set yrange [0:1]
 plot \
  "gnuplot.data" using 1:2 title "  0, .75, .25, 1", \
  "gnuplot.data" using 1:3 title "  0, .50, .50, 1", \
  "gnuplot.data" using 1:4 title "  0, .25, .75, 1", \
  "gnuplot.data" using 1:5 title "  0,   0,   1, 1", \
  "gnuplot.data" using 1:6 title ".25, 0,   1, .75", \
  "gnuplot.data" using 1:7 title ".50, 0,   1, .50", \
  "gnuplot.data" using 1:8 title ".75, 0,   1, .25"
  • Loading branch information
whot committed Nov 14, 2023
1 parent 81d24e2 commit 6471457
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ executable(
install: true,
)

executable(
'pressurecurve',
['tools/pressurecurve.c',
'src/wcmPressureCurve.c'],
include_directories: [dir_src],
install: false)

# Man pages
config_man = configuration_data()
config_man.set('VERSION', '@0@ @1@'.format(meson.project_name(), meson.project_version()))
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ xsetwacom_test_LDADD = $(X11_LIBS)
TESTS=$(check_PROGRAMS)
endif

EXTRA_DIST = wacom-record.c
EXTRA_DIST = wacom-record.c pressurecurve.c
114 changes: 114 additions & 0 deletions tools/pressurecurve.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2023 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <assert.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>

#include "wcmPressureCurve.h"

static void
usage(void) {
printf("Usage: pressurecurve [OPTIONS] x1 y1 x2 y2 ...\n");
printf("\n");
printf("This tool takes four coordinates in the range [0.0, 1.0] representing \n"
"the driver's pressure curve configuration.\n"
"The output contains one line with input pressure and output pressure for\n"
"each normalized [0.0, 1.0] input pressure value\n"
"\n"
"Multiple sets of 4 coordinates may be given \n");
}

int main(int argc, char **argv)
{
/* The driver pre-calculates the pressurecurve for each possible
* pressure value. Typically this is 2k or 8k for newer pens, here
* we use 1000 points to get smooth gnuplot output.
*
* The value in filterCurveToLine() is normalized into this range so
* the curve will have values in the range [0, 1000].
*/
const size_t npoints = 1000;

/* These two are hardcoded by the driver */
const double x0 = 0.0, y0 = 0.0;
const double x3 = 1.0, y3 = 1.0;

enum {
OPT_HELP,
};

static struct option long_options[] = {
{"help", no_argument, 0, OPT_HELP},
{0, 0, 0, 0},
};

int c;
while (1)
{
int option_index = 0;

c = getopt_long(argc, argv, "", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case OPT_HELP:
usage();
return 0;
default:
break;
}
}

if (optind + 4 > argc || (argc - optind) % 4 != 0) {
usage();
return 1;

}

size_t ncurves = (argc - optind) / 4;
int curve[ncurves][npoints];
int idx = 0;

printf("# column 0: input pressure value [0,1]\n");
while (optind < argc)
{
double x1 = atof(argv[optind++]);
double y1 = atof(argv[optind++]);
double x2 = atof(argv[optind++]);
double y2 = atof(argv[optind++]);

filterCurveToLine(curve[idx], npoints, x0, y0, x1, y1, x2, y2, x3, y3);

printf("# column %d: %f/%f %f/%f %f/%f %f/%f\n", idx, x0, y0, x1, y1, x2, y2, x3, y3);
idx++;
}

for (size_t i = 0; i < npoints; i++)
{
printf("%f", i/(double)npoints);
for (size_t j = 0; j < ncurves; j++)
printf(" %f", curve[j][i]/(double)npoints);
printf("\n");
}

return 0;
}

0 comments on commit 6471457

Please sign in to comment.