소스 검색

Merge pull request #130 from magwyz/master

Android driver propositions by magwyz
TheOnlyJoey 7 년 전
부모
커밋
6f91c10248
5개의 변경된 파일29개의 추가작업 그리고 68개의 파일을 삭제
  1. 7 0
      configure.ac
  2. 1 1
      pkg-config/openhmd.pc.in
  3. 3 0
      src/Makefile.am
  4. 18 13
      src/drv_android/android.c
  5. 0 54
      src/drv_android/android.h

+ 7 - 0
configure.ac

@@ -20,16 +20,23 @@ PKG_PROG_PKG_CONFIG([0.24])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 hidapi="hidapi"
+deps_ld_flags="-lhidapi"
 AC_SUBST(hidapi)
+AC_SUBST(deps_ld_flags)
 
 AC_SUBST(PKG_CONFIG_EXTRA_PATH, "")
 AC_SUBST(EXTRA_LD_FLAGS, "")
 
 AC_MSG_CHECKING([operating system])
 AS_CASE(["$host"],
+	[*-androideabi],
+		[hidapi=""
+		deps_ld_flags="-landroid"
+		AC_SUBST(EXTRA_LD_FLAGS, "-lm")],
 	[*-linux*],
 		[AC_MSG_RESULT([$host (Linux)])
 		hidapi="hidapi-libusb"
+		deps_ld_flags="-lhidapi-libusb"
 
 		#link with realtime lib on linux for clock_gettime, and libm for math functions such as sincosf
 		AC_SUBST(EXTRA_LD_FLAGS, "-lrt -lpthread -lm")],

+ 1 - 1
pkg-config/openhmd.pc.in

@@ -7,5 +7,5 @@ Description: API and drivers for immersive technology devices such as HMDs
 Version: 0.3.0
 Requires: @hidapi@
 Conflicts:
-Libs: -L${libdir} -lopenhmd -l@hidapi@
+Libs: -L${libdir} -lopenhmd @deps_ld_flags@
 Cflags: -I${includedir}

+ 3 - 0
src/Makefile.am

@@ -92,6 +92,9 @@ if BUILD_DRIVER_ANDROID
 
 libopenhmd_la_SOURCES += \
 	drv_android/android.c
+
+libopenhmd_la_CPPFLAGS += -DDRIVER_ANDROID
+libopenhmd_la_LDFLAGS += -landroid
 endif
 
 libopenhmd_la_LDFLAGS += $(EXTRA_LD_FLAGS)

+ 18 - 13
src/drv_android/android.c

@@ -20,7 +20,6 @@ typedef struct {
 
 	//Android specific
 	#ifdef __ANDROID__
-    android_app* state;
     ASensorManager* sensorManager;
     const ASensor* accelerometerSensor;
     const ASensor* gyroscopeSensor;
@@ -92,14 +91,13 @@ static void update_device(ohmd_device* device)
 {
     android_priv* priv = (android_priv*)device;
 
-    if(!priv->state)
-        return;
+    ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
 
     //We need this since during init the android_app state is not set yet
     if (priv->firstRun == 1)
     {
         priv->sensorEventQueue = ASensorManager_createEventQueue(priv->sensorManager,
-                                priv->state->looper, LOOPER_ID_USER, android_sensor_callback, (void*)priv);
+                                    looper, ALOOPER_POLL_CALLBACK, android_sensor_callback, (void*)priv);
 
         // Start sensors in case this was not done already.
         if (priv->accelerometerSensor != NULL)
@@ -116,6 +114,8 @@ static void update_device(ohmd_device* device)
         }
         priv->firstRun = 0;
     }
+
+    ALooper_pollAll(0, NULL, NULL, NULL);
 }
 
 static int getf(ohmd_device* device, ohmd_float_value type, float* out)
@@ -123,10 +123,17 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
 	android_priv* priv = (android_priv*)device;
 
 	switch(type){
-		case OHMD_ROTATION_QUAT: {
-				*(quatf*)out = priv->sensor_fusion.orient;
-				break;
-			}
+                case OHMD_ROTATION_QUAT: {
+                    if (!priv->gyroscopeSensor)
+                        *(quatf*)out = priv->sensor_fusion.orient;
+                    else {
+                        // 90° rotation to restore the standard frame
+                        quatf rotated = {-M_SQRT2 / 2, 0, 0, M_SQRT2 / 2};
+                        oquatf_mult_me(&rotated, &priv->sensor_fusion.orient);
+                        *(quatf*)out = rotated;
+                    }
+                    break;
+                }
 
 		case OHMD_POSITION_VECTOR:
 			out[0] = out[1] = out[2] = 0;
@@ -151,10 +158,6 @@ static int set_data(ohmd_device* device, ohmd_data_value type, void* in)
 	android_priv* priv = (android_priv*)device;
 
 	switch(type){
-		case OHMD_DRIVER_DATA: {
-		    priv->state = (android_app*)in;
-            break;
-		}
 		case OHMD_DRIVER_PROPERTIES: {
             set_android_properties(device, (ohmd_device_properties*)in);
             break;
@@ -217,8 +220,10 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
     //Check if accelerometer only fallback is required
     if (!priv->gyroscopeSensor)
         nofusion_init(&priv->sensor_fusion);
-    else
+    else {
         ofusion_init(&priv->sensor_fusion); //Default when all sensors are available
+        priv->sensor_fusion.flags = 0; // Disable the gravity
+    }
 
 	return (ohmd_device*)priv;
 }

+ 0 - 54
src/drv_android/android.h

@@ -34,58 +34,4 @@ typedef enum {
 
 struct android_app;
 
-struct android_poll_source {
-    int32_t id;
-
-    struct android_app* app;
-
-    void (*process)(struct android_app* app, struct android_poll_source* source);
-};
-
-typedef struct android_app {
-    void* userData;
-
-    void (*onAppCmd)(struct android_app* app, int32_t cmd);
-    int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);
-
-    ANativeActivity* activity;
-    AConfiguration* config;
-
-    void* savedState;
-    size_t savedStateSize;
-
-    ALooper* looper;
-    AInputQueue* inputQueue;
-    ANativeWindow* window;
-    ARect contentRect;
-
-    int activityState;
-    int destroyRequested;
-
-    pthread_mutex_t mutex;
-    pthread_cond_t cond;
-
-    int msgread;
-    int msgwrite;
-
-    pthread_t thread;
-
-    struct android_poll_source cmdPollSource;
-    struct android_poll_source inputPollSource;
-
-    int running;
-    int stateSaved;
-    int destroyed;
-    int redrawNeeded;
-    AInputQueue* pendingInputQueue;
-    ANativeWindow* pendingWindow;
-    ARect pendingContentRect;
-} android_app;
-
-enum {
-    LOOPER_ID_MAIN = 1,
-    LOOPER_ID_INPUT = 2,
-    LOOPER_ID_USER = 3
-};
-
 #endif // ANDROID_H