polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Linux / LID.html
blob63fa1f402646cf66723515bfd673905a82a7a2d6
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.42">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a71e12}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0019b7}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #326f17}
16 span.s1 {color: #000000}
17 span.s2 {color: #0019b7}
18 span.s3 {color: #606060}
19 span.s4 {color: #326f17}
20 span.s5 {color: #a71e12}
21 span.Apple-tab-span {white-space:pre}
22 </style>
23 </head>
24 <body>
25 <p class="p1">
26 =====================================================================<br>
27 LID -- Linux Input Device<br>
28 =====================================================================</p>
29 <p class="p1">
30 This class provides a way to access devices in the linux input<br>
31 layer, which supports many input devices (mouse, keyboard,<br>
32 joystick, gamepad, tablet) and busses (serial, PS/2, USB).</p>
33 <p class="p2"><br></p>
34 <p class="p3">It is advised to use <a href="../Control/GeneralHID.html"><span class="s2">GeneralHID</span></a> instead, which wraps the HIDDeviceService functionality, and produces crossplatform compatible code.</p>
35 <p class="p1">
36 =====================================================================<br>
37 Opening a device<br>
38 =====================================================================</p>
39 <p class="p1">
40 Input devices are accessed through device nodes, typically<br>
41 /dev/input/event[0-9]. When using a userspace daemon like udev,<br>
42 meaningful names can be assigned to devices.</p>
44 <p class="p1">raw device name:</p>
45 <p class="p3">
46 <span class="s1">d = </span>
47 <span class="s2">LID</span><span class="s1">(</span>"/dev/input/event4"<span class="s1">);</span></p>
48 <p class="p2"><br></p>
50 <p class="p1">symbolic device name</p>
51 <p class="p3"><span class="s1">d = </span><span class="s2">LID</span><span class="s1">(</span>"/dev/input/trackball"<span class="s1">);</span></p>
52 <p class="p2"><br></p>
54 <p class="p1">device name relative to LID.deviceRoot</p>
55 <p class="p3"><span class="s1">d = </span><span class="s2">LID</span><span class="s1">(</span>"gamepad"<span class="s1">);</span></p>
56 <p class="p2"><br></p>
57 <p class="p1">build a list of the available devices:</p>
58 <p class="p2"><br></p>
59 <p class="p4"><span class="s2">LID</span>.buildDeviceList</p>
60 <p class="p2"><br></p>
61 <p class="p1">
62 buildDeviceList builds a table of the devices found in LID.deviceRoot+"/event",
63 trying to open all that it finds, looking up its name and closing them again.
64 The result is returned and can later be accessed by LID.deviceList.</p>
65 <p class="p1">
66 You can query another name than "/event" by passing an argument. (the search will be: LID.deviceRoot++"/"++name++"*")</p>
68 <p class="p4"><span class="s2">LID</span>.buildDeviceList( <span class="s3">"mouse"</span> );</p>
69 <p class="p1">Note: this is likely to give the info that the devices could not be opened, as "mouse" uses another interface (you can of course access mice via the "event" interface)
70 </p>
71 <p class="p1">Note: if you cannot open the devices at all, please look in the helpfile for: Linux_udev_setup
72 <p class="p1">
73 =====================================================================<br>
74 Querying device information<br>
75 =====================================================================</p>
76 <p class="p2"><br></p>
77 <p class="p4">
78 d.info;<br>
79 d.info.name;<br>
80 d.info.vendor.asHexString(4);<br>
81 d.info.product.asHexString(4);<br>
82 </p>
83 <p class="p1">
84 =====================================================================<br>
85 Querying device capabilities<br>
86 =====================================================================</p>
88 <p class="p1">
89 Device capabilities are reported as event type and event code mappings. Event type and event code constants can be found in /usr/include/linux/input.h</p>
90 <p class="p2"><br></p>
91 <p class="p4">
92 d.caps;<br>
93 d.dumpCaps;</p>
94 <p class="p2"><br></p>
95 <p class="p1">
96 =====================================================================<br>
97 Event actions (raw events)<br>
98 =====================================================================<br>
100 <p class="p1">
101 The device's 'action' instance variable can be used for event notifications. it is passed the event type, code and current value.</p>
103 <p class="p2"><br></p>
104 <p class="p4">(</p>
105 <p class="p5"><span class="s1">d.action = { </span>| evtType, evtCode, evtValue |</p>
106 <p class="p4"><span class="Apple-tab-span"> </span>[evtType.asHexString(4), evtCode.asHexString(4), evtValue].postln</p>
107 <p class="p4">}</p>
108 <p class="p4">)</p>
109 <p class="p2"><br></p>
110 <p class="p4">d.action = <span class="s2">nil</span>;</p>
111 <p class="p2"><br></p>
113 <p class="p1">
114 If a device is detached LID will detect this, and close the device. It will execute a closeAction, which can be defined by the user:
115 </p>
116 <p class="p2"><br></p>
117 <p class="p4">d.closeAction = <span class="s2">{ "device was detached".postln; }</span>;</p>
118 <p class="p2"><br></p>
120 <p class="p1">
121 =====================================================================<br>
122 Event actions (raw slot events)<br>
123 =====================================================================</p>
124 <p class="p1">
125 When 'action' is nil, actions can be bound to specific events.</p>
126 <p class="p2"><br></p>
127 <p class="p4">(</p>
128 <p class="p4">d.slot(0x0001, 0x0120).action = { <span class="s2">| slot |</span></p>
129 <p class="p4"><span class="Apple-tab-span"> </span>[slot.type.asHexString(4), slot.code.asHexString(4), slot.rawValue].postln;</p>
130 <p class="p4">}</p>
131 <p class="p4">)</p>
132 <p class="p2">Relative slots can have deltaActions:</p>
133 <p class="p4">d.slot(0x0002, 0x0001).deltaAction = { <span class="s2">| slot |</span></p>
134 <p class="p4"><span class="Apple-tab-span"> </span>[slot.type.asHexString(4), slot.code.asHexString(4), slot.delta].postln;</p>
135 <p class="p4">}</p>
136 <p class="p4">)</p>
137 <p class="p2"><br></p>
138 <p class="p1">
139 =====================================================================<br>
140 Device specs<br>
141 =====================================================================</p>
142 <p class="p1">//</p>
143 <p class="p1">// Device specs are mappings between event codes and symbolic control</p>
144 <p class="p1">// names. New specs can be added to LID.specs via LID&gt;&gt;*register.</p>
145 <p class="p2"><br></p>
146 <p class="p1">// Add a mouse device spec for a Logitech trackball</p>
147 <p class="p4"><span class="s2">LID</span>.register(<span class="s4">'Logitech Trackball'</span>, <span class="s2">LID</span>.mouseDeviceSpec);</p>
148 <p class="p2"><br></p>
149 <p class="p1">// Add a custom device spec for a Logitech gamepad</p>
150 <p class="p4">(</p>
151 <p class="p6"><span class="s2">LID</span><span class="s1">.register(</span>'Logitech WingMan RumblePad'<span class="s1">, (</span></p>
152 <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span></span>// key</p>
153 <p class="p4"><span class="Apple-tab-span"> </span>rumble: #[0x0001, 0x0102],<span class="Apple-tab-span"> </span><span class="s5">// rumble (toggles ff)</span></p>
154 <p class="p4"><span class="Apple-tab-span"> </span>mode: #[0x0001, 0x0103],<span class="Apple-tab-span"> </span><span class="s5">// mode (switches h and l)</span></p>
155 <p class="p4"><span class="Apple-tab-span"> </span>a: #[0x0001, 0x0120],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button a</span></p>
156 <p class="p4"><span class="Apple-tab-span"> </span>b: #[0x0001, 0x0121],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button b</span></p>
157 <p class="p4"><span class="Apple-tab-span"> </span>c: #[0x0001, 0x0122],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button c</span></p>
158 <p class="p4"><span class="Apple-tab-span"> </span>x: #[0x0001, 0x0123],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button x</span></p>
159 <p class="p4"><span class="Apple-tab-span"> </span>y: #[0x0001, 0x0124],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button y</span></p>
160 <p class="p4"><span class="Apple-tab-span"> </span>z: #[0x0001, 0x0125],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button z</span></p>
161 <p class="p4"><span class="Apple-tab-span"> </span>l: #[0x0001, 0x0126],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// left front button</span></p>
162 <p class="p4"><span class="Apple-tab-span"> </span>r: #[0x0001, 0x0127],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// right front button</span></p>
163 <p class="p4"><span class="Apple-tab-span"> </span>s: #[0x0001, 0x0128],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// button s</span></p>
164 <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span></span>// abs</p>
165 <p class="p4"><span class="Apple-tab-span"> </span>lx: #[0x0003, 0x0000],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// left joystick x</span></p>
166 <p class="p4"><span class="Apple-tab-span"> </span>ly: #[0x0003, 0x0001],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// left joystick y</span></p>
167 <p class="p4"><span class="Apple-tab-span"> </span>rx: #[0x0003, 0x0005],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// right joystick x</span></p>
168 <p class="p4"><span class="Apple-tab-span"> </span>ry: #[0x0003, 0x0006],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// right joystick y</span></p>
169 <p class="p4"><span class="Apple-tab-span"> </span>hx: #[0x0003, 0x0010],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// hat x</span></p>
170 <p class="p4"><span class="Apple-tab-span"> </span>hy: #[0x0003, 0x0011],<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">// hat y</span></p>
171 <p class="p4"><span class="Apple-tab-span"> </span>slider: #[0x0003, 0x0002]<span class="Apple-tab-span"> </span><span class="s5">// slider</span></p>
172 <p class="p4">));</p>
173 <p class="p4">)</p>
174 <p class="p2"><br></p>
175 <p class="p1">// =====================================================================</p>
176 <p class="p1">// Event actions (symbolic slot events)</p>
177 <p class="p1">// =====================================================================</p>
178 <p class="p1">//</p>
179 <p class="p1">// When a device spec was registered for a given device name, slot</p>
180 <p class="p1">// actions can be assigned by using the symbolic control name.</p>
181 <p class="p2"><br></p>
182 <p class="p4">d[<span class="s4">\a</span>].action = { <span class="s2">| slot |</span> [<span class="s4">\a</span>, slot.value].postln };</p>
183 <p class="p2"><br></p>
184 <p class="p1">// There is also a default keyboard device spec.</p>
185 <p class="p2"><br></p>
186 <p class="p4">(</p>
187 <p class="p4"><span class="s2">LID</span>.keyboardDeviceSpec.keys.do { <span class="s2">| key |</span></p>
188 <p class="p4"><span class="Apple-tab-span"> </span>d[key].action = { <span class="s2">| slot |</span> [key, slot.value].postln }</p>
189 <p class="p4">}</p>
190 <p class="p4">)</p>
191 <p class="p2"><br></p>
192 <p class="p1">// =====================================================================</p>
193 <p class="p1">// LED's</p>
194 <p class="p1">// =====================================================================</p>
195 <p class="p2"><br></p>
196 <p class="p1">// some devices have LEDs which can be turned on and off. These show up</p>
197 <p class="p1">// with d.caps as events of type 0x0011</p>
198 <p class="p2"><br></p>
199 <p class="p3"><span class="s1">d = </span><span class="s2">LID</span><span class="s1">(</span>"/dev/input/event0"<span class="s1">);</span></p>
200 <p class="p1">// LED's can be turned on:</p>
201 <p class="p4">d.setLEDState( 0x0, 1 )</p>
202 <p class="p1">// (LED 0x0 should be available on any keyboard)</p>
203 <p class="p1">// and off:</p>
204 <p class="p4">d.setLEDState( 0x0, 0 )</p>
205 <p class="p4">d.close;</p>
206 <p class="p2"><br></p>
207 <p class="p1">// setLEDState( evtCode, evtValue ): value should be 1 or 0</p>
208 <p class="p2"><br></p>
209 <p class="p2"><br></p>
210 <p class="p1">// =====================================================================</p>
211 <p class="p1">// Grabbing devices</p>
212 <p class="p1">// =====================================================================</p>
213 <p class="p1">//</p>
214 <p class="p1">// Given proper permissions, devices can be grabbed to prevent use in</p>
215 <p class="p1">// other applications (including X). Be careful when grabbing mouse or</p>
216 <p class="p1">// keyboard!</p>
217 <p class="p2"><br></p>
218 <p class="p4">d[<span class="s4">\b</span>].action = { d.ungrab };</p>
219 <p class="p4">d.grab;</p>
220 <p class="p2"><br></p>
221 <p class="p4">d.isGrabbed;</p>
222 <p class="p2"><br></p>
223 <p class="p1">// =====================================================================</p>
224 <p class="p1">// Closing devices</p>
225 <p class="p1">// =====================================================================</p>
226 <p class="p2"><br></p>
227 <p class="p4">d.close;</p>
228 <p class="p4"><span class="s2">LID</span>.closeAll;</p>
229 <p class="p2"><br></p>
230 <p class="p1">// =====================================================================</p>
231 </body>
232 </html>