Skip to content

Commit d2079d1

Browse files
author
okay
committed
[input] refactor wacom and read max x,y from ioctls to set scaling properly
this makes MT_X_SCALAR and WACOM_X_SCALAR no longer necessary
1 parent 32f8ddc commit d2079d1

File tree

5 files changed

+102
-18
lines changed

5 files changed

+102
-18
lines changed

src/lamp/main.cpy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ rm_version := util::get_remarkable_version()
2525
#define DISPLAYWIDTH 1404
2626
#define DISPLAYHEIGHT 1872.0
2727

28-
#ifdef KOBO
28+
#if defined(REMARKABLE) | defined(DEV)
29+
#define MTWIDTH 767
30+
#define MTHEIGHT 1023
31+
#define WACOMWIDTH 15725.0
32+
#define WACOMHEIGHT 20967.0
33+
#define DISPLAYWIDTH 1404
34+
#define DISPLAYHEIGHT 1872.0
35+
#define MT_X_SCALAR (float(DISPLAYWIDTH) / float(MTWIDTH))
36+
#define MT_Y_SCALAR (float(DISPLAYHEIGHT) / float(MTHEIGHT))
37+
#define WACOM_X_SCALAR (float(DISPLAYWIDTH) / float(WACOMWIDTH))
38+
#define WACOM_Y_SCALAR (float(DISPLAYHEIGHT) / float(WACOMHEIGHT))
39+
#elif KOBO
2940
#define MTWIDTH DISPLAYWIDTH
3041
#define MTHEIGHT DISPLAYHEIGHT
3142
#define MT_X_SCALAR 1

src/rmkit/defines.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@
5454

5555

5656
// {{{ DISPLAY RELATED DEFINES
57-
// TODO: move these into individual files for each device type
58-
// TODO: this should happen alongside refactoring the wacom stylus handling
59-
#if defined(REMARKABLE) | defined(DEV)
57+
#ifdef DEV
58+
// in dev mode, we are assuming we have remarkable settings
6059
#define MTWIDTH 767
6160
#define MTHEIGHT 1023
6261
#define WACOMWIDTH 15725.0
@@ -67,11 +66,6 @@
6766
#define MT_Y_SCALAR (float(DISPLAYHEIGHT) / float(MTHEIGHT))
6867
#define WACOM_X_SCALAR (float(DISPLAYWIDTH) / float(WACOMWIDTH))
6968
#define WACOM_Y_SCALAR (float(DISPLAYHEIGHT) / float(WACOMHEIGHT))
70-
#elif KOBO
71-
#undef DISPLAYWIDTH
72-
#undef DISPLAYHEIGHT
73-
#define DISPLAYWIDTH 1264
74-
#define DISPLAYHEIGHT 1680
7569
#endif
7670

7771
#define TOOLBAR_HEIGHT 50

src/rmkit/fb/fb.cpy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,5 +863,4 @@ namespace framebuffer:
863863
fb_info::width = _FB->width
864864
fb_info::height = _FB->height
865865

866-
867866
return _FB

src/rmkit/input/events.cpy

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "../fb/fb_info.h"
66

77
//#define DEBUG_INPUT_EVENT 1
8-
8+
//#define DEBUG_INPUT_INIT 1
99
namespace input:
1010
extern int next_id = 1234
1111

@@ -97,13 +97,29 @@ namespace input:
9797
int slot = 0, left = -1
9898
bool lifted=false
9999

100-
float scale_y=1.0, scale_x=1.0
101-
int swap_xy=false, invert_x=false, invert_y=false
102100
static int MAX_SLOTS = 10
103101
struct Point:
104102
int x=-1, y=-1, left=-1
105103
;
106104

105+
static float scale_x=1.0
106+
static float scale_y=1.0
107+
int swap_xy=false, invert_x=false, invert_y=false
108+
static void set_extents(int w, h, dw, dh):
109+
#ifdef DEV
110+
scale_x = MT_X_SCALAR
111+
scale_y = MT_Y_SCALAR
112+
return
113+
#endif
114+
115+
scale_x = float(dw) / float(w)
116+
scale_y = float(dh) / float(h)
117+
#ifdef DEBUG_INPUT_INIT
118+
debug "TW, TH:", w, h
119+
debug "SET SCALING TO", scale_x, scale_y
120+
#endif
121+
122+
107123
// kobo libra rot0: swap_xy, invert_x
108124
// kobo libra rot180: swap_xy, invert_y
109125
// rm1: scale_x, scale_y, invert_x, invert_y
@@ -116,8 +132,6 @@ namespace input:
116132
// rM1
117133
invert_y = true
118134
if not rm2fb::IN_RM2FB_SHIM:
119-
scale_x = MT_X_SCALAR
120-
scale_y = MT_Y_SCALAR
121135
invert_x = true
122136
#elif KOBO
123137
rotation := util::rotation::get()
@@ -228,6 +242,29 @@ namespace input:
228242
int btn_touch = -1
229243
int eraser = -1
230244

