summaryrefslogtreecommitdiff
path: root/gesture.c
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 20:12:49 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 20:12:49 +0900
commit11c94add14eda814490eb82bb73027dfae98bb6d (patch)
tree81dff153645bc12307a771a76cc52d91a0e4aede /gesture.c
parentad4a2000161d801454163789fa4628156ea30da0 (diff)
downloadwiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.gz
wiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.bz2
* Use dynamically allocated memory, options don't work -- yet
Diffstat (limited to 'gesture.c')
-rw-r--r--gesture.c102
1 files changed, 49 insertions, 53 deletions
diff --git a/gesture.c b/gesture.c
index 0d77778..2f20e08 100644
--- a/gesture.c
+++ b/gesture.c
@@ -27,30 +27,29 @@
if (mesg->buttons & a) \
{ \
if (!b) \
- sendGesture(d, wiimoteNumber, c); \
+ sendGesture(d, wiimote, c); \
b = TRUE; \
} \
else \
{ \
if (b) \
- sendGesture(d, wiimoteNumber, e); \
+ sendGesture(d, wiimote, e); \
b = FALSE; \
} \
-static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
+static Bool sendGesture(CompDisplay *d, CompWiimote *wiimote, int type)
{
+ WIIMOTE_DISPLAY (d);
CompOption argument[2];
int nArgument = 0;
int i;
- WIIMOTE_DISPLAY (d);
-
- if (ad->cWiimote[wiimoteNumber].connected)
+ if (wiimote->connected)
{
- for (i = 0; i < ad->cWiimote[wiimoteNumber].nGesture; i++)
+ for (i = 0; i < wiimote->nGesture; i++)
{
- if (ad->cWiimote[wiimoteNumber].gesture[i].type == type)
+ if (wiimote->gesture[i].type == type) // Need to fix this
{
argument[nArgument].name = "window";
argument[nArgument].type = CompOptionTypeInt;
@@ -63,8 +62,8 @@ static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
nArgument++;
sendInfoToPlugin (d, argument, nArgument,
- ad->cWiimote[wiimoteNumber].gesture[i].pluginName,
- ad->cWiimote[wiimoteNumber].gesture[i].actionName);
+ wiimote->gesture[i].pluginName,
+ wiimote->gesture[i].actionName);
}
}
}
@@ -73,43 +72,40 @@ static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
}
void
-wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwiid_btn_mesg *mesg)
+wiimoteProcessButtons(CompDisplay *d, CompWiimote *wiimote, struct cwiid_btn_mesg *mesg)
{
- WIIMOTE_DISPLAY (d);
- CHECK_BUTTON( CWIID_BTN_A, ad->cWiimote[wiimoteNumber].buttons.A, 1, 2);
- CHECK_BUTTON( CWIID_BTN_B, ad->cWiimote[wiimoteNumber].buttons.B, 3, 4);
- CHECK_BUTTON( CWIID_BTN_UP, ad->cWiimote[wiimoteNumber].buttons.Up, 5, 6);
- CHECK_BUTTON( CWIID_BTN_DOWN, ad->cWiimote[wiimoteNumber].buttons.Down, 7, 8);
- CHECK_BUTTON( CWIID_BTN_LEFT, ad->cWiimote[wiimoteNumber].buttons.Left, 9, 10);
- CHECK_BUTTON( CWIID_BTN_RIGHT, ad->cWiimote[wiimoteNumber].buttons.Right, 11, 12);
- CHECK_BUTTON( CWIID_BTN_PLUS, ad->cWiimote[wiimoteNumber].buttons.Plus, 13, 14);
- CHECK_BUTTON( CWIID_BTN_MINUS, ad->cWiimote[wiimoteNumber].buttons.Minus, 15, 16);
- CHECK_BUTTON( CWIID_BTN_HOME, ad->cWiimote[wiimoteNumber].buttons.Home, 17, 18);
- CHECK_BUTTON( CWIID_BTN_1, ad->cWiimote[wiimoteNumber].buttons.One, 19, 20);
- CHECK_BUTTON( CWIID_BTN_2, ad->cWiimote[wiimoteNumber].buttons.Two, 21, 22);
+ CHECK_BUTTON( CWIID_BTN_A, wiimote->buttons.A, 1, 2);
+ CHECK_BUTTON( CWIID_BTN_B, wiimote->buttons.B, 3, 4);
+ CHECK_BUTTON( CWIID_BTN_UP, wiimote->buttons.Up, 5, 6);
+ CHECK_BUTTON( CWIID_BTN_DOWN, wiimote->buttons.Down, 7, 8);
+ CHECK_BUTTON( CWIID_BTN_LEFT, wiimote->buttons.Left, 9, 10);
+ CHECK_BUTTON( CWIID_BTN_RIGHT, wiimote->buttons.Right, 11, 12);
+ CHECK_BUTTON( CWIID_BTN_PLUS, wiimote->buttons.Plus, 13, 14);
+ CHECK_BUTTON( CWIID_BTN_MINUS, wiimote->buttons.Minus, 15, 16);
+ CHECK_BUTTON( CWIID_BTN_HOME, wiimote->buttons.Home, 17, 18);
+ CHECK_BUTTON( CWIID_BTN_1, wiimote->buttons.One, 19, 20);
+ CHECK_BUTTON( CWIID_BTN_2, wiimote->buttons.Two, 21, 22);
}
void
-wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, struct cwiid_nunchuk_mesg *mesg)
+wiimoteProcessNunchuckButtons (CompDisplay *d, CompWiimote *wiimote, struct cwiid_nunchuk_mesg *mesg)
{
- WIIMOTE_DISPLAY (d);
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_C, ad->cWiimote[wiimoteNumber].nunchuck.buttons.C, 23, 24);
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, ad->cWiimote[wiimoteNumber].nunchuck.buttons.Z, 25, 26);
+ CHECK_BUTTON ( CWIID_NUNCHUK_BTN_C, wiimote->nunchuck.buttons.C, 23, 24);
+ CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, wiimote->nunchuck.buttons.Z, 25, 26);
}
/* I would rather use #define, but it's bugged up, so I have to compromise */
static void
-wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, float *old, float value, int posGest, int negGest)
+wiimoteCheckGesture (CompScreen *s, CompWiimote *wiimote, float diff, float init, float *old, float value, int posGest, int negGest)
{
-
if (*old <= value - diff && value <= init)
- sendGesture (s->display, wiimoteNumber, negGest);
+ sendGesture (s->display, wiimote, negGest);
if (*old >= value + diff && value >= init)
- sendGesture (s->display, wiimoteNumber, posGest);
+ sendGesture (s->display, wiimote, posGest);
*old = value;
}
@@ -117,39 +113,39 @@ wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, f
Bool wiimoteCheckForGestures (void *vs)
{
CompScreen *s = (CompScreen *) vs;
- int i;
+ CompWiimote *wiimote;
float sens = wiimoteGetGestureSens (s->display);
WIIMOTE_DISPLAY (s->display);
- for (i = 0; i < MAX_WIIMOTES; i++)
+ for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next)
{
- if (ad->cWiimote[i].connected)
+ if (wiimote->connected)
{
/* Check Accellerometer */
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccY,
- &ad->cWiimote[i].acc.oldAccY,
- ad->cWiimote[i].acc.accY, 27, 28);
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccX,
- &ad->cWiimote[i].acc.oldAccX,
- ad->cWiimote[i].acc.accX, 29, 30);
+ wiimoteCheckGesture (s, wiimote, sens, wiimote->acc.initAccY,
+ &wiimote->acc.oldAccY,
+ wiimote->acc.accY, 27, 28);
+ wiimoteCheckGesture (s, wiimote, sens, wiimote->acc.initAccX,
+ &wiimote->acc.oldAccX,
+ wiimote->acc.accX, 29, 30);
/* Check Nunchuk */
- if (ad->cWiimote[i].nunchuck.connected)
+ if (wiimote->nunchuck.connected)
{
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccY,
- &ad->cWiimote[i].nunchuck.oldAccY,
- ad->cWiimote[i].nunchuck.accY, 31, 32 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccX,
- &ad->cWiimote[i].nunchuck.oldAccX,
- ad->cWiimote[i].nunchuck.accX, 33, 34 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickY,
- &ad->cWiimote[i].nunchuck.oldStickY,
- ad->cWiimote[i].nunchuck.stickY, 35, 36 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickX,
- &ad->cWiimote[i].nunchuck.oldStickX,
- ad->cWiimote[i].nunchuck.stickX, 37, 38 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initAccY,
+ &wiimote->nunchuck.oldAccY,
+ wiimote->nunchuck.accY, 31, 32 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initAccX,
+ &wiimote->nunchuck.oldAccX,
+ wiimote->nunchuck.accX, 33, 34 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initStickY,
+ &wiimote->nunchuck.oldStickY,
+ wiimote->nunchuck.stickY, 35, 36 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initStickX,
+ &wiimote->nunchuck.oldStickX,
+ wiimote->nunchuck.stickX, 37, 38 );
}
}
}