X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fmotion.c;h=2af60ef91fad316e507d477ddfe094c56a47211f;hb=8fd093d4130b4e7a5b4ca82f3934b6fdf1a10c8d;hp=8c48961f5e47b70a2a467350d06aac4cca6702b1;hpb=13ae40b0efc4f1b1ce205d9a057537047fcab3f4;p=vlc diff --git a/modules/control/motion.c b/modules/control/motion.c index 8c48961f5e..2af60ef91f 100644 --- a/modules/control/motion.c +++ b/modules/control/motion.c @@ -25,13 +25,14 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include +#include + +#include #include #include #include @@ -49,7 +50,8 @@ *****************************************************************************/ struct intf_sys_t { - enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR, UNIMOTION_SENSOR } sensor; + enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR, APPLESMC_SENSOR, + UNIMOTION_SENSOR } sensor; #ifdef __APPLE__ enum sms_hardware unimotion_hw; #endif @@ -72,17 +74,20 @@ static int GetOrientation( intf_thread_t *p_intf ); /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_shortname( N_("motion")); - set_category( CAT_INTERFACE ); - set_description( N_("motion control interface") ); +vlc_module_begin () + set_shortname( N_("motion")) + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + set_description( N_("motion control interface") ) + set_help( N_("Use HDAPS, AMS, APPLESMC or UNIMOTION motion sensors " \ + "to rotate the video") ) - add_bool( "motion-use-rotate", 0, NULL, - USE_ROTATE_TEXT, USE_ROTATE_TEXT, false ); + add_bool( "motion-use-rotate", false, NULL, + USE_ROTATE_TEXT, USE_ROTATE_TEXT, false ) - set_capability( "interface", 0 ); - set_callbacks( Open, Close ); -vlc_module_end(); + set_capability( "interface", 0 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * OpenIntf: initialise interface @@ -121,8 +126,26 @@ int Open ( vlc_object_t *p_this ) /* Apple Motion Sensor support */ p_intf->p_sys->sensor = AMS_SENSOR; } + else if( access( "/sys/devices/applesmc.768/position", R_OK ) == 0 ) + { + /* Apple SMC (newer macbooks) */ + /* Should be factorised with HDAPS */ + f = fopen( "/sys/devices/applesmc.768/calibrate", "r" ); + if( f ) + { + i_x = i_y = 0; + fscanf( f, "(%d,%d)", &i_x, &i_y ); + fclose( f ); + p_intf->p_sys->i_calibrate = i_x; + p_intf->p_sys->sensor = APPLESMC_SENSOR; + } + else + { + p_intf->p_sys->sensor = NO_SENSOR; + } + } #ifdef __APPLE__ - else if( p_intf->p_sys->unimotion_hw = detect_sms() ) + else if((p_intf->p_sys->unimotion_hw = detect_sms())) p_intf->p_sys->sensor = UNIMOTION_SENSOR; #endif else @@ -133,7 +156,8 @@ int Open ( vlc_object_t *p_this ) p_intf->pf_run = RunIntf; - p_intf->p_sys->b_use_rotate = config_GetInt( p_intf, "motion-use-rotate" ); + p_intf->p_sys->b_use_rotate = + var_InheritBool( p_intf, "motion-use-rotate" ); return VLC_SUCCESS; } @@ -160,7 +184,7 @@ static void RunIntf( intf_thread_t *p_intf ) int p_oldx[FILTER_LENGTH]; memset( p_oldx, 0, FILTER_LENGTH * sizeof( int ) ); - while( !intf_ShouldDie( p_intf ) ) + for( ;; ) { vout_thread_t *p_vout; const char *psz_filter, *psz_type; @@ -169,6 +193,7 @@ static void RunIntf( intf_thread_t *p_intf ) /* Wait a bit, get orientation, change filter if necessary */ msleep( INTF_IDLE_SLEEP ); + int canc = vlc_savecancel(); i_x = GetOrientation( p_intf ); i_sum += i_x - p_oldx[i]; p_oldx[i++] = i_x; @@ -190,7 +215,7 @@ static void RunIntf( intf_thread_t *p_intf ) vlc_object_release( p_obj ); } } - continue; + goto loop; } if( i_x < -HIGH_THRESHOLD && i_oldx > -LOW_THRESHOLD ) @@ -213,23 +238,21 @@ static void RunIntf( intf_thread_t *p_intf ) psz_type = "90"; } - if( !b_change ) + if( b_change ) { - continue; - } + p_vout = (vout_thread_t *) + vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); + if( p_vout ) + { + config_PutPsz( p_vout, "transform-type", psz_type ); + var_SetString( p_vout, "vout-filter", psz_filter ); + vlc_object_release( p_vout ); - p_vout = (vout_thread_t *) - vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); - if( !p_vout ) - { - continue; + i_oldx = i_x; + } } - - config_PutPsz( p_vout, "transform-type", psz_type ); - var_SetString( p_vout, "vout-filter", psz_filter ); - vlc_object_release( p_vout ); - - i_oldx = i_x; +loop: + vlc_restorecancel( canc ); } } #undef FILTER_LENGTH @@ -242,10 +265,8 @@ static void RunIntf( intf_thread_t *p_intf ) static int GetOrientation( intf_thread_t *p_intf ) { FILE *f; - int i_x, i_y; -#ifdef __APPLE__ - int i_z; -#endif + int i_x, i_y, i_z = 0; + switch( p_intf->p_sys->sensor ) { case HDAPS_SENSOR: @@ -272,6 +293,20 @@ static int GetOrientation( intf_thread_t *p_intf ) fclose( f ); return - i_x * 30; /* FIXME: arbitrary */ + + case APPLESMC_SENSOR: + f = fopen( "/sys/devices/applesmc.768/position", "r" ); + if( !f ) + { + return 0; + } + + i_x = i_y = i_z = 0; + fscanf( f, "(%d,%d,%d)", &i_x, &i_y, &i_z ); + fclose( f ); + + return ( i_x - p_intf->p_sys->i_calibrate ) * 10; + #ifdef __APPLE__ case UNIMOTION_SENSOR: if( read_sms_raw( p_intf->p_sys->unimotion_hw, &i_x, &i_y, &i_z ) )