Changeset 117 for branches/cwiidpy

Show
Ignore:
Timestamp:
05/22/07 16:57:41 (2 years ago)
Author:
dsmith
Message:

more cwiidpy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cwiidpy/Makefile

    r114 r117  
    88 
    99LDLIBS += -lcwiid 
    10 CFLAGS = -fpic -Wall -g -I/usr/include/python2.4 
     10CFLAGS = -fpic -W -Wall -g -I/usr/include/python2.4 
    1111LDFLAGS = -shared -fpic 
    1212 
  • branches/cwiidpy/Wiimote.c

    r114 r117  
    2020 * 
    2121 * ChangeLog: 
     22 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 
     23 * * changed disconnect to close 
     24 * * replaced command with attributes for rpt_mode, rumble, led, 
     25 *   added request_status method 
     26 * * fixed memory leak in get_mesg 
     27 * * added function names to argument parsing errors 
     28 * 
    2229 * 2007-05-15 L. Donnie Smith <cwiid@abstrakraft.org> 
    2330 * * revised message types 
     
    4451static void Wiimote_dealloc(Wiimote *self); 
    4552static int Wiimote_init(Wiimote *self, PyObject *args, PyObject *kwds); 
    46 static PyObject *Wiimote_disconnect(Wiimote *self); 
    47 static PyObject * 
    48        Wiimote_enable(Wiimote *self, PyObject *args, PyObject *kwds); 
     53static PyObject *Wiimote_close(Wiimote *self); 
     54 
     55static PyObject *Wiimote_enable(Wiimote *self, PyObject *args, PyObject *kwds); 
    4956static PyObject * 
    5057        Wiimote_disable(Wiimote *self, PyObject *args, PyObject *kwds); 
    51 static PyObject * 
    52         Wiimote_set_mesg_callback(Wiimote *self, PyObject *args, PyObject *kwds); 
     58 
     59static int 
     60        Wiimote_set_mesg_callback(Wiimote *self, PyObject *args, void *closure); 
    5361static PyObject *Wiimote_get_mesg(Wiimote *self); 
    5462static PyObject *Wiimote_get_state(Wiimote *self, void *closure); 
    55 static PyObject * 
    56         Wiimote_command(Wiimote *self, PyObject *args, PyObject *kwds); 
     63 
     64static PyObject *Wiimote_request_status(Wiimote *self); 
     65static int Wiimote_set_led(Wiimote *self, PyObject *PyLed, void *closure); 
     66static int 
     67        Wiimote_set_rumble(Wiimote *self, PyObject *PyRumble, void *closure); 
     68static int 
     69        Wiimote_set_rpt_mode(Wiimote *self, PyObject *PyRptMode, void *closure); 
     70 
    5771static PyObject *Wiimote_read(Wiimote *self, PyObject *args, PyObject *kwds); 
    5872static PyObject *Wiimote_write(Wiimote *self, PyObject *args, PyObject *kwds); 
     
    6579static PyMethodDef Wiimote_Methods[] = 
    6680{ 
    67         {"disconnect", (PyCFunction)Wiimote_disconnect, METH_NOARGS, 
    68          "disconnect wiimote"}, 
     81        {"close", (PyCFunction)Wiimote_close, METH_NOARGS, 
     82         "close wiimote connection"}, 
    6983        {"enable", (PyCFunction)Wiimote_enable, METH_VARARGS | METH_KEYWORDS, 
    7084         "enable flags on wiimote"}, 
     
    7589        {"get_mesg", (PyCFunction)Wiimote_get_mesg, METH_NOARGS, 
    7690         "blocking call to get messages"}, 
    77         {"command", (PyCFunction)Wiimote_command, METH_VARARGS | METH_KEYWORDS, 
    78          "send wiimote command"}, 
     91        {"request_status", (PyCFunction)Wiimote_request_status, METH_NOARGS, 
     92         "request status message"}, 
    7993        {"read", (PyCFunction)Wiimote_read, METH_VARARGS | METH_KEYWORDS, 
    8094         "read from wiimote"}, 
    8195        {"write", (PyCFunction)Wiimote_write, METH_VARARGS | METH_KEYWORDS, 
    8296         "write to wiimote"}, 
    83         {NULL, NULL
     97        {NULL, NULL, 0, NULL
    8498}; 
    8599 
    86100static PyGetSetDef Wiimote_GetSet[] = { 
    87101        {"state", (getter)Wiimote_get_state, NULL, "Wiimote state", NULL}, 
    88         {NULL} 
     102        {"mesg_callback", NULL, (setter)Wiimote_set_mesg_callback, 
     103         "Wiimote message callback", NULL}, 
     104        {"led", NULL, (setter)Wiimote_set_led, "Wiimote led state", NULL}, 
     105        {"rumble", NULL, (setter)Wiimote_set_rumble, "Wiimote rumble state", NULL}, 
     106        {"rpt_mode", NULL, (setter)Wiimote_set_rpt_mode, "Wiimote report mode", 
     107         NULL}, 
     108        {NULL, NULL, NULL, NULL, NULL} 
    89109}; 
    90110 
     
    150170{ 
    151171        if (self->wiimote) { 
    152                 cwiid_disconnect(self->wiimote); 
     172                cwiid_close(self->wiimote); 
    153173        } 
    154174        Py_XDECREF(self->callback); 
     
    162182 
    163183        /* Set up wiimote */ 
    164         if(!(wiimote = cwiid_connect(&bdaddr, flags))) { 
    165                 PyErr_SetString(PyExc_IOError, "Could not connect to wiimote"); 
     184        if(!(wiimote = cwiid_open(&bdaddr, flags))) { 
     185                PyErr_SetString(PyExc_IOError, "Could not open wiimote"); 
    166186                return -1; 
    167187        } 
     
    176196static int Wiimote_init(Wiimote* self, PyObject* args, PyObject *kwds) 
    177197{ 
    178         static char *kwlist[] = { "flags", NULL }; 
     198        static char *kwlist[] = {"flags", NULL}; 
    179199        int flags = 0; 
    180200 
    181         if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist, &flags)) { 
     201        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:cwiid.Wiimote.init", 
     202                                         kwlist, &flags)) { 
    182203                return -1; 
    183204        } 
     
    190211} 
    191212 
    192 static PyObject *Wiimote_disconnect(Wiimote *self) 
    193 { 
    194         if (cwiid_disconnect(self->wiimote)) { 
    195                 PyErr_SetString(PyExc_IOError, "Wiimote disconnect error"); 
     213static PyObject *Wiimote_close(Wiimote *self) 
     214{ 
     215        if (cwiid_close(self->wiimote)) { 
     216                PyErr_SetString(PyExc_IOError, "Wiimote close error"); 
    196217                self->wiimote = NULL; 
    197218                return NULL; 
     
    204225static PyObject *Wiimote_enable(Wiimote *self, PyObject *args, PyObject *kwds) 
    205226{ 
    206         static char *kwlist[] = { "flags", NULL }; 
     227        static char *kwlist[] = {"flags", NULL}; 
    207228        int flags; 
    208229 
    209         if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &flags)) { 
     230        if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:cwiid.Wiimote.enable", 
     231                                         kwlist, &flags)) { 
    210232                return NULL; 
    211233        } 
     
    221243static PyObject *Wiimote_disable(Wiimote *self, PyObject *args, PyObject *kwds) 
    222244{ 
    223         static char *kwlist[] = { "flags", NULL }; 
     245        static char *kwlist[] = {"flags", NULL}; 
    224246        int flags; 
    225247 
    226         if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &flags)) { 
     248        if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:cwiid.Wiimote.disable", 
     249                                         kwlist, &flags)) { 
    227250                return NULL; 
    228251        } 
     
    236259} 
    237260 
    238 static PyObject * 
    239         Wiimote_set_mesg_callback(Wiimote *self, PyObject *args, PyObject *kwds) 
    240 
    241         static char *kwlist[] = { "callback", NULL }; 
    242         PyObject *NewCallback, *OldCallback; 
    243  
    244         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &NewCallback)) { 
    245                 return NULL; 
    246         } 
     261static int 
     262        Wiimote_set_mesg_callback(Wiimote *self, PyObject *NewCallback, 
     263                                  void *closure) 
     264
     265        PyObject *OldCallback; 
     266 
    247267        if (!PyCallable_Check(NewCallback)) { 
    248268                PyErr_SetString(PyExc_TypeError, "callback must be callable!"); 
     
    253273                if (cwiid_set_mesg_callback(self->wiimote, callbackBridge)) { 
    254274                        PyErr_SetString(PyExc_IOError, "set callback error"); 
    255                         return NULL
     275                        return -1
    256276                } 
    257277        } 
     
    259279                if (cwiid_set_mesg_callback(self->wiimote, NULL)) { 
    260280                        PyErr_SetString(PyExc_IOError, "set callback error"); 
    261                         return NULL
     281                        return -1
    262282                } 
    263283        } 
     
    267287        self->callback = NewCallback; 
    268288 
    269         Py_RETURN_NONE
     289        return 0
    270290} 
    271291 
     
    275295        int mesg_count; 
    276296        struct timespec t; 
     297        PyObject *PyMesg; 
    277298 
    278299        if (cwiid_get_mesg(self->wiimote, &mesg_count, &mesg, &t)) { 
     
    286307        } 
    287308 
    288         return processMesgs(mesg_count, mesg); 
     309        PyMesg = processMesgs(mesg_count, mesg); 
     310 
     311        free(mesg); 
     312 
     313        return PyMesg; 
    289314} 
    290315 
     
    456481} 
    457482 
    458 static PyObject *Wiimote_command(Wiimote *self, PyObject *args, PyObject *kwds) 
     483static PyObject *Wiimote_request_status(Wiimote *self) 
     484
     485        if (cwiid_request_status(self->wiimote)) { 
     486                PyErr_SetString(PyExc_IOError, "Wiimote request status error"); 
     487                return NULL; 
     488        } 
     489 
     490        Py_RETURN_NONE; 
     491
     492 
     493static int Wiimote_set_led(Wiimote *self, PyObject *PyLed, void *closure) 
     494
     495        long led; 
     496 
     497        if (((led = PyInt_AsLong(PyLed)) == -1) && PyErr_Occurred()) { 
     498                return -1; 
     499        } 
     500 
     501        if (cwiid_set_led(self->wiimote, (uint8_t)led)) { 
     502                PyErr_SetString(PyExc_IOError, "Wiimote set led error"); 
     503                return -1; 
     504        } 
     505 
     506        return 0; 
     507
     508 
     509static int 
     510        Wiimote_set_rumble(Wiimote *self, PyObject *PyRumble, void *closure) 
     511
     512        long rumble; 
     513 
     514        if (((rumble = PyInt_AsLong(PyRumble)) == -1) && PyErr_Occurred()) { 
     515                return -1; 
     516        } 
     517 
     518        if (cwiid_set_rumble(self->wiimote, (uint8_t)rumble)) { 
     519                PyErr_SetString(PyExc_IOError, "Wiimote set rumble error"); 
     520                return -1; 
     521        } 
     522 
     523        return 0; 
     524
     525 
     526static int 
     527        Wiimote_set_rpt_mode(Wiimote *self, PyObject *PyRptMode, void *closure) 
     528
     529        long rpt_mode; 
     530 
     531        if (((rpt_mode = PyInt_AsLong(PyRptMode)) == -1) && PyErr_Occurred()) { 
     532                return -1; 
     533        } 
     534 
     535        if (cwiid_set_rpt_mode(self->wiimote, (uint8_t)rpt_mode)) { 
     536                PyErr_SetString(PyExc_IOError, "Wiimote set rpt_mode error"); 
     537                return -1; 
     538        } 
     539 
     540        return 0; 
     541
     542 
     543/* static PyObject *Wiimote_command(Wiimote *self, PyObject *args, PyObject *kwds) 
    459544{ 
    460545        static char *kwlist[] = { "command", "flags", NULL }; 
     
    470555        Py_RETURN_NONE; 
    471556} 
     557*/ 
    472558 
    473559static PyObject *Wiimote_read(Wiimote *self, PyObject *args, PyObject *kwds) 
     
    480566        PyObject *pyRetBuf; 
    481567 
    482         if (!PyArg_ParseTupleAndKeywords(args, kwds, "BII", kwlist, &flags
    483                                          &offset, &len)) { 
     568        if (!PyArg_ParseTupleAndKeywords(args, kwds, "BII:cwiid.Wiimote.read"
     569                                         kwlist, &flags, &offset, &len)) { 
    484570                return NULL; 
    485571        } 
     
    509595        int len; 
    510596 
    511         if (!PyArg_ParseTupleAndKeywords(args, kwds, "BIt#", kwlist, &flags
    512                                          &offset, &buf, &len)) { 
     597        if (!PyArg_ParseTupleAndKeywords(args, kwds, "BIt#:cwiid.Wiimote.write"
     598                                         kwlist, &flags, &offset, &buf, &len)) { 
    513599                return NULL; 
    514600        } 
     
    526612                       union cwiid_mesg mesg[], struct timespec *t) 
    527613{ 
    528         PyObject *argTuple; 
    529         PyObject *pyself; 
    530         /* PyObject *pyCallback; */ 
     614        PyObject *ArgTuple; 
     615        PyObject *PySelf; 
    531616        PyGILState_STATE gstate; 
    532617 
    533618        gstate = PyGILState_Ensure(); 
    534619 
    535         argTuple = processMesgs(mesg_count, mesg); 
     620        ArgTuple = processMesgs(mesg_count, mesg); 
    536621 
    537622        /* Put id and the list of messages as the arguments to the callback */ 
    538         pyself = (PyObject *) cwiid_get_data(wiimote); 
    539         PyObject_CallFunction(((Wiimote *)pyself)->callback, "(O)",argTuple); 
    540  
    541         Py_XDECREF(argTuple); 
     623        PySelf = (PyObject *) cwiid_get_data(wiimote); 
     624        PyObject_CallFunction(((Wiimote *)PySelf)->callback, "(O)", ArgTuple); 
     625 
     626        Py_XDECREF(ArgTuple); 
    542627        PyGILState_Release(gstate); 
    543628} 
  • branches/cwiidpy/cwiidmodule.c

    r114 r117  
    2020 * 
    2121 * ChangeLog: 
     22 * 2007-05-22 L. Donnie Smith <cwiid@abstrakraft.org> 
     23 * * clarified variable names 
     24 * 
    2225 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    2326 * * moved Wiimote class to separate files 
     
    7174PyMODINIT_FUNC initcwiid(void); 
    7275 
    73 /* CWiid constants, enumerations */ 
    74 #define CONST_MACRO(a) {#a, CWIID_##a} 
     76/* constants, enumerations */ 
     77#define CWIID_CONST_MACRO(a) {#a, CWIID_##a} 
    7578static struct { 
    7679        char *name; 
    7780        int value; 
    7881} cwiid_constants[] = { 
    79         CONST_MACRO(FLAG_MESG_IFC), 
    80         CONST_MACRO(FLAG_CONTINUOUS), 
    81         CONST_MACRO(FLAG_REPEAT_BTN), 
    82         CONST_MACRO(FLAG_NONBLOCK), 
    83         CONST_MACRO(RPT_STATUS), 
    84         CONST_MACRO(RPT_BTN), 
    85         CONST_MACRO(RPT_ACC), 
    86         CONST_MACRO(RPT_IR), 
    87         CONST_MACRO(RPT_NUNCHUK), 
    88         CONST_MACRO(RPT_CLASSIC), 
    89         CONST_MACRO(RPT_EXT), 
    90         CONST_MACRO(LED1_ON), 
    91         CONST_MACRO(LED2_ON), 
    92         CONST_MACRO(LED3_ON), 
    93         CONST_MACRO(LED4_ON), 
    94         CONST_MACRO(BTN_2), 
    95         CONST_MACRO(BTN_1), 
    96         CONST_MACRO(BTN_B), 
    97         CONST_MACRO(BTN_A), 
    98         CONST_MACRO(BTN_MINUS), 
    99         CONST_MACRO(BTN_HOME), 
    100         CONST_MACRO(BTN_LEFT), 
    101         CONST_MACRO(BTN_RIGHT), 
    102         CONST_MACRO(BTN_DOWN), 
    103         CONST_MACRO(BTN_UP), 
    104         CONST_MACRO(BTN_PLUS), 
    105         CONST_MACRO(NUNCHUK_BTN_Z), 
    106         CONST_MACRO(NUNCHUK_BTN_C), 
    107         CONST_MACRO(CLASSIC_BTN_UP), 
    108         CONST_MACRO(CLASSIC_BTN_LEFT), 
    109         CONST_MACRO(CLASSIC_BTN_ZR), 
    110         CONST_MACRO(CLASSIC_BTN_X), 
    111         CONST_MACRO(CLASSIC_BTN_A), 
    112         CONST_MACRO(CLASSIC_BTN_Y), 
    113         CONST_MACRO(CLASSIC_BTN_B), 
    114         CONST_MACRO(CLASSIC_BTN_ZL), 
    115         CONST_MACRO(CLASSIC_BTN_R), 
    116         CONST_MACRO(CLASSIC_BTN_PLUS), 
    117         CONST_MACRO(CLASSIC_BTN_HOME), 
    118         CONST_MACRO(CLASSIC_BTN_MINUS), 
    119         CONST_MACRO(CLASSIC_BTN_L), 
    120         CONST_MACRO(CLASSIC_BTN_DOWN), 
    121         CONST_MACRO(CLASSIC_BTN_RIGHT), 
    122         CONST_MACRO(RW_EEPROM), 
    123         CONST_MACRO(RW_REG), 
    124         CONST_MACRO(RW_DECODE), 
    125         CONST_MACRO(MAX_READ_LEN), 
    126         CONST_MACRO(X), 
    127         CONST_MACRO(Y), 
    128         CONST_MACRO(Z), 
    129         CONST_MACRO(IR_SRC_COUNT), 
    130         CONST_MACRO(IR_X_MAX), 
    131         CONST_MACRO(IR_Y_MAX), 
    132         CONST_MACRO(BATTERY_MAX), 
    133         CONST_MACRO(CLASSIC_L_STICK_MAX), 
    134         CONST_MACRO(CLASSIC_R_STICK_MAX), 
    135         CONST_MACRO(CLASSIC_LR_MAX), 
    136         CONST_MACRO(CMD_STATUS), 
    137         CONST_MACRO(CMD_LED), 
    138         CONST_MACRO(CMD_RUMBLE), 
    139         CONST_MACRO(CMD_RPT_MODE), 
    140         CONST_MACRO(MESG_STATUS), 
    141         CONST_MACRO(MESG_BTN), 
    142         CONST_MACRO(MESG_ACC), 
    143         CONST_MACRO(MESG_IR), 
    144         CONST_MACRO(MESG_NUNCHUK), 
    145         CONST_MACRO(MESG_CLASSIC), 
    146         CONST_MACRO(MESG_ERROR), 
    147         CONST_MACRO(MESG_UNKNOWN), 
    148         CONST_MACRO(EXT_NONE), 
    149         CONST_MACRO(EXT_NUNCHUK), 
    150         CONST_MACRO(EXT_CLASSIC), 
    151         CONST_MACRO(EXT_UNKNOWN), 
    152         CONST_MACRO(ERROR_DISCONNECT), 
    153         CONST_MACRO(ERROR_COMM), 
     82        CWIID_CONST_MACRO(FLAG_MESG_IFC), 
     83        CWIID_CONST_MACRO(FLAG_CONTINUOUS), 
     84        CWIID_CONST_MACRO(FLAG_REPEAT_BTN), 
     85        CWIID_CONST_MACRO(FLAG_NONBLOCK), 
     86        CWIID_CONST_MACRO(RPT_STATUS), 
     87        CWIID_CONST_MACRO(RPT_BTN), 
     88        CWIID_CONST_MACRO(RPT_ACC), 
     89        CWIID_CONST_MACRO(RPT_IR), 
     90        CWIID_CONST_MACRO(RPT_NUNCHUK), 
     91        CWIID_CONST_MACRO(RPT_CLASSIC), 
     92        CWIID_CONST_MACRO(RPT_EXT), 
     93        CWIID_CONST_MACRO(LED1_ON), 
     94        CWIID_CONST_MACRO(LED2_ON), 
     95        CWIID_CONST_MACRO(LED3_ON), 
     96        CWIID_CONST_MACRO(LED4_ON), 
     97        CWIID_CONST_MACRO(BTN_2), 
     98        CWIID_CONST_MACRO(BTN_1), 
     99        CWIID_CONST_MACRO(BTN_B), 
     100        CWIID_CONST_MACRO(BTN_A), 
     101        CWIID_CONST_MACRO(BTN_MINUS), 
     102        CWIID_CONST_MACRO(BTN_HOME), 
     103        CWIID_CONST_MACRO(BTN_LEFT), 
     104        CWIID_CONST_MACRO(BTN_RIGHT), 
     105        CWIID_CONST_MACRO(BTN_DOWN), 
     106        CWIID_CONST_MACRO(BTN_UP), 
     107        CWIID_CONST_MACRO(BTN_PLUS), 
     108        CWIID_CONST_MACRO(NUNCHUK_BTN_Z), 
     109        CWIID_CONST_MACRO(NUNCHUK_BTN_C), 
     110        CWIID_CONST_MACRO(CLASSIC_BTN_UP), 
     111        CWIID_CONST_MACRO(CLASSIC_BTN_LEFT), 
     112        CWIID_CONST_MACRO(CLASSIC_BTN_ZR), 
     113        CWIID_CONST_MACRO(CLASSIC_BTN_X), 
     114        CWIID_CONST_MACRO(CLASSIC_BTN_A), 
     115        CWIID_CONST_MACRO(CLASSIC_BTN_Y), 
     116        CWIID_CONST_MACRO(CLASSIC_BTN_B), 
     117        CWIID_CONST_MACRO(CLASSIC_BTN_ZL), 
     118        CWIID_CONST_MACRO(CLASSIC_BTN_R), 
     119        CWIID_CONST_MACRO(CLASSIC_BTN_PLUS), 
     120        CWIID_CONST_MACRO(CLASSIC_BTN_HOME), 
     121        CWIID_CONST_MACRO(CLASSIC_BTN_MINUS), 
     122        CWIID_CONST_MACRO(CLASSIC_BTN_L), 
     123        CWIID_CONST_MACRO(CLASSIC_BTN_DOWN), 
     124        CWIID_CONST_MACRO(CLASSIC_BTN_RIGHT), 
     125        CWIID_CONST_MACRO(RW_EEPROM), 
     126        CWIID_CONST_MACRO(RW_REG), 
     127        CWIID_CONST_MACRO(RW_DECODE), 
     128        CWIID_CONST_MACRO(MAX_READ_LEN), 
     129        CWIID_CONST_MACRO(X), 
     130        CWIID_CONST_MACRO(Y), 
     131        CWIID_CONST_MACRO(Z), 
     132        CWIID_CONST_MACRO(IR_SRC_COUNT), 
     133        CWIID_CONST_MACRO(IR_X_MAX), 
     134        CWIID_CONST_MACRO(IR_Y_MAX), 
     135        CWIID_CONST_MACRO(BATTERY_MAX), 
     136        CWIID_CONST_MACRO(CLASSIC_L_STICK_MAX), 
     137        CWIID_CONST_MACRO(CLASSIC_R_STICK_MAX), 
     138        CWIID_CONST_MACRO(CLASSIC_LR_MAX), 
     139        CWIID_CONST_MACRO(CMD_STATUS), 
     140        CWIID_CONST_MACRO(CMD_LED), 
     141        CWIID_CONST_MACRO(CMD_RUMBLE), 
     142        CWIID_CONST_MACRO(CMD_RPT_MODE), 
     143        CWIID_CONST_MACRO(MESG_STATUS), 
     144        CWIID_CONST_MACRO(MESG_BTN), 
     145        CWIID_CONST_MACRO(MESG_ACC), 
     146        CWIID_CONST_MACRO(MESG_IR), 
     147        CWIID_CONST_MACRO(MESG_NUNCHUK), 
     148        CWIID_CONST_MACRO(MESG_CLASSIC), 
     149        CWIID_CONST_MACRO(MESG_ERROR), 
     150        CWIID_CONST_MACRO(MESG_UNKNOWN), 
     151        CWIID_CONST_MACRO(EXT_NONE), 
     152        CWIID_CONST_MACRO(EXT_NUNCHUK), 
     153        CWIID_CONST_MACRO(EXT_CLASSIC), 
     154        CWIID_CONST_MACRO(EXT_UNKNOWN), 
     155        CWIID_CONST_MACRO(ERROR_DISCONNECT), 
     156        CWIID_CONST_MACRO(ERROR_COMM), 
    154157        {NULL, 0} 
    155158}; 
    156159 
    157160/* Associates cwiid functions with python ones */ 
    158 static PyMethodDef modMethods[] =  
     161static PyMethodDef Module_Methods[] =  
    159162{ 
    160         {NULL, NULL
     163        {NULL, NULL, 0, NULL
    161164}; 
    162165 
    163166PyMODINIT_FUNC initcwiid(void) 
    164167{ 
    165         PyObject *m
     168        PyObject *Module
    166169        int i; 
    167170 
     
    172175        } 
    173176 
    174         if (!(m = Py_InitModule3("cwiid", modMethods,  
    175           "Module for accessing the wiimote through cwiid"))) { 
     177        if (!(Module = Py_InitModule3("cwiid", Module_Methods, 
     178          "CWiid Wiimote Interface"))) { 
    176179                return; 
    177180        } 
    178181 
    179182        Py_INCREF(&Wiimote_Type); 
    180         PyModule_AddObject(m, "Wiimote", (PyObject*)&Wiimote_Type); 
     183        PyModule_AddObject(Module, "Wiimote", (PyObject*)&Wiimote_Type); 
    181184 
    182185        for (i = 0; cwiid_constants[i].name; i++) { 
    183186                /* No way to report errors from here, so just ignore them and hope 
    184187                 * for segfault */ 
    185                 PyModule_AddIntConstant(m, cwiid_constants[i].name, cwiid_constants[i].value); 
     188                PyModule_AddIntConstant(Module, cwiid_constants[i].name, 
     189                                        cwiid_constants[i].value); 
    186190        } 
    187191} 
    188