File nunchuk_stick.patch of Package cwiid

Index: wminput/plugins/nunchuk_acc/nunchuk_acc.c
===================================================================
--- wminput/plugins/nunchuk_acc/nunchuk_acc.c.orig
+++ wminput/plugins/nunchuk_acc/nunchuk_acc.c
@@ -21,6 +21,11 @@
 #include "wmplugin.h"
 
 #define PI	3.14159265358979323
+#define FLIP_UP		0x0001
+#define FLIP_DOWN	0x0002
+#define TWIST_RIGHT	0x0004
+#define TWIST_LEFT	0x0008
+
 
 static unsigned char info_init = 0;
 static struct wmplugin_info info;
@@ -40,11 +45,19 @@ static float Roll_Scale = 1.0;
 static float Pitch_Scale = 1.0;
 static float X_Scale = 1.0;
 static float Y_Scale = 1.0;
+static float StickX_Scale = 1.0;
+static float StickY_Scale = 1.0;
+static float Flip_Threshold = 1.0;
+static float Twist_Threshold= 1.0;
 
 struct wmplugin_info *wmplugin_info() {
 	if (!info_init) {
-		info.button_count = 0;
-		info.axis_count = 4;
+		info.button_count = 4;
+		info.button_info[0].name = "FlipUp";
+		info.button_info[1].name = "FlipDown";
+		info.button_info[2].name = "TwistLeft";
+		info.button_info[3].name = "TwistRight";
+		info.axis_count = 6;
 		info.axis_info[0].name = "Roll";
 		info.axis_info[0].type = WMPLUGIN_ABS;
 		info.axis_info[0].max  =  3141;
@@ -69,7 +82,20 @@ struct wmplugin_info *wmplugin_info() {
 		info.axis_info[3].min  = -16;
 		info.axis_info[3].fuzz = 0;
 		info.axis_info[3].flat = 0;
-		info.param_count = 4;
+		info.axis_info[4].name = "StickX";
+		info.axis_info[4].type = WMPLUGIN_ABS | WMPLUGIN_REL;
+		info.axis_info[4].max  =  16;
+		info.axis_info[4].min  = -16;
+		info.axis_info[4].fuzz = 0;
+		info.axis_info[4].flat = 0;
+		info.axis_info[5].name = "StickY";
+		info.axis_info[5].type = WMPLUGIN_ABS | WMPLUGIN_REL;
+		info.axis_info[5].max  =  16;
+		info.axis_info[5].min  = -16;
+		info.axis_info[5].fuzz = 0;
+		info.axis_info[5].flat = 0;
+
+		info.param_count = 8;
 		info.param_info[0].name = "Roll_Scale";
 		info.param_info[0].type = WMPLUGIN_PARAM_FLOAT;
 		info.param_info[0].ptr = &Roll_Scale;
@@ -82,6 +108,18 @@ struct wmplugin_info *wmplugin_info() {
 		info.param_info[3].name = "Y_Scale";
 		info.param_info[3].type = WMPLUGIN_PARAM_FLOAT;
 		info.param_info[3].ptr = &Y_Scale;
+		info.param_info[4].name = "StickX_Scale";
+		info.param_info[4].type = WMPLUGIN_PARAM_FLOAT;
+		info.param_info[4].ptr = &StickX_Scale;
+		info.param_info[5].name = "StickY_Scale";
+		info.param_info[5].type = WMPLUGIN_PARAM_FLOAT;
+		info.param_info[5].ptr = &StickY_Scale;
+		info.param_info[6].name = "Flip_Threshold";
+		info.param_info[6].type = WMPLUGIN_PARAM_FLOAT;
+		info.param_info[6].ptr = &Flip_Threshold;
+		info.param_info[7].name = "Twist_Threshold";
+		info.param_info[7].type = WMPLUGIN_PARAM_FLOAT;
+		info.param_info[7].ptr = &Twist_Threshold;
 		info_init = 1;
 	}
 	return &info;
@@ -139,6 +177,15 @@ static void process_nunchuk(struct cwiid
 	double a;
 	double roll, pitch;
 
+	if( mesg->stick[0] ) {
+		data.axes[4].valid=1;
+		data.axes[4].value=(mesg->stick[0]-128)/10;
+	}
+	if( mesg->stick[1] ) {
+		data.axes[5].valid=1;
+		data.axes[5].value=(mesg->stick[1]-128)/10;
+	}
+
 	a_x = (((double)mesg->acc[CWIID_X] - acc_cal.zero[CWIID_X]) /
 	      (acc_cal.one[CWIID_X] - acc_cal.zero[CWIID_X]))*NEW_AMOUNT +
 	      a_x*OLD_AMOUNT;
@@ -160,6 +207,20 @@ static void process_nunchuk(struct cwiid
 	data.axes[0].value = roll  * 1000 * Roll_Scale;
 	data.axes[1].value = pitch * 1000 * Pitch_Scale;
 
+	data.buttons=0;
+	if ( roll > Twist_Threshold ) {
+		data.buttons |= TWIST_LEFT;
+	}
+	if ( roll < -Twist_Threshold ) {
+		data.buttons |= TWIST_RIGHT;
+	}
+	if ( pitch > Flip_Threshold ) {
+		data.buttons |= FLIP_DOWN;
+	}
+	if ( pitch < -Flip_Threshold ) {
+		data.buttons |= FLIP_UP;
+	}
+
 	if ((a > 0.85) && (a < 1.15)) {
 		if ((fabs(roll)*(180/PI) > 10) && (fabs(pitch)*(180/PI) < 80)) {
 			data.axes[2].valid = 1;
openSUSE Build Service is sponsored by