Skip to content

Commit

Permalink
Added calibration instructions, failure checking in c and corrected a…
Browse files Browse the repository at this point in the history
…xis/abs info
  • Loading branch information
LinusCDE committed Mar 31, 2019
1 parent d886612 commit 3d18fe2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ Create a file called `/etc/X11/xorg.conf.d/10-evdev.conf` and add [this content]
In order to work in GIMP, the device must get enabled under `Edit -> Input devices`.


# Calibrating

It also is a good idea to calibrate the tablet using xinput_calibrator because the tablet screen will be streched to match your screen. That will result in a wrong aspect ratio.

When calibration using xinput_calibrator use the pdf, open it on the reMarkable and touch the points there.

(I essentially just recorded the calibration screen, took a screenshot, changed the colors, added borders, and created a pdf from it.)

# Credits

Huge thanks to benthor's [HuionKamvasGT191LinuxDriver](https://github.com/benthor/HuionKamvasGT191LinuxDriver) (found
Expand Down
31 changes: 20 additions & 11 deletions tabletDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ void addAbsCapability(int fd, int code, int32_t value, int32_t min, int32_t max,
abs_setup.code = code;
abs_setup.absinfo = abs_info;

ioctl(fd, UI_ABS_SETUP, &abs_setup); // Set abs data
if(ioctl(fd, UI_ABS_SETUP, &abs_setup) < 0) { // Set abs data
perror("Failed to absolute info to uinput-device (old kernel?)");
exit(1);
}
}

int main(int argc, char** argv)
Expand Down Expand Up @@ -83,14 +86,14 @@ int main(int argc, char** argv)

// See https://python-evdev.readthedocs.io/en/latest/apidoc.html#evdev.device.AbsInfo.resolution
// Resolution = max(20967, 15725) / (21*10) # Height of display is 21cm. Format is units/mm. => ca. 100 (99.84285714285714)
// Tilt resolution = 12400 / ((math.pi / 180) * 140 (max angle)) (Format: units/radian) => ca. 5074 (5074.769042587292)
// Tilt resolution = 12600 / ((math.pi / 180) * 140 (max angle)) (Format: units/radian) => ca. 5074 (5074.769042587292)
ioctl(fd, UI_SET_EVBIT, EV_ABS);
addAbsCapability(fd, ABS_PRESSURE, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 4095, /*Resolution:*/ 0, /*Fuzz:*/ 0, /*Flat:*/ 0 );
addAbsCapability(fd, ABS_DISTANCE, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 110, /*Resolution:*/ 0, /*Fuzz:*/ 0, /*Flat:*/ 0 );
addAbsCapability(fd, ABS_TILT_X, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 12400, /*Resolution:*/ 5074, /*Fuzz:*/ 0, /*Flat:*/ 6200);
addAbsCapability(fd, ABS_TILT_Y, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 12400, /*Resolution:*/ 5074, /*Fuzz:*/ 0, /*Flat:*/ 6200);
addAbsCapability(fd, ABS_X, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 20967, /*Resolution:*/ 100, /*Fuzz:*/ 0, /*Flat:*/ 0 );
addAbsCapability(fd, ABS_Y, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 15725, /*Resolution:*/ 100, /*Fuzz:*/ 0, /*Flat:*/ 0 );
addAbsCapability(fd, ABS_PRESSURE, /*Value:*/ 0, /*Min:*/ 0, /*Max:*/ 4095, /*Resolution:*/ 0, /*Fuzz:*/ 0, /*Flat:*/ 0);
addAbsCapability(fd, ABS_DISTANCE, /*Value:*/ 95, /*Min:*/ 0, /*Max:*/ 255, /*Resolution:*/ 0, /*Fuzz:*/ 0, /*Flat:*/ 0);
addAbsCapability(fd, ABS_TILT_X, /*Value:*/ 0, /*Min:*/ -9000, /*Max:*/ 9000, /*Resolution:*/ 5074, /*Fuzz:*/ 0, /*Flat:*/ 0);
addAbsCapability(fd, ABS_TILT_Y, /*Value:*/ 0, /*Min:*/ -9000, /*Max:*/ 9000, /*Resolution:*/ 5074, /*Fuzz:*/ 0, /*Flat:*/ 0);
addAbsCapability(fd, ABS_X, /*Value:*/ 11344, /*Min:*/ 0, /*Max:*/ 20967, /*Resolution:*/ 100, /*Fuzz:*/ 0, /*Flat:*/ 0);
addAbsCapability(fd, ABS_Y, /*Value:*/ 10471, /*Min:*/ 0, /*Max:*/ 15725, /*Resolution:*/ 100, /*Fuzz:*/ 0, /*Flat:*/ 0);

