Commit 79ab1f8a authored by Pierre Ynard's avatar Pierre Ynard

motion: fail if no sensor is available

Also proper fallback
parent 867738b5
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
...@@ -46,7 +47,7 @@ ...@@ -46,7 +47,7 @@
struct motion_sensors_t struct motion_sensors_t
{ {
enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR, APPLESMC_SENSOR, enum { HDAPS_SENSOR, AMS_SENSOR, APPLESMC_SENSOR,
UNIMOTION_SENSOR } sensor; UNIMOTION_SENSOR } sensor;
#ifdef HAVE_MACOS_UNIMOTION #ifdef HAVE_MACOS_UNIMOTION
enum sms_hardware unimotion_hw; enum sms_hardware unimotion_hw;
...@@ -69,41 +70,27 @@ motion_sensors_t *motion_create( vlc_object_t *obj ) ...@@ -69,41 +70,27 @@ motion_sensors_t *motion_create( vlc_object_t *obj )
return NULL; return NULL;
} }
if( access( "/sys/devices/platform/hdaps/position", R_OK ) == 0 ) if( access( "/sys/devices/platform/hdaps/position", R_OK ) == 0
&& ( f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" ) ) )
{ {
/* IBM HDAPS support */ /* IBM HDAPS support */
f = fopen( "/sys/devices/platform/hdaps/calibrate", "r" ); motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
if( f ) fclose( f );
{ motion->sensor = HDAPS_SENSOR;
motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
fclose( f );
motion->sensor = HDAPS_SENSOR;
}
else
{
motion->sensor = NO_SENSOR;
}
} }
else if( access( "/sys/devices/ams/x", R_OK ) == 0 ) else if( access( "/sys/devices/ams/x", R_OK ) == 0 )
{ {
/* Apple Motion Sensor support */ /* Apple Motion Sensor support */
motion->sensor = AMS_SENSOR; motion->sensor = AMS_SENSOR;
} }
else if( access( "/sys/devices/platform/applesmc.768/position", R_OK ) == 0 ) else if( access( "/sys/devices/platform/applesmc.768/position", R_OK ) == 0
&& ( f = fopen( "/sys/devices/platform/applesmc.768/calibrate", "r" ) ) )
{ {
/* Apple SMC (newer macbooks) */ /* Apple SMC (newer macbooks) */
/* Should be factorised with HDAPS */ /* Should be factorised with HDAPS */
f = fopen( "/sys/devices/platform/applesmc.768/calibrate", "r" ); motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
if( f ) fclose( f );
{ motion->sensor = APPLESMC_SENSOR;
motion->i_calibrate = fscanf( f, "(%d,%d)", &i_x, &i_y ) == 2 ? i_x: 0;
fclose( f );
motion->sensor = APPLESMC_SENSOR;
}
else
{
motion->sensor = NO_SENSOR;
}
} }
#ifdef HAVE_MACOS_UNIMOTION #ifdef HAVE_MACOS_UNIMOTION
else if( (motion->unimotion_hw = detect_sms()) ) else if( (motion->unimotion_hw = detect_sms()) )
...@@ -112,7 +99,9 @@ motion_sensors_t *motion_create( vlc_object_t *obj ) ...@@ -112,7 +99,9 @@ motion_sensors_t *motion_create( vlc_object_t *obj )
else else
{ {
/* No motion sensor support */ /* No motion sensor support */
motion->sensor = NO_SENSOR; msg_Err( obj, "No motion sensor available" );
free( motion );
return NULL;
} }
memset( motion->p_oldx, 0, sizeof( motion->p_oldx ) ); memset( motion->p_oldx, 0, sizeof( motion->p_oldx ) );
...@@ -199,9 +188,8 @@ static int GetOrientation( motion_sensors_t *motion ) ...@@ -199,9 +188,8 @@ static int GetOrientation( motion_sensors_t *motion )
else else
return 0; return 0;
#endif #endif
case NO_SENSOR:
default: default:
return 0; assert( 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