Commit c48a5132 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Motion: code simplification, cleaning and error-checking

parent d529bcc3
...@@ -38,18 +38,18 @@ ...@@ -38,18 +38,18 @@
#include <vlc_vout.h> #include <vlc_vout.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
#include "TargetConditionals.h" # include "TargetConditionals.h"
#if !TARGET_OS_IPHONE # if !TARGET_OS_IPHONE
#define HAVE_MACOS_UNIMOTION # define HAVE_MACOS_UNIMOTION
#endif # endif
#endif #endif
#ifdef HAVE_MACOS_UNIMOTION #ifdef HAVE_MACOS_UNIMOTION
#include "unimotion.h" # include "unimotion.h"
#endif #endif
/***************************************************************************** /*****************************************************************************
...@@ -103,7 +103,7 @@ int Open ( vlc_object_t *p_this ) ...@@ -103,7 +103,7 @@ int Open ( vlc_object_t *p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
FILE *f; FILE *f;
int i_x, i_y; int i_x = 0, i_y = 0;
p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
if( p_intf->p_sys == NULL ) if( p_intf->p_sys == NULL )
...@@ -117,10 +117,8 @@ int Open ( vlc_object_t *p_this ) ...@@ -117,10 +117,8 @@ int Open ( vlc_object_t *p_this )
f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" ); f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" );
if( f ) if( f )
{ {
i_x = i_y = 0; p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
fscanf( f, "(%d,%d)", &i_x, &i_y );
fclose( f ); fclose( f );
p_intf->p_sys->i_calibrate = i_x;
p_intf->p_sys->sensor = HDAPS_SENSOR; p_intf->p_sys->sensor = HDAPS_SENSOR;
} }
else else
...@@ -140,10 +138,8 @@ int Open ( vlc_object_t *p_this ) ...@@ -140,10 +138,8 @@ int Open ( vlc_object_t *p_this )
f = fopen( "/sys/devices/applesmc.768/calibrate", "r" ); f = fopen( "/sys/devices/applesmc.768/calibrate", "r" );
if( f ) if( f )
{ {
i_x = i_y = 0; p_intf->p_sys->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
fscanf( f, "(%d,%d)", &i_x, &i_y );
fclose( f ); fclose( f );
p_intf->p_sys->i_calibrate = i_x;
p_intf->p_sys->sensor = APPLESMC_SENSOR; p_intf->p_sys->sensor = APPLESMC_SENSOR;
} }
else else
...@@ -152,7 +148,7 @@ int Open ( vlc_object_t *p_this ) ...@@ -152,7 +148,7 @@ int Open ( vlc_object_t *p_this )
} }
} }
#ifdef HAVE_MACOS_UNIMOTION #ifdef HAVE_MACOS_UNIMOTION
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; p_intf->p_sys->sensor = UNIMOTION_SENSOR;
#endif #endif
else else
...@@ -163,9 +159,9 @@ int Open ( vlc_object_t *p_this ) ...@@ -163,9 +159,9 @@ int Open ( vlc_object_t *p_this )
p_intf->pf_run = RunIntf; p_intf->pf_run = RunIntf;
p_intf->p_sys->b_use_rotate = p_intf->p_sys->b_use_rotate = var_InheritBool( p_intf, "motion-use-rotate" );
var_InheritBool( p_intf, "motion-use-rotate" );
msg_Dbg( p_intf, "Motion detection correctly loaded" );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -272,7 +268,8 @@ loop: ...@@ -272,7 +268,8 @@ loop:
static int GetOrientation( intf_thread_t *p_intf ) static int GetOrientation( intf_thread_t *p_intf )
{ {
FILE *f; FILE *f;
int i_x, i_y, i_z = 0; int i_x = 0, i_y = 0, i_z = 0;
int i_ret;
switch( p_intf->p_sys->sensor ) switch( p_intf->p_sys->sensor )
{ {
...@@ -283,11 +280,13 @@ static int GetOrientation( intf_thread_t *p_intf ) ...@@ -283,11 +280,13 @@ static int GetOrientation( intf_thread_t *p_intf )
return 0; return 0;
} }
i_x = i_y = 0; i_ret = fscanf( f, "(%d,%d)", &i_x, &i_y );
fscanf( f, "(%d,%d)", &i_x, &i_y );
fclose( f ); fclose( f );
return ( i_x - p_intf->p_sys->i_calibrate ) * 10; if( i_ret < 2 )
return 0;
else
return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
case AMS_SENSOR: case AMS_SENSOR:
f = fopen( "/sys/devices/ams/x", "r" ); f = fopen( "/sys/devices/ams/x", "r" );
...@@ -296,10 +295,13 @@ static int GetOrientation( intf_thread_t *p_intf ) ...@@ -296,10 +295,13 @@ static int GetOrientation( intf_thread_t *p_intf )
return 0; return 0;
} }
fscanf( f, "%d", &i_x); i_ret = fscanf( f, "%d", &i_x);
fclose( f ); fclose( f );
return - i_x * 30; /* FIXME: arbitrary */ if( i_ret < 1 )
return 0;
else
return - i_x * 30; /* FIXME: arbitrary */
case APPLESMC_SENSOR: case APPLESMC_SENSOR:
f = fopen( "/sys/devices/applesmc.768/position", "r" ); f = fopen( "/sys/devices/applesmc.768/position", "r" );
...@@ -308,11 +310,13 @@ static int GetOrientation( intf_thread_t *p_intf ) ...@@ -308,11 +310,13 @@ static int GetOrientation( intf_thread_t *p_intf )
return 0; return 0;
} }
i_x = i_y = i_z = 0; i_ret = fscanf( f, "(%d,%d,%d)", &i_x, &i_y, &i_z );
fscanf( f, "(%d,%d,%d)", &i_x, &i_y, &i_z );
fclose( f ); fclose( f );
return ( i_x - p_intf->p_sys->i_calibrate ) * 10; if( i_ret < 3 )
return 0;
else
return ( i_x - p_intf->p_sys->i_calibrate ) * 10;
#ifdef HAVE_MACOS_UNIMOTION #ifdef HAVE_MACOS_UNIMOTION
case UNIMOTION_SENSOR: case UNIMOTION_SENSOR:
...@@ -330,6 +334,7 @@ static int GetOrientation( intf_thread_t *p_intf ) ...@@ -330,6 +334,7 @@ static int GetOrientation( intf_thread_t *p_intf )
else else
return 0; return 0;
#endif #endif
case NO_SENSOR:
default: default:
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment