]> git.sesse.net Git - vlc/blobdiff - modules/control/motion.c
Plugins: include vlc_common.h directly instead of vlc/vlc.h
[vlc] / modules / control / motion.c
index b32070110baf22f46b771843ba827a5f18f0aed6..ccecf4d0829637af6728c253c20afbb0d3e7e183 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <string.h>
 #include <math.h>
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_vout.h>
 
  *****************************************************************************/
 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
     int i_calibrate;
 
-    vlc_bool_t b_use_rotate;
+    bool b_use_rotate;
 };
 
 /*****************************************************************************
@@ -69,12 +74,14 @@ static int GetOrientation( intf_thread_t *p_intf );
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_shortname( _("motion"));
+    set_shortname( N_("motion"));
     set_category( CAT_INTERFACE );
-    set_description( _("motion control interface") );
+    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, VLC_FALSE );
+              USE_ROTATE_TEXT, USE_ROTATE_TEXT, false );
 
     set_capability( "interface", 0 );
     set_callbacks( Open, Close );
@@ -117,6 +124,24 @@ 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() )
         p_intf->p_sys->sensor = UNIMOTION_SENSOR;
@@ -160,7 +185,7 @@ static void RunIntf( intf_thread_t *p_intf )
     {
         vout_thread_t *p_vout;
         const char *psz_filter, *psz_type;
-        vlc_bool_t b_change = VLC_FALSE;
+        bool b_change = false;
 
         /* Wait a bit, get orientation, change filter if necessary */
         msleep( INTF_IDLE_SLEEP );
@@ -191,20 +216,20 @@ static void RunIntf( intf_thread_t *p_intf )
 
         if( i_x < -HIGH_THRESHOLD && i_oldx > -LOW_THRESHOLD )
         {
-            b_change = VLC_TRUE;
+            b_change = true;
             psz_filter = "transform";
             psz_type = "270";
         }
         else if( ( i_x > -LOW_THRESHOLD && i_oldx < -HIGH_THRESHOLD )
                  || ( i_x < LOW_THRESHOLD && i_oldx > HIGH_THRESHOLD ) )
         {
-            b_change = VLC_TRUE;
+            b_change = true;
             psz_filter = "";
             psz_type = "";
         }
         else if( i_x > HIGH_THRESHOLD && i_oldx < LOW_THRESHOLD )
         {
-            b_change = VLC_TRUE;
+            b_change = true;
             psz_filter = "transform";
             psz_type = "90";
         }
@@ -238,10 +263,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:
@@ -268,6 +291,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 ) )