Пример #1
0
// public module function, return a tuple with (x,y,z) coordinates
static PyObject* coords(PyObject *self, PyObject *args) {
    int x, y, z;
	int type;
	
	// discover hardware type (powerbook, ibook, hirespb, macbookpro)
	type = detect_sms();

	// launch exception if hardware is not supported
	if( type == unknown ){
		PyErr_SetString(AppleSMSError, "No motion sensor available");
		return 0;
	}

	// grab sensor raw coordinates
	int result = read_sms_raw(type, &x, &y, &z);

	// create exception if result is lower than 1
	if( result < 1 ){
		switch(result){
			case  0: PyErr_SetString(AppleSMSError, "Hardware type not supported"); break;
			case -1: PyErr_SetString(AppleSMSError, "IOServiceGetMatchingServices returned error"); break;
			case -2: PyErr_SetString(AppleSMSError, "No motion sensor available"); break;
			case -3: PyErr_SetString(AppleSMSError, "Could not open motion sensor device"); break;
			case -4: PyErr_SetString(AppleSMSError, "No coords"); break;
		}
	    return 0;
	}
	
	// build tuple to return
	return Py_BuildValue("(i,i,i)", x, y, z);
}
motion_sensors_t *motion_create( vlc_object_t *obj )
{
    FILE *f;
    int i_x = 0, i_y = 0;

    motion_sensors_t *motion = malloc( sizeof( motion_sensors_t ) );
    if( unlikely( motion == NULL ) )
    {
        return NULL;
    }

    if( access( "/sys/devices/platform/hdaps/position", 04/*R_OK*/ ) == 0 			// sunqueen modify
        && ( f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" ) ) )
    {
        /* IBM HDAPS support */
        motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
        fclose( f );
        motion->sensor = HDAPS_SENSOR;
        msg_Dbg( obj, "HDAPS motion detection correctly loaded" );
    }
    else if( access( "/sys/devices/ams/x", 04/*R_OK*/ ) == 0 )			// sunqueen modify
    {
        /* Apple Motion Sensor support */
        motion->sensor = AMS_SENSOR;
        msg_Dbg( obj, "AMS motion detection correctly loaded" );
    }
    else if( access( "/sys/devices/platform/applesmc.768/position", 04/*R_OK*/ ) == 0 			// sunqueen modify
             && ( f = fopen( "/sys/devices/platform/applesmc.768/calibrate", "r" ) ) )
    {
        /* Apple SMC (newer macbooks) */
        /* Should be factorised with HDAPS */
        motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
        fclose( f );
        motion->sensor = APPLESMC_SENSOR;
        msg_Dbg( obj, "Apple SMC motion detection correctly loaded" );
    }
#ifdef HAVE_MACOS_UNIMOTION
    else if( (motion->unimotion_hw = detect_sms()) )
    {
        motion->sensor = UNIMOTION_SENSOR;
        msg_Dbg( obj, "UniMotion motion detection correctly loaded" );
    }
#endif
    else
    {
        /* No motion sensor support */
        msg_Err( obj, "No motion sensor available" );
        free( motion );
        return NULL;
    }

    memset( motion->p_oldx, 0, sizeof( motion->p_oldx ) );
    motion->i = 0;
    motion->i_sum = 0;
    return motion;
}
Пример #3
0
void *akabookmotion_new(t_symbol *s, short argc, t_atom *argv)
{
	t_akabookmotion *x = (t_akabookmotion *)newobject(akabookmotion_class);
	x->m_zout = intout(x);
	x->m_yout = intout(x);
	x->m_xout = intout(x);
	
	x->type = detect_sms();
	if (x->type == unknown)
		error("aka.bookmotion: Can't find/identify a Motion Sensor.");
		
	return x;
}
Пример #4
0
PyMODINIT_FUNC
initpymotion(void)
{
	g_accelerometerType = detect_sms();

	if (g_accelerometerType == unknown)
	{
		PyErr_SetString(PyExc_ImportError, 
			"Failed to initialize the UniMotion library: No known motion sensor devices detected");
		return;
	}

	Py_InitModule("pymotion", pymotionMethods);
}
Пример #5
0
/*****************************************************************************
 * OpenIntf: initialise interface
 *****************************************************************************/
int Open ( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
    FILE *f;
    int i_x = 0, i_y = 0;

    p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
    if( p_intf->p_sys == NULL )
    {
        return VLC_ENOMEM;
    }

    if( access( "/sys/devices/platform/hdaps/position", R_OK ) == 0 )
    {
        /* IBM HDAPS support */
        f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" );
        if( f )
        {
            p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
            fclose( f );
            p_intf->p_sys->sensor = HDAPS_SENSOR;
        }
        else
        {
            p_intf->p_sys->sensor = NO_SENSOR;
        }
    }
    else if( access( "/sys/devices/ams/x", R_OK ) == 0 )
    {
        /* Apple Motion Sensor support */
        p_intf->p_sys->sensor = AMS_SENSOR;
    }
    else if( access( "/sys/devices/platform/applesmc.768/position", R_OK ) == 0 )
    {
        /* Apple SMC (newer macbooks) */
        /* Should be factorised with HDAPS */
        f = fopen( "/sys/devices/platform/applesmc.768/calibrate", "r" );
        if( f )
        {
            p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
            fclose( f );
            p_intf->p_sys->sensor = APPLESMC_SENSOR;
        }
        else
        {
            p_intf->p_sys->sensor = NO_SENSOR;
        }
    }
#ifdef HAVE_MACOS_UNIMOTION
    else if( (p_intf->p_sys->unimotion_hw = detect_sms()) )
        p_intf->p_sys->sensor = UNIMOTION_SENSOR;
#endif
    else
    {
        /* No motion sensor support */
        p_intf->p_sys->sensor = NO_SENSOR;
    }

    p_intf->pf_run = RunIntf;

    p_intf->p_sys->b_use_rotate = var_InheritBool( p_intf, "motion-use-rotate" );

    msg_Dbg( p_intf, "Motion detection correctly loaded" );
    return VLC_SUCCESS;
}