Changeset 109

Show
Ignore:
Timestamp:
05/09/07 20:04:35 (2 years ago)
Author:
dsmith
Message:

cwiidpy: get_state

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cwiidpy/cwiidmodule.c

    r108 r109  
    2020 * 
    2121 * ChangeLog: 
     22 * 2007-05-07 L. Donnie Smith <cwiid@abstrakraft.org> 
     23 * * finished get_state 
    2224 * 2007-05-07 L. Donnie Smith <cwiid@abstrakraft.org> 
    2325 * * C-style comments 
     
    494496        } 
    495497 
    496         PyState = Py_BuildValue("{s:b,s:b,s:b,s:b,s:h}", 
     498        PyState = Py_BuildValue("{s:b,s:b,s:b,s:b,s:i,s:i}", 
    497499                                "rpt_mode", state.rpt_mode, 
    498500                                "led", state.led, 
    499501                                "rumble", state.rumble, 
    500502                                "battery", state.battery, 
    501                                 "ext_type", state.ext_type); 
    502  
    503         if (state.rpt_mode | CWIID_RPT_BTN) { 
     503                                "ext_type", state.ext_type, 
     504                                "error", state.error); 
     505 
     506        if (state.rpt_mode & CWIID_RPT_BTN) { 
    504507                PyObject *PyBtn = Py_BuildValue("i", state.buttons); 
    505508                if (!PyBtn) { 
     
    515518        } 
    516519 
    517         if (state.rpt_mode | CWIID_RPT_ACC) { 
    518                 PyObject *PyAcc = Py_BuildValue("{s:i,s:i,s:i}", 
     520        if (state.rpt_mode & CWIID_RPT_ACC) { 
     521                PyObject *PyAcc = Py_BuildValue("{s:b,s:b,s:b}", 
    519522                                                                    "x", state.acc[CWIID_X], 
    520523                                            "y", state.acc[CWIID_Y], 
     
    530533                } 
    531534                Py_DECREF(PyAcc); 
     535        } 
     536 
     537        if (state.rpt_mode & CWIID_RPT_IR) { 
     538                int i; 
     539                PyObject *PyIr = PyList_New(CWIID_IR_SRC_COUNT); 
     540 
     541                if (!PyIr) { 
     542                        Py_DECREF(PyState); 
     543                        return NULL; 
     544                } 
     545 
     546                if (PyDict_SetItemString(PyState, "ir_src", PyIr)) { 
     547                        Py_DECREF(PyState); 
     548                        Py_DECREF(PyIr); 
     549                        return NULL; 
     550                } 
     551 
     552                Py_DECREF(PyIr); 
     553 
     554                for (i=0; i < CWIID_IR_SRC_COUNT; i++) { 
     555                        PyObject *PyIrSrc; 
     556 
     557                        if (state.ir_src[i].valid) { 
     558                                PyIrSrc = Py_BuildValue("{s:{s:i,s:i},s:b}", 
     559                                                        "pos", 
     560                                                          "x", state.ir_src[i].pos[CWIID_X], 
     561                                                          "y", state.ir_src[i].pos[CWIID_Y], 
     562                                                        "size", state.ir_src[i].size); 
     563                                if (!PyIrSrc) { 
     564                                        Py_DECREF(PyState); 
     565                                        return NULL; 
     566                                } 
     567                        } 
     568                        else { 
     569                                Py_INCREF(PyIrSrc = Py_None); 
     570                        } 
     571 
     572                        PyList_SET_ITEM(PyIr, i, PyIrSrc); 
     573                } 
     574        } 
     575 
     576        switch (state.ext_type) { 
     577                PyObject *PyExt; 
     578        case CWIID_EXT_NUNCHUK: 
     579                if (state.rpt_mode & CWIID_RPT_NUNCHUK) { 
     580                        PyExt = Py_BuildValue("{s:{s:b,s:b},s:{s:b,s:b,s:b},s:i}", 
     581                                              "stick", 
     582                                                "x", state.ext.nunchuk.stick[CWIID_X], 
     583                                                "y", state.ext.nunchuk.stick[CWIID_Y], 
     584                                              "acc", 
     585                                                "x", state.ext.nunchuk.acc[CWIID_X], 
     586                                                "y", state.ext.nunchuk.acc[CWIID_Y], 
     587                                                "z", state.ext.nunchuk.acc[CWIID_Z], 
     588                                              "buttons", state.ext.nunchuk.buttons); 
     589 
     590                        if (!PyExt) { 
     591                                Py_DECREF(PyState); 
     592                                return NULL; 
     593                        } 
     594 
     595                        if (PyDict_SetItemString(PyState, "nunchuk", PyExt)) { 
     596                                Py_DECREF(PyState); 
     597                                Py_DECREF(PyExt); 
     598                                return NULL; 
     599                        } 
     600 
     601                        Py_DECREF(PyExt); 
     602                } 
     603                break; 
     604        case CWIID_EXT_CLASSIC: 
     605                if (state.rpt_mode & CWIID_RPT_CLASSIC) { 
     606                        PyExt = Py_BuildValue("{s:{s:b,s:b},s:{s:b,s:b},s:b,s:b,s:i}", 
     607                                              "l_stick", 
     608                                                "x", state.ext.classic.l_stick[CWIID_X], 
     609                                                "y", state.ext.classic.l_stick[CWIID_Y], 
     610                                              "r_stick", 
     611                                                "x", state.ext.classic.r_stick[CWIID_X], 
     612                                                "y", state.ext.classic.r_stick[CWIID_Y], 
     613                                              "l", state.ext.classic.l, 
     614                                              "r", state.ext.classic.r, 
     615                                              "buttons", state.ext.classic.buttons); 
     616 
     617                        if (!PyExt) { 
     618                                Py_DECREF(PyState); 
     619                                return NULL; 
     620                        } 
     621 
     622                        if (PyDict_SetItemString(PyState, "classic", PyExt)) { 
     623                                Py_DECREF(PyState); 
     624                                Py_DECREF(PyExt); 
     625                                return NULL; 
     626                        } 
     627 
     628                        Py_DECREF(PyExt); 
     629                } 
     630                break; 
     631        default: 
     632                break; 
    532633        } 
    533634