diff options
author | Antonio Ospite <ospite@studenti.unina.it> | 2013-12-16 04:52:17 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2013-12-16 05:13:35 -0500 |
commit | c2729850985934a3124319f8ff1d46d8c72bb012 (patch) | |
tree | 74238d313e0479e72341accd1176270f69ea6b0b /Documentation/input | |
parent | 7d0e6192c2f36139e4aa5e4107f4d7fb56d9f290 (diff) |
Input: joystick - use sizeof(VARIABLE) in documentation
Use the preferred style sizeof(VARIABLE) instead of sizeof(TYPE) in the
joystick API documentation, Documentation/CodingStyle states that this
is the preferred style for allocations but using it elsewhere is good
too.
Also fix some errors like "sizeof(struct mybuffer)" which didn't mean
anything.
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'Documentation/input')
-rw-r--r-- | Documentation/input/joystick-api.txt | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/Documentation/input/joystick-api.txt b/Documentation/input/joystick-api.txt index f95f64838788..943b18eac918 100644 --- a/Documentation/input/joystick-api.txt +++ b/Documentation/input/joystick-api.txt | |||
@@ -23,7 +23,7 @@ By default, the device is opened in blocking mode. | |||
23 | ~~~~~~~~~~~~~~~~ | 23 | ~~~~~~~~~~~~~~~~ |
24 | 24 | ||
25 | struct js_event e; | 25 | struct js_event e; |
26 | read (fd, &e, sizeof(struct js_event)); | 26 | read (fd, &e, sizeof(e)); |
27 | 27 | ||
28 | where js_event is defined as | 28 | where js_event is defined as |
29 | 29 | ||
@@ -34,8 +34,8 @@ where js_event is defined as | |||
34 | __u8 number; /* axis/button number */ | 34 | __u8 number; /* axis/button number */ |
35 | }; | 35 | }; |
36 | 36 | ||
37 | If the read is successful, it will return sizeof(struct js_event), unless | 37 | If the read is successful, it will return sizeof(e), unless you wanted to read |
38 | you wanted to read more than one event per read as described in section 3.1. | 38 | more than one event per read as described in section 3.1. |
39 | 39 | ||
40 | 40 | ||
41 | 2.1 js_event.type | 41 | 2.1 js_event.type |
@@ -99,9 +99,9 @@ may work well if you handle JS_EVENT_INIT events separately, | |||
99 | 99 | ||
100 | if ((js_event.type & ~JS_EVENT_INIT) == JS_EVENT_BUTTON) { | 100 | if ((js_event.type & ~JS_EVENT_INIT) == JS_EVENT_BUTTON) { |
101 | if (js_event.value) | 101 | if (js_event.value) |
102 | buttons_state |= (1 << js_event.number); | 102 | buttons_state |= (1 << js_event.number); |
103 | else | 103 | else |
104 | buttons_state &= ~(1 << js_event.number); | 104 | buttons_state &= ~(1 << js_event.number); |
105 | } | 105 | } |
106 | 106 | ||
107 | is much safer since it can't lose sync with the driver. As you would | 107 | is much safer since it can't lose sync with the driver. As you would |
@@ -144,14 +144,14 @@ all events on the queue (that is, until you get a -1). | |||
144 | For example, | 144 | For example, |
145 | 145 | ||
146 | while (1) { | 146 | while (1) { |
147 | while (read (fd, &e, sizeof(struct js_event)) > 0) { | 147 | while (read (fd, &e, sizeof(e)) > 0) { |
148 | process_event (e); | 148 | process_event (e); |
149 | } | 149 | } |
150 | /* EAGAIN is returned when the queue is empty */ | 150 | /* EAGAIN is returned when the queue is empty */ |
151 | if (errno != EAGAIN) { | 151 | if (errno != EAGAIN) { |
152 | /* error */ | 152 | /* error */ |
153 | } | 153 | } |
154 | /* do something interesting with processed events */ | 154 | /* do something interesting with processed events */ |
155 | } | 155 | } |
156 | 156 | ||
157 | One reason for emptying the queue is that if it gets full you'll start | 157 | One reason for emptying the queue is that if it gets full you'll start |
@@ -181,7 +181,7 @@ at a time using the typical read(2) functionality. For that, you would | |||
181 | replace the read above with something like | 181 | replace the read above with something like |
182 | 182 | ||
183 | struct js_event mybuffer[0xff]; | 183 | struct js_event mybuffer[0xff]; |
184 | int i = read (fd, mybuffer, sizeof(struct mybuffer)); | 184 | int i = read (fd, mybuffer, sizeof(mybuffer)); |
185 | 185 | ||
186 | In this case, read would return -1 if the queue was empty, or some | 186 | In this case, read would return -1 if the queue was empty, or some |
187 | other value in which the number of events read would be i / | 187 | other value in which the number of events read would be i / |
@@ -269,9 +269,9 @@ The driver offers backward compatibility, though. Here's a quick summary: | |||
269 | struct JS_DATA_TYPE js; | 269 | struct JS_DATA_TYPE js; |
270 | while (1) { | 270 | while (1) { |
271 | if (read (fd, &js, JS_RETURN) != JS_RETURN) { | 271 | if (read (fd, &js, JS_RETURN) != JS_RETURN) { |
272 | /* error */ | 272 | /* error */ |
273 | } | 273 | } |
274 | usleep (1000); | 274 | usleep (1000); |
275 | } | 275 | } |
276 | 276 | ||
277 | As you can figure out from the example, the read returns immediately, | 277 | As you can figure out from the example, the read returns immediately, |