remogatto-ffi-swig-generator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ pkg/
2
+ generated/
3
+ *.gem
4
+ *.xml
5
+ *#
6
+ .#*
7
+ announcement.txt
8
+
data/History.txt ADDED
@@ -0,0 +1,25 @@
1
+ == 0.2.1 / 2009-03-06
2
+
3
+ * 1 minor enhancement
4
+ * Removed old lib/ffi-generator.rb file.
5
+
6
+ == 0.2.0 / 2009-03-05
7
+
8
+ * 1 major enhancement
9
+ * Added support for callbacks.
10
+ * Changed the package name from ffi-generator to ffi-swig-generator
11
+
12
+ * 1 minor enhancement
13
+ * C functions with one void argument are correctly generated as FFI
14
+ functions with no arguments.
15
+
16
+ == 0.1.0 / 2009-02-16
17
+
18
+ * a bunch of minor fixes
19
+ * fix the gem build process
20
+ * new interface file for the wiiuse example
21
+
22
+ == 0.0.1 / 2009-02-13
23
+
24
+ * 1 major enhancement
25
+ * Birthday!
data/README.rdoc ADDED
@@ -0,0 +1,99 @@
1
+ ffi-swig-generator
2
+ by Andrea Fazzi
3
+ http://github.com/remogatto/ffi-swig-generator/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ ffi-swig-generator is a ruby-ffi wrapper code generator based on SWIG
8
+ interface files.
9
+
10
+ ffi-swig-generator is able to traverse a XML parse tree file generated
11
+ by the +swig+ command and to produce a ruby-ffi interface file from
12
+ it.
13
+
14
+ ffi-swig-generator is shipped with a command line tool (ffi-gen) and a rake
15
+ task that automates the code generation process.
16
+
17
+ ffi-swig-generator XML capabilities are provided by nokogiri.
18
+
19
+ == FEATURES/PROBLEMS:
20
+
21
+ * The program is able to generate:
22
+ * all C native types
23
+ * #define constants
24
+ * typedefs
25
+ * struct, union, array and enum types
26
+ * callbacks (pointers to functions)
27
+ * Naive indentation of the generated code
28
+
29
+ == SYNOPSIS:
30
+
31
+ From command line:
32
+
33
+ ffi-gen mylib.xml mylib.rb
34
+
35
+ From a Rakefile:
36
+
37
+ require 'ffi-swig-generator'
38
+ FFI::Generator::Task.new :input_fn => 'my_interface_dir/*.i' output_dir => 'my_output_dir'
39
+
40
+ == REQUIREMENTS:
41
+
42
+ * rake >= 0.8.3
43
+ * nokogiri >= 1.1.1
44
+ * swig >= 1.3
45
+
46
+ == DOWNLOAD/INSTALL:
47
+
48
+ To download and install the gem from github:
49
+
50
+ [sudo] gem sources -a http://gems.github.com
51
+ [sudo] gem install remogatto-ffi-swig-generator
52
+
53
+ To download the develpment trunk:
54
+
55
+ git clone git://github.com/remogatto/ffi-swig-generator.git
56
+
57
+ == EXAMPLES:
58
+
59
+ See the examples in examples/ folder.
60
+
61
+ libc.i is an interface file containing some excerpt of libc functions.
62
+
63
+ wiiuse.i is a enough complex example of a C header file interface. It
64
+ reproduces the content of wiiuse.h, the header file of the wiiuse
65
+ library. wiiuse is a C library that handles the connection with
66
+ Nintendo Wiimote devices. The interface file is almost a mere
67
+ copy/paste from the original header file.
68
+
69
+ == QUICK START:
70
+
71
+ git clone git://github.com/remogatto/ffi-swig-generator.git
72
+ sudo apt-get install swig
73
+ sudo gem install nokogiri rake
74
+ cd ffi-swig-generator/examples && rake ffi:generate
75
+
76
+ == LICENSE:
77
+
78
+ (The MIT License)
79
+
80
+ Copyright (c) 2008 Andrea Fazzi
81
+
82
+ Permission is hereby granted, free of charge, to any person obtaining
83
+ a copy of this software and associated documentation files (the
84
+ 'Software'), to deal in the Software without restriction, including
85
+ without limitation the rights to use, copy, modify, merge, publish,
86
+ distribute, sublicense, and/or sell copies of the Software, and to
87
+ permit persons to whom the Software is furnished to do so, subject to
88
+ the following conditions:
89
+
90
+ The above copyright notice and this permission notice shall be
91
+ included in all copies or substantial portions of the Software.
92
+
93
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
95
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
96
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
97
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
98
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
99
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+
2
+ # Look in the tasks/setup.rb file for the various options that can be
3
+ # configured in this Rakefile. The .rake files in the tasks directory
4
+ # are where the options are used.
5
+
6
+ begin
7
+ require 'bones'
8
+ Bones.setup
9
+ rescue LoadError
10
+ begin
11
+ load 'tasks/setup.rb'
12
+ rescue LoadError
13
+ raise RuntimeError, '### please install the "bones" gem ###'
14
+ end
15
+ end
16
+
17
+ ensure_in_path 'lib'
18
+ require 'ffi-generator'
19
+
20
+ task :default => 'spec:run'
21
+
22
+ PROJ.name = 'ffi-swig-generator'
23
+ PROJ.authors = 'Andrea Fazzi'
24
+ PROJ.email = 'andrea.fazzi@alcacoop.it'
25
+ PROJ.url = 'http://github.com/remogatto/ffi-swig-generator/tree/master'
26
+ PROJ.version = FFI::Generator::VERSION
27
+ PROJ.rubyforge.name = 'ffi-swig-generator'
28
+
29
+ PROJ.readme_file = 'README.rdoc'
30
+
31
+ PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD' << 'EXAMPLES'
32
+ PROJ.ann.email[:from] = 'andrea.fazzi@alca.le.it'
33
+ PROJ.ann.email[:to] << 'dev@ruby-ffi.kenai.com' << 'users@ruby-ffi.kenai.com'
34
+ PROJ.ann.email[:server] = 'smtp.gmail.com'
35
+
36
+ PROJ.ruby_opts = []
37
+ PROJ.spec.opts << '--color'
38
+
39
+ depend_on 'rake'
40
+ depend_on 'nokogiri'
41
+
42
+ # EOF
data/bin/ffi-gen ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib ffi-generator]))
5
+
6
+ FFI::Generator::Application.run
7
+
data/examples/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ffi-generator]))
2
+
3
+ FFI::Generator::Task.new :input_fn => 'interfaces/*.i', :output_dir => 'generated'
4
+
@@ -0,0 +1,26 @@
1
+ %module libc
2
+
3
+ %{
4
+ require 'rubygems'
5
+ require 'ffi'
6
+
7
+ module LibC
8
+ extend FFI::Library
9
+ %}
10
+
11
+ typedef unsigned int size_t;
12
+
13
+ struct timeval {
14
+ unsigned long tv_sec;
15
+ unsigned long tv_usec;
16
+ };
17
+
18
+ size_t strlen (const char *s);
19
+ char * strcat (char *restrict to, const char *restrict from);
20
+ int strcmp (const char *s1, const char *s2);
21
+
22
+ int gettimeofday (struct timeval *tp, struct timezone *tzp);
23
+
24
+ %{
25
+ end
26
+ %}
@@ -0,0 +1,672 @@
1
+ %module wiiuse
2
+
3
+ %{
4
+ require 'ffi'
5
+
6
+ module Wiiuse
7
+ extend FFI::Library
8
+ ffi_lib 'wiiuse'
9
+ %}
10
+
11
+ /*
12
+ * wiiuse
13
+ *
14
+ * Written By:
15
+ * Michael Laforest < para >
16
+ * Email: < thepara (--AT--) g m a i l [--DOT--] com >
17
+ *
18
+ * Copyright 2006-2007
19
+ *
20
+ * This file is part of wiiuse.
21
+ *
22
+ * This program is free software; you can redistribute it and/or modify
23
+ * it under the terms of the GNU General Public License as published by
24
+ * the Free Software Foundation; either version 3 of the License, or
25
+ * (at your option) any later version.
26
+ *
27
+ * This program is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ *
35
+ * $Header$
36
+ *
37
+ */
38
+
39
+ /**
40
+ * @file
41
+ *
42
+ * @brief API header file.
43
+ *
44
+ * If this file is included from inside the wiiuse source
45
+ * and not from a third party program, then wiimote_internal.h
46
+ * is also included which extends this file.
47
+ */
48
+
49
+ #ifndef WIIUSE_H_INCLUDED
50
+ #define WIIUSE_H_INCLUDED
51
+
52
+ #ifdef _WIN32
53
+ /* windows */
54
+ #include <windows.h>
55
+
56
+ /**
57
+ * @enum win32_bt_stack_t
58
+ * @brief Available bluetooth stacks for Windows.
59
+ */
60
+ typedef enum win_bt_stack_t {
61
+ WIIUSE_STACK_UNKNOWN,
62
+ WIIUSE_STACK_MS,
63
+ WIIUSE_STACK_BLUESOLEIL
64
+ } win_bt_stack_t;
65
+
66
+ #else
67
+ /* nix */
68
+ #include <bluetooth/bluetooth.h>
69
+ #endif
70
+
71
+ #ifdef WIIUSE_INTERNAL_H_INCLUDED
72
+ #define WCONST
73
+ #else
74
+ #define WCONST const
75
+ #endif
76
+
77
+ /* led bit masks */
78
+ #define WIIMOTE_LED_NONE 0x00
79
+ #define WIIMOTE_LED_1 0x10
80
+ #define WIIMOTE_LED_2 0x20
81
+ #define WIIMOTE_LED_3 0x40
82
+ #define WIIMOTE_LED_4 0x80
83
+
84
+ /* button codes */
85
+ #define WIIMOTE_BUTTON_TWO 0x0001
86
+ #define WIIMOTE_BUTTON_ONE 0x0002
87
+ #define WIIMOTE_BUTTON_B 0x0004
88
+ #define WIIMOTE_BUTTON_A 0x0008
89
+ #define WIIMOTE_BUTTON_MINUS 0x0010
90
+ #define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
91
+ #define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
92
+ #define WIIMOTE_BUTTON_HOME 0x0080
93
+ #define WIIMOTE_BUTTON_LEFT 0x0100
94
+ #define WIIMOTE_BUTTON_RIGHT 0x0200
95
+ #define WIIMOTE_BUTTON_DOWN 0x0400
96
+ #define WIIMOTE_BUTTON_UP 0x0800
97
+ #define WIIMOTE_BUTTON_PLUS 0x1000
98
+ #define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
99
+ #define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
100
+ #define WIIMOTE_BUTTON_UNKNOWN 0x8000
101
+ #define WIIMOTE_BUTTON_ALL 0x1F9F
102
+
103
+ /* nunchul button codes */
104
+ #define NUNCHUK_BUTTON_Z 0x01
105
+ #define NUNCHUK_BUTTON_C 0x02
106
+ #define NUNCHUK_BUTTON_ALL 0x03
107
+
108
+ /* classic controller button codes */
109
+ #define CLASSIC_CTRL_BUTTON_UP 0x0001
110
+ #define CLASSIC_CTRL_BUTTON_LEFT 0x0002
111
+ #define CLASSIC_CTRL_BUTTON_ZR 0x0004
112
+ #define CLASSIC_CTRL_BUTTON_X 0x0008
113
+ #define CLASSIC_CTRL_BUTTON_A 0x0010
114
+ #define CLASSIC_CTRL_BUTTON_Y 0x0020
115
+ #define CLASSIC_CTRL_BUTTON_B 0x0040
116
+ #define CLASSIC_CTRL_BUTTON_ZL 0x0080
117
+ #define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
118
+ #define CLASSIC_CTRL_BUTTON_PLUS 0x0400
119
+ #define CLASSIC_CTRL_BUTTON_HOME 0x0800
120
+ #define CLASSIC_CTRL_BUTTON_MINUS 0x1000
121
+ #define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
122
+ #define CLASSIC_CTRL_BUTTON_DOWN 0x4000
123
+ #define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
124
+ #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
125
+
126
+ /* guitar hero 3 button codes */
127
+ #define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
128
+ #define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
129
+ #define GUITAR_HERO_3_BUTTON_GREEN 0x0010
130
+ #define GUITAR_HERO_3_BUTTON_BLUE 0x0020
131
+ #define GUITAR_HERO_3_BUTTON_RED 0x0040
132
+ #define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
133
+ #define GUITAR_HERO_3_BUTTON_PLUS 0x0400
134
+ #define GUITAR_HERO_3_BUTTON_MINUS 0x1000
135
+ #define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
136
+ #define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
137
+
138
+
139
+ /* wiimote option flags */
140
+ #define WIIUSE_SMOOTHING 0x01
141
+ #define WIIUSE_CONTINUOUS 0x02
142
+ #define WIIUSE_ORIENT_THRESH 0x04
143
+ #define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
144
+
145
+ #define WIIUSE_ORIENT_PRECISION 100.0f
146
+
147
+ /* expansion codes */
148
+ #define EXP_NONE 0
149
+ #define EXP_NUNCHUK 1
150
+ #define EXP_CLASSIC 2
151
+ #define EXP_GUITAR_HERO_3 3
152
+
153
+ /* IR correction types */
154
+ typedef enum ir_position_t {
155
+ WIIUSE_IR_ABOVE,
156
+ WIIUSE_IR_BELOW
157
+ } ir_position_t;
158
+
159
+ /**
160
+ * @enum WIIUSE_EVENT_TYPE
161
+ * @brief Events that wiiuse can generate from a poll.
162
+ */
163
+ typedef enum WIIUSE_EVENT_TYPE {
164
+ WIIUSE_NONE = 0,
165
+ WIIUSE_EVENT,
166
+ WIIUSE_STATUS,
167
+ WIIUSE_CONNECT,
168
+ WIIUSE_DISCONNECT,
169
+ WIIUSE_UNEXPECTED_DISCONNECT,
170
+ WIIUSE_READ_DATA,
171
+ WIIUSE_NUNCHUK_INSERTED,
172
+ WIIUSE_NUNCHUK_REMOVED,
173
+ WIIUSE_CLASSIC_CTRL_INSERTED,
174
+ WIIUSE_CLASSIC_CTRL_REMOVED,
175
+ WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
176
+ WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
177
+ } WIIUSE_EVENT_TYPE;
178
+
179
+
180
+ /**
181
+ * @enum aspect_t
182
+ * @brief Screen aspect ratio.
183
+ */
184
+ typedef enum aspect_t {
185
+ WIIUSE_ASPECT_4_3,
186
+ WIIUSE_ASPECT_16_9
187
+ } aspect_t;
188
+
189
+
190
+ /**
191
+ * @brief Check if a button is pressed.
192
+ * @param dev Pointer to a wiimote_t or expansion structure.
193
+ * @param button The button you are interested in.
194
+ * @return 1 if the button is pressed, 0 if not.
195
+ */
196
+ #define IS_PRESSED(dev, button) ((dev->btns & button) == button)
197
+
198
+ /**
199
+ * @brief Check if a button is being held.
200
+ * @param dev Pointer to a wiimote_t or expansion structure.
201
+ * @param button The button you are interested in.
202
+ * @return 1 if the button is held, 0 if not.
203
+ */
204
+ #define IS_HELD(dev, button) ((dev->btns_held & button) == button)
205
+
206
+ /**
207
+ * @brief Check if a button is released on this event. \n\n
208
+ * This does not mean the button is not pressed, it means \n
209
+ * this button was just now released.
210
+ * @param dev Pointer to a wiimote_t or expansion structure.
211
+ * @param button The button you are interested in.
212
+ * @return 1 if the button is released, 0 if not.
213
+ *
214
+ */
215
+ #define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
216
+
217
+ /**
218
+ * @brief Check if a button has just been pressed this event.
219
+ * @param dev Pointer to a wiimote_t or expansion structure.
220
+ * @param button The button you are interested in.
221
+ * @return 1 if the button is pressed, 0 if not.
222
+ */
223
+ #define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
224
+
225
+ /**
226
+ * @brief Return the IR sensitivity level.
227
+ * @param wm Pointer to a wiimote_t structure.
228
+ * @param lvl [out] Pointer to an int that will hold the level setting.
229
+ * If no level is set 'lvl' will be set to 0.
230
+ */
231
+ #define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
232
+ do { \
233
+ if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
234
+ else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
235
+ else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
236
+ else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
237
+ else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
238
+ else *lvl = 0; \
239
+ } while (0)
240
+
241
+ #define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
242
+ #define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
243
+ #define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
244
+ #define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
245
+
246
+ #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
247
+
248
+ /*
249
+ * Largest known payload is 21 bytes.
250
+ * Add 2 for the prefix and round up to a power of 2.
251
+ */
252
+ #define MAX_PAYLOAD 32
253
+
254
+ /*
255
+ * This is left over from an old hack, but it may actually
256
+ * be a useful feature to keep so it wasn't removed.
257
+ */
258
+ #ifdef WIN32
259
+ #define WIIMOTE_DEFAULT_TIMEOUT 10
260
+ #define WIIMOTE_EXP_TIMEOUT 10
261
+ #endif
262
+
263
+ typedef unsigned char byte;
264
+ typedef char sbyte;
265
+
266
+ struct wiimote_t;
267
+ struct vec3b_t;
268
+ struct orient_t;
269
+ struct gforce_t;
270
+
271
+
272
+ /**
273
+ * @brief Callback that handles a read event.
274
+ *
275
+ * @param wm Pointer to a wiimote_t structure.
276
+ * @param data Pointer to the filled data block.
277
+ * @param len Length in bytes of the data block.
278
+ *
279
+ * @see wiiuse_init()
280
+ *
281
+ * A registered function of this type is called automatically by the wiiuse
282
+ * library when the wiimote has returned the full data requested by a previous
283
+ * call to wiiuse_read_data().
284
+ */
285
+ typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
286
+
287
+
288
+ /**
289
+ * @struct read_req_t
290
+ * @brief Data read request structure.
291
+ */
292
+ struct read_req_t {
293
+ wiiuse_read_cb cb; /**< read data callback */
294
+ byte* buf; /**< buffer where read data is written */
295
+ unsigned int addr; /**< the offset that the read started at */
296
+ unsigned short size; /**< the length of the data read */
297
+ unsigned short wait; /**< num bytes still needed to finish read */
298
+ byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
299
+
300
+ struct read_req_t* next; /**< next read request in the queue */
301
+ };
302
+
303
+
304
+ /**
305
+ * @struct vec2b_t
306
+ * @brief Unsigned x,y byte vector.
307
+ */
308
+ typedef struct vec2b_t {
309
+ byte x, y;
310
+ } vec2b_t;
311
+
312
+
313
+ /**
314
+ * @struct vec3b_t
315
+ * @brief Unsigned x,y,z byte vector.
316
+ */
317
+ typedef struct vec3b_t {
318
+ byte x, y, z;
319
+ } vec3b_t;
320
+
321
+
322
+ /**
323
+ * @struct vec3f_t
324
+ * @brief Signed x,y,z float struct.
325
+ */
326
+ typedef struct vec3f_t {
327
+ float x, y, z;
328
+ } vec3f_t;
329
+
330
+
331
+ /**
332
+ * @struct orient_t
333
+ * @brief Orientation struct.
334
+ *
335
+ * Yaw, pitch, and roll range from -180 to 180 degrees.
336
+ */
337
+ typedef struct orient_t {
338
+ float roll; /**< roll, this may be smoothed if enabled */
339
+ float pitch; /**< pitch, this may be smoothed if enabled */
340
+ float yaw;
341
+
342
+ float a_roll; /**< absolute roll, unsmoothed */
343
+ float a_pitch; /**< absolute pitch, unsmoothed */
344
+ } orient_t;
345
+
346
+
347
+ /**
348
+ * @struct gforce_t
349
+ * @brief Gravity force struct.
350
+ */
351
+ typedef struct gforce_t {
352
+ float x, y, z;
353
+ } gforce_t;
354
+
355
+
356
+ /**
357
+ * @struct accel_t
358
+ * @brief Accelerometer struct. For any device with an accelerometer.
359
+ */
360
+ typedef struct accel_t {
361
+ struct vec3b_t cal_zero; /**< zero calibration */
362
+ struct vec3b_t cal_g; /**< 1g difference around 0cal */
363
+
364
+ float st_roll; /**< last smoothed roll value */
365
+ float st_pitch; /**< last smoothed roll pitch */
366
+ float st_alpha; /**< alpha value for smoothing [0-1] */
367
+ } accel_t;
368
+
369
+
370
+ /**
371
+ * @struct ir_dot_t
372
+ * @brief A single IR source.
373
+ */
374
+ typedef struct ir_dot_t {
375
+ byte visible; /**< if the IR source is visible */
376
+
377
+ unsigned int x; /**< interpolated X coordinate */
378
+ unsigned int y; /**< interpolated Y coordinate */
379
+
380
+ short rx; /**< raw X coordinate (0-1023) */
381
+ short ry; /**< raw Y coordinate (0-767) */
382
+
383
+ byte order; /**< increasing order by x-axis value */
384
+
385
+ byte size; /**< size of the IR dot (0-15) */
386
+ } ir_dot_t;
387
+
388
+
389
+ /**
390
+ * @struct ir_t
391
+ * @brief IR struct. Hold all data related to the IR tracking.
392
+ */
393
+ typedef struct ir_t {
394
+ struct ir_dot_t dot[4]; /**< IR dots */
395
+ byte num_dots; /**< number of dots at this time */
396
+
397
+ enum aspect_t aspect; /**< aspect ratio of the screen */
398
+
399
+ enum ir_position_t pos; /**< IR sensor bar position */
400
+
401
+ unsigned int vres[2]; /**< IR virtual screen resolution */
402
+ int offset[2]; /**< IR XY correction offset */
403
+ int state; /**< keeps track of the IR state */
404
+
405
+ int ax; /**< absolute X coordinate */
406
+ int ay; /**< absolute Y coordinate */
407
+
408
+ int x; /**< calculated X coordinate */
409
+ int y; /**< calculated Y coordinate */
410
+
411
+ float distance; /**< pixel distance between first 2 dots*/
412
+ float z; /**< calculated distance */
413
+ } ir_t;
414
+
415
+
416
+ /**
417
+ * @struct joystick_t
418
+ * @brief Joystick calibration structure.
419
+ *
420
+ * The angle \a ang is relative to the positive y-axis into quadrant I
421
+ * and ranges from 0 to 360 degrees. So if the joystick is held straight
422
+ * upwards then angle is 0 degrees. If it is held to the right it is 90,
423
+ * down is 180, and left is 270.
424
+ *
425
+ * The magnitude \a mag is the distance from the center to where the
426
+ * joystick is being held. The magnitude ranges from 0 to 1.
427
+ * If the joystick is only slightly tilted from the center the magnitude
428
+ * will be low, but if it is closer to the outter edge the value will
429
+ * be higher.
430
+ */
431
+ typedef struct joystick_t {
432
+ struct vec2b_t max; /**< maximum joystick values */
433
+ struct vec2b_t min; /**< minimum joystick values */
434
+ struct vec2b_t center; /**< center joystick values */
435
+
436
+ float ang; /**< angle the joystick is being held */
437
+ float mag; /**< magnitude of the joystick (range 0-1) */
438
+ } joystick_t;
439
+
440
+
441
+ /**
442
+ * @struct nunchuk_t
443
+ * @brief Nunchuk expansion device.
444
+ */
445
+ typedef struct nunchuk_t {
446
+ struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
447
+ struct joystick_t js; /**< joystick calibration */
448
+
449
+ int* flags; /**< options flag (points to wiimote_t.flags) */
450
+
451
+ byte btns; /**< what buttons have just been pressed */
452
+ byte btns_held; /**< what buttons are being held down */
453
+ byte btns_released; /**< what buttons were just released this */
454
+
455
+ float orient_threshold; /**< threshold for orient to generate an event */
456
+ int accel_threshold; /**< threshold for accel to generate an event */
457
+
458
+ struct vec3b_t accel; /**< current raw acceleration data */
459
+ struct orient_t orient; /**< current orientation on each axis */
460
+ struct gforce_t gforce; /**< current gravity forces on each axis */
461
+ } nunchuk_t;
462
+
463
+
464
+ /**
465
+ * @struct classic_ctrl_t
466
+ * @brief Classic controller expansion device.
467
+ */
468
+ typedef struct classic_ctrl_t {
469
+ short btns; /**< what buttons have just been pressed */
470
+ short btns_held; /**< what buttons are being held down */
471
+ short btns_released; /**< what buttons were just released this */
472
+
473
+ float r_shoulder; /**< right shoulder button (range 0-1) */
474
+ float l_shoulder; /**< left shoulder button (range 0-1) */
475
+
476
+ struct joystick_t ljs; /**< left joystick calibration */
477
+ struct joystick_t rjs; /**< right joystick calibration */
478
+ } classic_ctrl_t;
479
+
480
+
481
+ /**
482
+ * @struct guitar_hero_3_t
483
+ * @brief Guitar Hero 3 expansion device.
484
+ */
485
+ typedef struct guitar_hero_3_t {
486
+ short btns; /**< what buttons have just been pressed */
487
+ short btns_held; /**< what buttons are being held down */
488
+ short btns_released; /**< what buttons were just released this */
489
+
490
+ float whammy_bar; /**< whammy bar (range 0-1) */
491
+
492
+ struct joystick_t js; /**< joystick calibration */
493
+ } guitar_hero_3_t;
494
+
495
+
496
+ /**
497
+ * @struct expansion_t
498
+ * @brief Generic expansion device plugged into wiimote.
499
+ */
500
+ union union_t {
501
+ struct nunchuk_t nunchuk;
502
+ struct classic_ctrl_t classic;
503
+ struct guitar_hero_3_t gh3;
504
+ };
505
+
506
+ typedef struct expansion_t {
507
+ int type; /**< type of expansion attached */
508
+ union_t controller;
509
+ } expansion_t;
510
+
511
+ /**
512
+ * @struct wiimote_state_t
513
+ * @brief Significant data from the previous event.
514
+ */
515
+ typedef struct wiimote_state_t {
516
+ /* expansion_t */
517
+ float exp_ljs_ang;
518
+ float exp_rjs_ang;
519
+ float exp_ljs_mag;
520
+ float exp_rjs_mag;
521
+ unsigned short exp_btns;
522
+ struct orient_t exp_orient;
523
+ struct vec3b_t exp_accel;
524
+ float exp_r_shoulder;
525
+ float exp_l_shoulder;
526
+
527
+ /* ir_t */
528
+ int ir_ax;
529
+ int ir_ay;
530
+ float ir_distance;
531
+
532
+ struct orient_t orient;
533
+ unsigned short btns;
534
+
535
+ struct vec3b_t accel;
536
+ } wiimote_state_t;
537
+
538
+
539
+ struct bdaddr_t {
540
+ unsigned char b[6];
541
+ };
542
+
543
+ /**
544
+ * @struct wiimote_t
545
+ * @brief Wiimote structure.
546
+ */
547
+ typedef struct wiimote_t {
548
+ WCONST int unid; /**< user specified id */
549
+
550
+ #ifndef WIN32
551
+ WCONST struct bdaddr_t bdaddr; /**< bt address */
552
+ WCONST char bdaddr_str[18]; /**< readable bt address */
553
+ WCONST int out_sock; /**< output socket */
554
+ WCONST int in_sock; /**< input socket */
555
+ #else
556
+ WCONST HANDLE dev_handle; /**< HID handle */
557
+ WCONST OVERLAPPED hid_overlap; /**< overlap handle */
558
+ WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
559
+ WCONST int timeout; /**< read timeout */
560
+ WCONST byte normal_timeout; /**< normal timeout */
561
+ WCONST byte exp_timeout; /**< timeout for expansion handshake */
562
+ #endif
563
+
564
+ WCONST int state; /**< various state flags */
565
+ WCONST byte leds; /**< currently lit leds */
566
+ WCONST float battery_level; /**< battery level */
567
+
568
+ WCONST int flags; /**< options flag */
569
+
570
+ WCONST byte handshake_state; /**< the state of the connection handshake */
571
+
572
+ WCONST struct read_req_t* read_req; /**< list of data read requests */
573
+ WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
574
+ WCONST struct expansion_t exp; /**< wiimote expansion device */
575
+
576
+ WCONST struct vec3b_t accel; /**< current raw acceleration data */
577
+ WCONST struct orient_t orient; /**< current orientation on each axis */
578
+ WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
579
+
580
+ WCONST struct ir_t ir; /**< IR data */
581
+
582
+ WCONST unsigned short btns; /**< what buttons have just been pressed */
583
+ WCONST unsigned short btns_held; /**< what buttons are being held down */
584
+ WCONST unsigned short btns_released; /**< what buttons were just released this */
585
+
586
+ WCONST float orient_threshold; /**< threshold for orient to generate an event */
587
+ WCONST int accel_threshold; /**< threshold for accel to generate an event */
588
+
589
+ WCONST struct wiimote_state_t lstate; /**< last saved state */
590
+
591
+ WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
592
+ WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
593
+ } wiimote;
594
+
595
+
596
+ /*****************************************
597
+ *
598
+ * Include API specific stuff
599
+ *
600
+ *****************************************/
601
+
602
+ #ifdef _WIN32
603
+ #define WIIUSE_EXPORT_DECL __declspec(dllexport)
604
+ #define WIIUSE_IMPORT_DECL __declspec(dllimport)
605
+ #else
606
+ #define WIIUSE_EXPORT_DECL
607
+ #define WIIUSE_IMPORT_DECL
608
+ #endif
609
+
610
+ #ifdef WIIUSE_COMPILE_LIB
611
+ #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
612
+ #else
613
+ #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
614
+ #endif
615
+
616
+ #ifdef __cplusplus \
617
+ extern "C" {
618
+ #endif
619
+
620
+ /* wiiuse.c */
621
+ WIIUSE_EXPORT extern const char* wiiuse_version();
622
+
623
+ WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
624
+ WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
625
+ WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
626
+ WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
627
+ WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
628
+ WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
629
+ WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
630
+ WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
631
+ WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
632
+ WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
633
+ WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
634
+ WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
635
+ WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
636
+ WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
637
+ WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
638
+ WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
639
+ WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
640
+ WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
641
+
642
+ /* connect.c */
643
+ WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
644
+ WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
645
+ WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
646
+
647
+ /* events.c */
648
+ WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
649
+
650
+ /* ir.c */
651
+ WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
652
+ WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
653
+ WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
654
+ WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
655
+ WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
656
+
657
+ /* nunchuk.c */
658
+ WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
659
+ WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
660
+
661
+
662
+ #ifdef __cplusplus \
663
+ }
664
+ #endif
665
+
666
+
667
+ #endif /* WIIUSE_H_INCLUDED */
668
+
669
+ %{
670
+ end
671
+ %}
672
+