Commit: 22570c0ab4e81adb1a68c35a2b31a3a5f12541af
Author: Joey Ferwerda
Date:   Thu Feb 23 20:04:56 2017 +0100
Branches: HMD_viewport
https://developer.blender.org/rB22570c0ab4e81adb1a68c35a2b31a3a5f12541af

- Updated OpenHMD with fixes from their master (commit 2379647)

===================================================================

M       extern/openhmd/CMakeLists.txt
M       extern/openhmd/include/openhmd.h
M       extern/openhmd/src/drv_android/android.c
M       extern/openhmd/src/drv_dummy/dummy.c
M       extern/openhmd/src/drv_external/external.c
M       extern/openhmd/src/drv_oculus_rift/packet.c
M       extern/openhmd/src/drv_oculus_rift/rift.c
M       extern/openhmd/src/drv_oculus_rift/rift.h
M       extern/openhmd/src/fusion.c
M       extern/openhmd/src/omath.c
M       extern/openhmd/src/omath.h
M       extern/openhmd/src/openhmd.c
M       extern/openhmd/src/openhmdi.h
M       extern/openhmd/src/platform-posix.c
M       extern/openhmd/src/platform-win32.c
M       extern/openhmd/src/platform.h
A       extern/openhmd/src/queue.c
A       extern/openhmd/src/queue.h

===================================================================

diff --git a/extern/openhmd/CMakeLists.txt b/extern/openhmd/CMakeLists.txt
index 7792c6fcdc..6dfef7a707 100644
--- a/extern/openhmd/CMakeLists.txt
+++ b/extern/openhmd/CMakeLists.txt
@@ -33,6 +33,7 @@ set(SRC
        src/omath.c
        src/platform-posix.c
        src/fusion.c
+       src/queue.c
 )
 
 # TODO: Either remove this or move to main CMakeLists.txt
diff --git a/extern/openhmd/include/openhmd.h b/extern/openhmd/include/openhmd.h
index dafb806411..5468fb55b9 100644
--- a/extern/openhmd/include/openhmd.h
+++ b/extern/openhmd/include/openhmd.h
@@ -44,6 +44,7 @@ typedef enum {
        OHMD_S_UNKNOWN_ERROR = -1,
        OHMD_S_INVALID_PARAMETER = -2,
        OHMD_S_UNSUPPORTED = -3,
+       OHMD_S_INVALID_OPERATION = -4,
 
        /** OHMD_S_USER_RESERVED and below can be used for user purposes, such 
as errors within ohmd wrappers, etc. */
        OHMD_S_USER_RESERVED = -16384,
@@ -125,6 +126,14 @@ typedef enum {
        /** int[1] (get): Physical vertical resolution of the device screen. */
        OHMD_SCREEN_VERTICAL_RESOLUTION       =  1,
 
+       /** int[1] (get): Get number of events waiting in digital input event 
queue. */
+       OHMD_BUTTON_EVENT_COUNT               =  2,
+       /** int[1] (get): Get if the there was an overflow in the event queue 
causing events to be dropped. */
+       OHMD_BUTTON_EVENT_OVERFLOW            =  3,
+       /** int[1] (get): Get the number of physical digital input buttons on 
the device. */
+       OHMD_BUTTON_COUNT                     =  4,
+       /** int[2] (get): Performs an event pop action. Format: [button_index, 
button_state], where button_state is either OHMD_BUTTON_DOWN or OHMD_BUTTON_UP 
*/
+       OHMD_BUTTON_POP_EVENT                 =  5,
 } ohmd_int_value;
 
 /** A collection of data information types used for setting information with 
ohmd_set_data(). */
@@ -146,6 +155,14 @@ typedef enum {
        OHMD_IDS_AUTOMATIC_UPDATE = 0,
 } ohmd_int_settings;
 
+/** Button states for digital input events. */
+typedef enum {
+       /** Button was pressed. */
+       OHMD_BUTTON_DOWN = 0,
+       /** Button was released. */
+       OHMD_BUTTON_UP   = 1
+} ohmd_button_state;
+
 /** An opaque pointer to a context structure. */
 typedef struct ohmd_context ohmd_context;
 
diff --git a/extern/openhmd/src/drv_android/android.c 
b/extern/openhmd/src/drv_android/android.c
index d021a21b89..9ba3e3fb76 100644
--- a/extern/openhmd/src/drv_android/android.c
+++ b/extern/openhmd/src/drv_android/android.c
@@ -191,8 +191,8 @@ static ohmd_device* open_device(ohmd_driver* driver, 
ohmd_device_desc* desc)
        priv->base.properties.vsize = 0.093600f;
        priv->base.properties.hres = 1280;
        priv->base.properties.vres = 800;
-       priv->base.properties.lens_sep = 0.063500;
-       priv->base.properties.lens_vpos = 0.046800;
+       priv->base.properties.lens_sep = 0.063500f;
+       priv->base.properties.lens_vpos = 0.046800f;
        priv->base.properties.fov = DEG_TO_RAD(125.5144f);
        priv->base.properties.ratio = (1280.0f / 800.0f) / 2.0f;
 
diff --git a/extern/openhmd/src/drv_dummy/dummy.c 
b/extern/openhmd/src/drv_dummy/dummy.c
index 2b5436ef62..9f9adf84d4 100644
--- a/extern/openhmd/src/drv_dummy/dummy.c
+++ b/extern/openhmd/src/drv_dummy/dummy.c
@@ -66,10 +66,11 @@ static ohmd_device* open_device(ohmd_driver* driver, 
ohmd_device_desc* desc)
        priv->base.properties.vsize = 0.093600f;
        priv->base.properties.hres = 1280;
        priv->base.properties.vres = 800;
-       priv->base.properties.lens_sep = 0.063500;
-       priv->base.properties.lens_vpos = 0.046800;
+       priv->base.properties.lens_sep = 0.063500f;
+       priv->base.properties.lens_vpos = 0.046800f;
        priv->base.properties.fov = DEG_TO_RAD(125.5144f);
        priv->base.properties.ratio = (1280.0f / 800.0f) / 2.0f;
+       priv->base.properties.digital_button_count = 4;
 
        // calculate projection eye projection matrices from the device 
properties
        ohmd_calc_default_proj_matrices(&priv->base.properties);
diff --git a/extern/openhmd/src/drv_external/external.c 
b/extern/openhmd/src/drv_external/external.c
index a675e333c3..7e4340567e 100644
--- a/extern/openhmd/src/drv_external/external.c
+++ b/extern/openhmd/src/drv_external/external.c
@@ -84,8 +84,8 @@ static ohmd_device* open_device(ohmd_driver* driver, 
ohmd_device_desc* desc)
        priv->base.properties.vsize = 0.093600f;
        priv->base.properties.hres = 1280;
        priv->base.properties.vres = 800;
-       priv->base.properties.lens_sep = 0.063500;
-       priv->base.properties.lens_vpos = 0.046800;
+       priv->base.properties.lens_sep = 0.063500f;
+       priv->base.properties.lens_vpos = 0.046800f;
        priv->base.properties.fov = DEG_TO_RAD(125.5144f);
        priv->base.properties.ratio = (1280.0f / 800.0f) / 2.0f;
 
@@ -130,9 +130,8 @@ ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx)
 
        drv->get_device_list = get_device_list;
        drv->open_device = open_device;
