summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-03 23:04:25 +0900
committerSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-03 23:04:25 +0900
commit2350e71f42893344bd3d74c73755b4808d488818 (patch)
tree0530b25d6c57976f1f1456162947f9df18ef6048
parent870b3c403d94aa710aefd9d3c781e82c8eaa6f75 (diff)
downloadwiimote-2350e71f42893344bd3d74c73755b4808d488818.tar.gz
wiimote-2350e71f42893344bd3d74c73755b4808d488818.tar.bz2
* Actual movement gesture support now working
-rw-r--r--compiz-wiimote.h1
-rw-r--r--wiimote.c60
-rw-r--r--wiimote.xml.in16
3 files changed, 61 insertions, 16 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index ab5b8bb..80f4962 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -338,6 +338,7 @@ typedef struct _WiimoteDisplay
HandleEventProc handleEvent;
CompTimeoutHandle infoTimeoutHandle;
+ CompTimeoutHandle gestureTimeoutHandle;
CompTimeoutHandle checkingTimeoutHandle;
} WiimoteDisplay;
diff --git a/wiimote.c b/wiimote.c
index ddc5a62..6b083d0 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -805,18 +805,18 @@ static Bool sendReports(void *vs)
report[2] = ad->cWiimote[i].irDistance;
break;
case WiimoteReportTypeAccellerometer:
- report[0] = (float) ( (int) (ad->cWiimote[i].acc.accDX / sens) * sens);
- report[1] = (float) ( (int) (ad->cWiimote[i].acc.accDY / sens) * sens);
- report[2] = (float) ( (int) (ad->cWiimote[i].acc.accDZ / sens) * sens);
+ report[0] = (float) ( (int) (ad->cWiimote[i].acc.accDX / sens));
+ report[1] = (float) ( (int) (ad->cWiimote[i].acc.accDY / sens));
+ report[2] = (float) ( (int) (ad->cWiimote[i].acc.accDZ / sens));
break;
case WiimoteReportTypeNunchuckAccellerometer:
- report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDX / sens) * sens);
- report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDY / sens) * sens);
- report[2] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDZ / sens) * sens);
+ report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDX / sens));
+ report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDY / sens));
+ report[2] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDZ / sens));
break;
case WiimoteReportTypeNunchuckStick:
- report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDX / sens) * sens);
- report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDY / sens) * sens);
+ report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDX / sens));
+ report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDY / sens));
report[2] = 0.0f;
break;
}
@@ -938,23 +938,51 @@ wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, struct cwiid_n
CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, ad->cWiimote[wiimoteNumber].nunchuck.buttons.Z, 25, 26);
}
-#define CHECK_GESTURE (pos, neg, old, value) \
- if (((old - sens) < new
+/* I would rather use #define, but it's bugged up, so I have to compromise */
-/*static Bool
+static void
+wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float *old, float value, int posGest, int negGest)
+{
+ if (*old <= value - diff)
+ sendGesture (s->display, wiimoteNumber, negGest);
+ if (*old >= value + diff)
+ sendGesture (s->display, wiimoteNumber, posGest);
+
+ *old = value;
+}
+
+static Bool
wiimoteCheckForGestures (void *vs)
{
CompScreen *s = (CompScreen *) vs;
- int i, j;
+ int i;
+ float sens = wiimoteGetGestureSens (s->display);
- WIIMOTE_SCREEN (s);
WIIMOTE_DISPLAY (s->display);
for (i = 0; i < MAX_WIIMOTES; i++)
{
if (ad->cWiimote[i].connected)
{
- if (*/
+ /* Check Accellerometer */
+
+ wiimoteCheckGesture (s, i, sens, &ad->cWiimote[i].acc.oldAccY,
+ ad->cWiimote[i].acc.accY, 27, 28);
+ wiimoteCheckGesture (s, i, sens, &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,
+ ad->cWiimote[i].nunchuck.accY, 31, 32 );
+ wiimoteCheckGesture ( s, i, sens, &ad->cWiimote[i].nunchuck.oldAccX,
+ ad->cWiimote[i].nunchuck.accX, 33, 34 );
+ }
+ }
+ }
+ return TRUE;
+}
/* Prototype cwiid_callback with cwiid_callback_t, define it with the actual
@@ -1231,6 +1259,9 @@ wiimoteDisable (CompDisplay *d,
if (ad->infoTimeoutHandle)
compRemoveTimeout (ad->infoTimeoutHandle);
+
+ if (ad->gestureTimeoutHandle)
+ compRemoveTimeout (ad->gestureTimeoutHandle);
/* Remove the lights timeout handle */
@@ -1288,6 +1319,7 @@ wiimoteSendInfo (CompDisplay *d,
*/
ad->infoTimeoutHandle = compAddTimeout(wiimoteGetPollInterval (s->display) , sendReports, s);
+ ad->gestureTimeoutHandle = compAddTimeout(wiimoteGetGestureTimeout (s->display) , wiimoteCheckForGestures, s);
}
return TRUE;
}
diff --git a/wiimote.xml.in b/wiimote.xml.in
index bb13ccd..1892fdb 100644
--- a/wiimote.xml.in
+++ b/wiimote.xml.in
@@ -26,10 +26,22 @@
<group>
<_short>Wiimote Setup</_short>
<option name="poll_interval" type="int">
- <_short>How often to call the reporting action</_short>
- <_long>The more often you call it, the higher the CPU usage will be, so be careful with this!</_long>
+ <_short>Reporting Timeout</_short>
+ <_long>The more often you call it, the higher the CPU usage will be, so be careful with this! The less you call it however, means the jerkier the reporting</_long>
<default>25</default>
</option>
+ <option name="gesture_timeout" type="int">
+ <_short>Gesture Timeout</_short>
+ <_long>The more often you call it, the higher the CPU usage will be and the faster you have to move</_long>
+ <default>25</default>
+ </option>
+ <option name="gesture_sens" type="float">
+ <_short>Gesture Sensitvity</_short>
+ <_long>How much the readings must differ between gesture checks</_long>
+ <min>0.1</min>
+ <max>50.0</max>
+ <default>10.0</default>
+ </option>
<subgroup>
<_short>Individual Setup</_short>
<option name="x_calibration_mul" type="list">