Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/external/wiicpp/wiic/wiic_macros.h @ 10422

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

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

  • Property svn:executable set to *
File size: 9.1 KB
Line 
1/*
2 *    wiic_macros.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 macros and typedef.
36 *
37 *      Contains all the macros to manage the state of the Wiimote,
38 *      its component, and other devices, as well as some useful
39 *      typedef. This header is included in wiic.h.
40 */
41/* wiimote state flags */
42#define WIIMOTE_STATE_DEV_FOUND                         0x00001
43#define WIIMOTE_STATE_HANDSHAKE                         0x00002 /* actual connection exists but no handshake yet */
44#define WIIMOTE_STATE_HANDSHAKE_COMPLETE        0x00004 /* actual connection exists but no handshake yet */
45#define WIIMOTE_STATE_CONNECTED                         0x00008
46#define WIIMOTE_STATE_RUMBLE                            0x00010
47#define WIIMOTE_STATE_ACC                                       0x00020
48#define WIIMOTE_STATE_EXP                                       0x00040
49#define WIIMOTE_STATE_IR                                        0x00080
50#define WIIMOTE_STATE_SPEAKER                           0x00100
51#define WIIMOTE_STATE_IR_SENS_LVL1                      0x00200
52#define WIIMOTE_STATE_IR_SENS_LVL2                      0x00400
53#define WIIMOTE_STATE_IR_SENS_LVL3                      0x00800
54#define WIIMOTE_STATE_IR_SENS_LVL4                      0x01000
55#define WIIMOTE_STATE_IR_SENS_LVL5                      0x02000
56#define WIIMOTE_STATE_EXP_HANDSHAKE                     0x04000 /* Added to handle handshaking concurrency between Motion Plus and other expansion types */
57#define WIIMOTE_STATE_EXP_FAILED                        0x08000
58#define WIIMOTE_STATE_MOTION_PLUS                       0x10000 /**< MotionPlus state flag, set when the MotionPlus is used */ 
59#define WIIMOTE_STATE_SPEAKER_MUTE                      0x20000 /**< Speaker Mute */   
60
61#define WIIMOTE_INIT_STATES                                     (WIIMOTE_STATE_IR_SENS_LVL3)
62
63/* macro to manage states */
64#define WIIMOTE_IS_SET(wm, s)                   ((wm->state & (s)) == (s))
65#define WIIMOTE_ENABLE_STATE(wm, s)             (wm->state |= (s))
66#define WIIMOTE_DISABLE_STATE(wm, s)    (wm->state &= ~(s))
67#define WIIMOTE_TOGGLE_STATE(wm, s)             ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
68
69/* macro to manage flags */
70#define WIIMOTE_IS_FLAG_SET(wm, s)              ((wm->flags & (s)) == (s))
71#define WIIMOTE_ENABLE_FLAG(wm, s)              (wm->flags |= (s))
72#define WIIMOTE_DISABLE_FLAG(wm, s)             (wm->flags &= ~(s))
73#define WIIMOTE_TOGGLE_FLAG(wm, s)              ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
74
75#define NUNCHUK_IS_FLAG_SET(wm, s)              ((*(wm->flags) & (s)) == (s))
76
77/* misc macros */
78#define WIIMOTE_ID(wm)                                  (wm->unid)
79#define WIIMOTE_IS_CONNECTED(wm)                (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
80
81/* led bit masks */
82#define WIIMOTE_LED_NONE                                0x00
83#define WIIMOTE_LED_1                                   0x10
84#define WIIMOTE_LED_2                                   0x20
85#define WIIMOTE_LED_3                                   0x40
86#define WIIMOTE_LED_4                                   0x80
87
88/* button codes */
89#define WIIMOTE_BUTTON_TWO                              0x0001
90#define WIIMOTE_BUTTON_ONE                              0x0002
91#define WIIMOTE_BUTTON_B                                0x0004
92#define WIIMOTE_BUTTON_A                                0x0008
93#define WIIMOTE_BUTTON_MINUS                    0x0010
94#define WIIMOTE_BUTTON_ZACCEL_BIT6              0x0020
95#define WIIMOTE_BUTTON_ZACCEL_BIT7              0x0040
96#define WIIMOTE_BUTTON_HOME                             0x0080
97#define WIIMOTE_BUTTON_LEFT                             0x0100
98#define WIIMOTE_BUTTON_RIGHT                    0x0200
99#define WIIMOTE_BUTTON_DOWN                             0x0400
100#define WIIMOTE_BUTTON_UP                               0x0800
101#define WIIMOTE_BUTTON_PLUS                             0x1000
102#define WIIMOTE_BUTTON_ZACCEL_BIT4              0x2000
103#define WIIMOTE_BUTTON_ZACCEL_BIT5              0x4000
104#define WIIMOTE_BUTTON_UNKNOWN                  0x8000
105#define WIIMOTE_BUTTON_ALL                              0x1F9F
106
107/* nunchuk button codes */
108#define NUNCHUK_BUTTON_Z                                0x01
109#define NUNCHUK_BUTTON_C                                0x02
110#define NUNCHUK_BUTTON_ALL                              0x03
111
112/* classic controller button codes */
113#define CLASSIC_CTRL_BUTTON_UP                  0x0001
114#define CLASSIC_CTRL_BUTTON_LEFT                0x0002
115#define CLASSIC_CTRL_BUTTON_ZR                  0x0004
116#define CLASSIC_CTRL_BUTTON_X                   0x0008
117#define CLASSIC_CTRL_BUTTON_A                   0x0010
118#define CLASSIC_CTRL_BUTTON_Y                   0x0020
119#define CLASSIC_CTRL_BUTTON_B                   0x0040
120#define CLASSIC_CTRL_BUTTON_ZL                  0x0080
121#define CLASSIC_CTRL_BUTTON_FULL_R              0x0200
122#define CLASSIC_CTRL_BUTTON_PLUS                0x0400
123#define CLASSIC_CTRL_BUTTON_HOME                0x0800
124#define CLASSIC_CTRL_BUTTON_MINUS               0x1000
125#define CLASSIC_CTRL_BUTTON_FULL_L              0x2000
126#define CLASSIC_CTRL_BUTTON_DOWN                0x4000
127#define CLASSIC_CTRL_BUTTON_RIGHT               0x8000
128#define CLASSIC_CTRL_BUTTON_ALL                 0xFEFF
129
130/* guitar hero 3 button codes */
131#define GUITAR_HERO_3_BUTTON_STRUM_UP   0x0001
132#define GUITAR_HERO_3_BUTTON_YELLOW             0x0008
133#define GUITAR_HERO_3_BUTTON_GREEN              0x0010
134#define GUITAR_HERO_3_BUTTON_BLUE               0x0020
135#define GUITAR_HERO_3_BUTTON_RED                0x0040
136#define GUITAR_HERO_3_BUTTON_ORANGE             0x0080
137#define GUITAR_HERO_3_BUTTON_PLUS               0x0400
138#define GUITAR_HERO_3_BUTTON_MINUS              0x1000
139#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
140#define GUITAR_HERO_3_BUTTON_ALL                0xFEFF
141
142
143/* wiimote option flags */
144#define WIIC_SMOOTHING                          0x01
145#define WIIC_CONTINUOUS                         0x04
146#define WIIC_ORIENT_THRESH                      0x04
147#define WIIC_INIT_FLAGS                         (WIIC_SMOOTHING | WIIC_ORIENT_THRESH)
148
149/* expansion codes */
150#define EXP_NONE                                                0
151#define EXP_NUNCHUK                                             1
152#define EXP_CLASSIC                                             2
153#define EXP_GUITAR_HERO_3                               3
154#define EXP_MOTION_PLUS                                 4
155#define EXP_BALANCE_BOARD                               5
156
157/**
158 *      @brief Check if a button is pressed.
159 *      @param dev              Pointer to a wiimote_t or expansion structure.
160 *      @param button   The button you are interested in.
161 *      @return 1 if the button is pressed, 0 if not.
162 */
163#define IS_PRESSED(dev, button)         ((dev->btns & button) == button)
164
165/**
166 *      @brief Check if a button is being held.
167 *      @param dev              Pointer to a wiimote_t or expansion structure.
168 *      @param button   The button you are interested in.
169 *      @return 1 if the button is held, 0 if not.
170 */
171#define IS_HELD(dev, button)                    ((dev->btns_held & button) == button)
172
173/**
174 *      @brief Check if a button is released on this event.                                     \n\n
175 *                      This does not mean the button is not pressed, it means          \n
176 *                      this button was just now released.
177 *      @param dev              Pointer to a wiimote_t or expansion structure.
178 *      @param button   The button you are interested in.
179 *      @return 1 if the button is released, 0 if not.
180 *
181 */
182#define IS_RELEASED(dev, button)                ((dev->btns_released & button) == button)
183
184/**
185 *      @brief Check if a button has just been pressed this event.
186 *      @param dev              Pointer to a wiimote_t or expansion structure.
187 *      @param button   The button you are interested in.
188 *      @return 1 if the button is pressed, 0 if not.
189 */
190#define IS_JUST_PRESSED(dev, button)    (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
191
192/**
193 *      @brief Return the IR sensitivity level.
194 *      @param wm               Pointer to a wiimote_t structure.
195 *      @param lvl              [out] Pointer to an int that will hold the level setting.
196 *      If no level is set 'lvl' will be set to 0.
197 */
198#define WIIC_GET_IR_SENSITIVITY(wm, lvl)                                                                        \
199                        do {                                                                                                            \
200                                if ((wm->state & WIIMOTE_STATE_IR_SENS_LVL1) == WIIMOTE_STATE_IR_SENS_LVL1)             *lvl = 1;       \
201                                else if ((wm->state & WIIMOTE_STATE_IR_SENS_LVL2) == WIIMOTE_STATE_IR_SENS_LVL2)        *lvl = 2;       \
202                                else if ((wm->state & WIIMOTE_STATE_IR_SENS_LVL3) == WIIMOTE_STATE_IR_SENS_LVL3)        *lvl = 3;       \
203                                else if ((wm->state & WIIMOTE_STATE_IR_SENS_LVL4) == WIIMOTE_STATE_IR_SENS_LVL4)        *lvl = 4;       \
204                                else if ((wm->state & WIIMOTE_STATE_IR_SENS_LVL5) == WIIMOTE_STATE_IR_SENS_LVL5)        *lvl = 5;       \
205                                else                                                                    *lvl = 0;               \
206                        } while (0)
207
208#define WIIC_USING_ACC(wm)                      ((wm->state & WIIMOTE_STATE_ACC) == WIIMOTE_STATE_ACC)
209#define WIIC_USING_EXP(wm)                      ((wm->state & WIIMOTE_STATE_EXP) == WIIMOTE_STATE_EXP)
210#define WIIC_USING_IR(wm)                               ((wm->state & WIIMOTE_STATE_IR) == WIIMOTE_STATE_IR)
211#define WIIC_USING_SPEAKER(wm)          ((wm->state & WIIMOTE_STATE_SPEAKER) == WIIMOTE_STATE_SPEAKER)
212#define WIIC_SPEAKER_MUTED(wm)          ((wm->state & WIIMOTE_STATE_SPEAKER_MUTE) == WIIMOTE_STATE_SPEAKER_MUTE)
213#define WIIC_USING_MOTION_PLUS(wm)      ((wm->state & WIIMOTE_STATE_MOTION_PLUS) == WIIMOTE_STATE_MOTION_PLUS)
214#define WIIC_IS_LED_SET(wm, num)                ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
215
216/** TYPEDEFS */
217typedef unsigned char byte;
218typedef char sbyte;
219
220/**
221 *      @brief Callback that handles a read event.
222 *
223 *      @param wm               Pointer to a wiimote_t structure.
224 *      @param data             Pointer to the filled data block.
225 *      @param len              Length in bytes of the data block.
226 *
227 *      @see wiic_init()
228 *
229 *      A registered function of this type is called automatically by the wiiuse
230 *      library when the wiimote has returned the full data requested by a previous
231 *      call to wiiuse_read_data().
232 */
233struct wiimote_t;
234typedef void (*wiic_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
235
236/**
237 *      @enum aspect_t
238 *      @brief Screen aspect ratio.
239 */
240typedef enum aspect_t {
241        WIIC_ASPECT_4_3,
242        WIIC_ASPECT_16_9
243} aspect_t;
Note: See TracBrowser for help on using the repository browser.