Debian Codegraph @

debian/patches/python3-build-azzra

raw
1 Index: cwiid/python/Wiimote.c
2 ===================================================================
3 --- cwiid.orig/python/Wiimote.c
4 +++ cwiid/python/Wiimote.c
5 @@ -1,5 +1,5 @@
6 /*
7 - * Copyright (C) 2007 Justin M. Tulloss <[email protected]>
8 + * Copyright (C) 2007 Justin M. Tulloss <[email protected]>, L. Donnie Smith <[email protected]>
9 *
10 * Interface from Python to libcwiid
11 *
12 @@ -18,96 +18,54 @@
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
14 * Boston, MA 02110-1301 USA
15 *
16 - * ChangeLog:
17 - * 2008-01-19 L. Donnie Smith <[email protected]>
18 - * * print callback error tracebacks
19 - *
20 - * 2007-06-18 L. Donnie Smith <[email protected]>
21 - * * revised error messages and doc strings
22 - *
23 - * 2007-06-05 L. Donnie Smith <[email protected]>
24 - * * removed Wiimote_FromC function
25 - * * added bdaddr argument to Wiimote.init
26 - * * overloaded Wiimote.init to accept CObject (existing wiimote),
27 - * and logic to avoid closing it on dealloc
28 - *
29 - * 2007-06-01 L. Donnie Smith <[email protected]>
30 - * * added Wiimote_FromC
31 - * * added get_acc_cal
32 - *
33 - * 2007-05-27 Arthur Peters <[email protected]>
34 - * * removed set_mesg_callback from methods table
35 - *
36 - * 2007-05-22 L. Donnie Smith <[email protected]>
37 - * * changed disconnect to close
38 - * * replaced command with attributes for rpt_mode, rumble, led,
39 - * added request_status method
40 - * * fixed memory leak in get_mesg
41 - * * added function names to argument parsing errors
42 - * * changed to processMesg to ConvertMesgArray with global visibility
43 - *
44 - * 2007-05-15 L. Donnie Smith <[email protected]>
45 - * * revised message types
46 - * * revised argument/keylist parsing
47 - *
48 - * 2007-05-14 L. Donnie Smith <[email protected]>
49 - * * moved Wiimote class to separate file
50 */
51
52 #include "Python.h"
53 #include "structmember.h"
54 #include <errno.h>
55 #include <bluetooth/bluetooth.h>
56 -#include "cwiid.h"
57 -
58 -#if (PY_VERSION_HEX < 0x02050000)
59 - #ifndef PY_SSIZE_T_MIN
60 - typedef int Py_ssize_t;
61 - #define PY_SSIZE_T_MAX INT_MAX
62 - #define PY_SSIZE_T_MIN INT_MIN
63 - #endif
64 -#endif
65 +#include <cwiid.h>
66
67 typedef struct {
68 PyObject_HEAD
69 cwiid_wiimote_t *wiimote;
70 - PyVarObject *callback;
71 + PyObject *callback;
72 char close_on_dealloc;
73 } Wiimote;
74
75 /* method prototypes */
76 -static PyVarObject *
77 - Wiimote_new(PyTypeObject *type, PyVarObject *args, PyVarObject *kwds);
78 +static PyObject *
79 + Wiimote_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
80 static void Wiimote_dealloc(Wiimote *self);
81 -static int Wiimote_init(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
82 -static PyVarObject *Wiimote_close(Wiimote *self);
83 +static int Wiimote_init(Wiimote *self, PyObject *args, PyObject *kwds);
84 +static PyObject *Wiimote_close(Wiimote *self);
85
86 -static PyVarObject *Wiimote_enable(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
87 -static PyVarObject *
88 - Wiimote_disable(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
89 +static PyObject *Wiimote_enable(Wiimote *self, PyObject *args, PyObject *kwds);
90 +static PyObject *
91 + Wiimote_disable(Wiimote *self, PyObject *args, PyObject *kwds);
92
93 static int
94 - Wiimote_set_mesg_callback(Wiimote *self, PyVarObject *args, void *closure);
95 -static PyVarObject *Wiimote_get_mesg(Wiimote *self);
96 -static PyVarObject *Wiimote_get_state(Wiimote *self, void *closure);
97 -static PyVarObject *Wiimote_get_acc_cal(Wiimote *self, PyVarObject *args,
98 - PyVarObject *kwds);
99 -static PyVarObject *Wiimote_get_balance_cal(Wiimote *self);
100 + Wiimote_set_mesg_callback(Wiimote *self, PyObject *args, void *closure);
101 +static PyObject *Wiimote_get_mesg(Wiimote *self);
102 +static PyObject *Wiimote_get_state(Wiimote *self, void *closure);
103 +static PyObject *Wiimote_get_acc_cal(Wiimote *self, PyObject *args,
104 + PyObject *kwds);
105 +static PyObject *Wiimote_get_balance_cal(Wiimote *self);
106
107 -static PyVarObject *Wiimote_request_status(Wiimote *self);
108 -static int Wiimote_set_led(Wiimote *self, PyVarObject *PyLed, void *closure);
109 +static PyObject *Wiimote_request_status(Wiimote *self);
110 +static int Wiimote_set_led(Wiimote *self, PyObject *PyLed, void *closure);
111 static int
112 - Wiimote_set_rumble(Wiimote *self, PyVarObject *PyRumble, void *closure);
113 + Wiimote_set_rumble(Wiimote *self, PyObject *PyRumble, void *closure);
114 static int
115 - Wiimote_set_rpt_mode(Wiimote *self, PyVarObject *PyRptMode, void *closure);
116 + Wiimote_set_rpt_mode(Wiimote *self, PyObject *PyRptMode, void *closure);
117
118 -static PyVarObject *Wiimote_send_rpt(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
119 -static PyVarObject *Wiimote_read(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
120 -static PyVarObject *Wiimote_write(Wiimote *self, PyVarObject *args, PyVarObject *kwds);
121 +static PyObject *Wiimote_send_rpt(Wiimote *self, PyObject *args, PyObject *kwds);
122 +static PyObject *Wiimote_read(Wiimote *self, PyObject *args, PyObject *kwds);
123 +static PyObject *Wiimote_write(Wiimote *self, PyObject *args, PyObject *kwds);
124
125 /* helper prototypes */
126 static cwiid_mesg_callback_t CallbackBridge;
127 -PyVarObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]);
128 +PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]);
129
130 static PyMethodDef Wiimote_Methods[] =
131 {
132 @@ -149,12 +107,11 @@ static PyGetSetDef Wiimote_GetSet[] = {
133 };
134
135 PyTypeObject Wiimote_Type = {
136 - PyObject_HEAD_INIT(NULL)
137 - 0, /* ob_size */
138 - "cwiid.Wiimote", /* tp_name */
139 - sizeof(Wiimote), /* tp_basicsize */
140 + PyVarObject_HEAD_INIT(NULL, 0)
141 + "cwiid.Wiimote", /* tp_name */
142 + sizeof(Wiimote), /* tp_basicsize */
143 0, /* tp_itemsize */
144 - (destructor)Wiimote_dealloc, /* tp_dealloc */
145 + (destructor)Wiimote_dealloc, /* tp_dealloc */
146 0, /* tp_print */
147 0, /* tp_getattr */
148 0, /* tp_setattr */
149 @@ -170,29 +127,29 @@ PyTypeObject Wiimote_Type = {
150 0, /* tp_setattro */
151 0, /* tp_as_buffer */
152 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
153 - "CWiid Wiimote connection object", /* tp_doc */
154 + "CWiid Wiimote connection object", /* tp_doc */
155 0, /* tp_traverse */
156 0, /* tp_clear */
157 0, /* tp_richcompare */
158 0, /* tp_weaklistoffset */
159 0, /* tp_iter */
160 0, /* tp_iternext */
161 - Wiimote_Methods, /* tp_methods */
162 + Wiimote_Methods, /* tp_methods */
163 0, /* tp_members */
164 - Wiimote_GetSet, /* tp_getset */
165 + Wiimote_GetSet, /* tp_getset */
166 0, /* tp_base */
167 0, /* tp_dict */
168 0, /* tp_descr_get */
169 0, /* tp_descr_set */
170 0, /* tp_dictoffset */
171 - (initproc)Wiimote_init, /* tp_init */
172 + (initproc)Wiimote_init, /* tp_init */
173 0, /* tp_alloc */
174 - Wiimote_new, /* tp_new */
175 + Wiimote_new, /* tp_new */
176 };
177
178 /* Allocate and deallocate functions */
179 -static PyVarObject *
180 - Wiimote_new(PyTypeObject *type, PyVarObject *args, PyVarObject *kwds)
181 +static PyObject *
182 + Wiimote_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
183 {
184 Wiimote* self;
185
186 @@ -201,10 +158,9 @@ static PyVarObject *
187 }
188
189 self->wiimote = NULL;
190 - Py_INCREF(self->callback = Py_None);
191 self->close_on_dealloc = 0;
192
193 - return (PyVarObject*) self;
194 + return (PyObject*) self;
195 }
196
197 static void Wiimote_dealloc(Wiimote *self)
198 @@ -213,13 +169,14 @@ static void Wiimote_dealloc(Wiimote *sel
199 cwiid_close(self->wiimote);
200 }
201 Py_XDECREF(self->callback);
202 - Py_TYPE(self)->tp_free((PyVarObject *)self);
203 + //self->ob_type->tp_free((PyObject *)self);
204 + Py_TYPE(self)->tp_free((PyObject *)self);
205 }
206
207 -static int Wiimote_init(Wiimote* self, PyVarObject* args, PyVarObject *kwds)
208 +static int Wiimote_init(Wiimote* self, PyObject* args, PyObject *kwds)
209 {
210 static char *kwlist[] = {"bdaddr", "flags", NULL};
211 - PyVarObject *PyObj;
212 + PyObject *PyObj;
213 cwiid_wiimote_t *wiimote = NULL;
214 char *str_bdaddr = NULL;
215 bdaddr_t bdaddr;
216 @@ -229,8 +186,8 @@ static int Wiimote_init(Wiimote* self, P
217 * an existing CObject. Otherwise, create a new one */
218 if (PyTuple_Size(args) == 1) {
219 PyObj = PyTuple_GET_ITEM(args, 0);
220 - if (PyCObject_Check(PyObj)) {
221 - wiimote = PyCObject_AsVoidPtr(PyObj);
222 + if (PyCapsule_CheckExact(PyObj)) {
223 + wiimote = PyCapsule_GetPointer(PyObj, "dynamr");
224 self->close_on_dealloc = 0;
225 }
226 }
227 @@ -251,6 +208,10 @@ static int Wiimote_init(Wiimote* self, P
228 bdaddr = *BDADDR_ANY;
229 }
230
231 + if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 5) {
232 + PyEval_InitThreads();
233 + }
234 +
235 Py_BEGIN_ALLOW_THREADS
236 wiimote = cwiid_open(&bdaddr, flags);
237 Py_END_ALLOW_THREADS
238 @@ -265,13 +226,14 @@ static int Wiimote_init(Wiimote* self, P
239 }
240
241 cwiid_set_data(wiimote, self);
242 + Py_INCREF(self->callback = Py_None);
243 self->wiimote = wiimote;
244 return 0;
245 }
246
247 #define SET_CLOSED_ERROR PyErr_SetString(PyExc_ValueError, "Wiimote is closed")
248
249 -static PyVarObject *Wiimote_close(Wiimote *self)
250 +static PyObject *Wiimote_close(Wiimote *self)
251 {
252 if (!self->wiimote) {
253 SET_CLOSED_ERROR;
254 @@ -289,7 +251,7 @@ static PyVarObject *Wiimote_close(Wiimot
255 Py_RETURN_NONE;
256 }
257
258 -static PyVarObject *Wiimote_enable(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
259 +static PyObject *Wiimote_enable(Wiimote *self, PyObject *args, PyObject *kwds)
260 {
261 static char *kwlist[] = {"flags", NULL};
262 int flags;
263 @@ -312,7 +274,7 @@ static PyVarObject *Wiimote_enable(Wiimo
264 Py_RETURN_NONE;
265 }
266
267 -static PyVarObject *Wiimote_disable(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
268 +static PyObject *Wiimote_disable(Wiimote *self, PyObject *args, PyObject *kwds)
269 {
270 static char *kwlist[] = {"flags", NULL};
271 int flags;
272 @@ -336,10 +298,10 @@ static PyVarObject *Wiimote_disable(Wiim
273 }
274
275 static int
276 - Wiimote_set_mesg_callback(Wiimote *self, PyVarObject *NewCallback,
277 + Wiimote_set_mesg_callback(Wiimote *self, PyObject *NewCallback,
278 void *closure)
279 {
280 - PyVarObject *OldCallback;
281 + PyObject *OldCallback;
282
283 if (!self->wiimote) {
284 SET_CLOSED_ERROR;
285 @@ -368,17 +330,18 @@ static int
286
287 Py_INCREF(NewCallback);
288 Py_DECREF(OldCallback);
289 +
290 self->callback = NewCallback;
291
292 return 0;
293 }
294
295 -static PyVarObject *Wiimote_get_mesg(Wiimote *self)
296 +static PyObject *Wiimote_get_mesg(Wiimote *self)
297 {
298 union cwiid_mesg *mesg;
299 int mesg_count;
300 struct timespec t;
301 - PyVarObject *PyMesg;
302 + PyObject *PyMesg;
303
304 if (!self->wiimote) {
305 SET_CLOSED_ERROR;
306 @@ -403,10 +366,10 @@ static PyVarObject *Wiimote_get_mesg(Wii
307 return PyMesg;
308 }
309
310 -static PyVarObject *Wiimote_get_state(Wiimote* self, void *closure)
311 +static PyObject *Wiimote_get_state(Wiimote* self, void *closure)
312 {
313 struct cwiid_state state;
314 - PyVarObject *PyState;
315 + PyObject *PyState;
316
317 if (!self->wiimote) {
318 SET_CLOSED_ERROR;
319 @@ -427,7 +390,7 @@ static PyVarObject *Wiimote_get_state(Wi
320 "error", state.error);
321
322 if (state.rpt_mode & CWIID_RPT_BTN) {
323 - PyVarObject *PyBtn = Py_BuildValue("I", state.buttons);
324 + PyObject *PyBtn = Py_BuildValue("I", state.buttons);
325 if (!PyBtn) {
326 Py_DECREF(PyState);
327 return NULL;
328 @@ -441,7 +404,7 @@ static PyVarObject *Wiimote_get_state(Wi
329 }
330
331 if (state.rpt_mode & CWIID_RPT_ACC) {
332 - PyVarObject *PyAcc = Py_BuildValue("(B,B,B)",
333 + PyObject *PyAcc = Py_BuildValue("(B,B,B)",
334 state.acc[CWIID_X],
335 state.acc[CWIID_Y],
336 state.acc[CWIID_Z]);
337 @@ -459,7 +422,7 @@ static PyVarObject *Wiimote_get_state(Wi
338
339 if (state.rpt_mode & CWIID_RPT_IR) {
340 int i;
341 - PyVarObject *PyIr = PyList_New(CWIID_IR_SRC_COUNT);
342 + PyObject *PyIr = PyList_New(CWIID_IR_SRC_COUNT);
343
344 if (!PyIr) {
345 Py_DECREF(PyState);
346 @@ -475,8 +438,8 @@ static PyVarObject *Wiimote_get_state(Wi
347 Py_DECREF(PyIr);
348
349 for (i=0; i < CWIID_IR_SRC_COUNT; i++) {
350 - PyVarObject *PyIrSrc;
351 - PyVarObject *PySize;
352 + PyObject *PyIrSrc;
353 + PyObject *PySize;
354
355 if (state.ir_src[i].valid) {
356 PyIrSrc = Py_BuildValue("{s:(I,I)}",
357 @@ -489,7 +452,7 @@ static PyVarObject *Wiimote_get_state(Wi
358 }
359
360 if (state.ir_src[i].size != -1) {
361 - if (!(PySize = PyInt_FromLong(
362 + if (!(PySize = PyLong_FromLong(
363 (long)state.ir_src[i].size))) {
364 Py_DECREF(PyState);
365 Py_DECREF(PyIrSrc);
366 @@ -514,7 +477,7 @@ static PyVarObject *Wiimote_get_state(Wi
367 }
368
369 switch (state.ext_type) {
370 - PyVarObject *PyExt;
371 + PyObject *PyExt;
372 case CWIID_EXT_NUNCHUK:
373 if (state.rpt_mode & CWIID_RPT_NUNCHUK) {
374 PyExt = Py_BuildValue("{s:(B,B),s:(B,B,B),s:I}",
375 @@ -596,11 +559,15 @@ static PyVarObject *Wiimote_get_state(Wi
376 break;
377 case CWIID_EXT_MOTIONPLUS:
378 if (state.rpt_mode & CWIID_RPT_MOTIONPLUS) {
379 - PyExt = Py_BuildValue("{s:(I,I,I)}",
380 + PyExt = Py_BuildValue("{s:(I,I,I),s:(I,I,I)}",
381 "angle_rate",
382 - state.ext.motionplus.angle_rate[CWIID_PHI],
383 - state.ext.motionplus.angle_rate[CWIID_THETA],
384 - state.ext.motionplus.angle_rate[CWIID_PSI]);
385 + state.ext.motionplus.angle_rate[CWIID_PHI],
386 + state.ext.motionplus.angle_rate[CWIID_THETA],
387 + state.ext.motionplus.angle_rate[CWIID_PSI],
388 + "low_speed",
389 + state.ext.motionplus.low_speed[CWIID_PHI],
390 + state.ext.motionplus.low_speed[CWIID_THETA],
391 + state.ext.motionplus.low_speed[CWIID_PSI]);
392
393 if (!PyExt) {
394 Py_DECREF(PyState);
395 @@ -623,13 +590,13 @@ static PyVarObject *Wiimote_get_state(Wi
396 return PyState;
397 }
398
399 -static PyVarObject *Wiimote_get_acc_cal(Wiimote *self, PyVarObject *args,
400 - PyVarObject *kwds)
401 +static PyObject *Wiimote_get_acc_cal(Wiimote *self, PyObject *args,
402 + PyObject *kwds)
403 {
404 static char *kwlist[] = { "ext_type", NULL };
405 int ext_type;
406 struct acc_cal acc_cal;
407 - PyVarObject *PyAccCal;
408 + PyObject *PyAccCal;
409
410 if (!self->wiimote) {
411 SET_CLOSED_ERROR;
412 @@ -658,10 +625,10 @@ static PyVarObject *Wiimote_get_acc_cal(
413 return PyAccCal;
414 }
415
416 -static PyVarObject *Wiimote_get_balance_cal(Wiimote *self)
417 +static PyObject *Wiimote_get_balance_cal(Wiimote *self)
418 {
419 struct balance_cal balance_cal;
420 - PyVarObject *PyBalCal;
421 + PyObject *PyBalCal;
422
423 if (cwiid_get_balance_cal(self->wiimote, &balance_cal)) {
424 PyErr_SetString(PyExc_RuntimeError,
425 @@ -688,7 +655,7 @@ static PyVarObject *Wiimote_get_balance_
426 return PyBalCal;
427 }
428
429 -static PyVarObject *Wiimote_request_status(Wiimote *self)
430 +static PyObject *Wiimote_request_status(Wiimote *self)
431 {
432 if (!self->wiimote) {
433 SET_CLOSED_ERROR;
434 @@ -703,7 +670,7 @@ static PyVarObject *Wiimote_request_stat
435 Py_RETURN_NONE;
436 }
437
438 -static int Wiimote_set_led(Wiimote *self, PyVarObject *PyLed, void *closure)
439 +static int Wiimote_set_led(Wiimote *self, PyObject *PyLed, void *closure)
440 {
441 long led;
442
443 @@ -712,7 +679,7 @@ static int Wiimote_set_led(Wiimote *self
444 return -1;
445 }
446
447 - if (((led = PyInt_AsLong(PyLed)) == -1) && PyErr_Occurred()) {
448 + if (((led = PyLong_AsLong(PyLed)) == -1) && PyErr_Occurred()) {
449 return -1;
450 }
451
452 @@ -726,7 +693,7 @@ static int Wiimote_set_led(Wiimote *self
453 }
454
455 static int
456 - Wiimote_set_rumble(Wiimote *self, PyVarObject *PyRumble, void *closure)
457 + Wiimote_set_rumble(Wiimote *self, PyObject *PyRumble, void *closure)
458 {
459 long rumble;
460
461 @@ -735,7 +702,7 @@ static int
462 return -1;
463 }
464
465 - if (((rumble = PyInt_AsLong(PyRumble)) == -1) && PyErr_Occurred()) {
466 + if (((rumble = PyLong_AsLong(PyRumble)) == -1) && PyErr_Occurred()) {
467 return -1;
468 }
469
470 @@ -749,7 +716,7 @@ static int
471 }
472
473 static int
474 - Wiimote_set_rpt_mode(Wiimote *self, PyVarObject *PyRptMode, void *closure)
475 + Wiimote_set_rpt_mode(Wiimote *self, PyObject *PyRptMode, void *closure)
476 {
477 long rpt_mode;
478
479 @@ -758,7 +725,7 @@ static int
480 return -1;
481 }
482
483 - if (((rpt_mode = PyInt_AsLong(PyRptMode)) == -1) && PyErr_Occurred()) {
484 + if (((rpt_mode = PyLong_AsLong(PyRptMode)) == -1) && PyErr_Occurred()) {
485 return -1;
486 }
487
488 @@ -771,7 +738,7 @@ static int
489 return 0;
490 }
491
492 -/* static PyVarObject *Wiimote_command(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
493 +/* static PyObject *Wiimote_command(Wiimote *self, PyObject *args, PyObject *kwds)
494 {
495 static char *kwlist[] = { "command", "flags", NULL };
496 int command, flags;
497 @@ -787,7 +754,7 @@ static int
498 }
499 */
500
501 -static PyVarObject *Wiimote_send_rpt(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
502 +static PyObject *Wiimote_send_rpt(Wiimote *self, PyObject *args, PyObject *kwds)
503 {
504 static char *kwlist[] = { "flags", "report", "buffer", NULL };
505 unsigned char flags, report;
506 @@ -812,14 +779,14 @@ static PyVarObject *Wiimote_send_rpt(Wii
507 Py_RETURN_NONE;
508 }
509
510 -static PyVarObject *Wiimote_read(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
511 +static PyObject *Wiimote_read(Wiimote *self, PyObject *args, PyObject *kwds)
512 {
513 static char *kwlist[] = { "flags", "offset", "len", NULL };
514 unsigned char flags;
515 unsigned int offset;
516 Py_ssize_t len;
517 void *buf;
518 - PyVarObject *pyRetBuf;
519 + PyObject *pyRetBuf;
520
521 if (!self->wiimote) {
522 SET_CLOSED_ERROR;
523 @@ -831,10 +798,10 @@ static PyVarObject *Wiimote_read(Wiimote
524 return NULL;
525 }
526
527 - if (!(pyRetBuf = PyBuffer_New(len))) {
528 + if (!(pyRetBuf = malloc(len))) {
529 return NULL;
530 }
531 - if (PyVarObject_AsWriteBuffer(pyRetBuf, &buf, &len)) {
532 + if (PyObject_AsWriteBuffer(pyRetBuf, &buf, &len)) {
533 Py_DECREF(pyRetBuf);
534 return NULL;
535 }
536 @@ -847,7 +814,7 @@ static PyVarObject *Wiimote_read(Wiimote
537 return pyRetBuf;
538 }
539
540 -static PyVarObject *Wiimote_write(Wiimote *self, PyVarObject *args, PyVarObject *kwds)
541 +static PyObject *Wiimote_write(Wiimote *self, PyObject *args, PyObject *kwds)
542 {
543 static char *kwlist[] = { "flags", "offset", "buffer", NULL };
544 unsigned char flags;
545 @@ -876,8 +843,8 @@ static PyVarObject *Wiimote_write(Wiimot
546 static void CallbackBridge(cwiid_wiimote_t *wiimote, int mesg_count,
547 union cwiid_mesg mesg[], struct timespec *t)
548 {
549 - PyVarObject *ArgTuple;
550 - PyVarObject *PySelf;
551 + PyObject *ArgTuple;
552 + PyObject *PySelf;
553 PyGILState_STATE gstate;
554
555 gstate = PyGILState_Ensure();
556 @@ -885,8 +852,8 @@ static void CallbackBridge(cwiid_wiimote
557 ArgTuple = ConvertMesgArray(mesg_count, mesg);
558
559 /* Put id and the list of messages as the arguments to the callback */
560 - PySelf = (PyVarObject *) cwiid_get_data(wiimote);
561 - if (!PyVarObject_CallFunction(((Wiimote *)PySelf)->callback, "(O, d)",
562 + PySelf = (PyObject *) cwiid_get_data(wiimote);
563 + if (!PyObject_CallFunction(((Wiimote *)PySelf)->callback, "(O, d)",
564 ArgTuple,
565 t->tv_sec + ((double) t->tv_nsec) * 1e-9)) {
566 PyErr_Print();
567 @@ -918,15 +885,16 @@ static void CallbackBridge(cwiid_wiimote
568 * "right_bottom":right_bottom,
569 * "left_top":left_top,
570 * "left_bottom":left_bottom},
571 - * (cwiid.MOTIONPLUS_MESG,{"angle_rate":(psi,theta,phi)},
572 + * (cwiid.MOTIONPLUS_MESG,{"angle_rate":(psi,theta,phi),
573 + * "low_speed":(psi,theta,phi)},
574 * (cwiid.ERROR_MESG,error)]
575 */
576 -PyVarObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[])
577 +PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[])
578 {
579 - PyVarObject *mesglist; /* List of message tuples */
580 - PyVarObject *amesg; /* A single message (type, [arguments]) */
581 - PyVarObject *mesgVal; /* Dictionary of arguments for a message */
582 - PyVarObject *PyIrList;
583 + PyObject *mesglist; /* List of message tuples */
584 + PyObject *amesg; /* A single message (type, [arguments]) */
585 + PyObject *mesgVal; /* Dictionary of arguments for a message */
586 + PyObject *PyIrList;
587 int i, j;
588
589 if (!(mesglist = PyList_New(mesg_count))) {
590 @@ -956,8 +924,8 @@ PyVarObject *ConvertMesgArray(int mesg_c
591 }
592
593 for (j=0; j < CWIID_IR_SRC_COUNT; j++) {
594 - PyVarObject *PyIrSrc;
595 - PyVarObject *PySize;
596 + PyObject *PyIrSrc;
597 + PyObject *PySize;
598
599 if (mesg[i].ir_mesg.src[j].valid) {
600 PyIrSrc = Py_BuildValue("{s:(I,I)}",
601 @@ -972,7 +940,7 @@ PyVarObject *ConvertMesgArray(int mesg_c
602 }
603
604 if (mesg[i].ir_mesg.src[j].size != -1) {
605 - if (!(PySize = PyInt_FromLong(
606 + if (!(PySize = PyLong_FromLong(
607 (long)mesg[i].ir_mesg.src[j].size))) {
608 Py_DECREF(PyIrList);
609 Py_DECREF(PyIrSrc);
610 @@ -1037,11 +1005,16 @@ PyVarObject *ConvertMesgArray(int mesg_c
611 mesg[i].balance_mesg.left_bottom);
612 break;
613 case CWIID_MESG_MOTIONPLUS:
614 - mesgVal = Py_BuildValue("{s:(I,I,I)}",
615 + mesgVal = Py_BuildValue("{s:(I,I,I),s:(I,I,I)}",
616 "angle_rate",
617 - mesg[i].motionplus_mesg.angle_rate[CWIID_PHI],
618 - mesg[i].motionplus_mesg.angle_rate[CWIID_THETA],
619 - mesg[i].motionplus_mesg.angle_rate[CWIID_PSI]);
620 + mesg[i].motionplus_mesg.angle_rate[CWIID_PHI],
621 + mesg[i].motionplus_mesg.angle_rate[CWIID_THETA],
622 + mesg[i].motionplus_mesg.angle_rate[CWIID_PSI],
623 + "low_speed",
624 + mesg[i].motionplus_mesg.low_speed[CWIID_PHI],
625 + mesg[i].motionplus_mesg.low_speed[CWIID_THETA],
626 + mesg[i].motionplus_mesg.low_speed[CWIID_PSI]);
627 +
628 break;
629 case CWIID_MESG_ERROR:
630 mesgVal = Py_BuildValue("i", mesg[i].error_mesg.error);
631 Index: cwiid/python/cwiidmodule.c
632 ===================================================================
633 --- cwiid.orig/python/cwiidmodule.c
634 +++ cwiid/python/cwiidmodule.c
635 @@ -1,5 +1,5 @@
636 /*
637 - * Copyright (C) 2007 Justin M. Tulloss <[email protected]>
638 + * Copyright (C) 2007 Justin M. Tulloss <[email protected]>, L. Donnie Smith <[email protected]>
639 *
640 * Interface from Python to libcwiid
641 *
642 @@ -18,67 +18,21 @@
643 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
644 * Boston, MA 02110-1301 USA
645 *
646 - * ChangeLog:
647 - * 2007-06-05 L. Donnie Smith <[email protected]>
648 - * * removed Wiimote_FromC function
649 - *
650 - * 2007-06-01 L. Donnie Smith <[email protected]>
651 - * * added CObjects for Wiimote_FromC and ConvertMesgArray
652 - *
653 - * 2007-05-22 L. Donnie Smith <[email protected]>
654 - * * clarified variable names
655 - *
656 - * 2007-05-14 L. Donnie Smith <[email protected]>
657 - * * moved Wiimote class to separate files
658 - *
659 - * 2007-05-12 L. Donnie Smith <[email protected]>
660 - * * added keywords to read
661 - * * finished get_mesg
662 - * * cleaned up types in get_state
663 - * * finished processMesgs
664 - *
665 - * 2007-05-09 L. Donnie Smith <[email protected]>
666 - * * finished get_state
667 - * * fixed read buffer issue
668 - * * implemented write
669 - * * cleaned up types
670 - * * removed notImplemented (no longer needed)
671 - *
672 - * 2007-05-07 L. Donnie Smith <[email protected]>
673 - * * C-style comments
674 - * * changed struct name to Wiimote
675 - * * removed dlopen, unused includes
676 - * * spaces to tabs, misc stylistic changes to match CWiid code
677 - * * changed self types to Wiimote
678 - * * made bdaddr local
679 - * * improved error checking in Wiimote_init
680 - * * implemented disconnect, enable, disable
681 - * * partially implemented get_state
682 - *
683 - * 2007-05-07 Justin M. Tulloss <[email protected]>
684 - * * Refactored according to dsmith's wishes, removed unnecessary locks
685 - * * implemented read
686 - *
687 - * 2007-04-26 Justin M. Tulloss <[email protected]>
688 - * * Updated for new libcwiid API
689 - *
690 - * 2007-04-24 Justin M. Tulloss <[email protected]>
691 - * * Initial Changelog
692 */
693
694 #include "Python.h"
695
696 #include <stdlib.h>
697
698 -#include "cwiid.h"
699 +#include <cwiid.h>
700 #include "structmember.h"
701
702 /* externally defined types */
703 extern PyTypeObject Wiimote_Type;
704 -extern PyVarObject *ConvertMesgArray(int, union cwiid_mesg []);
705 +extern PyObject *ConvertMesgArray(int, union cwiid_mesg []);
706
707 /* cwiid module initializer */
708 -PyMODINIT_FUNC init_cwiid(void);
709 +PyMODINIT_FUNC PyInit_cwiid(void);
710
711 /* constants, enumerations */
712 #define CWIID_CONST_MACRO(a) {#a, CWIID_##a}
713 @@ -182,47 +136,46 @@ static PyMethodDef Module_Methods[] =
714 };
715
716 static struct PyModuleDef moduledef = {
717 - PyModuleDef_HEAD_INIT,
718 - "cwiid", /* m_name */
719 - "CWiid Wiimote Interface", /* m_doc */
720 - -1, /* m_size */
721 - Module_Methods, /* m_methods */
722 - NULL, /* m_reload */
723 - NULL, /* m_traverse */
724 - NULL, /* m_clear */
725 - NULL, /* m_free */
726 + PyModuleDef_HEAD_INIT,
727 + "cwiid", /* m_name */
728 + "Cwiid FFS!", /* m_doc */
729 + -1, /* m_size */
730 + Module_Methods, /* m_methods */
731 + NULL, /* m_reload */
732 + NULL, /* m_traverse */
733 + NULL, /* m_clear */
734 + NULL, /* m_free */
735 };
736
737 -
738 -PyMODINIT_FUNC init_cwiid(void)
739 +PyMODINIT_FUNC PyInit_cwiid(void)
740 {
741 - PyVarObject *Module;
742 - PyVarObject *CObj;
743 + PyObject *Module;
744 + PyObject *CCapsule;
745 int i;
746
747 - PyEval_InitThreads();
748 -
749 - if (PyType_Ready(&Wiimote_Type) < 0) {
750 - return;
751 + if (!(Module = PyModule_Create(&moduledef))) {
752 + return NULL;
753 }
754
755 - if (!(Module = PyModule_Create(&moduledef))) {
756 - return;
757 + Wiimote_Type.tp_new = PyType_GenericNew;
758 + if (PyType_Ready(&Wiimote_Type) < 0) {
759 + return NULL;
760 }
761
762 Py_INCREF(&Wiimote_Type);
763 - PyModule_AddObject(Module, "Wiimote", (PyVarObject*)&Wiimote_Type);
764 + PyModule_AddObject(Module, "Wiimote", (PyObject *)&Wiimote_Type);
765
766 for (i = 0; cwiid_constants[i].name; i++) {
767 /* No way to report errors from here, so just ignore them and hope
768 * for segfault */
769 PyModule_AddIntConstant(Module, cwiid_constants[i].name,
770 - cwiid_constants[i].value);
771 + cwiid_constants[i].value);
772 }
773
774 - if (!(CObj = PyCObject_FromVoidPtr(ConvertMesgArray, NULL))) {
775 - return;
776 + if (!(CCapsule = PyCapsule_New(ConvertMesgArray, "dynamr", NULL))) {
777 + return NULL;
778 }
779 - PyModule_AddObject(Module, "ConvertMesgArray", CObj);
780 + PyModule_AddObject(Module, "ConvertMesgArray", CCapsule);
781 +
782 + return Module;
783 }
784 -
785 Index: cwiid/python/setup.py
786 ===================================================================
787 --- cwiid.orig/python/setup.py
788 +++ cwiid/python/setup.py
789 @@ -1,16 +1,10 @@
790 from distutils.core import setup, Extension
791 -from subprocess import PIPE, Popen
792 -import os, re
793
794 -changelogFile = os.path.join(os.path.dirname(__file__), "..", "debian", "changelog")
795 -p=Popen(f"dpkg-parsechangelog -l {changelogFile} | grep Version",
796 - shell=True, stdout=PIPE)
797 -out, err = p.communicate()
798 -version = out.decode("utf-8").strip()
799 -m = re.match(r"^[^0-9]*([.0-9]*).*$",version, re.M)
800 -version = m.group(1)
801 -
802 -setup(name='cwiid',
803 - version=version,
804 - ext_modules=[Extension('cwiid', ['cwiidmodule.c', 'Wiimote.c'])]
805 - )
806 +setup(
807 + name='cwiid',
808 + version='3.0.0',
809 + description='Python3 module for libcwiid',
810 + author='Azzra',
811 + author_email='[email protected]',
812 + ext_modules=[Extension('cwiid', ['cwiidmodule.c', 'Wiimote.c'], libraries=['cwiid', 'bluetooth'])]
813 +)
814 Index: cwiid/libcwiid/bluetooth.c
815 ===================================================================
816 --- cwiid.orig/libcwiid/bluetooth.c
817 +++ cwiid/libcwiid/bluetooth.c
818 @@ -1,4 +1,4 @@
819 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
820 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
821 *
822 * This program is free software; you can redistribute it and/or modify
823 * it under the terms of the GNU General Public License as published by
824 @@ -14,27 +14,6 @@
825 * along with this program; if not, write to the Free Software
826 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
827 *
828 - * ChangeLog:
829 - * 2007-04-24 L. Donnie Smith ([email protected]>
830 - * * revised error messages
831 - *
832 - * 2007-04-12 L. Donnie Smith <[email protected]>
833 - * * streamlined wiimote filter
834 - *
835 - * 2007-04-09 L. Donnie Smith <[email protected]>
836 - * * renamed wiimote to libcwiid, renamed structures accordingly
837 - *
838 - * 2007-04-07 L. Donnie Smith <[email protected]>
839 - * * changed cwiid_info.class to btclass
840 - *
841 - * 2007-04-03 L. Donnie Smith <[email protected]>
842 - * * fixed cwiid_find_wiimote seg fault
843 - *
844 - * 2007-04-02 L. Donnie Smith <[email protected]>
845 - * * exception handling bugs
846 - *
847 - * 2007-04-01 L. Donnie Smith <[email protected]>
848 - * * created file
849 */
850
851 #include <stdlib.h>
852 Index: cwiid/libcwiid/command.c
853 ===================================================================
854 --- cwiid.orig/libcwiid/command.c
855 +++ cwiid/libcwiid/command.c
856 @@ -1,4 +1,4 @@
857 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
858 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
859 *
860 * This program is free software; you can redistribute it and/or modify
861 * it under the terms of the GNU General Public License as published by
862 @@ -14,32 +14,6 @@
863 * along with this program; if not, write to the Free Software
864 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
865 *
866 - * ChangeLog:
867 - * 2007-05-16 L. Donnie Smith <[email protected]>
868 - * * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble,
869 - * cwiid_set_rpt_mode
870 - *
871 - * 2007-04-24 L. Donnie Smith <[email protected]>
872 - * * rewrite for API overhaul
873 - * * added rw and beep functions from rw.c
874 - *
875 - * 2007-04-09 L. Donnie Smith <[email protected]>
876 - * * renamed wiimote to libcwiid, renamed structures accordingly
877 - *
878 - * 2007-04-04 L. Donnie Smith <[email protected]>
879 - * * updated cwiid_read and cwiid_write to trigger and detect rw_error
880 - *
881 - * 2007-03-14 L. Donnie Smith <[email protected]>
882 - * * audited error checking (coda and error handler sections)
883 - * * updated comments
884 - * * cwiid_read - changed to obey decode flag only for register read
885 - *
886 - * 2007-03-06 L. Donnie Smith <[email protected]>
887 - * * added wiimote parameter to cwiid_err calls
888 - *
889 - * 2007-03-01 L. Donnie Smith <[email protected]>
890 - * * Initial ChangeLog
891 - * * type audit (stdint, const, char booleans)
892 */
893
894 #include <stdint.h>
895 Index: cwiid/libcwiid/connect.c
896 ===================================================================
897 --- cwiid.orig/libcwiid/connect.c
898 +++ cwiid/libcwiid/connect.c
899 @@ -1,4 +1,4 @@
900 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
901 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
902 *
903 * This program is free software; you can redistribute it and/or modify
904 * it under the terms of the GNU General Public License as published by
905 @@ -14,40 +14,6 @@
906 * along with this program; if not, write to the Free Software
907 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
908 *
909 - * ChangeLog:
910 - * 2009-06-13 L. Donnie Smith <[email protected]>
911 - * * add cwiid_open_timeout function, call it with default from cwiid_open
912 - *
913 - * 2007-06-14 L. Donnie Smith <[email protected]>
914 - * * added sleep after cwiid_find_wiimote call
915 - *
916 - * 2007-05-16 L. Donnie Smith <[email protected]>
917 - * * remove error_pipe init and destruct
918 - * * renamed connect and disconnect to open and close
919 - *
920 - * 2007-04-24 L. Donnie Smith <[email protected]>
921 - * * rewrite for API overhaul
922 - *
923 - * 2007-04-09 L. Donnie Smith <[email protected]>
924 - * * renamed wiimote to libcwiid, renamed structures accordingly
925 - *
926 - * 2007-04-04 L. Donnie Smith <[email protected]>
927 - * * cancel rw operations from cwiid_disconnect
928 - *
929 - * 2007-04-01 L. Donnie Smith <[email protected]>
930 - * * cwiid_connect now takes a pointer to bdaddr_t
931 - * * changed cwiid_findfirst to cwiid_find_wiimote
932 - *
933 - * 2007-03-14 L. Donnie Smith <[email protected]>
934 - * * changed memcpy to bacmp
935 - * * audited error checking (coda and error handler sections)
936 - * * updated comments
937 - *
938 - * 2007-03-06 L. Donnie Smith <[email protected]>
939 - * * added wiimote parameter to cwiid_err calls
940 - *
941 - * 2007-03-01 L. Donnie Smith <[email protected]>
942 - * * Initial ChangeLog
943 */
944
945 #include <stdlib.h>
946 @@ -67,41 +33,14 @@ static int wiimote_id = 0;
947 /* TODO: Turn this onto a macro on next major so version */
948 cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags)
949 {
950 - return cwiid_open_timeout(bdaddr, flags, 5);
951 + return cwiid_open_timeout(bdaddr, flags, DEFAULT_TIMEOUT);
952 }
953
954 cwiid_wiimote_t *cwiid_open_timeout(bdaddr_t *bdaddr, int flags, int timeout)
955 {
956 - struct wiimote *wiimote = NULL;
957 struct sockaddr_l2 remote_addr;
958 - char mesg_pipe_init = 0, status_pipe_init = 0, rw_pipe_init = 0,
959 - state_mutex_init = 0, rw_mutex_init = 0, rpt_mutex_init = 0,
960 - router_thread_init = 0, status_thread_init = 0;
961 - void *pthread_ret;
962 -
963 - /* Allocate wiimote */
964 - if ((wiimote = malloc(sizeof *wiimote)) == NULL) {
965 - cwiid_err(NULL, "Memory allocation error (cwiid_wiimote_t)");
966 - goto ERR_HND;
967 - }
968 -
969 - /* set flags */
970 - wiimote->flags = flags;
971 -
972 - /* For error detection */
973 - wiimote->ctl_socket = wiimote->int_socket = -1;
974 -
975 - /* Global Lock, Store and Increment wiimote_id */
976 - if (pthread_mutex_lock(&global_mutex)) {
977 - cwiid_err(NULL, "Mutex lock error (global mutex)");
978 - goto ERR_HND;
979 - }
980 - wiimote->id = wiimote_id++;
981 - if (pthread_mutex_unlock(&global_mutex)) {
982 - cwiid_err(wiimote, "Mutex unlock error (global mutex) - "
983 - "deadlock warning");
984 - goto ERR_HND;
985 - }
986 + int ctl_socket = -1, int_socket = -1;
987 + struct wiimote *wiimote = NULL;
988
989 /* If BDADDR_ANY is given, find available wiimote */
990 if (bacmp(bdaddr, BDADDR_ANY) == 0) {
991 @@ -117,27 +56,178 @@ cwiid_wiimote_t *cwiid_open_timeout(bdad
992 remote_addr.l2_family = AF_BLUETOOTH;
993 remote_addr.l2_bdaddr = *bdaddr;
994 remote_addr.l2_psm = htobs(CTL_PSM);
995 - if ((wiimote->ctl_socket =
996 + if ((ctl_socket =
997 socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1) {
998 - cwiid_err(wiimote, "Socket creation error (control socket)");
999 + cwiid_err(NULL, "Socket creation error (control socket)");
1000 goto ERR_HND;
1001 }
1002 - if (connect(wiimote->ctl_socket, (struct sockaddr *)&remote_addr,
1003 + if (connect(ctl_socket, (struct sockaddr *)&remote_addr,
1004 sizeof remote_addr)) {
1005 - cwiid_err(wiimote, "Socket connect error (control channel)");
1006 + cwiid_err(NULL, "Socket connect error (control socket)");
1007 goto ERR_HND;
1008 }
1009
1010 /* Interrupt Channel */
1011 remote_addr.l2_psm = htobs(INT_PSM);
1012 - if ((wiimote->int_socket =
1013 + if ((int_socket =
1014 socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1) {
1015 - cwiid_err(wiimote, "Socket creation error (interrupt socket)");
1016 + cwiid_err(NULL, "Socket creation error (interrupt socket)");
1017 goto ERR_HND;
1018 }
1019 - if (connect(wiimote->int_socket, (struct sockaddr *)&remote_addr,
1020 + if (connect(int_socket, (struct sockaddr *)&remote_addr,
1021 sizeof remote_addr)) {
1022 - cwiid_err(wiimote, "Socket connect error (interrupt channel)");
1023 + cwiid_err(NULL, "Socket connect error (interrupt socket)");
1024 + goto ERR_HND;
1025 + }
1026 +
1027 + if ((wiimote = cwiid_new(ctl_socket, int_socket, flags)) == NULL) {
1028 + /* Raises its own error */
1029 + goto ERR_HND;
1030 + }
1031 +
1032 + return wiimote;
1033 +
1034 +ERR_HND:
1035 + /* Close Sockets */
1036 + if (ctl_socket != -1) {
1037 + if (close(ctl_socket)) {
1038 + cwiid_err(NULL, "Socket close error (control socket)");
1039 + }
1040 + }
1041 + if (int_socket != -1) {
1042 + if (close(int_socket)) {
1043 + cwiid_err(NULL, "Socket close error (interrupt socket)");
1044 + }
1045 + }
1046 + return NULL;
1047 +}
1048 +
1049 +cwiid_wiimote_t *cwiid_listen(int flags)
1050 +{
1051 + struct sockaddr_l2 local_addr;
1052 + struct sockaddr_l2 remote_addr;
1053 + socklen_t socklen;
1054 + int ctl_server_socket = -1, int_server_socket = -1,
1055 + ctl_socket = -1, int_socket = -1;
1056 + struct wiimote *wiimote = NULL;
1057 +
1058 + /* Connect to Wiimote */
1059 + /* Control Channel */
1060 + memset(&local_addr, 0, sizeof local_addr);
1061 + local_addr.l2_family = AF_BLUETOOTH;
1062 + local_addr.l2_bdaddr = *BDADDR_ANY;
1063 + local_addr.l2_psm = htobs(CTL_PSM);
1064 + if ((ctl_server_socket =
1065 + socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1) {
1066 + cwiid_err(NULL, "Socket creation error (control socket)");
1067 + goto ERR_HND;
1068 + }
1069 + if (bind(ctl_server_socket, (struct sockaddr *)&local_addr,
1070 + sizeof local_addr)) {
1071 + cwiid_err(NULL, "Socket bind error (control socket)");
1072 + goto ERR_HND;
1073 + }
1074 + if (listen(ctl_server_socket, 1)) {
1075 + cwiid_err(NULL, "Socket listen error (control socket)");
1076 + goto ERR_HND;
1077 + }
1078 +
1079 + /* Interrupt Channel */
1080 + local_addr.l2_psm = htobs(INT_PSM);
1081 + if ((int_server_socket =
1082 + socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1) {
1083 + cwiid_err(NULL, "Socket creation error (interrupt socket)");
1084 + goto ERR_HND;
1085 + }
1086 + if (bind(int_server_socket, (struct sockaddr *)&local_addr,
1087 + sizeof local_addr)) {
1088 + cwiid_err(NULL, "Socket bind error (interrupt socket)");
1089 + goto ERR_HND;
1090 + }
1091 + if (listen(int_server_socket, 1)) {
1092 + cwiid_err(NULL, "Socket listen error (interrupt socket)");
1093 + goto ERR_HND;
1094 + }
1095 +
1096 + /* Block for Connections */
1097 + if ((ctl_socket = accept(ctl_server_socket, (struct sockaddr *)&remote_addr, &socklen)) < 0) {
1098 + cwiid_err(NULL, "Socket accept error (control socket)");
1099 + goto ERR_HND;
1100 + }
1101 + if ((int_socket = accept(int_server_socket, (struct sockaddr *)&remote_addr, &socklen)) < 0) {
1102 + cwiid_err(NULL, "Socket accept error (interrupt socket)");
1103 + goto ERR_HND;
1104 + }
1105 +
1106 + /* Close server sockets */
1107 + if (close(ctl_server_socket)) {
1108 + cwiid_err(NULL, "Socket close error (control socket)");
1109 + }
1110 + if (close(int_server_socket)) {
1111 + cwiid_err(NULL, "Socket close error (interrupt socket)");
1112 + }
1113 +
1114 + if ((wiimote = cwiid_new(ctl_socket, int_socket, flags)) == NULL) {
1115 + /* Raises its own error */
1116 + goto ERR_HND;
1117 + }
1118 +
1119 + return wiimote;
1120 +
1121 +ERR_HND:
1122 + /* Close Sockets */
1123 + if (ctl_server_socket != -1) {
1124 + if (close(ctl_server_socket)) {
1125 + cwiid_err(NULL, "Socket close error (control server socket)");
1126 + }
1127 + }
1128 + if (int_server_socket != -1) {
1129 + if (close(int_server_socket)) {
1130 + cwiid_err(NULL, "Socket close error (interrupt server socket)");
1131 + }
1132 + }
1133 + if (ctl_socket != -1) {
1134 + if (close(ctl_socket)) {
1135 + cwiid_err(NULL, "Socket close error (control socket)");
1136 + }
1137 + }
1138 + if (int_socket != -1) {
1139 + if (close(int_socket)) {
1140 + cwiid_err(NULL, "Socket close error (interrupt socket)");
1141 + }
1142 + }
1143 +
1144 + return NULL;
1145 +}
1146 +
1147 +cwiid_wiimote_t *cwiid_new(int ctl_socket, int int_socket, int flags)
1148 +{
1149 + struct wiimote *wiimote = NULL;
1150 + char mesg_pipe_init = 0, status_pipe_init = 0, rw_pipe_init = 0,
1151 + state_mutex_init = 0, rw_mutex_init = 0, rpt_mutex_init = 0,
1152 + router_thread_init = 0, status_thread_init = 0;
1153 + void *pthread_ret;
1154 +
1155 + /* Allocate wiimote */
1156 + if ((wiimote = malloc(sizeof *wiimote)) == NULL) {
1157 + cwiid_err(NULL, "Memory allocation error (cwiid_wiimote_t)");
1158 + goto ERR_HND;
1159 + }
1160 +
1161 + /* set sockets and flags */
1162 + wiimote->ctl_socket = ctl_socket;
1163 + wiimote->int_socket = int_socket;
1164 + wiimote->flags = flags;
1165 +
1166 + /* Global Lock, Store and Increment wiimote_id */
1167 + if (pthread_mutex_lock(&global_mutex)) {
1168 + cwiid_err(NULL, "Mutex lock error (global mutex)");
1169 + goto ERR_HND;
1170 + }
1171 + wiimote->id = wiimote_id++;
1172 + if (pthread_mutex_unlock(&global_mutex)) {
1173 + cwiid_err(wiimote, "Mutex unlock error (global mutex) - "
1174 + "deadlock warning");
1175 goto ERR_HND;
1176 }
1177
1178 @@ -190,7 +280,7 @@ cwiid_wiimote_t *cwiid_open_timeout(bdad
1179 /* Set rw_status before starting router thread */
1180 wiimote->rw_status = RW_IDLE;
1181
1182 - /* Launch interrupt channel listener and dispatch threads */
1183 + /* Launch interrupt socket listener and dispatch threads */
1184 if (pthread_create(&wiimote->router_thread, NULL,
1185 (void *(*)(void *))&router_thread, wiimote)) {
1186 cwiid_err(wiimote, "Thread creation error (router thread)");
1187 @@ -236,17 +326,6 @@ ERR_HND:
1188 }
1189 }
1190
1191 - /* Close Sockets */
1192 - if (wiimote->int_socket != -1) {
1193 - if (close(wiimote->int_socket)) {
1194 - cwiid_err(wiimote, "Socket close error (interrupt channel)");
1195 - }
1196 - }
1197 - if (wiimote->ctl_socket != -1) {
1198 - if (close(wiimote->ctl_socket)) {
1199 - cwiid_err(wiimote, "Socket close error (control channel)");
1200 - }
1201 - }
1202 /* Close Pipes */
1203 if (mesg_pipe_init) {
1204 if (close(wiimote->mesg_pipe[0]) || close(wiimote->mesg_pipe[1])) {
1205 @@ -289,6 +368,14 @@ int cwiid_close(cwiid_wiimote_t *wiimote
1206 {
1207 void *pthread_ret;
1208
1209 + /* Stop rumbling, otherwise wiimote continues to rumble for
1210 + few seconds after closing the connection! There should be no
1211 + need to check if stopping fails: we are closing the connection
1212 + in any case. */
1213 + if (wiimote->state.rumble) {
1214 + cwiid_set_rumble(wiimote, 0);
1215 + }
1216 +
1217 /* Cancel and join router_thread and status_thread */
1218 if (pthread_cancel(wiimote->router_thread)) {
1219 /* if thread quit abnormally, would have printed it's own error */
1220 @@ -322,10 +409,10 @@ int cwiid_close(cwiid_wiimote_t *wiimote
1221
1222 /* Close sockets */
1223 if (close(wiimote->int_socket)) {
1224 - cwiid_err(wiimote, "Socket close error (interrupt channel)");
1225 + cwiid_err(wiimote, "Socket close error (interrupt socket)");
1226 }
1227 if (close(wiimote->ctl_socket)) {
1228 - cwiid_err(wiimote, "Socket close error (control channel)");
1229 + cwiid_err(wiimote, "Socket close error (control socket)");
1230 }
1231 /* Close Pipes */
1232 if (close(wiimote->mesg_pipe[0]) || close(wiimote->mesg_pipe[1])) {
1233 Index: cwiid/libcwiid/cwiid.h
1234 ===================================================================
1235 --- cwiid.orig/libcwiid/cwiid.h
1236 +++ cwiid/libcwiid/cwiid.h
1237 @@ -1,4 +1,4 @@
1238 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1239 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1240 *
1241 * This program is free software; you can redistribute it and/or modify
1242 * it under the terms of the GNU General Public License as published by
1243 @@ -14,44 +14,6 @@
1244 * along with this program; if not, write to the Free Software
1245 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1246 *
1247 - * ChangeLog:
1248 - * 2007-08-14 L. Donnie Smith <[email protected]>
1249 - * * make cwiid_err_default public
1250 - *
1251 - * 2007-05-16 L. Donnie Smith <[email protected]>
1252 - * * changed cwiid_connect, cwiid_disconnect to cwiid_open, cwiid_close
1253 - * * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble,
1254 - * cwiid_set_rpt_mode
1255 - *
1256 - * 2007-05-14 L. Donnie Smith <[email protected]>
1257 - * * added timestamp to message functions
1258 - * * added cwiid_get_acc_cal
1259 - *
1260 - * 2007-04-24 L. Donnie Smith <[email protected]>
1261 - * * rewrite for API overhaul
1262 - *
1263 - * 2007-04-09 L. Donnie Smith <[email protected]>
1264 - * * renamed wiimote to libcwiid, renamed structures accordingly
1265 - *
1266 - * 2007-04-07 L. Donnie Smith <[email protected]>
1267 - * * changed cwiid_info.class to btclass
1268 - *
1269 - * 2007-04-04 L. Donnie Smith <[email protected]>
1270 - * * added cwiid_mesg_error message type
1271 - *
1272 - * 2007-04-01 L. Donnie Smith <[email protected]>
1273 - * * cwiid_connect now takes a pointer to bdaddr_t
1274 - * * added cwiid_info definition and macros
1275 - * * added cwiid_get_info_array prototype
1276 - * * changed cwiid_findfirst to cwiid_find_wiimote
1277 - *
1278 - * 2007-03-05 L. Donnie Smith <[email protected]>
1279 - * * added cwiid_err_t definition
1280 - * * added cwiid_set_err prototype
1281 - *
1282 - * 2007-03-01 L. Donnie Smith <[email protected]>
1283 - * * Initial ChangeLog
1284 - * * type audit (stdint, const, char booleans)
1285 */
1286
1287 #ifndef CWIID_H
1288 @@ -263,6 +225,7 @@ struct cwiid_balance_mesg {
1289 struct cwiid_motionplus_mesg {
1290 enum cwiid_mesg_type type;
1291 uint16_t angle_rate[3];
1292 + uint8_t low_speed[3];
1293 };
1294
1295 struct cwiid_error_mesg {
1296 @@ -307,6 +270,7 @@ struct balance_state {
1297
1298 struct motionplus_state {
1299 uint16_t angle_rate[3];
1300 + uint8_t low_speed[3];
1301 };
1302
1303 union ext_state {
1304 @@ -359,6 +323,7 @@ void cwiid_err_default(struct wiimote *w
1305 #define cwiid_disconnect cwiid_close
1306 cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags);
1307 cwiid_wiimote_t *cwiid_open_timeout(bdaddr_t *bdaddr, int flags, int timeout);
1308 +cwiid_wiimote_t *cwiid_listen(int flags);
1309 int cwiid_close(cwiid_wiimote_t *wiimote);
1310
1311 int cwiid_get_id(cwiid_wiimote_t *wiimote);
1312 Index: cwiid/libcwiid/cwiid.pc.in
1313 ===================================================================
1314 --- cwiid.orig/libcwiid/cwiid.pc.in
1315 +++ cwiid/libcwiid/cwiid.pc.in
1316 @@ -3,8 +3,6 @@ exec_prefix=@exec_prefix@
1317 libdir=@libdir@
1318 includedir=@includedir@
1319 sysconfdir=@sysconfdir@
1320 -cwiid_config_dir=${sysconfdir}/cwiid
1321 -cwiid_plugins_dir=@CWIID_PLUGINS_DIR@
1322
1323 Name: CWiid
1324 Description: CWiid Wiimote Interface
1325 Index: cwiid/libcwiid/cwiid_internal.h
1326 ===================================================================
1327 --- cwiid.orig/libcwiid/cwiid_internal.h
1328 +++ cwiid/libcwiid/cwiid_internal.h
1329 @@ -1,4 +1,4 @@
1330 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1331 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1332 *
1333 * This program is free software; you can redistribute it and/or modify
1334 * it under the terms of the GNU General Public License as published by
1335 @@ -14,32 +14,6 @@
1336 * along with this program; if not, write to the Free Software
1337 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1338 *
1339 - * ChangeLog:
1340 - * 2007-05-16 L. Donnie Smith <[email protected]>
1341 - * * remove error_pipe
1342 - * * add struct mesg_array to process_error
1343 - *
1344 - * 2007-05-14 L. Donnie Smith <[email protected]>
1345 - * * added timestamp to mesg_array
1346 - *
1347 - * 2007-04-24 L. Donnie Smith <[email protected]>
1348 - * * rewrite for API overhaul
1349 - *
1350 - * 2007-04-09 L. Donnie Smith <[email protected]>
1351 - * * renamed wiimote to libcwiid, renamed structures accordingly
1352 - *
1353 - * 2007-04-04 L. Donnie Smith <[email protected]>
1354 - * * moved RW error state to separate member
1355 - *
1356 - * 2007-04-01 L. Donnie Smith <[email protected]>
1357 - * * removed CWIID_CMP_LEN macro and cwiid_findfirst prototype
1358 - *
1359 - * 2007-03-05 L. Donnie Smith <[email protected]>
1360 - * * added wiimote parameter to cwiid_err prototype
1361 - *
1362 - * 2007-03-01 L. Donnie Smith <[email protected]>
1363 - * * Initial ChangeLog
1364 - * * type audit (stdint, const, char booleans)
1365 */
1366
1367 #ifndef CWIID_INTERNAL_H
1368 @@ -50,6 +24,8 @@
1369 #include <sys/types.h> /* ssize_t */
1370 #include "cwiid.h"
1371
1372 +#define DEFAULT_TIMEOUT 5
1373 +
1374 /* Bluetooth magic numbers */
1375 #define BT_TRANS_MASK 0xF0
1376 #define BT_TRANS_HANDSHAKE 0x00
1377 @@ -114,18 +90,30 @@
1378 #define NUNCHUK_BTN_MASK 0x03
1379
1380 /* Extension Values */
1381 -#define EXT_NONE 0x2E
1382 -#define EXT_PARTIAL 0xFF
1383 -#define EXT_NUNCHUK 0x00
1384 -#define EXT_CLASSIC 0x01
1385 -#define EXT_BALANCE 0x2A
1386 -#define EXT_MOTIONPLUS 0x04
1387 +#define EXT_NONE 0x2E2E
1388 +#define EXT_PARTIAL 0xFFFF
1389 +#define EXT_NUNCHUK 0x0000
1390 +#define EXT_CLASSIC 0x0101
1391 +#define EXT_BALANCE 0x0402
1392 +#define EXT_MOTIONPLUS 0x0405
1393
1394 /* IR Enable blocks */
1395 -#define MARCAN_IR_BLOCK_1 "\x00\x00\x00\x00\x00\x00\x90\x00\xC0"
1396 -#define MARCAN_IR_BLOCK_2 "\x40\x00"
1397 -#define CLIFF_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\xAA\x00\x64"
1398 -#define CLIFF_IR_BLOCK_2 "\x63\x03"
1399 +#define MARCAN_IR_BLOCK_1 "\x00\x00\x00\x00\x00\x00\x90\x00\xC0"
1400 +#define MARCAN_IR_BLOCK_2 "\x40\x00"
1401 +#define CLIFF_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\xAA\x00\x64"
1402 +#define CLIFF_IR_BLOCK_2 "\x63\x03"
1403 +#define MAX_SENSITIVITY_IR_BLOCK_1 "\x00\x00\x00\x00\x00\x00\x90\x00\x41"
1404 +#define MAX_SENSITIVITY_IR_BLOCK_2 "\x40\x00"
1405 +#define WII_L1_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\x64\x00\xFE"
1406 +#define WII_L1_IR_BLOCK_2 "\xFD\x05"
1407 +#define WII_L2_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\x96\x00\xB4"
1408 +#define WII_L2_IR_BLOCK_2 "\xB3\x04"
1409 +#define WII_L3_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\xAA\x00\x64"
1410 +#define WII_L3_IR_BLOCK_2 "\x63\x03"
1411 +#define WII_L4_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\xC8\x00\x36"
1412 +#define WII_L4_IR_BLOCK_2 "\x35\x03"
1413 +#define WII_L5_IR_BLOCK_1 "\x02\x00\x00\x71\x01\x00\x72\x00\x20"
1414 +#define WII_L5_IR_BLOCK_2 "\x1F\x03"
1415
1416 /* Write Sequences */
1417 enum write_seq_type {
1418 @@ -188,6 +176,8 @@ struct wiimote {
1419 };
1420
1421 /* prototypes */
1422 +cwiid_wiimote_t *cwiid_new(int ctl_socket, int int_socket, int flags);
1423 +
1424 /* thread.c */
1425 void *router_thread(struct wiimote *wiimote);
1426 void *status_thread(struct wiimote *wiimote);
1427 Index: cwiid/libcwiid/interface.c
1428 ===================================================================
1429 --- cwiid.orig/libcwiid/interface.c
1430 +++ cwiid/libcwiid/interface.c
1431 @@ -1,4 +1,4 @@
1432 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1433 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1434 *
1435 * This program is free software; you can redistribute it and/or modify
1436 * it under the terms of the GNU General Public License as published by
1437 @@ -14,13 +14,6 @@
1438 * along with this program; if not, write to the Free Software
1439 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1440 *
1441 - * ChangeLog:
1442 - * 2007-05-14 L. Donnie Smith <[email protected]>
1443 - * * added timestamp to cwiid_get_mesg
1444 - * * added cwiid_get_acc_cal
1445 - *
1446 - * 2007-04-24 L. Donnie Smith <[email protected]>
1447 - * * created for API overhaul
1448 */
1449
1450 #include <errno.h>
1451 Index: cwiid/libcwiid/process.c
1452 ===================================================================
1453 --- cwiid.orig/libcwiid/process.c
1454 +++ cwiid/libcwiid/process.c
1455 @@ -1,4 +1,4 @@
1456 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1457 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1458 *
1459 * This program is free software; you can redistribute it and/or modify
1460 * it under the terms of the GNU General Public License as published by
1461 @@ -14,12 +14,6 @@
1462 * along with this program; if not, write to the Free Software
1463 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1464 *
1465 - * ChangeLog:
1466 - * 2007-05-16 L. Donnie Smith <[email protected]>
1467 - * * process_err adds error_mesg to mesg_array
1468 - *
1469 - * 2007-04-24 L. Donnie Smith <[email protected]>
1470 - * * created for API overhaul (moved from old event.c)
1471 */
1472
1473 #include <unistd.h>
1474 @@ -239,6 +233,7 @@ int process_ext(struct wiimote *wiimote,
1475 balance_mesg->left_bottom = ((uint16_t)data[6]<<8 |
1476 (uint16_t)data[7]);
1477 }
1478 + break;
1479 case CWIID_EXT_MOTIONPLUS:
1480 if (wiimote->state.rpt_mode & CWIID_RPT_MOTIONPLUS) {
1481 motionplus_mesg = &ma->array[ma->count++].motionplus_mesg;
1482 @@ -249,6 +244,9 @@ int process_ext(struct wiimote *wiimote,
1483 (uint16_t)data[1];
1484 motionplus_mesg->angle_rate[CWIID_PSI] = ((uint16_t)data[3] & 0xFC)<<6 |
1485 (uint16_t)data[0];
1486 + motionplus_mesg->low_speed[CWIID_PHI] = ((uint8_t)data[3] & 0x01);
1487 + motionplus_mesg->low_speed[CWIID_THETA] = ((uint8_t)data[4] & 0x02)>>1;
1488 + motionplus_mesg->low_speed[CWIID_PSI] = ((uint8_t)data[3] & 0x02)>>1;
1489 }
1490 break;
1491 }
1492 Index: cwiid/libcwiid/state.c
1493 ===================================================================
1494 --- cwiid.orig/libcwiid/state.c
1495 +++ cwiid/libcwiid/state.c
1496 @@ -1,4 +1,4 @@
1497 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1498 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1499 *
1500 * This program is free software; you can redistribute it and/or modify
1501 * it under the terms of the GNU General Public License as published by
1502 @@ -14,9 +14,6 @@
1503 * along with this program; if not, write to the Free Software
1504 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1505 *
1506 - * ChangeLog:
1507 - * 2007-04-24 L. Donnie Smith <[email protected]>
1508 - * * created for API overhaul (update_rpt_mode moved from command.c)
1509 */
1510
1511 #include <string.h>
1512 @@ -85,6 +82,9 @@ int update_state(struct wiimote *wiimote
1513 memcpy(wiimote->state.ext.motionplus.angle_rate,
1514 mesg->motionplus_mesg.angle_rate,
1515 sizeof wiimote->state.ext.motionplus.angle_rate);
1516 + memcpy(wiimote->state.ext.motionplus.low_speed,
1517 + mesg->motionplus_mesg.low_speed,
1518 + sizeof wiimote->state.ext.motionplus.low_speed);
1519 break;
1520 case CWIID_MESG_ERROR:
1521 wiimote->state.error = mesg->error_mesg.error;
1522 @@ -105,8 +105,8 @@ int update_state(struct wiimote *wiimote
1523 }
1524
1525 /* IR Sensitivity Block */
1526 -unsigned char ir_block1[] = CLIFF_IR_BLOCK_1;
1527 -unsigned char ir_block2[] = CLIFF_IR_BLOCK_2;
1528 +unsigned char ir_block1[] = MAX_SENSITIVITY_IR_BLOCK_1;
1529 +unsigned char ir_block2[] = MAX_SENSITIVITY_IR_BLOCK_2;
1530
1531 struct write_seq ir_enable10_seq[] = {
1532 {WRITE_SEQ_RPT, RPT_IR_ENABLE1, (const void *)"\x04", 1, 0},
1533 Index: cwiid/libcwiid/thread.c
1534 ===================================================================
1535 --- cwiid.orig/libcwiid/thread.c
1536 +++ cwiid/libcwiid/thread.c
1537 @@ -1,4 +1,4 @@
1538 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1539 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1540 *
1541 * This program is free software; you can redistribute it and/or modify
1542 * it under the terms of the GNU General Public License as published by
1543 @@ -14,41 +14,6 @@
1544 * along with this program; if not, write to the Free Software
1545 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1546 *
1547 - * ChangeLog:
1548 - * 2007-05-16 L. Donnie Smith <[email protected]>
1549 - * * send error_mesg from process_error
1550 - *
1551 - * 2007-05-14 L. Donnie Smith <[email protected]>
1552 - * * added timestamp to message array
1553 - *
1554 - * 2007-04-24 L. Donnie Smith <[email protected]>
1555 - * * rewrite for API overhaul (renamed from event.c)
1556 - *
1557 - * 2007-04-09 L. Donnie Smith <[email protected]>
1558 - * * renamed wiimote to libcwiid, renamed structures accordingly
1559 - *
1560 - * 2007-04-08 L. Donnie Smith <[email protected]>
1561 - * * fixed incompatible pointer warning in process_error
1562 - *
1563 - * 2007-04-08 Petter Reinholdtsen <[email protected]>
1564 - * * fixed signed/unsigned comparison error in int_listen
1565 - *
1566 - * 2007-04-04 L. Donnie Smith <[email protected]>
1567 - * * implemented process_error to handle socket read errors
1568 - * * added rw_status triggers to read and write handlers
1569 - *
1570 - * 2007-03-14 L. Donnie Smith <[email protected]>
1571 - * * audit error checking
1572 - * * reorganized file
1573 - * * moved int_listen read/write code to process_read and process_write
1574 - * * updated (some/a few) comments
1575 - *
1576 - * 2007-03-06 L. Donnie Smith <[email protected]>
1577 - * * added wiimote parameter to cwiid_err calls
1578 - *
1579 - * 2007-03-01 L. Donnie Smith <[email protected]>
1580 - * * Initial ChangeLog
1581 - * * type audit (stdint, const, char booleans)
1582 */
1583
1584 #include <stdint.h>
1585 @@ -196,13 +161,13 @@ void *status_thread(struct wiimote *wiim
1586
1587 if (status_mesg->ext_type == CWIID_EXT_UNKNOWN) {
1588 /* Read extension ID */
1589 - if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 1, &buf[0])) {
1590 + if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 2, &buf)) {
1591 cwiid_err(wiimote, "Read error (extension error)");
1592 status_mesg->ext_type = CWIID_EXT_UNKNOWN;
1593 }
1594 /* If the extension didn't change, or if the extension is a
1595 * MotionPlus, no init necessary */
1596 - switch (buf[0]) {
1597 + switch ((buf[0] << 8) | buf[1]) {
1598 case EXT_NONE:
1599 status_mesg->ext_type = CWIID_EXT_NONE;
1600 break;
1601 @@ -232,12 +197,12 @@ void *status_thread(struct wiimote *wiim
1602 status_mesg->ext_type = CWIID_EXT_UNKNOWN;
1603 }
1604 /* Read extension ID */
1605 - else if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 1, &buf[0])) {
1606 + else if (cwiid_read(wiimote, CWIID_RW_REG, 0xA400FE, 2, &buf)) {
1607 cwiid_err(wiimote, "Read error (extension error)");
1608 status_mesg->ext_type = CWIID_EXT_UNKNOWN;
1609 }
1610 else {
1611 - switch (buf[0]) {
1612 + switch ((buf[0] << 8) | buf[1]) {
1613 case EXT_NONE:
1614 case EXT_PARTIAL:
1615 status_mesg->ext_type = CWIID_EXT_NONE;
1616 Index: cwiid/libcwiid/util.c
1617 ===================================================================
1618 --- cwiid.orig/libcwiid/util.c
1619 +++ cwiid/libcwiid/util.c
1620 @@ -1,4 +1,4 @@
1621 -/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1622 +/* Copyright (C) 2007 L. Donnie Smith <[email protected]>
1623 *
1624 * This program is free software; you can redistribute it and/or modify
1625 * it under the terms of the GNU General Public License as published by
1626 @@ -14,38 +14,6 @@
1627 * along with this program; if not, write to the Free Software
1628 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1629 *
1630 - * ChangeLog:
1631 - * 2008-08-14 L. Donnie Smith <[email protected]>
1632 - * * make cwiid_err_default public
1633 - * * clean up cwiid_err
1634 - *
1635 - * 2007-04-24 L. Donnie Smith <[email protected]>
1636 - * * rewrite for API overhaul
1637 - *
1638 - * 2007-04-09 L. Donnie Smith <[email protected]>
1639 - * * renamed wiimote to libcwiid, renamed structures accordingly
1640 - *
1641 - * 2007-04-08 Petter Reinholdtsen <[email protected]>
1642 - * * fixed signed/unsigned comparison warning in send_report and
1643 - * exec_write_seq
1644 - *
1645 - * 2007-04-01 L. Donnie Smith <[email protected]>
1646 - * * removed cwiid_findfirst (moved to bluetooth.c)
1647 - *
1648 - * 2007-03-27 L. Donnie Smith <[email protected]>
1649 - * * moved cwiid_findfirst to bluetooth.c
1650 - *
1651 - * 2007-03-14 L. Donnie Smith <[email protected]>
1652 - * * audited error checking (coda and error handler sections)
1653 - *
1654 - * 2007-03-05 L. Donnie Smith <[email protected]>
1655 - * * created cwiid_err_func variable
1656 - * * created cwiid_err_default
1657 - * * added wiimote parameter to cwiid_err definition and calls
1658 - *
1659 - * 2007-03-01 L. Donnie Smith <[email protected]>
1660 - * * Initial ChangeLog
1661 - * * type audit (stdint, const, char booleans)
1662 */
1663
1664 #include <errno.h>