-       drv->get_device_list = get_device_list;
-       drv->open_device = open_device;
        drv->destroy = destroy_driver;
+       drv->ctx = ctx;
 
        return drv;
 }
diff --git a/extern/openhmd/src/drv_oculus_rift/packet.c 
b/extern/openhmd/src/drv_oculus_rift/packet.c
index 1bf4743aac..0e7c56fef1 100644
--- a/extern/openhmd/src/drv_oculus_rift/packet.c
+++ b/extern/openhmd/src/drv_oculus_rift/packet.c
@@ -107,11 +107,12 @@ bool decode_tracker_sensor_msg(pkt_tracker_sensor* msg, 
const unsigned char* buf
        SKIP_CMD;
        msg->num_samples = READ8;
        msg->timestamp = READ16;
+       msg->timestamp *= 1000; // DK1 timestamps are in milliseconds
        msg->last_command_id = READ16;
        msg->temperature = READ16;
 
-       int actual = OHMD_MIN(msg->num_samples, 3);
-       for(int i = 0; i < actual; i++){
+       msg->num_samples = OHMD_MIN(msg->num_samples, 3);
+       for(int i = 0; i < msg->num_samples; i++){
                decode_sample(buffer, msg->samples[i].accel);
                buffer += 8;
 
@@ -120,7 +121,7 @@ bool decode_tracker_sensor_msg(pkt_tracker_sensor* msg, 
const unsigned char* buf
        }
 
        // Skip empty samples
-       buffer += (3 - actual) * 16;
+       buffer += (3 - msg->num_samples) * 16;
        for(int i = 0; i < 3; i++){
                msg->mag[i] = READ16;
        }
@@ -138,12 +139,16 @@ bool decode_tracker_sensor_msg_dk2(pkt_tracker_sensor* 
msg, const unsigned char*
        SKIP_CMD;
        msg->last_command_id = READ16;
        msg->num_samples = READ8;
+       /* Next is the number of samples since start, excluding the samples
+       contained in this packet */
        buffer += 2; // unused: nb_samples_since_start
        msg->temperature = READ16;
        msg->timestamp = READ32;
 
-       int actual = OHMD_MIN(msg->num_samples, 2);
-       for(int i = 0; i < actual; i++){
+       /* Second sample value is junk (outdated/uninitialized) value if
+       num_samples < 2. */
+       msg->num_samples = OHMD_MIN(msg->num_samples, 2);
+       for(int i = 0; i < msg->num_samples; i++){
                decode_sample(buffer, msg->samples[i].accel);
                buffer += 8;
 
@@ -152,7 +157,7 @@ bool decode_tracker_sensor_msg_dk2(pkt_tracker_sensor* msg, 
const unsigned char*
        }
 
        // Skip empty samples
-       buffer += (2 - actual) * 16;
+       buffer += (2 - msg->num_samples) * 16;
 
        for(int i = 0; i < 3; i++){
                msg->mag[i] = READ16;
@@ -262,7 +267,7 @@ void dump_packet_tracker_sensor(const pkt_tracker_sensor* 
sensor)
        LOGD("  num samples:     %u", sensor->num_samples);
        LOGD("  magnetic field:  %i %i %i", sensor->mag[0], sensor->mag[1], 
sensor->mag[2]);
 
-       for(int i = 0; i < OHMD_MIN(sensor->num_samples, 3); i++){
+       for(int i = 0; i < sensor->num_samples; i++){
                LOGD("    accel: %d %d %d", sensor->samples[i].accel[0], 
sensor->samples[i].accel[1], sensor->samples[i].accel[2]);
                LOGD("    gyro:  %d %d %d", sensor->samples[i].gyro[0], 
sensor->samples[i].gyro[1], sensor->samples[i].gyro[2]);
        }
diff --git a/extern/openhmd/src/drv_oculus_rift/rift.c 
b/extern/openhmd/src/drv_oculus_rift/rift.c
index f6399d6fca..ee045f8bea 100644
--- a/extern/openhmd/src/drv_oculus_rift/rift.c
+++ b/extern/openhmd/src/drv_oculus_rift/rift.c
@@ -29,6 +29,7 @@ typedef struct {
        rift_coordinate_frame coordinate_frame, hw_coordinate_frame;
        pkt_sensor_config sensor_config;
        pkt_tracker_sensor sensor;
+       uint32_t last_imu_timestamp;
        double last_keep_alive;
        fusion sensor_fusion;
        vec3f raw_mag, raw_accel, raw_gyro;
@@ -112,22 +113,26 @@ static void handle_tracker_sensor_msg(rift_priv* priv, 
unsigned char* buffer, in
 
        dump_packet_tracker_sensor(s);
 
-       // TODO handle missed samples etc.
-
-       float dt = s->num_samples > 3 ? (s->num_samples - 2) * TICK_LEN : 
TICK_LEN;
-
        int32_t mag32[] = { s->mag[0], s->mag[1], s->mag[2] };
        vec3f_from_rift_vec(mag32, &priv->raw_mag);
 
-       for(int i = 0; i < OHMD_MIN(s->num_samples, 3); i++){
+       // TODO: handle overflows in a nicer way
+       float dt = TICK_LEN; // TODO: query the Rift for the sample rate
+       if (s->timestamp > priv->last_imu_timestamp)
+       {
+               dt = (s->timestamp - priv->last_imu_timestamp) / 1000000.0f;
+               dt -= (s->num_samples - 1) * TICK_LEN; // TODO: query the Rift 
for the sample rate
+       }
+
+       for(int i = 0; i < s->num_samples; i++){
                vec3f_from_rift_vec(s->samples[i].accel, &priv->raw_accel);
                vec3f_from_rift_vec(s->samples[i].gyro, &priv->raw_gyro);
 
                ofusion_update(&priv->sensor_fusion, dt, &priv->raw_gyro, 
&priv->raw_accel, &priv->raw_mag);
-
-               // reset dt to tick_len for the last samples if there were more 
than one sample
-               dt = TICK_LEN;
+               dt = TICK_LEN; // TODO: query the Rift for the sample rate
        }
+
+       priv->last_imu_timestamp = s->timestamp;
 }
 
 static void update_device(ohmd_device* device)
@@ -226,6 +231,8 @@ static ohmd_device* open_device(ohmd_driver* driver, 
ohmd_device_desc* desc)
        if(!priv)
                goto cleanup;
 
+       priv->last_imu_timestamp = -1;
+
        priv->base.ctx = driver->ctx;
 
        // Open the HID device
@@ -377,6 +384,8 @@ static void destroy_driver(ohmd_driver* drv)
        LOGD("shutting down driver");
        hid_exit();
        free(drv);
+
+       ohmd_toggle_ovr_service(1); //re-enable OVRService if previously running
 }
 
 ohmd_driver* ohmd_create_oculus_rift_drv(ohmd_context* ctx)
@@ -385,6 +394,8 @@ ohmd_driver* ohmd_create_oculus_rift_drv(ohmd_context* ctx)
        if(drv == NULL)
                return NULL;
 
+       ohmd_toggle_ovr_service(0); //disable OVRService if running
+
        drv->get_device_list = get_device_list;
        drv->open_device = open_device;
        drv->destroy = destroy_driver;
diff --git a/extern/openhmd/src/drv_oculus_rift/rift.h 
b/extern/openhmd/src/drv_oculus_rift/rift.h
index a176a77bb3..8a5474977c 100644
--- a/extern/openhmd/src/drv_oculus_rift/rift.h
+++ b/extern/openhmd/src/drv_oculus_rift/rift.h
@@ -63,7 +63,7 @@ typedef struct {
 
 typedef struct

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to