summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-03 10:17:55 +0900
committerSam Spilsbury <Sam@ACER-SUSE.SUSE>2008-03-03 10:17:55 +0900
commit1702942127e03380977a776488da042b928a046b (patch)
tree77102ec2784b91f2c1f088c911d313e50c4030c8
parentef6f4659e8c491f35ba0233bab04379db48199b4 (diff)
downloadwiimote-1702942127e03380977a776488da042b928a046b.tar.gz
wiimote-1702942127e03380977a776488da042b928a046b.tar.bz2
* Cleanup
-rw-r--r--compiz-wiimote.h115
-rw-r--r--wiimote.c46
2 files changed, 74 insertions, 87 deletions
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index 3bd558e..ab5b8bb 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -33,56 +33,6 @@ COMPIZ_BEGIN_DECLS
#define MAX_REPORTS 16
#define MAX_WIIMOTES 10
-/* Wiimote Button id's */
-
-#define CONF_WM_BTN_UP 0
-#define CONF_WM_BTN_DOWN 1
-#define CONF_WM_BTN_LEFT 2
-#define CONF_WM_BTN_RIGHT 3
-#define CONF_WM_BTN_A 4
-#define CONF_WM_BTN_B 5
-#define CONF_WM_BTN_MINUS 6
-#define CONF_WM_BTN_PLUS 7
-#define CONF_WM_BTN_HOME 8
-#define CONF_WM_BTN_1 9
-#define CONF_WM_BTN_2 10
-
-#define CONF_NC_BTN_C 0
-#define CONF_NC_BTN_Z 1
-
-#define CONF_CC_BTN_UP 0
-#define CONF_CC_BTN_DOWN 1
-#define CONF_CC_BTN_LEFT 2
-#define CONF_CC_BTN_RIGHT 3
-#define CONF_CC_BTN_MINUS 4
-#define CONF_CC_BTN_PLUS 5
-#define CONF_CC_BTN_HOME 6
-#define CONF_CC_BTN_A 7
-#define CONF_CC_BTN_B 8
-#define CONF_CC_BTN_X 9
-#define CONF_CC_BTN_Y 10
-#define CONF_CC_BTN_ZL 11
-#define CONF_CC_BTN_ZR 12
-#define CONF_CC_BTN_L 13
-#define CONF_CC_BTN_R 14
-
-#define CONF_WM_BTN_COUNT 11
-#define CONF_NC_BTN_COUNT 2
-#define CONF_CC_BTN_COUNT 15
-
-#define CONF_WM_AXIS_DPAD_X 0
-#define CONF_WM_AXIS_DPAD_Y 1
-#define CONF_NC_AXIS_STICK_X 2
-#define CONF_NC_AXIS_STICK_Y 3
-#define CONF_CC_AXIS_DPAD_X 4
-#define CONF_CC_AXIS_DPAD_Y 5
-#define CONF_CC_AXIS_L_STICK_X 6
-#define CONF_CC_AXIS_L_STICK_Y 7
-#define CONF_CC_AXIS_R_STICK_X 8
-#define CONF_CC_AXIS_R_STICK_Y 9
-#define CONF_CC_AXIS_L 10
-#define CONF_CC_AXIS_R 11
-
/* Enums */
typedef enum _WiimoteGestureType{
@@ -217,10 +167,6 @@ typedef struct _WiiAcc
/* Used for determining 'angle' */
- float oldAccX;
- float oldAccY;
- float oldAccZ;
-
float accDX;
float accDY;
float accDZ;
@@ -230,10 +176,12 @@ typedef struct _WiiAcc
float initAccX;
float initAccY;
float initAccZ;
-
- float accAngX;
- float accAngY;
- float accAngZ;
+
+ /* Used for gesture checking */
+
+ float oldAccX;
+ float oldAccY;
+ float oldAccZ;
} WiiAcc;
@@ -250,28 +198,54 @@ typedef struct _WiiNunchuck
{
Bool connected;
+ NunchuckButtonState buttons;
+
/* Accellerometer Stuff */
+ /* Absolute Values */
+
float accX;
float accY;
float accZ;
+
+ /* Calibration */
float initAccX;
float initAccY;
float initAccZ;
+ /* Angle Values */
+
float accDX;
float accDY;
float accDZ;
+ /* Used for gesture checking */
+
+ float oldAccX;
+ float oldAccY;
+ float oldAccZ;
+
+ /* Nunchuck Stick */
+ /* Calibration */
+
float initStickX;
float initStickY;
+ /* Absolute values */
+
float stickX;
float stickY;
+ /* Angle values */
+
float stickDX;
float stickDY;
+
+ /* Used for gesture checking */
+
+ float oldStickX;
+ float oldStickY;
} WiiNunchuck;
typedef struct _CompWiimote
@@ -309,24 +283,6 @@ typedef struct _CompWiimote
WiimotePointerType pointerType;
- /* Determine what the Wiimote is allowed to do */
-
- Bool canReport;
- Bool canAccGest;
- Bool canAccNunchuckGest;
- Bool canButtonGest;
-
- /* Action callback handlers */
-
- char *accPluginName;
- char *accActionName;
-
- char *nunchuckPluginName;
- char *nunchuckActionName;
-
- char *irPluginName;
- char *irActionName;
-
/* Positioning Tools */
float irDistance;
@@ -346,6 +302,9 @@ typedef struct _CompWiimote
/* Timeout Handles */
CompTimeoutHandle lightsTimeoutHandle;
+
+ pthread_t connectWiimote; /* Threading Handler */
+
} CompWiimote;
/* Core / Display / Screen structs */
@@ -364,7 +323,7 @@ typedef struct _WiimoteDisplay
Bool isIR[4];
- int count; // Oh, it's just for a nice little thing
+ int count;
CompWiimote cWiimote[MAX_WIIMOTES];
int nWiimote;
@@ -377,8 +336,6 @@ typedef struct _WiimoteDisplay
Bool CallbackSet;
- pthread_t connectWiimote; /* Threading Handler */
-
HandleEventProc handleEvent;
CompTimeoutHandle infoTimeoutHandle;
CompTimeoutHandle checkingTimeoutHandle;
diff --git a/wiimote.c b/wiimote.c
index 28c2e52..93bc480 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -896,10 +896,6 @@ static int findMax (CompDisplay *d, int ir1, int ir2, int ir3, int ir4)
/* Loosely based off wminput */
-static void wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwiid_btn_mesg *mesg)
-{
- WIIMOTE_DISPLAY (d);
-
#define CHECK_BUTTON(a,b,c,e) \
if (mesg->buttons & a) \
{ \
@@ -914,6 +910,11 @@ static void wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwii
b = FALSE; \
} \
+static void
+wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, 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);
@@ -927,6 +928,35 @@ static void wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwii
CHECK_BUTTON( CWIID_BTN_2, ad->cWiimote[wiimoteNumber].buttons.Two, 21, 22);
}
+
+static void
+wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, 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);
+}
+
+#define CHECK_GESTURE (pos, neg, old, value) \
+ if (((old - sens) < new
+
+/*static Bool
+wiimoteCheckForGestures (void *vs)
+{
+ CompScreen *s = (CompScreen *) vs;
+ int i, j;
+
+ WIIMOTE_SCREEN (s);
+ WIIMOTE_DISPLAY (s->display);
+
+ for (i = 0; i < MAX_WIIMOTES; i++)
+ {
+ if (ad->cWiimote[i].connected)
+ {
+ if (*/
+
+
/* 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 */
@@ -1153,7 +1183,7 @@ wiimoteToggle (CompDisplay *d,
compLogMessage (d, "wiimote", CompLogLevelInfo,
"Hold down the 1 and 2 Buttons on your Nintendo Wii Remote now");
// Create the second thread.
- rc = pthread_create(&ad->connectWiimote, &secondThreadAttr, connectWiimote, (void *)d);
+ rc = pthread_create(&ad->cWiimote[ad->nWiimote].connectWiimote, &secondThreadAttr, connectWiimote, (void *)d);
// Clean up second thread's attribute.
pthread_attr_destroy(&secondThreadAttr);
@@ -1191,10 +1221,10 @@ wiimoteDisable (CompDisplay *d,
ad->cWiimote[ad->nWiimote - 1].connected = FALSE;
- rc = pthread_join(ad->connectWiimote, NULL); // Wait for second thread to complete it's operation.
+ rc = pthread_join(ad->cWiimote[ad->nWiimote -1].connectWiimote, NULL); // Wait for second thread to complete it's operation.
if (rc)
compLogMessage (d, "wiimote", CompLogLevelError,
- "Threading error occurred. If this happened after you disconnected a second Wii remote, Ignore this\n");
+ "Threading error occurred.\n");
/* Remove that timeout handle... */
@@ -1205,7 +1235,7 @@ wiimoteDisable (CompDisplay *d,
if (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle)
compRemoveTimeout (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle);
- compLogMessage (d, "wiimote", CompLogLevelError,
+ compLogMessage (d, "wiimote", CompLogLevelInfo,
"Closing connection to most recently connected Wii Remote\n");
if (cwiid_close(ad->cWiimote[ad->nWiimote - 1].wiimote)) {
compLogMessage (d, "wiimote", CompLogLevelError,