245+
// rM has swapped axis and inverted y by default
246+
static float scale_x=1.0
247+
static float scale_y=1.0
248+
int swap_xy=false, invert_x=false, invert_y=false
249+
static void set_extents(int w, h, dw, dh):
250+
#ifdef DEV
251+
scale_x = WACOM_X_SCALAR
252+
scale_y = WACOM_Y_SCALAR
253+
return
254+
#endif
255+
scale_x = float(dw) / float(w)
256+
scale_y = float(dh) / float(h)
257+
#ifdef DEBUG_INPUT_INIT
258+
debug "WW, WH:", w, h
259+
debug "SET SCALING TO", scale_x, scale_y
260+
#endif
261+
262+
WacomEvent():
263+
#if defined(REMARKABLE) | defined(DEV)
264+
swap_xy = true
265+
invert_y = true
266+
#endif
267+
231268
def marshal():
232269
SynMotionEvent syn_ev;
233270
syn_ev.x = self.x
@@ -256,12 +293,24 @@ namespace input:
256293

257294
handle_abs(input_event data):
258295
#if defined(REMARKABLE) | defined(DEV)
296+
if swap_xy:
297+
if data.code == ABS_X:
298+
data.code = ABS_Y
299+
else if data.code == ABS_Y:
300+
data.code = ABS_X
301+
259302
switch data.code:
260303
case ABS_Y:
261-
self.x = data.value * WACOM_X_SCALAR
304+
if invert_y:
305+
self.y = framebuffer::fb_info::display_height - data.value * scale_y
306+
else:
307+
self.y = data.value * scale_y
262308
break
263309
case ABS_X:
264-
self.y = (WACOMHEIGHT - data.value) * WACOM_Y_SCALAR
310+
if invert_x:
311+
self.x = framebuffer::fb_info::display_width - data.value * scale_x
312+
else:
313+
self.x = data.value * scale_x
265314
break
266315
case ABS_TILT_X:
267316
self.tilt_x = data.value

src/rmkit/input/input.cpy

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/ioctl.h>
88

99
#include "../defines.h"
10+
#include "../fb/fb_info.h"
1011
#include "events.h"
1112
#include "gestures.h"
1213
#include "device_id.h"
@@ -28,7 +29,6 @@ namespace input:
2829
T prev_ev, event
2930
vector<T> events
3031

31-
3232
InputClass():
3333
pass
3434

@@ -113,6 +113,7 @@ namespace input:
113113
socketpair(AF_UNIX, SOCK_STREAM, 0, ipc_fd)
114114

115115
self.monitor(input::ipc_fd[0])
116+
self.set_scaling(framebuffer::fb_info::display_width, framebuffer::fb_info::display_height)
116117
return
117118

118119

@@ -148,6 +149,36 @@ namespace input:
148149

149150
self.monitor(fd)
150151

152+
// adapted from https://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/064/6429/6429l17.html
153+
// NOTE: we assume that we only need max value from here and its anchored at 0,
154+
// this may not be true in the future
155+
tuple<struct input_absinfo, struct input_absinfo> read_extents(int fd, x_id, y_id):
156+
uint8_t abs_b[ABS_MAX/8 + 1]
157+
struct input_absinfo abs_feat
158+
abs_bit := EVIOCGBIT(EV_ABS, sizeof(abs_b))
159+
ioctl(fd, abs_bit, abs_b)
160+
161+
struct input_absinfo x_feat, y_feat
162+
if (ioctl(fd, EVIOCGABS(x_id), &x_feat)):
163+
perror("evdev EVIOCGABS ioctl");
164+
if (ioctl(fd, EVIOCGABS(y_id), &y_feat)):
165+
perror("evdev EVIOCGABS ioctl");
166+
167+
if x_feat.maximum < y_feat.maximum:
168+
return x_feat, y_feat
169+
return y_feat, x_feat
170+
171+
void set_scaling(int display_width, int display_height):
172+
if self.wacom.fd > 0:
173+
xf, yf := self.read_extents(self.wacom.fd, ABS_X, ABS_Y)
174+
WacomEvent::set_extents(xf.maximum, yf.maximum, display_width, display_height)
175+
176+
if self.touch.fd > 0:
177+
xf, yf := self.read_extents(self.touch.fd, ABS_MT_POSITION_X, ABS_MT_POSITION_Y)
178+
TouchEvent::set_extents(xf.maximum, yf.maximum, display_width, display_height)
179+
return
180+
181+
151182
void reset_events():
152183
self.wacom.clear()
153184
self.touch.clear()

0 commit comments

Comments
 (0)