Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/external/wiicpp/wiic/wiic_structs.h @ 9780

Last change on this file since 9780 was 9780, checked in by georgr, 10 years ago

WiiCpp library successfully (?) added - won't work without libbluetooth-dev

  • Property svn:executable set to *
File size: 14.2 KB
Line 
1/*
2 *    wiic_structs.h
3 *
4 *        This file is part of WiiC, written by:
5 *              Gabriele Randelli
6 *              Email: randelli@dis.uniroma1.it
7 *
8 *    Copyright 2010
9 *             
10 *        This file is based on Wiiuse, written By:
11 *              Michael Laforest        < para >
12 *              Email: < thepara (--AT--) g m a i l [--DOT--] com >
13 *
14 *        Copyright 2006-2007
15 *
16 *    This program is free software; you can redistribute it and/or modify
17 *    it under the terms of the GNU General Public License as published by
18 *    the Free Software Foundation; either version 3 of the License, or
19 *    (at your option) any later version.
20 *
21 *    This program is distributed in the hope that it will be useful,
22 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
23 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 *    GNU General Public License for more details.
25 *
26 *    You should have received a copy of the GNU General Public License
27 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
28 *
29 *        $Header$
30 */
31
32/**
33 *      @file
34 *
35 *      @brief WiiC structures.
36 *
37 *      Contains all the data structures, that represents
38 *      devices, sensors, and everything necessary. This header
39 *      is included in wiic.h.
40 */
41struct vec3b_t;
42struct orient_t;
43struct gforce_t;
44
45/**
46 *      @struct read_req_t
47 *      @brief Data read request structure.
48 */
49struct read_req_t {
50        wiic_read_cb cb;                        /**< read data callback                                                                                 */
51        byte* buf;                                      /**< buffer where read data is written                                                  */
52        unsigned int addr;                      /**< the offset that the read started at                                                */
53        unsigned short size;            /**< the length of the data read                                                                */
54        unsigned short wait;            /**< num bytes still needed to finish read                                              */
55        byte dirty;                                     /**< set to 1 if not using callback and needs to be cleaned up  */
56
57        struct read_req_t* next;        /**< next read request in the queue                                                             */
58};
59
60/*** COMMON STRUCTURES ***/
61
62/**
63 *      @struct vec2b_t
64 *      @brief Unsigned x,y byte vector.
65 */
66typedef struct vec2b_t {
67        byte x, y;
68} vec2b_t;
69
70
71/**
72 *      @struct vec3b_t
73 *      @brief Unsigned x,y,z byte vector.
74 */
75typedef struct vec3b_t {
76        byte x, y, z;
77} vec3b_t;
78
79/**
80 *      @struct vec3f_t
81 *      @brief Signed x,y,z float struct.
82 */
83typedef struct vec3f_t {
84        float x, y, z;
85} vec3f_t;
86
87/**
88 *      @struct ang3s_t
89 *      @brief RPY short int angles.
90 */
91typedef struct ang3s_t {
92        short roll, pitch, yaw;
93} ang3s_t;
94
95/**
96 *      @struct ang3f_t
97 *      @brief RPY float angles.
98 */
99typedef struct ang3f_t {
100        float roll, pitch, yaw;
101} ang3f_t;
102
103/**
104 *      @struct orient_t
105 *      @brief Orientation struct.
106 *
107 *      Yaw, pitch, and roll range from -180 to 180 degrees.
108 */
109typedef struct orient_t {
110        struct ang3f_t angle;   /**< roll, pitch and yaw (this may be smoothed if enabled)      */
111} orient_t;
112
113/**
114 *      @struct ang_rate_t
115 *      @brief Angular rate struct.
116 *
117 *      Yaw, pitch, and roll rate from -180 to 180 degrees.
118 */
119typedef struct ang_rate_t {
120        struct ang3f_t rate;    /**< roll, pitch and yaw rate (this may be smoothed if enabled) */
121        struct ang3f_t a_rate;  /**< roll, pitch and yaw rate (unsmoothed)      */
122} ang_rate_t;
123
124/**
125 *      @struct vel_t
126 *      @brief Velocity struct.
127 */
128typedef struct vel_t {
129        struct ang3s_t vel;             /**< raw rate, this may be smoothed if enabled  */
130        struct ang3s_t a_vel;   /**< raw rate (unsmoothed)      */
131} vel_t;
132
133/**
134 *      @struct gforce_t
135 *      @brief Gravity force struct.
136 */
137typedef struct gforce_t {
138        struct vec3f_t vec;             /**< gforce, this may be smoothed if enabled    */
139        struct vec3f_t a_vec;   /**< gforce (unsmoothed)        */
140} gforce_t;
141
142
143/**
144 *      @struct accel_t
145 *      @brief Accelerometer struct. For any device with an accelerometer.
146 */
147typedef struct accel_t {
148        struct vec3b_t cal_zero;                /**< zero calibration                                   */
149        struct vec3b_t cal_g;                   /**< 1g difference around 0cal                  */
150        float st_alpha;                                 /**< alpha value for smoothing [0-1]    */
151} accel_t;
152
153/**
154 *      @struct gyro_t
155 *      @brief Gyro struct. For any device with a gyroscope.
156 */
157typedef struct gyro_t {
158        struct vec3b_t cal_zero;                /**< zero calibration                                   */
159        float st_alpha;                                 /**< alpha value for smoothing [0-1]    */
160} gyro_t;
161
162/**
163 *  @struct pressure_t
164 *  @brief Pressure sensor struct. Contains four pressure sensor measurements. Used for the Wii Balance Board.
165 */
166typedef struct pressure_t {
167        unsigned short top_left;
168        unsigned short top_right;
169        unsigned short bottom_left;
170        unsigned short bottom_right;
171} pressure_t;
172
173/**
174 *  @struct pressure_weight_t
175 *  @brief Pressure sensor weight struct. Contains four pressure sensor measurements in Kg. Used for the Wii Balance Board.
176 */
177typedef struct pressure_weight_t {
178        float top_left;
179        float top_right;
180        float bottom_left;
181        float bottom_right;
182        float weight; // This is the sum of the weight on the four sensors
183} pressure_weight_t;
184
185/* IR correction types */
186typedef enum ir_position_t {
187        WIIC_IR_ABOVE,
188        WIIC_IR_BELOW
189} ir_position_t;
190
191/**
192 *      @struct ir_dot_t
193 *      @brief A single IR source.
194 */
195typedef struct ir_dot_t {
196        byte visible;                                   /**< if the IR source is visible                */
197
198        unsigned int x;                                 /**< interpolated X coordinate                  */
199        unsigned int y;                                 /**< interpolated Y coordinate                  */
200
201        short rx;                                               /**< raw X coordinate (0-1023)                  */
202        short ry;                                               /**< raw Y coordinate (0-767)                   */
203
204        byte order;                                             /**< increasing order by x-axis value   */
205
206        byte size;                                              /**< size of the IR dot (0-15)                  */
207} ir_dot_t;
208
209
210/**
211 *      @struct ir_t
212 *      @brief IR struct. Hold all data related to the IR tracking.
213 */
214typedef struct ir_t {
215        struct ir_dot_t dot[4];                 /**< IR dots                                                    */
216        byte num_dots;                                  /**< number of dots at this time                */
217
218        enum aspect_t aspect;                   /**< aspect ratio of the screen                 */
219
220        enum ir_position_t pos;                 /**< IR sensor bar position                             */
221
222        unsigned int vres[2];                   /**< IR virtual screen resolution               */
223        int offset[2];                                  /**< IR XY correction offset                    */
224        int state;                                              /**< keeps track of the IR state                */
225
226        int ax;                                                 /**< absolute X coordinate                              */
227        int ay;                                                 /**< absolute Y coordinate                              */
228
229        int x;                                                  /**< calculated X coordinate                    */
230        int y;                                                  /**< calculated Y coordinate                    */
231
232        float distance;                                 /**< pixel distance between first 2 dots*/
233        float z;                                                /**< calculated distance                                */
234} ir_t;
235
236
237/**
238 *      @struct joystick_t
239 *      @brief Joystick calibration structure.
240 *
241 *      The angle \a ang is relative to the positive y-axis into quadrant I
242 *      and ranges from 0 to 360 degrees.  So if the joystick is held straight
243 *      upwards then angle is 0 degrees.  If it is held to the right it is 90,
244 *      down is 180, and left is 270.
245 *
246 *      The magnitude \a mag is the distance from the center to where the
247 *      joystick is being held.  The magnitude ranges from 0 to 1.
248 *      If the joystick is only slightly tilted from the center the magnitude
249 *      will be low, but if it is closer to the outter edge the value will
250 *      be higher.
251 */
252typedef struct joystick_t {
253        struct vec2b_t max;                             /**< maximum joystick values    */
254        struct vec2b_t min;                             /**< minimum joystick values    */
255        struct vec2b_t center;                  /**< center joystick values             */
256
257        float ang;                                              /**< angle the joystick is being held           */
258        float mag;                                              /**< magnitude of the joystick (range 0-1)      */
259} joystick_t;
260
261
262/**
263 *      @struct nunchuk_t
264 *      @brief Nunchuk expansion device.
265 */
266typedef struct nunchuk_t {
267        struct accel_t accel_calib;             /**< nunchuk accelerometer calibration          */
268        struct joystick_t js;                   /**< joystick calibration                                       */
269
270        int* flags;                                             /**< options flag (points to wiimote_t.flags) */
271
272        byte btns;                                              /**< what buttons have just been pressed        */
273        byte btns_held;                                 /**< what buttons are being held down           */
274        byte btns_released;                             /**< what buttons were just released this       */
275
276        float orient_threshold;                 /**< threshold for orient to generate an event */
277        int accel_threshold;                    /**< threshold for accel to generate an event */
278
279        struct vec3b_t accel;                   /**< current raw acceleration data                      */
280        struct orient_t orient;                 /**< current orientation on each axis           */
281        struct orient_t a_orient;               /**< current orientation on each axis (unsmoothed)              */
282        struct gforce_t gforce;                 /**< current gravity forces on each axis        */
283        struct gforce_t a_gforce;               /**< current gravity forces on each axis (unsmoothed)   */
284} nunchuk_t;
285
286
287/**
288 *      @struct classic_ctrl_t
289 *      @brief Classic controller expansion device.
290 */
291typedef struct classic_ctrl_t {
292        short btns;                                             /**< what buttons have just been pressed        */
293        short btns_held;                                /**< what buttons are being held down           */
294        short btns_released;                    /**< what buttons were just released this       */
295
296        float r_shoulder;                               /**< right shoulder button (range 0-1)          */
297        float l_shoulder;                               /**< left shoulder button (range 0-1)           */
298
299        struct joystick_t ljs;                  /**< left joystick calibration                          */
300        struct joystick_t rjs;                  /**< right joystick calibration                         */
301} classic_ctrl_t;
302
303
304/**
305 *      @struct guitar_hero_3_t
306 *      @brief Guitar Hero 3 expansion device.
307 */
308typedef struct guitar_hero_3_t {
309        short btns;                                             /**< what buttons have just been pressed        */
310        short btns_held;                                /**< what buttons are being held down           */
311        short btns_released;                    /**< what buttons were just released this       */
312
313        float whammy_bar;                               /**< whammy bar (range 0-1)                                     */
314
315        struct joystick_t js;                   /**< joystick calibration                                       */
316} guitar_hero_3_t;
317
318/**
319 *      @struct balance_board_t
320 *      @brief Balance Board expansion device.
321 */
322typedef struct balance_board_t {
323        struct pressure_t cal_low_weight; // equivalent 0Kg
324        struct pressure_t cal_medium_weight; // equivalent 17Kg
325        struct pressure_t cal_high_weight; // equivalent 34Kg
326        struct pressure_t pressure_raw_data; // Actual reading
327        struct pressure_weight_t pressure_weight; // In Kg
328} balance_board_t;
329
330/**
331 *      @struct motion_plus_t
332 *      @brief Motion Plus expansion device.
333 */
334typedef struct motion_plus_t {
335        struct ang3s_t a_raw_gyro;                      /**< current raw gyroscope data (unsmoothed) */
336        struct ang3s_t raw_gyro;                        /**< current raw gyroscope data (smoothed, if enabled) */
337        struct ang3s_t cal_gyro;                        /**< calibration raw gyroscope data */
338        struct ang3f_t a_gyro_rate;             /**< current gyro angle rate (unsmoothed) */
339        struct ang3f_t gyro_rate;               /**< current gyro angle rate (smoothed, if enabled) */
340        struct orient_t orient;                         /**< current orientation on each axis using Motion Plus gyroscopes */
341        byte acc_mode;                                          /**< Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) */
342        int raw_gyro_threshold;                 /**< threshold for gyroscopes to generate an event */
343        int smooth;                                     /**< smoothing enabled/disabled */
344        float smooth_alpha;                             /**< smoothness alpha parameter*/
345} motion_plus_t;
346
347
348/**
349 *      @struct expansion_t
350 *      @brief Generic expansion device plugged into wiimote.
351 */
352typedef struct expansion_t {
353        int type;                                               /**< type of expansion attached                         */
354
355        union {
356                struct nunchuk_t nunchuk;
357                struct classic_ctrl_t classic;
358                struct guitar_hero_3_t gh3;
359                struct motion_plus_t mp;
360                struct balance_board_t bb;
361        };
362} expansion_t;
363
364
365/**
366 *      @struct wiimote_state_t
367 *      @brief Significant data from the previous event.
368 */
369typedef struct wiimote_state_t {
370        /* expansion_t */
371        float exp_ljs_ang;
372        float exp_rjs_ang;
373        float exp_ljs_mag;
374        float exp_rjs_mag;
375        unsigned short exp_btns;
376        struct orient_t exp_orient;
377        struct vec3b_t exp_accel;
378        float exp_r_shoulder;
379        float exp_l_shoulder;
380       
381        /* motion_plus_t */
382        byte mp_acc_mode;
383        struct ang3s_t mp_raw_gyro;
384       
385        /* balance_board_t */
386        struct pressure_t pressure_raw_data;
387
388        /* ir_t */
389        int ir_ax;
390        int ir_ay;
391        float ir_distance;
392
393        /* wiimote_t */
394        struct orient_t orient;
395        unsigned short btns;
396        struct vec3b_t accel;
397} wiimote_state_t;
398
399
400/**
401 *      @enum WIIC_EVENT_TYPE
402 *      @brief Events that wiic can generate from a poll.
403 */
404typedef enum WIIC_EVENT_TYPE {
405        WIIC_NONE = 0,
406        WIIC_EVENT,
407        WIIC_STATUS,
408        WIIC_CONNECT,
409        WIIC_DISCONNECT,
410        WIIC_UNEXPECTED_DISCONNECT,
411        WIIC_READ_DATA,
412        WIIC_NUNCHUK_INSERTED,
413        WIIC_NUNCHUK_REMOVED,
414        WIIC_CLASSIC_CTRL_INSERTED,
415        WIIC_CLASSIC_CTRL_REMOVED,
416        WIIC_GUITAR_HERO_3_CTRL_INSERTED,
417        WIIC_GUITAR_HERO_3_CTRL_REMOVED,
418        WIIC_MOTION_PLUS_INSERTED,
419        WIIC_MOTION_PLUS_REMOVED,
420        WIIC_BALANCE_BOARD_INSERTED,
421        WIIC_BALANCE_BOARD_REMOVED
422} WIIC_EVENT_TYPE;
423
424/**
425 *      @struct wiimote_t
426 *      @brief Wiimote structure.
427 */
428typedef struct wiimote_t {
429        WCONST int unid;                                                /**< user specified id                                          */
430
431        #ifdef __APPLE__
432                WCONST IOBluetoothDeviceRef device;     /**  Device reference object                */
433                WCONST CFStringRef address;             /**  MacOS-like device address string       */
434                WCONST IOBluetoothL2CAPChannelRef inputCh;              /**  Input L2CAP channel                                        */     
435                WCONST IOBluetoothL2CAPChannelRef outputCh;     /**  Output L2CAP channel                                       */
436                WCONST IOBluetoothUserNotificationRef disconnectionRef; /**  Disconnection Notification Reference **/
437                WCONST void* connectionHandler; /** Wiimote connection handler for MACOSX **/
438        #elif LINUX
439                WCONST bdaddr_t bdaddr;                         /**< bt address                                                         */
440                WCONST int out_sock;                            /**< output socket                                                      */
441                WCONST int in_sock;                                     /**< input socket                                                       */     
442        #endif
443       
444        WCONST char bdaddr_str[18];                     /**< readable bt address                                        */
445        WCONST struct wiimote_state_t lstate;   /**< last saved state                                           */
446        WCONST int state;                                               /**< various state flags                                        */
447        WCONST int flags;                                               /**< options flag                                                       */
448        WCONST int autoreconnect;                               /**< auto-reconnect the device in case of unexpected disconnection */
449        WCONST byte handshake_state;                    /**< the state of the connection handshake      */
450       
451        WCONST byte leds;                                               /**< currently lit leds                                         */
452        WCONST float battery_level;                             /**< battery level                                                      */
453
454        WCONST struct read_req_t* read_req;             /**< list of data read requests                         */
455        WCONST struct expansion_t exp;                  /**< wiimote expansion device                           */
456
457        WCONST struct accel_t accel_calib;              /**< wiimote accelerometer calibration          */
458        WCONST struct vec3b_t accel;                    /**< current raw acceleration data                      */
459        WCONST struct orient_t orient;                  /**< current orientation on each axis (smoothed and unsmoothed)         */
460        WCONST struct gforce_t gforce;                  /**< current gravity forces on each axis (smoothed and unsmoothed)      */
461        WCONST float orient_threshold;                  /**< threshold for orient to generate an event */
462        WCONST int accel_threshold;                             /**< threshold for accel to generate an event */
463
464        WCONST struct ir_t ir;                                  /**< IR data                                                            */
465
466        WCONST unsigned short btns;                             /**< what buttons have just been pressed        */
467        WCONST unsigned short btns_held;                /**< what buttons are being held down           */
468        WCONST unsigned short btns_released;    /**< what buttons were just released this       */
469
470        WCONST WIIC_EVENT_TYPE event;                   /**< type of event that occured                         */
471        WCONST byte event_buf[MAX_PAYLOAD];             /**< event buffer                                                       */
472       
473        struct timeval timestamp;                               /**< Absolute timestamp (relative to the most recent data) */
474} wiimote;
Note: See TracBrowser for help on using the repository browser.