Debian Codegraph @

src/evdev/ff.py

raw
1 import ctypes
2
3 from . import ecodes
4
5 _u8 = ctypes.c_uint8
6 _u16 = ctypes.c_uint16
7 _u32 = ctypes.c_uint32
8 _s16 = ctypes.c_int16
9 _s32 = ctypes.c_int32
10
11
12 class Replay(ctypes.Structure):
13 """
14 Defines scheduling of the force-feedback effect
15 @length: duration of the effect
16 @delay: delay before effect should start playing
17 """
18
19 _fields_ = [
20 ("length", _u16),
21 ("delay", _u16),
22 ]
23
24
25 class Trigger(ctypes.Structure):
26 """
27 Defines what triggers the force-feedback effect
28 @button: number of the button triggering the effect
29 @interval: controls how soon the effect can be re-triggered
30 """
31
32 _fields_ = [
33 ("button", _u16),
34 ("interval", _u16),
35 ]
36
37
38 class Envelope(ctypes.Structure):
39 """
40 Generic force-feedback effect envelope
41 @attack_length: duration of the attack (ms)
42 @attack_level: level at the beginning of the attack
43 @fade_length: duration of fade (ms)
44 @fade_level: level at the end of fade
45
46 The @attack_level and @fade_level are absolute values; when applying
47 envelope force-feedback core will convert to positive/negative
48 value based on polarity of the default level of the effect.
49 Valid range for the attack and fade levels is 0x0000 - 0x7fff
50 """
51
52 _fields_ = [
53 ("attack_length", _u16),
54 ("attack_level", _u16),
55 ("fade_length", _u16),
56 ("fade_level", _u16),
57 ]
58
59
60 class Constant(ctypes.Structure):
61 """
62 Defines parameters of a constant force-feedback effect
63 @level: strength of the effect; may be negative
64 @envelope: envelope data
65 """
66
67 _fields_ = [
68 ("level", _s16),
69 ("ff_envelope", Envelope),
70 ]
71
72
73 class Ramp(ctypes.Structure):
74 """
75 Defines parameters of a ramp force-feedback effect
76 @start_level: beginning strength of the effect; may be negative
77 @end_level: final strength of the effect; may be negative
78 @envelope: envelope data
79 """
80
81 _fields_ = [
82 ("start_level", _s16),
83 ("end_level", _s16),
84 ("ff_envelope", Envelope),
85 ]
86
87
88 class Condition(ctypes.Structure):
89 """
90 Defines a spring or friction force-feedback effect
91 @right_saturation: maximum level when joystick moved all way to the right
92 @left_saturation: same for the left side
93 @right_coeff: controls how fast the force grows when the joystick moves to the right
94 @left_coeff: same for the left side
95 @deadband: size of the dead zone, where no force is produced
96 @center: position of the dead zone
97 """
98
99 _fields_ = [
100 ("right_saturation", _u16),
101 ("left_saturation", _u16),
102 ("right_coeff", _s16),
103 ("left_coeff", _s16),
104 ("deadband", _u16),
105 ("center", _s16),
106 ]
107
108
109 class Periodic(ctypes.Structure):
110 """
111 Defines parameters of a periodic force-feedback effect
112 @waveform: kind of the effect (wave)
113 @period: period of the wave (ms)
114 @magnitude: peak value
115 @offset: mean value of the wave (roughly)
116 @phase: 'horizontal' shift
117 @envelope: envelope data
118 @custom_len: number of samples (FF_CUSTOM only)
119 @custom_data: buffer of samples (FF_CUSTOM only)
120 """
121
122 _fields_ = [
123 ("waveform", _u16),
124 ("period", _u16),
125 ("magnitude", _s16),
126 ("offset", _s16),
127 ("phase", _u16),
128 ("envelope", Envelope),
129 ("custom_len", _u32),
130 ("custom_data", ctypes.POINTER(_s16)),
131 ]
132
133
134 class Rumble(ctypes.Structure):
135 """
136 Defines parameters of a periodic force-feedback effect
137 @strong_magnitude: magnitude of the heavy motor
138 @weak_magnitude: magnitude of the light one
139
140 Some rumble pads have two motors of different weight. Strong_magnitude
141 represents the magnitude of the vibration generated by the heavy one.
142 """
143
144 _fields_ = [
145 ("strong_magnitude", _u16),
146 ("weak_magnitude", _u16),
147 ]
148
149
150 class EffectType(ctypes.Union):
151 _fields_ = [
152 ("ff_constant_effect", Constant),
153 ("ff_ramp_effect", Ramp),
154 ("ff_periodic_effect", Periodic),
155 ("ff_condition_effect", Condition * 2), # one for each axis
156 ("ff_rumble_effect", Rumble),
157 ]
158
159
160 class Effect(ctypes.Structure):
161 _fields_ = [
162 ("type", _u16),
163 ("id", _s16),
164 ("direction", _u16),
165 ("ff_trigger", Trigger),
166 ("ff_replay", Replay),
167 ("u", EffectType),
168 ]
169
170
171 class UInputUpload(ctypes.Structure):
172 _fields_ = [
173 ("request_id", _u32),
174 ("retval", _s32),
175 ("effect", Effect),
176 ("old", Effect),
177 ]
178
179
180 class UInputErase(ctypes.Structure):
181 _fields_ = [
182 ("request_id", _u32),
183 ("retval", _s32),
184 ("effect_id", _u32),
185 ]
186
187
188 # ff_types = {
189 # ecodes.FF_CONSTANT,
190 # ecodes.FF_PERIODIC,
191 # ecodes.FF_RAMP,
192 # ecodes.FF_SPRING,
193 # ecodes.FF_FRICTION,
194 # ecodes.FF_DAMPER,
195 # ecodes.FF_RUMBLE,
196 # ecodes.FF_INERTIA,
197 # ecodes.FF_CUSTOM,
198 # }