summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-06 23:41:59 +0900
committerSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-06 23:41:59 +0900
commit94b22cea308526656d300d3511f531f816364c73 (patch)
tree3b2efa698c2a969d884c46322bfdf23f7af3360b
parent0a44d5cdb5b1412345fe90782a67524c7b7d1abf (diff)
downloadwiimote-94b22cea308526656d300d3511f531f816364c73.tar.gz
wiimote-94b22cea308526656d300d3511f531f816364c73.tar.bz2
* Add system to prevent 'neutral movements' from calling gestures
-rw-r--r--wiimote.c95
1 files changed, 50 insertions, 45 deletions
diff --git a/wiimote.c b/wiimote.c
index 29f6f8f..6481cef 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -18,10 +18,7 @@
* are and what you did.
*
* TODO:
- * - Button Support
- * - Nunchuck Support
- * - Gesture Support
- * - Wiimote Modes
+ * - Gesture timeout
*/
#include <stdio.h>
#include <stdlib.h>
@@ -871,38 +868,6 @@ static Bool sendReports(void *vs)
}
-static int findMin (CompDisplay *d, int ir1, int ir2, int ir3, int ir4)
-{
- WIIMOTE_DISPLAY (d);
-
- int min = ir1;
-
- if ((ir2 < min) && ad->isIR[1])
- min = ir2;
- if ((ir3 < min) && ad->isIR[2])
- min = ir3;
- if ((ir4 < min) && ad->isIR[3])
- min = ir4;
-
- return min;
-}
-
-static int findMax (CompDisplay *d, int ir1, int ir2, int ir3, int ir4)
-{
- WIIMOTE_DISPLAY (d);
-
- int max = ir1;
-
- if ((ir2 > max) && ad->isIR[1])
- max = ir2;
- if ((ir3 > max) && ad->isIR[2])
- max = ir3;
- if ((ir4 > max) && ad->isIR[3])
- max = ir4;
-
- return max;
-}
-
/* Loosely based off wminput */
#define CHECK_BUTTON(a,b,c,e) \
@@ -950,11 +915,12 @@ wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, struct cwiid_n
/* 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 *old, float value, int posGest, int negGest)
+wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, float *old, float value, int posGest, int negGest)
{
- if (*old <= value - diff)
+
+ if (*old <= value - diff && value <= init)
sendGesture (s->display, wiimoteNumber, negGest);
- if (*old >= value + diff)
+ if (*old >= value + diff && value >= init)
sendGesture (s->display, wiimoteNumber, posGest);
*old = value;
@@ -975,21 +941,27 @@ wiimoteCheckForGestures (void *vs)
{
/* Check Accellerometer */
- wiimoteCheckGesture (s, i, sens, &ad->cWiimote[i].acc.oldAccY,
+ 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.oldAccX,
+ wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccX,
+ &ad->cWiimote[i].acc.oldAccX,
ad->cWiimote[i].acc.accX, 29, 30);
/* Check Nunchuk */
if (ad->cWiimote[i].nunchuck.connected)
{
- wiimoteCheckGesture ( s, i, sens, &ad->cWiimote[i].nunchuck.oldAccY,
+ 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.oldAccX,
+ 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.oldStickY,
+ 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.oldStickX,
+ wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickX,
+ &ad->cWiimote[i].nunchuck.oldStickX,
ad->cWiimote[i].nunchuck.stickX, 37, 38 );
}
}
@@ -998,6 +970,39 @@ wiimoteCheckForGestures (void *vs)
}
+/* Utility */
+static int findMin (CompDisplay *d, int ir1, int ir2, int ir3, int ir4)
+{
+ WIIMOTE_DISPLAY (d);
+
+ int min = ir1;
+
+ if ((ir2 < min) && ad->isIR[1])
+ min = ir2;
+ if ((ir3 < min) && ad->isIR[2])
+ min = ir3;
+ if ((ir4 < min) && ad->isIR[3])
+ min = ir4;
+
+ return min;
+}
+
+static int findMax (CompDisplay *d, int ir1, int ir2, int ir3, int ir4)
+{
+ WIIMOTE_DISPLAY (d);
+
+ int max = ir1;
+
+ if ((ir2 > max) && ad->isIR[1])
+ max = ir2;
+ if ((ir3 > max) && ad->isIR[2])
+ max = ir3;
+ if ((ir4 > max) && ad->isIR[3])
+ max = ir4;
+
+ return max;
+}
+
/* Prototype cwiid_callback with cwiid_callback_t, define it with the actual
* type - this will cause a compile error (rather than some undefined bizarre
* behavior) if cwiid_callback_t changes */