Changeset 105

Show
Ignore:
Timestamp:
05/07/07 19:46:39 (2 years ago)
Author:
dsmith
Message:

cwiidpy read function

Files:

Legend:

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

    r104 r105  
    324324static PyObject *Wiimote_read(PyObject *self, PyObject *args) 
    325325{ 
    326         return notImplemented(); 
     326        /* Python types */ 
     327        PyObject* pyflags; 
     328        PyObject* pyoffset; 
     329        PyObject* pylength; 
     330 
     331        PyObject* pyRetBuf; 
     332 
     333        /* C types */ 
     334        uint8_t flags; 
     335        uint32_t offset; 
     336        uint32_t length; 
     337        void * buf; 
     338 
     339    PyArg_UnpackTuple(args, "read", 3, 3, &pyflags,&pyoffset,&pylength); 
     340    if(!(PyInt_Check(pyflags)  
     341                && PyInt_Check(pyoffset)  
     342                && PyInt_Check(pylength))) 
     343    { 
     344        PyErr_SetString(PyExc_TypeError, "arguments must be ints"); 
     345    } 
     346         
     347    /* marshal everything over */ 
     348    flags  = (uint8_t)  PyInt_AsLong(pyflags); 
     349    offset = (uint32_t) PyInt_AsLong(pyoffset); 
     350        length = (uint32_t) PyInt_AsLong(pylength); 
     351 
     352        /* TODO: More error checking */ 
     353        buf = malloc(length); 
     354        cwiid_read(((cwiidmodule*)self)->wiimote,flags,offset,length,buf); 
     355        pyRetBuf = PyBuffer_FromMemory((char*)buf, length); 
     356        free(buf); 
     357 
     358        Py_XINCREF(pyRetBuf); 
     359        return pyRetBuf; 
    327360} 
    328361