aboutsummaryrefslogtreecommitdiff
path: root/wiiremote/aka.wiiremote_b2_pd-port.patch
blob: 3f961128981fa0750fe809808d304d4c87a3d407 (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
--- /Users/hans/Desktop/aka.wiiremote-b2-src/aka.wiiremote.c	2006-12-15 08:36:06.000000000 -0500
+++ aka.wiiremote.c	2006-12-16 17:05:31.000000000 -0500
@@ -1,15 +1,28 @@
 // aka.wiiremote.c
 // Copyright by Masayuki Akamatsu
+// port to Pd by Hans-Christoph Steiner <hans@at.or.at>
 
+
+#ifdef PD
+#include "m_pd.h"
+#define SETLONG SETFLOAT
+static t_class *wiiremote_class;
+#else /* Max */
 #include "ext.h"
+#endif
 #include "wiiremote.h"
 
 #define kInterval	100
 #define	kMaxTrial	100
 
+
 typedef struct _akawiiremote
 {
+#ifdef PD
+	t_object        x_obj;
+#else /* Max */
 	struct object	obj;
+#endif
 	
 	WiiRemoteRef	wiiremote;
 	
@@ -44,6 +57,36 @@
 void *akawiiremote_new(t_symbol *s, short ac, t_atom *av);
 void akawiiremote_free(t_akawiiremote *x);
 
+#ifdef PD
+void wiiremote_setup()
+{
+	wiiremote_class = class_new(gensym("wiiremote"), 
+								 (t_newmethod)akawiiremote_new, 
+								 (t_method)akawiiremote_free,
+								 sizeof(t_akawiiremote),
+								 CLASS_DEFAULT,
+								 A_GIMME,0);
+
+	class_addbang(wiiremote_class,(t_method)akawiiremote_bang);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_connect,gensym("connect"),0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_disconnect,gensym("disconnect"),0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_motionsensor,gensym("motionsensor"), A_DEFFLOAT, 0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("irsensor"), A_DEFFLOAT, 0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_vibration,gensym("vibration"), A_DEFFLOAT, 0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_led,gensym("led"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_getbatterylevel,gensym("getbatterylevel"),0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansionstatus,gensym("getexpansionstatus"),0);
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_getledstatus,gensym("getledstatus"),0);
+	
+	class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0);
+	
+	post("aka.wiiremote 1.0B2-UB by Masayuki Akamatsu");
+	post("\tPd port by Hans-Christoph Steiner");
+	
+	akawiiremote_count = 0;
+}
+#else /* Max */
 void main()
 {
 	setup((t_messlist **)&akawiiremote_class, (method)akawiiremote_new, (method)akawiiremote_free, (short)sizeof(t_akawiiremote), 0L, A_GIMME, 0);
@@ -66,7 +109,7 @@
 	
 	akawiiremote_count = 0;
 }
-
+#endif /* PD */
 //--------------------------------------------------------------------------------------------
 
 void akawiiremote_bang(t_akawiiremote *x)
@@ -76,6 +119,27 @@
 	if (x->wiiremote->device == nil)
 		return;	// do nothing
 	
+#ifdef PD
+	outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData);
+
+	if (x->wiiremote->isIRSensorEnabled)
+	{
+		SETFLOAT(list,     x->wiiremote->posX);
+		SETFLOAT(list + 1, x->wiiremote->posY);
+		SETFLOAT(list + 2, x->wiiremote->angle);
+		SETFLOAT (list + 3, x->wiiremote->tracking);
+		outlet_list(x->irOut, &s_list, 4, list); 
+	}
+
+	if (x->wiiremote->isMotionSensorEnabled)
+	{
+		SETFLOAT(list,     x->wiiremote->accX);
+		SETFLOAT(list + 1, x->wiiremote->accY);
+		SETFLOAT(list + 2, x->wiiremote->accZ);
+		SETFLOAT(list + 3, x->wiiremote->orientation);
+		outlet_list(x->accOut, &s_list, 4, list); 
+	}
+#else /* Max */	
 	outlet_int(x->buttonsOut, x->wiiremote->buttonData);
 
 	if (x->wiiremote->isIRSensorEnabled)
