aboutsummaryrefslogtreecommitdiff
path: root/misc/cwiid/add_other_plugins_#487498.patch
blob: c9d28963a10d886dcb2fbe5ac3106de5ee35928c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
Index: cwiid-0.6.00+svn184.orig/wminput/plugins/Makefile.in
===================================================================
--- cwiid-0.6.00+svn184.orig.orig/wminput/plugins/Makefile.in	2008-06-24 21:43:05.000000000 +0200
+++ cwiid-0.6.00+svn184.orig/wminput/plugins/Makefile.in	2009-03-27 13:15:50.000000000 +0100
@@ -2,7 +2,7 @@
 
 include @top_builddir@/defs.mak
 
-PLUGINS = ir_ptr acc nunchuk_acc led nunchuk_stick2btn
+PLUGINS = ir_ptr ir_fps acc nunchuk_acc led nunchuk_stick2btn nunchuk_kb
 
 all install clean distclean uninstall: TARGET += $(MAKECMDGOALS)
 
Index: cwiid-0.6.00+svn184.orig/wminput/plugins/ir_fps/Makefile.in
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ cwiid-0.6.00+svn184.orig/wminput/plugins/ir_fps/Makefile.in	2009-03-27 13:15:50.000000000 +0100
@@ -0,0 +1,15 @@
+#Copyright (C) 2007 L. Donnie Smith
+
+include @top_builddir@/defs.mak
+
+PLUGIN_NAME = ir_fps
+SOURCES = ir_fps.c
+CFLAGS += -I@top_builddir@/wminput -I@top_builddir@/libcwiid
+INST_DIR = $(CWIID_PLUGINS_DIR)
+
+include $(COMMON)/include/plugin.mak
+
+distclean: clean
+	rm Makefile
+
+.PHONY: distclean
Index: cwiid-0.6.00+svn184.orig/wminput/plugins/ir_fps/ir_fps.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ cwiid-0.6.00+svn184.orig/wminput/plugins/ir_fps/ir_fps.c	2009-03-27 13:15:50.000000000 +0100
@@ -0,0 +1,162 @@
+/* Copyright (C) 2007 L. Donnie Smith <cwiidabstrakraft.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "wmplugin.h"
+
+#define DEBOUNCE_THRESHOLD	50
+
+//deadzone is a circle of diameter a 10th of the screen
+#define DEADZONE (CWIID_IR_X_MAX*CWIID_IR_X_MAX+CWIID_IR_Y_MAX*CWIID_IR_Y_MAX)/100
+
+//speed is here
+#define XSPEED 10/(CWIID_IR_X_MAX/2)
+#define YSPEED 10/(CWIID_IR_Y_MAX/2)
+
+cwiid_wiimote_t *wiimote;
+
+static struct wmplugin_info info;
+static struct wmplugin_data data;
+
+wmplugin_info_t wmplugin_info;
+wmplugin_init_t wmplugin_init;
+wmplugin_exec_t wmplugin_exec;
+
+struct wmplugin_info *wmplugin_info() {
+	static unsigned char info_init = 0;
+
+	if (!info_init) {
+		info.button_count = 0;
+		info.axis_count = 2;
+		info.axis_info[0].name = "X";
+		info.axis_info[0].type = WMPLUGIN_REL;
+		info.axis_info[0].max  = CWIID_IR_X_MAX;
+		info.axis_info[0].min  = 0;
+		info.axis_info[0].fuzz = 0;
+		info.axis_info[0].flat = 0;
+		info.axis_info[1].name = "Y";
+		info.axis_info[1].type = WMPLUGIN_REL;
+		info.axis_info[1].max  = CWIID_IR_Y_MAX;
+		info.axis_info[1].min  = 0;
+		info.axis_info[1].fuzz = 0;
+		info.axis_info[1].flat = 0;
+		info.param_count = 0;
+		info_init = 1;
+	}
+	return &info;
+}
+
+int wmplugin_init(int id, cwiid_wiimote_t *arg_wiimote)
+{
+	wiimote = arg_wiimote;
+
+	data.buttons = 0;
+
+	if (wmplugin_set_rpt_mode(id, CWIID_RPT_IR)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[])
+{
+	static int src_index = -1;
+	static int debounce = 0;
+	static uint8_t old_flag;
+
+	int i;
+	uint8_t flag;
+	struct cwiid_ir_mesg *ir_mesg;
+	int dx, dy;
+
+	ir_mesg = NULL;
+	for (i=0; i < mesg_count; i++) {
+		if (mesg[i].type == CWIID_MESG_IR) {
+			ir_mesg = &mesg[i].ir_mesg;
+		}
+	}
+
+	if (!ir_mesg) {
+		return NULL;
+	}
+
+	/* invalidate src index if source is no longer present */
+	if ((src_index != -1) && !ir_mesg->src[src_index].valid) {
+		if (debounce > DEBOUNCE_THRESHOLD) {
+			src_index = -1;
+		}
+		else {
+			debounce++;
+		}
+	}
+	else {
+		debounce = 0;
+	}
+
+	/* of not set, pick largest available source */
+	if (src_index == -1) {
+		for (i=0; i < CWIID_IR_SRC_COUNT; i++) {
+			if (ir_mesg->src[i].valid) {
+				if ((src_index == -1) ||
+				  (ir_mesg->src[i].size > ir_mesg->src[src_index].size)) {
+					src_index = i;
+				}
+			}
+		}
+	}
+
+	/* LEDs */
+	switch (src_index) {
+	case 0:
+		flag = CWIID_LED1_ON;
+		break;
+	case 1:
+		flag = CWIID_LED2_ON;
+		break;
+	case 2:
+		flag = CWIID_LED3_ON;
+		break;
+	case 3:
+		flag = CWIID_LED4_ON;
+		break;
+	default:
+		flag = 0;
+		break;
+	}
+	if (flag != old_flag) {
+		cwiid_set_led(wiimote, flag);
+		old_flag = flag;
+	}
+
+	if ((src_index == -1) || !ir_mesg->src[src_index].valid) {
+		data.axes[0].valid = data.axes[1].valid = 0;
+	}
+	else {
+		data.axes[0].valid = data.axes[1].valid = 1;
+		dx = CWIID_IR_X_MAX/2 - ir_mesg->src[src_index].pos[CWIID_X];
+		dy = ir_mesg->src[src_index].pos[CWIID_Y] - CWIID_IR_Y_MAX/2;
+		if (dx*dx+dy*dy > DEADZONE){
+			data.axes[0].value = dx*XSPEED;
+			data.axes[1].value = dy*YSPEED;
+		}else {
+			data.axes[0].value = 0;
+			data.axes[1].value = 0;
+		}
+	}
+	return &data;
+}
Index: cwiid-0.6.00+svn184.orig/wminput/plugins/nunchuk_kb/Makefile.in
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ cwiid-0.6.00+svn184.orig/wminput/plugins/nunchuk_kb/Makefile.in	2009-03-27 13:15:50.000000000 +0100
@@ -0,0 +1,16 @@
+#Copyright (C) 2007 L. Donnie Smith
+
+include @top_builddir@/defs.mak
+
+PLUGIN_NAME = nunchuk_kb
+SOURCES = nunchuk_kb.c
+CFLAGS += -I@top_builddir@/wminput -I@top_builddir@/libcwiid
+LDLIBS += -lm
+INST_DIR = $(CWIID_PLUGINS_DIR)
+
+include $(COMMON)/include/plugin.mak
+
+distclean: clean
+	rm Makefile
+
+.PHONY: distclean
Index: cwiid-0.6.00+svn184.orig/wminput/plugins/nunchuk_kb/nunchuk_kb.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ cwiid-0.6.00+svn184.orig/wminput/plugins/nunchuk_kb/nunchuk_kb.c	2009-03-27 13:15:50.000000000 +0100
@@ -0,0 +1,116 @@
+/* Copyright (C) 2007 L. Donnie Smith <cwiid@abstrakraft.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <math.h>
+
+#include "wmplugin.h"
+
+/* Button flags */
+#define STICK_KEY_UP		0x0001
+#define STICK_KEY_DOWN		0x0002
+#define STICK_KEY_RIGHT		0x0004
+#define STICK_KEY_LEFT		0x0008
+#define STICK_MID_VAL		128
+#define STICK_NEUTRAL		20
+
+static unsigned char info_init = 0;
+static struct wmplugin_info info;
+static struct wmplugin_data data;
+
+static cwiid_wiimote_t *wiimote;
+
+static struct acc_cal acc_cal;
+static int plugin_id;
+
+wmplugin_info_t wmplugin_info;
+wmplugin_init_t wmplugin_init;
+wmplugin_exec_t wmplugin_exec;
+static void process_nunchuk(struct cwiid_nunchuk_mesg *mesg);
+
+static float Roll_Scale = 1.0;
+static float Pitch_Scale = 1.0;
+static float X_Scale = 1.0;
+static float Y_Scale = 1.0;
+
+struct wmplugin_info *wmplugin_info() {
+	if (!info_init) {
+		info.button_count = 4;
+		info.button_info[0].name = "Up";
+		info.button_info[1].name = "Down";
+		info.button_info[2].name = "Right";
+		info.button_info[3].name = "Left";
+		info.axis_count = 0;
+		info_init = 1;
+	}
+	return &info;
+}
+
+int wmplugin_init(int id, cwiid_wiimote_t *arg_wiimote)
+{
+	plugin_id = id;
+	wiimote = arg_wiimote;
+	data.buttons = 0;
+	data.axes[0].valid = 1;
+	data.axes[1].valid = 1;
+	if (wmplugin_set_rpt_mode(id, CWIID_RPT_STATUS | CWIID_RPT_NUNCHUK)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[])
+{
+	int i;
+	enum cwiid_ext_type ext_type = CWIID_EXT_NONE;
+	struct wmplugin_data *ret = NULL;
+
+	for (i=0; i < mesg_count; i++) {
+		switch (mesg[i].type) {
+		case CWIID_MESG_STATUS:
+			if ((mesg[i].status_mesg.ext_type == CWIID_EXT_NUNCHUK) &&
+			  (ext_type != CWIID_EXT_NUNCHUK)) {
+				if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NUNCHUK, &acc_cal)) {
+					wmplugin_err(plugin_id, "calibration error");
+				}
+			}
+			ext_type = mesg[i].status_mesg.ext_type;
+			break;
+		case CWIID_MESG_NUNCHUK:
+			process_nunchuk(&mesg[i].nunchuk_mesg);
+			ret = &data;
+			break;
+		default:
+			break;
+		}
+	}
+
+	return ret;
+}
+
+static void process_nunchuk(struct cwiid_nunchuk_mesg *mesg)
+{
+	double stx=(double)mesg->stick[CWIID_X];
+	double sty=(double)mesg->stick[CWIID_Y];
+	data.buttons=0;
+	if (sty > STICK_MID_VAL+STICK_NEUTRAL) data.buttons |= STICK_KEY_UP;
+	if (sty < STICK_MID_VAL-STICK_NEUTRAL) data.buttons |= STICK_KEY_DOWN;
+	if (stx > STICK_MID_VAL+STICK_NEUTRAL) data.buttons |= STICK_KEY_RIGHT;
+	if (stx < STICK_MID_VAL-STICK_NEUTRAL) data.buttons |= STICK_KEY_LEFT;
+}
+
Index: cwiid-0.6.00+svn184.orig/wminput/configs/fps_config
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ cwiid-0.6.00+svn184.orig/wminput/configs/fps_config	2009-03-27 13:15:50.000000000 +0100
@@ -0,0 +1,32 @@
+# Fps config for wminput by kyrlian
+# needs plugins ir_fps and nunchuk_kb
+# available from http://kyrlian.free.fr/binaries/cwiid/latest/
+# wminput source and info at http://abstrakraft.org/cwiid/
+
+# IR for mouse REL - fps style
+Plugin.ir_fps.X	= REL_X
+Plugin.ir_fps.Y	= REL_Y
+
+#custom buttons
+Wiimote.A               = BTN_LEFT
+Wiimote.B               = BTN_RIGHT
+Wiimote.Up              = KEY_UP
+Wiimote.Down    	= KEY_DOWN
+Wiimote.Left    	= KEY_LEFT
+Wiimote.Right   	= KEY_RIGHT
+Wiimote.Minus  		= KEY_PAGEDOWN
+Wiimote.Plus   		= KEY_PAGEUP
+Wiimote.Home  		= KEY_ESC
+
+Wiimote.1       	= KEY_TAB
+Wiimote.2       	= KEY_ESC
+
+Nunchuk.C               = KEY_C
+Nunchuk.Z               = KEY_SPACE
+
+#plugin for nunchuk stick
+Plugin.nunchuk_kb.Up	= KEY_W
+Plugin.nunchuk_kb.Down	= KEY_S
+Plugin.nunchuk_kb.Left	= KEY_A
+Plugin.nunchuk_kb.Right	= KEY_D
+
Index: cwiid-0.6.00+svn184.orig/configure.ac
===================================================================
--- cwiid-0.6.00+svn184.orig.orig/configure.ac	2008-06-24 21:43:05.000000000 +0200
+++ cwiid-0.6.00+svn184.orig/configure.ac	2009-03-27 13:15:50.000000000 +0100
@@ -142,8 +142,10 @@
 	[wminput/Makefile]
 	[wminput/plugins/Makefile]
 	[wminput/plugins/ir_ptr/Makefile]
+	[wminput/plugins/ir_fps/Makefile]
 	[wminput/plugins/acc/Makefile]
 	[wminput/plugins/nunchuk_acc/Makefile]
+	[wminput/plugins/nunchuk_kb/Makefile]
 	[wminput/plugins/led/Makefile]
  	[wminput/plugins/nunchuk_stick2btn/Makefile]
 	[lswm/Makefile]