Lines Matching +full:read +full:- +full:1

1 .. _joystick-api:
7 :Author: Ragnar Hojland Espinosa <ragnar@macula.net> - 7 Aug 1998
18 driver now reports only any changes of its state. See joystick-api.txt,
35 (JS_EVENT_INIT) that you can read to obtain the initial state of the
49 read (fd, &e, sizeof(e));
60 If the read is successful, it will return sizeof(e), unless you wanted to read
61 more than one event per read as described in section 3.1.
65 -------------
86 ---------------
95 1st Axis X 0
96 1st Axis Y 1
108 --------------
110 For an axis, ``value`` is a signed integer between -32767 and +32767
112 don't read a 0 when the joystick is ``dead``, or if it doesn't span the
115 For a button, ``value`` for a press button event is 1 and for a release
121 buttons_state ^= (1 << js_event.number);
130 buttons_state |= (1 << js_event.number);
132 buttons_state &= ~(1 << js_event.number);
141 -------------
152 If you open the device in blocking mode, a read will block (that is,
153 wait) forever until an event is generated and effectively read. There
157 a) use select to wait until there's data to be read on fd, or
161 b) open the device in non-blocking mode (O_NONBLOCK)
165 ----------
167 If read returns -1 when reading in O_NONBLOCK mode, this isn't
169 are no events pending to be read on the driver queue. You should read
170 all events on the queue (that is, until you get a -1).
176 while (1) {
177 while (read (fd, &e, sizeof(e)) > 0) {
195 mentioned, or because too much time elapses from one read to another
200 the driver will switch to startup mode and next time you read it,
212 In the above code, you might as well want to read more than one event
213 at a time using the typical read(2) functionality. For that, you would
214 replace the read above with something like::
217 int i = read (fd, mybuffer, sizeof(mybuffer));
219 In this case, read would return -1 if the queue was empty, or some
220 other value in which the number of events read would be i /
238 For example, to read the number of axes::
245 -------------
247 JSIOGCVERSION is a good way to check in run-time whether the running
249 IOCTL will fail. For a compile-time decision, you can test the
257 ----------
259 JSIOCGNAME(len) allows you to get the name string of the joystick - the same
271 -------------
303 while (1) {
304 if (read (fd, &js, JS_RETURN) != JS_RETURN) {
310 As you can figure out from the example, the read returns immediately,
327 first_button_state = js.buttons & 1;
331 except that the values are non-negative. The 1.2.8+ drivers use a
332 fixed range for reporting the values, 1 being the minimum, 128 the