Skip to content

Commit d6be1cf

Browse files
committed
move into python package
1 parent 37c4558 commit d6be1cf

File tree

11 files changed

+334
-67
lines changed

11 files changed

+334
-67
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# remarkable_sim
2+
3+
![](screenshot.png)
4+
5+
## Install
6+
7+
Tkinter is a dependency. (`python3-tk` in Debian/Ubuntu)
8+
9+
pip install remarkable-sim
10+
11+
## Usage
12+
13+
resim
14+
15+
`resim` will create 3 FIFOs at `event0`, `event1`, and `event2` in the current directory and will attempt to read from `fb.pgm` 10 times per second. The application under test should write to this framebuffer file and read evdev events from the FIFOs.
16+

evdev_notes.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
- [event docs](https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt)
2+
3+
codes resolved with python evdev
4+
5+
dict(evdev.resolve_ecodes_dict({3: [0, 1, 24, 25, 26, 27]}))
6+
7+
# evdev Message Structure
8+
- https://stackoverflow.com/questions/23480741/obtaining-evdev-event-code-from-raw-bytes
9+
10+
- 4 byte unsigned integer - seconds
11+
- 4 byte unsigned integer - microseconds
12+
- 2 byte unsigned integer - type
13+
- 2 byte unsigned integer - code
14+
- 4 byte signed integer - value
15+
16+
# Coordinate Systems
17+
18+
Stylus Touch TKinter
19+
+---------+ +---------+ +---------+
20+
| x | | y | | +---x |
21+
| | | | | | | | |
22+
| | | | | | | | |
23+
| +--- y | | x---+ | | y |
24+
+---------+ +---------+ +---------+
25+
|o o o| |o o o| |o o o|
26+
+---------+ +---------+ +---------+
27+
28+
# evdev Event Files and Codes
29+
30+
## event0 - Stylus
31+
- type 0 - ev_sync
32+
- type 1 - ev_key
33+
- code [code #] - [name] - [desc] - [range]
34+
- code 320 - toolpen - -
35+
- code 321 - toolrubber - -
36+
- code 330 - touch - -
37+
- code 331 - stylus - -
38+
- code 332 - stylus2 - -
39+
- type 3 - ev_abs - absolute
40+
- code 0 - abs_x - xpos - (0: bottom, 20967: top)
41+
- code 1 - abs_y - ypos - (0: left, 15725: right)
42+
- code 24 - abs_pressure - (0, 4095)
43+
- code 25 - abs_distance - distance between pen and surface - (0: lowered, ~100: raised)
44+
- code 26 - abs_tilt_x - (-6300: pen flat pointing up, 6300: pen flat pointing down)
45+
- code 27 - abs_tilt_y - (-6300: pen flat pointing right, 6300: pen flat pointing left
46+
47+
## event1 - Touch
48+
- type 0 - ev_sync
49+
- type 1 - ev_key
50+
- type 3 - ev_abs
51+
- code 25 - abs_mt_distance - unused?
52+
- code 47 - abs_mt_slot - multitouch position number (see protocol example B in docs)
53+
- code 48 - abs_mt_touch_major - touch size major axis - needs further study {4: pointer touch, 24: thumb touch}
54+
- code 49 - abs_mt_touch_minor - touch size minor axis -
55+
- code 52 - abs_mt_orientation - touch orientation
56+
- code 53 - abs_mt_position_x - xpos - (0: right side, 767: left side)
57+
- code 54 - abs_mt_position_y - ypos - (0: bottom, 1023: top
58+
- code 57 - abs_mt_tracking_id - press/release
59+
- value=X - increments by +1 with each press
60+
- value=-1 - release
61+
- code 58 - abs_mt_pressure - not really pressure but contact area - {30: very light touch, 90: typical touch during swipe, 150: thumb on screen}
62+
63+
## event2 - Buttons
64+
- type 0 - ev_sync
65+
- type 1 - ev_key
66+
- code 102 - home - middle button
67+
- value 1 - press
68+
- value 0 - release
69+
- code 105 - left - left button
70+
- code 106 - right - right button
71+
- code 116 - power - suspend button
72+
- code 143 - wakeup - unused?
73+
74+

remarkable_sim/__init__.py

Whitespace-only changes.
2.35 KB
Binary file not shown.
File renamed without changes.

remarkable_sim/evsim.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import time
2+
import os
3+
import struct
4+
import stat
5+
6+
def affine_map(x, a0, a1, b0, b1):
7+
"""Map x in range (a0, a1) to (b0, b1)
8+
Args:
9+
x (float): input
10+
a0 (float): input range start
11+
a1 (float): input range start
12+
b0 (float): output range start
13+
b1 (float): output range start
14+
15+
Returns:
16+
int: mapped coordinate
17+
"""
18+
19+
return int(((x - a0) / a1) * b1 + b0)
20+
21+
def makefifo(path):
22+
"""Make a fifo, delete existing fifo
23+
24+
Args:
25+
path (str): path to new fifo
26+
"""
27+
28+
if os.path.exists(path) and stat.S_ISFIFO(os.stat(path).st_mode):
29+
os.remove(path)
30+
31+
os.mkfifo(path)
32+
33+
return os.open(path, os.O_RDWR)
34+
35+
36+
# write evdev events to fifos
37+
def write_evdev(f, e_type, e_code, e_value):
38+
"""Write evdev events to fifo
39+
40+
Args:
41+
f (int): fd of fifo
42+
e_type (int): evdev event type
43+
e_code (int): evdev event code
44+
e_value (int): evdev event value
45+
"""
46+
47+
print(f, e_type, e_code, e_value)
48+
49+
t = time.time_ns()
50+
t_seconds = int(t / 1e9)
51+
t_microseconds = int(t / 1e3 % 1e6)
52+
os.write(
53+
f,
54+
struct.pack(
55+
'2IHHi',
56+
t_seconds,
57+
t_microseconds,
58+
e_type,
59+
e_code,
60+
e_value
61+
)
62+
)
63+
64+
# ----- evdev codes -----
65+
# see evdev_notes.md
66+
67+
# tuples containing (type, code)
68+
69+
code_sync = (0, 0, 0)
70+
71+
codes_stylus = {
72+
'toolpen': (1, 320),
73+
'toolrubber': (1, 321),
74+
'touch': (1, 330),
75+
'stylus': (1, 331),
76+
'stylus2': (1, 332),
77+
'abs_x': (3, 0),
78+
'abs_y': (3, 1),
79+
'abs_pressure': (3, 24),
80+
'abs_distance': (3, 25),
81+
'abs_tilt_x': (3, 26),
82+
'abs_tilt_y': (3, 27)
83+
}
84+
85+
codes_touch = {
86+
'abs_mt_distance': (3, 25),
87+
'abs_mt_slot': (3, 47),
88+
'abs_mt_touch_major': (3, 48),
89+
'abs_mt_touch_minor': (3, 49),
90+
'abs_mt_orientation': (3, 52),
91+
'abs_mt_position_x': (3, 53),
92+
'abs_mt_position_y': (3, 54),
93+
'abs_mt_tracking_id': (3, 57),
94+
'abs_mt_pressure': (3, 58)
95+
}
96+
97+
codes_button = {
98+
'home': (1, 102),
99+
'left': (1, 105),
100+
'right': (1, 106),
101+
'power': (1, 116),
102+
'wakeup': (1, 143)
103+
}
104+
105+
stylus_max_x = 20967
106+
stylus_max_y = 15725
107+
touch_max_x = 767
108+
touch_max_y = 1023
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)