@@ -95,6 +159,7 @@
 		SETLONG(list + 3, x->wiiremote->orientation);
 		outlet_list(x->accOut, 0L, 4, &list); 
 	}
+#endif /* PD */
 	
 	wiiremote_getstatus();
 }
@@ -173,11 +238,19 @@
 {
 	t_atom list[4]; 
 	
+#ifdef PD
+	SETFLOAT(list,     x->wiiremote->isLED1Illuminated);
+	SETFLOAT(list + 1, x->wiiremote->isLED2Illuminated);
+	SETFLOAT(list + 2, x->wiiremote->isLED3Illuminated);
+	SETFLOAT(list + 3, x->wiiremote->isLED4Illuminated);
+	outlet_anything(x->statusOut, gensym("ledstatus"), 4, list);
+#else /* Max */
 	SETLONG(list,     x->wiiremote->isLED1Illuminated);
 	SETLONG(list + 1, x->wiiremote->isLED2Illuminated);
 	SETLONG(list + 2, x->wiiremote->isLED3Illuminated);
 	SETLONG(list + 3, x->wiiremote->isLED4Illuminated);
 	outlet_anything(x->statusOut, gensym("ledstatus"), 4, &list);		
+#endif
 }
 
 //--------------------------------------------------------------------------------------------
@@ -222,11 +295,13 @@
 
 void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s)
 {
+#ifndef PD /* Max */
 	if (m==ASSIST_INLET)
 	{
 		sprintf(s,"connect, bang, disconnect....");
 	}
 	else  
+#endif /* NOT PD */
 	{
 		switch(a)
 		{
@@ -242,6 +317,17 @@
 
 void *akawiiremote_new(t_symbol *s, short ac, t_atom *av)
 {
+#ifdef PD
+	t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class);
+	
+	x->clock = clock_new(x, (t_method)akawiiremote_clock);
+
+	/* create anything outlet used for HID data */ 
+	x->statusOut = outlet_new(&x->x_obj, 0);
+	x->buttonsOut = outlet_new(&x->x_obj, &s_float);
+	x->irOut = outlet_new(&x->x_obj, &s_list);
+	x->accOut = outlet_new(&x->x_obj, &s_list);
+#else /* Max */	
 	t_akawiiremote *x;
 	
 	x = (t_akawiiremote *)newobject(akawiiremote_class);
@@ -249,13 +335,15 @@
 	x->wiiremote = wiiremote_init();
 	
 	x->clock = clock_new(x, (method)akawiiremote_clock);
-	x->trial = 0;
-	x->interval	= kInterval;
 	
 	x->statusOut = outlet_new(x, 0);
 	x->buttonsOut = intout(x);
 	x->irOut = listout(x);
 	x->accOut = listout(x);
+#endif /* PD */
+	x->trial = 0;
+	x->interval	= kInterval;
+	
 
 	akawiiremote_count++;
 	return x;
@@ -267,6 +355,12 @@
 	if (akawiiremote_count == 0)
 		wiiremote_disconnect();
 	
+#ifdef PD
+	if (x->clock)
+		clock_unset(x->clock);
+	clock_free(x->clock);
+#else /* Max */	
 	freeobject(x->clock); 
+#endif
 }
 
--- /Users/hans/Desktop/aka.wiiremote-b2-src/wiiremote.h	2006-12-14 10:21:42.000000000 -0500
+++ wiiremote.h	2006-12-16 16:48:38.000000000 -0500
@@ -2,9 +2,13 @@
 // Copyright by Masayuki Akamatsu
 // Based on "DarwiinRemote" by Hiroaki Kimura
 
+#include <CoreFoundation/CoreFoundation.h>
 #include <IOBluetooth/Bluetooth.h>
 #include <IOBluetooth/IOBluetoothUserLib.h>
 
+#include <stdio.h>
+#include <string.h>
+
 typedef struct {
 	int x, y, s;
 } IRData;
--- /Users/hans/Desktop/aka.wiiremote-b2-src/wiiremote.c	2006-12-15 08:31:05.000000000 -0500
+++ wiiremote.c	2006-12-16 17:12:14.000000000 -0500
@@ -4,6 +4,8 @@
 
 #include "wiiremote.h"
 
+#include <unistd.h>
+
 // this type is used a lot (data array):
 typedef unsigned char darr[];