Changeset 123 for branches/dev
- Timestamp:
- 06/05/07 19:07:48 (2 years ago)
- Files:
-
- branches/dev/ChangeLog (modified) (1 diff)
- branches/dev/python/Makefile.in (modified) (1 diff)
- branches/dev/python/Wiimote.c (modified) (10 diffs)
- branches/dev/python/cwiidmodule.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dev/ChangeLog
r120 r123 1 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 2 python 3 * removed Wiimote_FromC function 4 * added bdaddr argument to Wiimote.init 5 * overloaded Wiimote.init to accept CObject (existing wiimote), 6 and logic to avoid closing it on dealloc 7 1 8 2007-06-01 Nick <nickishappy@gmail.com> 2 9 lswm branches/dev/python/Makefile.in
r119 r123 18 18 19 19 clean: 20 rm -r build20 rm -rf build 21 21 22 22 distclean: clean branches/dev/python/Wiimote.c
r119 r123 20 20 * 21 21 * ChangeLog: 22 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 23 * * removed Wiimote_FromC function 24 * * added bdaddr argument to Wiimote.init 25 * * overloaded Wiimote.init to accept CObject (existing wiimote), 26 * and logic to avoid closing it on dealloc 27 * 22 28 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 23 29 * * added Wiimote_FromC … … 46 52 #include "structmember.h" 47 53 #include <errno.h> 54 #include <bluetooth/bluetooth.h> 48 55 #include "cwiid.h" 49 56 … … 52 59 cwiid_wiimote_t *wiimote; 53 60 PyObject *callback; 61 char close_on_dealloc; 54 62 } Wiimote; 55 63 … … 85 93 static cwiid_mesg_callback_t CallbackBridge; 86 94 PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]); 87 PyObject *Wiimote_FromC(cwiid_wiimote_t *wiimote);88 static int cwiid_start(Wiimote *self, int flags);89 95 90 96 static PyMethodDef Wiimote_Methods[] = … … 174 180 self->wiimote = NULL; 175 181 Py_INCREF(self->callback = Py_None); 182 self->close_on_dealloc = 0; 176 183 177 184 return (PyObject*) self; … … 180 187 static void Wiimote_dealloc(Wiimote *self) 181 188 { 182 if (self-> wiimote) {189 if (self->close_on_dealloc && self->wiimote) { 183 190 cwiid_close(self->wiimote); 184 191 } … … 190 197 { 191 198 cwiid_wiimote_t *wiimote; 192 bdaddr_t bdaddr = *BDADDR_ANY;193 199 194 200 /* Set up wiimote */ 195 if(!(wiimote = cwiid_open(&bdaddr, flags))) {196 PyErr_SetString(PyExc_IOError, "Could not open wiimote");197 return -1;198 }199 201 200 202 /* keep pyobject with wiimote */ … … 207 209 static int Wiimote_init(Wiimote* self, PyObject* args, PyObject *kwds) 208 210 { 209 static char *kwlist[] = {"flags", NULL}; 211 static char *kwlist[] = {"bdaddr", "flags", NULL}; 212 PyObject *PyObj; 213 cwiid_wiimote_t *wiimote = NULL; 214 char *str_bdaddr = NULL; 215 bdaddr_t bdaddr; 210 216 int flags = 0; 211 217 212 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:cwiid.Wiimote.init", 213 kwlist, &flags)) { 214 return -1; 215 } 216 217 if (cwiid_start(self, flags)) { 218 return -1; 219 } 220 218 /* Overloaded function - if a single CObject is passed in, it's 219 * an existing CObject. Otherwise, create a new one */ 220 if (PyTuple_Size(args) == 1) { 221 PyObj = PyTuple_GET_ITEM(args, 0); 222 if (PyCObject_Check(PyObj)) { 223 wiimote = PyCObject_AsVoidPtr(PyObj); 224 self->close_on_dealloc = 0; 225 } 226 } 227 228 if (!wiimote) { 229 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|si:cwiid.Wiimote.init", 230 kwlist, &str_bdaddr, &flags)) { 231 return -1; 232 } 233 234 if (str_bdaddr) { 235 if (str2ba(str_bdaddr, &bdaddr)) { 236 PyErr_SetString(PyExc_IOError, "bad bdaddr"); 237 return -1; 238 } 239 } 240 else { 241 bdaddr = *BDADDR_ANY; 242 } 243 244 if (!(wiimote = cwiid_open(&bdaddr, flags))) { 245 PyErr_SetString(PyExc_IOError, "Could not open wiimote"); 246 return -1; 247 } 248 else { 249 self->close_on_dealloc = 1; 250 } 251 } 252 253 cwiid_set_data(wiimote, self); 254 self->wiimote = wiimote; 221 255 return 0; 222 256 } … … 668 702 } 669 703 670 PyObject *Wiimote_FromC(cwiid_wiimote_t *wiimote)671 {672 Wiimote *PyWiimote;673 674 if (!(PyWiimote = (Wiimote *)PyObject_CallMethod((PyObject *)&Wiimote_Type,675 "__new__", "(O)",676 &Wiimote_Type))) {677 return NULL;678 }679 680 cwiid_set_data(wiimote, PyWiimote);681 PyWiimote->wiimote = wiimote;682 683 return (PyObject *)PyWiimote;684 }685 686 704 /* This is the function responsible for marshaling the cwiid messages from 687 705 * C to python. It's rather complicated since it uses a complex C union … … 694 712 * 695 713 * Ex: 696 * mesgs =>[( CWIID_STATUS_MESG,{"battery":battery,"ext_type":ext_type}),697 * ( CWIID_BTN_MESG,buttons),698 * ( CWIID_ACC_MESG,(x,y,z)),699 * ( CWIID_IR_MESG,[{"pos":(x,y),"size":size}, ...]),700 * ( CWIID_NUNCHUK_MESG,{"stick":(x,y),"acc":(x,y,z),714 * mesgs =>[(cwiid.STATUS_MESG,{"battery":battery,"ext_type":ext_type}), 715 * (cwiid.BTN_MESG,buttons), 716 * (cwiid.ACC_MESG,(x,y,z)), 717 * (cwiid.IR_MESG,[{"pos":(x,y),"size":size}, ...]), 718 * (cwiid.NUNCHUK_MESG,{"stick":(x,y),"acc":(x,y,z), 701 719 * "buttons":buttons}, 702 * ( CWIID_CLASSIC_MESG,{"l_stick":(x,y),"r_stick":(x,y),"l":l,"r":r,720 * (cwiid.CLASSIC_MESG,{"l_stick":(x,y),"r_stick":(x,y),"l":l,"r":r, 703 721 * "buttons":buttons}, 704 * ( CWIID_ERROR_MESG,error)]722 * (cwiid.ERROR_MESG,error)] 705 723 */ 706 724 PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]) branches/dev/python/cwiidmodule.c
r118 r123 20 20 * 21 21 * ChangeLog: 22 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 23 * * removed Wiimote_FromC function 24 * 22 25 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 23 26 * * added CObjects for Wiimote_FromC and ConvertMesgArray … … 74 77 extern PyTypeObject Wiimote_Type; 75 78 extern PyObject *ConvertMesgArray(int, union cwiid_mesg []); 76 extern PyObject *Wiimote_FromC(cwiid_wiimote_t *);77 79 78 80 /* cwiid module initializer */ … … 200 202 } 201 203 PyModule_AddObject(Module, "ConvertMesgArray", CObj); 202 203 if (!(CObj = PyCObject_FromVoidPtr(Wiimote_FromC, NULL))) {204 return;205 }206 PyModule_AddObject(Module, "Wiimote_FromC", CObj);207 204 } 208 205