struct uinput_setup usetup;
memset(&usetup, 0, sizeof(usetup));
Expand All @@ -99,9 +102,15 @@ int main(int argc, char** argv)
//usetup.id.product = 0x7890; /* sample product */
usetup.id.version = 0x3;
strcpy(usetup.name, "reMarkableTablet-FakePen"); // Has to end with "pen" to work in Krita!!!
ioctl(fd, UI_DEV_SETUP, &usetup);

ioctl(fd, UI_DEV_CREATE);
if(ioctl(fd, UI_DEV_SETUP, &usetup) < 0) {
perror("Failed to setup uinput-device (old kernel?)");
return 1;
}

if(ioctl(fd, UI_DEV_CREATE) < 0) {
perror("Failed to create uinput-device");
return 1;
}

void closeDevice() {
ioctl(fd, UI_DEV_DESTROY);
Expand Down
13 changes: 7 additions & 6 deletions tabletDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@
# BTN_TOOL_PEN == 1 means that the pen is hovering over the tablet
# BTN_TOUCH == 1 means that the pen is touching the tablet

# This WONT'T WORK with libinput since the resolution is never actually set.
# This WONT'T WORK with libinput since the resolution is never actually set
# and pydev uses an old method for creating the uinput-device which can't set the resolution.
# This is fixed in the c-version but doesn't quite work yet, too.
capabilities = {
ecodes.EV_KEY: [ecodes.BTN_TOOL_PEN, ecodes.BTN_TOUCH],
EV_ABS: [
(WACOM_EVCODE_PRESSURE, AbsInfo(value=0, min=0, max=4095, fuzz=0, flat=0, resolution=0)),
(WACOM_EVCODE_DISTANCE, AbsInfo(value=0, min=0, max=110, fuzz=0, flat=0, resolution=0)),
(WACOM_EVCODE_XTILT, AbsInfo(value=0, min=0, max=12400, fuzz=0, flat=6200, resolution=5074)),
(WACOM_EVCODE_YTILT, AbsInfo(value=0, min=0, max=12400, fuzz=0, flat=6200, resolution=5074)),
(WACOM_EVCODE_XPOS, AbsInfo(value=0, min=0, max=WACOM_HEIGHT, fuzz=0, flat=0, resolution=100)),
(WACOM_EVCODE_YPOS, AbsInfo(value=0, min=0, max=WACOM_WIDTH, fuzz=0, flat=0, resolution=100))
(WACOM_EVCODE_DISTANCE, AbsInfo(value=95, min=0, max=255, fuzz=0, flat=0, resolution=0)),
(WACOM_EVCODE_XTILT, AbsInfo(value=0, min=-9000, max=9000, fuzz=0, flat=0, resolution=5074)),
(WACOM_EVCODE_YTILT, AbsInfo(value=0, min=-9000, max=9000, fuzz=0, flat=0, resolution=5074)),
(WACOM_EVCODE_XPOS, AbsInfo(value=11344, min=0, max=WACOM_HEIGHT, fuzz=0, flat=0, resolution=100)),
(WACOM_EVCODE_YPOS, AbsInfo(value=10471, min=0, max=WACOM_WIDTH, fuzz=0, flat=0, resolution=100))
]
}

Expand Down
Binary file not shown.

0 comments on commit 3d18fe2

Please sign in to comment.