static PyObject* pymotion_read_scaled(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; int x, y, z; if (!read_sms_scaled(g_accelerometerType, &x, &y, &z)) { PyErr_SetString(PyExc_RuntimeError, "Failed to read accelerometer data."); return NULL; } return Py_BuildValue("(iii)", x, y, z); }
//-------------------------------- bool ofxSuddenMotion::readMotion(){ if(!bHasHardware){ if(bVerbose)printf("ofxSuddenMotion - no hardware found / make sure to call setupHardware() first \n"); return false; } bool bRead = false; if( valueMode == OFX_SM_RAW ){ int rawX, rawY, rawZ; bRead = read_sms_raw(hardwareType, &rawX, &rawY, &rawZ); if(bRead){ actualX = (double)rawX; actualY = (double)rawY; actualZ = (double)rawZ; } }else if(valueMode == OFX_SM_REAL){ double realX, realY, realZ; bRead = read_sms_real(hardwareType, &realX, &realY, &realZ); if(bRead){ actualX = realX; actualY = realY; actualZ = realZ; } }else if(valueMode == OFX_SM_SCALED){ int scaledX, scaledY, scaledZ; bRead = read_sms_scaled(hardwareType, &scaledX, &scaledY, &scaledZ); if(bRead){ actualX = (double)scaledX; actualY = (double)scaledY; actualZ = (double)scaledZ; } }else{ if(bVerbose)printf("ofxSuddenMotion - incorrect value mode\n"); return false; } if( bRead ){ x = actualX - offsetX; y = actualY - offsetY; z = actualZ - offsetZ; //smooth values smoothX *= smoothPct; smoothY *= smoothPct; smoothZ *= smoothPct; smoothX += x * (1.0- smoothPct); smoothY += y * (1.0- smoothPct); smoothZ += z * (1.0- smoothPct); }else { if(bVerbose)printf("ofxSuddenMotion - problem reading sms data\n"); } return bRead; }