Ver código fonte

Merge pull request #154 from Douglas-3Glasses/master

3Glasses D3 Driver provided by 3Glasses!
TheOnlyJoey 7 anos atrás
pai
commit
5ac4dc10a5
10 arquivos alterados com 583 adições e 2 exclusões
  1. 13 0
      CMakeLists.txt
  2. 13 0
      configure.ac
  3. 9 1
      meson.build
  4. 1 1
      meson_options.txt
  5. 11 0
      src/Makefile.am
  6. 188 0
      src/drv_3glasses/packet.c
  7. 305 0
      src/drv_3glasses/xgvr.c
  8. 38 0
      src/drv_3glasses/xgvr.h
  9. 4 0
      src/openhmd.c
  10. 1 0
      src/openhmdi.h

+ 13 - 0
CMakeLists.txt

@@ -38,6 +38,7 @@ OPTION(OPENHMD_DRIVER_WMR "Windows Mixed Reality" ON)
 OPTION(OPENHMD_DRIVER_PSVR "Sony PSVR" ON)
 OPTION(OPENHMD_DRIVER_HTC_VIVE "HTC Vive" ON)
 OPTION(OPENHMD_DRIVER_NOLO "NOLO VR CV1" ON)
+OPTION(OPENHMD_DRIVER_XGVR "3Glasses HMD" ON)
 OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" ON)
 OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
 
@@ -118,6 +119,18 @@ if(OPENHMD_DRIVER_NOLO)
 	set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
 endif(OPENHMD_DRIVER_NOLO)
 
+if(OPENHMD_DRIVER_XGVR)
+	set(openhmd_source_files ${openhmd_source_files}
+	${CMAKE_CURRENT_LIST_DIR}/src/drv_3glasses/xgvr.c
+	${CMAKE_CURRENT_LIST_DIR}/src/drv_3glasses/packet.c
+	)
+	add_definitions(-DDRIVER_XGVR)
+
+	find_package(HIDAPI REQUIRED)
+	include_directories(${HIDAPI_INCLUDE_DIRS})
+	set(LIBS ${LIBS} ${HIDAPI_LIBRARIES})
+endif(OPENHMD_DRIVER_XGVR)
+
 if (OPENHMD_DRIVER_EXTERNAL)
 	set(openhmd_source_files ${openhmd_source_files}
 	${CMAKE_CURRENT_LIST_DIR}/src/drv_external/external.c

+ 13 - 0
configure.ac

@@ -102,6 +102,15 @@ AC_ARG_ENABLE([driver-nolo],
 
 AM_CONDITIONAL([BUILD_DRIVER_NOLO], [test "x$driver_nolo_enabled" != "xno"])
 
+# 3Glasses HMD driver
+AC_ARG_ENABLE([driver-xgvr],
+        [AS_HELP_STRING([--disable-driver-xgvr],
+                [disable building of 3glasses driver [default=yes]])],
+        [driver_xgvr_enabled=$enableval],
+        [driver_xgvr_enabled='yes'])
+
+AM_CONDITIONAL([BUILD_DRIVER_XGVR], [test "x$driver_xgvr_enabled" != "xno"])
+
 # External Driver
 AC_ARG_ENABLE([driver-external],
         [AS_HELP_STRING([--disable-driver-external],
@@ -140,6 +149,10 @@ AS_IF([test "x$driver_psvr_enabled" != "xno"],
 AS_IF([test "x$driver_nolo_enabled" != "xno"],
 	[PKG_CHECK_MODULES([hidapi], [$hidapi] >= 0.0.5)])
 
+# Libs required by 3Glasses HMD Driver
+AS_IF([test "x$driver_xgvr_enabled" != "xno"],
+        [PKG_CHECK_MODULES([hidapi], [$hidapi] >= 0.0.5)])
+
 # Do we build OpenGL example?
 AC_ARG_ENABLE([openglexample],
         [AS_HELP_STRING([--enable-openglexample],

+ 9 - 1
meson.build

@@ -82,6 +82,15 @@ if _drivers.contains('wmr')
 	deps += dep_hidapi
 endif
 
+if _drivers.contains('xgvr')
+	sources += [
+		'src/drv_3glasses/xgvr.c',
+		'src/drv_3glasses/packet.c',
+	]
+	c_args += '-DDRIVER_XGVR'
+	deps += dep_hidapi
+endif
+
 if _drivers.contains('external')
 	sources += [
 		'src/drv_external/external.c'
@@ -96,7 +105,6 @@ if _drivers.contains('android')
 	c_args += '-DDRIVER_ANDROID'
 endif
 
-
 openhmd_lib = library('openhmd', sources, include_directories : include_directories('./include'), c_args : c_args, dependencies : deps, install : true, version : library_version)
 
 # build examples and install pkg-config file + header only for shared library. shared is the default

+ 1 - 1
meson_options.txt

@@ -1,2 +1,2 @@
 option('examples', type : 'array', choices : ['simple', 'opengl', ''], value : ['simple'])
-option('drivers', type : 'array', choices : ['rift', 'deepoon', 'psvr', 'vive', 'nolo', 'wmr', 'external', 'android'], value : ['rift', 'deepoon', 'psvr', 'vive', 'nolo', 'wmr', 'external'])
+option('drivers', type : 'array', choices : ['rift', 'deepoon', 'psvr', 'vive', 'nolo', 'wmr', 'xgvr', 'external', 'android'], value : ['rift', 'deepoon', 'psvr', 'vive', 'nolo', 'wmr', 'xgvr', 'external'])

+ 11 - 0
src/Makefile.am

@@ -82,6 +82,17 @@ libopenhmd_la_LDFLAGS += $(hidapi_LIBS)
 
 endif
 
+if BUILD_DRIVER_XGVR
+
+libopenhmd_la_SOURCES += \
+	drv_3glasses/xgvr.c \
+	drv_3glasses/packet.c
+
+libopenhmd_la_CPPFLAGS += $(hidapi_CFLAGS) -DDRIVER_XGVR
+libopenhmd_la_LDFLAGS += $(hidapi_LIBS)
+
+endif
+
 if BUILD_DRIVER_EXTERNAL
 
 libopenhmd_la_SOURCES += \

+ 188 - 0
src/drv_3glasses/packet.c

@@ -0,0 +1,188 @@
+/*
+ ***************************************************************************************************
+ *                  3Glasses HMD Driver - Packet Decoding and Utilities
+ *
+ * File   : packet.h
+ * Author : Duncan Li (duncan.li@3glasses.com)
+ *          Douglas Xie (dongyang.xie@3glasses.com )
+ * Version: V1.0
+ * Date   : 10-June-2018
+ ***************************************************************************************************
+ * Copyright (C) 2018 VR Technology Holdings Limited.  All rights reserved.
+ * Website:  www.3glasses.com    www.vrshow.com
+ ***************************************************************************************************
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include "xgvr.h"
+
+#ifdef _MSC_VER
+#define inline __inline
+#endif
+
+typedef union {
+    float fdata;
+    unsigned long ldata;
+} float_long_t;
+
+inline static void float_to_byte(const float f, unsigned char *byte)
+{
+    float_long_t fl;
+    fl.fdata = f;
+    byte[0] = (unsigned char)fl.ldata;
+    byte[1] = (unsigned char)(fl.ldata >> 8);
+    byte[2] = (unsigned char)(fl.ldata >> 16);
+    byte[3] = (unsigned char)(fl.ldata >> 24);
+}
+
+inline static void byte_to_float(float *f, const unsigned char *byte)
+{
+    float_long_t fl;
+    fl.ldata = 0;
+    fl.ldata = byte[3];
+    fl.ldata = (fl.ldata << 8) | byte[2];
+    fl.ldata = (fl.ldata << 8) | byte[1];
+    fl.ldata = (fl.ldata << 8) | byte[0];
+    *f = fl.fdata;
+}
+
+inline static uint8_t read_uint8(const unsigned char** buffer)
+{
+    uint8_t ret = **buffer;
+    *buffer += 1;
+    return ret;
+}
+
+inline static uint16_t read_uint16(const unsigned char** buffer)
+{
+    uint16_t ret = **buffer | (*(*buffer + 1) << 8);
+    *buffer += 2;
+    return ret;
+}
+
+inline static int16_t read_int16(const unsigned char** buffer)
+{
+    int16_t ret = **buffer | (*(*buffer + 1) << 8);
+    *buffer += 2;
+    return ret;
+}
+
+inline static uint32_t read_uint32(const unsigned char** buffer)
+{
+    uint32_t ret = **buffer | (*(*buffer + 1) << 8) | (*(*buffer + 2) << 16) | (*(*buffer + 3) << 24);
+    *buffer += 4;
+    return ret;
+}
+
+inline static int32_t read_int32(const unsigned char** buffer)
+{
+    int32_t ret = **buffer | (*(*buffer + 1) << 8) | (*(*buffer + 2) << 16) | (*(*buffer + 3) << 24);
+    *buffer += 4;
+    return ret;
+}
+
+inline static float read_float(const unsigned char** buffer)
+{
+    float ret = 0;
+    byte_to_float(&ret, *buffer);
+    *buffer += 4;
+    return ret;
+}
+
+static inline void _quat_norm(float *in, float *out)
+{
+    double m = sqrt(in[0] * in[0] + in[1] * in[1] + in[2] * in[2] + in[3] * in[3]);
+    out[0] = in[0] / m;
+    out[1] = in[1] / m;
+    out[2] = in[2] / m;
+    out[3] = in[3] / m;
+}
+
+static inline void _quat_mul(float *in1, float *in2, float *out)
+{
+    out[0] = in1[0] * in2[3] + in1[1] * in2[2] - in1[2] * in2[1] + in1[3] * in2[0];
+    out[1] = -in1[0] * in2[2] + in1[1] * in2[3] + in1[2] * in2[0] + in1[3] * in2[1];
+    out[2] = in1[0] * in2[1] - in1[1] * in2[0] + in1[2] * in2[3] + in1[3] * in2[2];
+    out[3] = -in1[0] * in2[0] - in1[1] * in2[1] - in1[2] * in2[2] + in1[3] * in2[3];
+    _quat_norm(out, out);
+}
+
+static inline void _quat_inv(float *in, float *out)
+{
+    float _buf[4];
+    _quat_norm(in, _buf);
+    out[0] = -_buf[0];
+    out[1] = -_buf[1];
+    out[2] = -_buf[2];
+    out[3] = _buf[3];
+}
+
+static void _hmd_v2_quat_rotate(float *in, float *out)
+{
+    float _buf[4] = {0, 0.70710678118, 0, 0.70710678118};
+    float _buf2[4];
+    _quat_mul(in, _buf, _buf2);
+    out[0] = -_buf2[1]; // x
+    out[1] = _buf2[2]; // y
+    out[2] = -_buf2[0]; // z
+    out[3] = _buf2[3]; // w
+}
+
+int xgvr_decode_version_packet(const unsigned char* buffer, int size,  uint8_t *bootloader_version_major, uint8_t *bootloader_version_minor, uint8_t *runtime_version_major, uint8_t *runtime_version_minor)
+{
+    if (size != 8) {
+        LOGE("invalid 3glasses version packet size (expected 8 but got %d)", size);
+        return -1;
+    }
+
+    // skip report_id
+    read_uint8(&buffer);
+
+    *bootloader_version_major = read_uint8(&buffer);
+    *bootloader_version_minor = read_uint8(&buffer);
+    *runtime_version_major = read_uint8(&buffer);
+    *runtime_version_minor = read_uint8(&buffer);
+
+    return 0;
+}
+
+int xgvr_decode_hmd_data_packet(const unsigned char* buffer, int size, xgvr_hmd_data_t *data)
+{
+    uint8_t i = 0;
+    float quat[4];
+
+    if (size != 64) {
+        LOGE("invalid 3glasses message revd packet size (expected 64 but got %d)", size);
+        return -1;
+    }
+
+    // skip Report ID, 1Byte
+    buffer += 1;
+    data->panel_status = read_uint8(&buffer);
+    data->timestamp = read_uint16(&buffer);
+    data->temperature = read_uint8(&buffer);
+    // skip IPD, 1Byte
+    buffer += 1;
+    // skip pad, 4Byte align
+    buffer += 2;
+    for (i = 0; i < 4; i++) {
+        quat[i] = read_float(&buffer);
+    }
+    _hmd_v2_quat_rotate(quat, data->quat);
+    for (i = 0; i < 3; i++) {
+        data->acc[i] = read_float(&buffer);
+    }
+    for (i = 0; i < 3; i++) {
+        data->gyr[i] = read_float(&buffer);
+    }
+    for (i = 0; i < 3; i++) {
+        data->mag[i] = read_float(&buffer);
+    }
+    data->touch[0] = read_uint8(&buffer);
+    data->touch[1] = read_uint8(&buffer);
+    data->als = read_uint8(&buffer);
+    data->button = read_uint8(&buffer);
+
+    return 0;
+}

+ 305 - 0
src/drv_3glasses/xgvr.c

@@ -0,0 +1,305 @@
+/*
+ ***************************************************************************************************
+ *                  3Glasses HMD Driver - HID/USB Driver Implementation
+ *
+ * File   : xgvr.c
+ * Author : Duncan Li (duncan.li@3glasses.com)
+ *          Douglas Xie (dongyang.xie@3glasses.com )
+ * Version: V1.0
+ * Date   : 10-June-2018
+ ***************************************************************************************************
+ * Copyright (C) 2018 VR Technology Holdings Limited.  All rights reserved.
+ * Website:  www.3glasses.com    www.vrshow.com
+ ***************************************************************************************************
+ */
+
+#include <stdlib.h>
+#include <hidapi.h>
+#include <string.h>
+#include <stdio.h>
+#include <time.h>
+#include <assert.h>
+
+#include "xgvr.h"
+#include "../hid.h"
+
+/* 3Glasses SKU id */
+#define PLATFORM_SKU_D3V1_M41V2     0
+#define PLATFORM_SKU_D3V2_M42V3     1
+#define PLATFORM_SKU_D3C_M3V3       2
+#define PLATFORM_SKU_D2C_M3V3       3
+#define PLATFORM_SKU_S1_V5          4
+#define PLATFORM_SKU_S1_V8          5
+
+/* 3Glasses feature report id */
+#define FEATURE_BUFFER_SIZE         256
+#define FEATURE_SENSOR_ID           0x83
+#define FEATURE_COMMAND_REPORT_ID   0x06
+
+typedef struct {
+    uint16_t usb_vid;
+    uint16_t usb_pid;
+    char *desc;
+    int sku;
+} xgvr_platform_sku_t;
+xgvr_platform_sku_t platform_sku[] = {
+    {
+        0x2b1c, 0x0200, "3Glasses-D3V1", PLATFORM_SKU_D3V1_M41V2,
+    },
+    {
+        0x2b1c, 0x0201, "3Glasses-D3V2", PLATFORM_SKU_D3V2_M42V3,
+    },
+    {
+        0x2b1c, 0x0202, "3Glasses-D3C", PLATFORM_SKU_D3C_M3V3,
+    },
+    {
+        0x2b1c, 0x0203, "3Glasses-D2C", PLATFORM_SKU_D2C_M3V3,
+    },
+    {
+        0x2b1c, 0x0100, "3Glasses-S1V5", PLATFORM_SKU_S1_V5,
+    },
+    {
+        0x2b1c, 0x0101, "3Glasses-S1V8", PLATFORM_SKU_S1_V8,
+    },
+};
+
+typedef struct {
+    ohmd_device device;
+    hid_device* hid_handle;
+    int sku;
+    xgvr_hmd_data_t hmd_data;
+    struct {
+        uint8_t bootloader_version_major;
+        uint8_t bootloader_version_minor;
+        uint8_t runtime_version_major;
+        uint8_t runtime_version_minor;
+    } version;
+} xgvr_priv;
+
+static xgvr_priv* _xgvr_priv_get(ohmd_device* device)
+{
+    return (xgvr_priv*)device;
+}
+
+static int _get_feature_report(xgvr_priv* priv, unsigned char report_id, unsigned char* buf)
+{
+    memset(buf, 0, FEATURE_BUFFER_SIZE);
+    buf[0] = report_id;
+    return hid_get_feature_report(priv->hid_handle, buf, FEATURE_BUFFER_SIZE);
+}
+
+static int _send_feature_report(xgvr_priv* priv, const unsigned char *data, size_t length)
+{
+    return hid_send_feature_report(priv->hid_handle, data, length);
+}
+
+static void _priv_update_firmware_version(xgvr_priv* priv)
+{
+    unsigned char buf[FEATURE_BUFFER_SIZE];
+    int size;
+
+    size = _get_feature_report(priv, FEATURE_COMMAND_REPORT_ID, buf);
+    if (size <= 0) {
+        LOGE("error reading firmware version");
+    } else {
+        xgvr_decode_version_packet(buf, size, &priv->version.bootloader_version_major, &priv->version.bootloader_version_minor, &priv->version.runtime_version_major, &priv->version.runtime_version_minor);
+        LOGD("Version Report: 3Glasses HMD");
+        LOGD("  bootloader version:  %d.%02d", priv->version.bootloader_version_major, priv->version.bootloader_version_minor);
+        LOGD("  runtime version   :  %d.%02d", priv->version.runtime_version_major, priv->version.runtime_version_minor);
+    }
+}
+
+static void _priv_update_properties(xgvr_priv* priv)
+{
+    // TODO: update the device properties for d3 series
+    priv->device.properties.hsize = 0.120960f;
+    priv->device.properties.vsize = 0.068040f;
+    priv->device.properties.hres = 2560;
+    priv->device.properties.vres = 1440;
+    priv->device.properties.lens_sep = 0.063000f;
+    priv->device.properties.lens_vpos = priv->device.properties.vsize / 2;
+    priv->device.properties.fov = DEG_TO_RAD(111.435f);
+    priv->device.properties.ratio = (priv->device.properties.hres / 2.0f) / priv->device.properties.vres;
+
+    // Some buttons and axes
+    priv->device.properties.control_count = 3;
+    priv->device.properties.controls_hints[0] = OHMD_MENU;        // button bit 0
+    priv->device.properties.controls_hints[1] = OHMD_HOME;        // button bit 1
+    priv->device.properties.controls_hints[2] = OHMD_TRIGGER;     // proxmity
+    priv->device.properties.controls_types[0] = OHMD_DIGITAL;
+    priv->device.properties.controls_types[1] = OHMD_DIGITAL;
+    priv->device.properties.controls_types[2] = OHMD_DIGITAL;
+
+    //setup generic distortion coeffs, from hand-calibration
+    ohmd_set_universal_distortion_k(&(priv->device.properties), 0.75239515, -0.84751135, 0.42455423, 0.66200626);
+    ohmd_set_universal_aberration_k(&(priv->device.properties), 1.0, 1.0, 1.0);
+}
+
+static void _update_device(ohmd_device* device)
+{
+    int size = 0;
+    unsigned char buffer[FEATURE_BUFFER_SIZE];
+    xgvr_priv* priv = _xgvr_priv_get(device);
+
+    while ((size = hid_read(priv->hid_handle, buffer, FEATURE_BUFFER_SIZE)) > 0) {
+        if (buffer[0] == FEATURE_SENSOR_ID) {
+            xgvr_decode_hmd_data_packet(buffer, size, &priv->hmd_data);
+        } else {
+            LOGE("unknown message type: %u", buffer[0]);
+        }
+    }
+
+    if (size < 0) {
+        LOGE("error reading from device");
+    }
+}
+
+static int _getf(ohmd_device* device, ohmd_float_value type, float* out)
+{
+    xgvr_priv* priv = _xgvr_priv_get(device);
+
+
+    switch (type) {
+    case OHMD_ROTATION_QUAT:
+        *(quatf*)out = *(quatf*)&priv->hmd_data.quat;
+        break;
+
+    case OHMD_POSITION_VECTOR:
+        out[0] = out[1] = out[2] = 0;
+        break;
+
+    case OHMD_DISTORTION_K:
+        // TODO this should be set to the equivalent of no distortion
+        memset(out, 0, sizeof(float) * 6);
+        break;
+
+    case OHMD_CONTROLS_STATE:
+        out[0] = priv->hmd_data.button & 0x01;
+        out[1] = priv->hmd_data.button & 0x02;
+        out[2] = priv->hmd_data.als;
+        break;
+
+    default:
+        ohmd_set_error(priv->device.ctx, "invalid type given to getf (%ud)", type);
+        return -1;
+        break;
+    }
+
+    return 0;
+}
+
+static void _close_device(ohmd_device* device)
+{
+    LOGD("closing device");
+    xgvr_priv* priv = _xgvr_priv_get(device);
+    hid_close(priv->hid_handle);
+    free(priv);
+}
+
+#define UDEV_WIKI_URL "https://github.com/OpenHMD/OpenHMD/wiki/Udev-rules-list"
+static ohmd_device* _open_device(ohmd_driver* driver, ohmd_device_desc* desc)
+{
+    xgvr_priv* priv = ohmd_alloc(driver->ctx, sizeof(xgvr_priv));
+    if (!priv)
+        goto cleanup;
+
+    priv->device.ctx = driver->ctx;
+
+    // Open the HID device
+    priv->hid_handle = hid_open_path(desc->path);
+
+    if (!priv->hid_handle) {
+        char* path = _hid_to_unix_path(desc->path);
+        ohmd_set_error(driver->ctx, "Could not open %s.\n"
+                       "Check your permissions: "
+                       UDEV_WIKI_URL, path);
+        free(path);
+        goto cleanup;
+    }
+
+    if (hid_set_nonblocking(priv->hid_handle, 1) == -1) {
+        ohmd_set_error(driver->ctx, "failed to set non-blocking on device");
+        goto cleanup;
+    }
+
+    // Set default device properties
+    ohmd_set_default_device_properties(&priv->device.properties);
+
+    if ((priv->sku == PLATFORM_SKU_D3V1_M41V2) || (priv->sku == PLATFORM_SKU_D3V2_M42V3) || (priv->sku == PLATFORM_SKU_D3C_M3V3) || (priv->sku == PLATFORM_SKU_D2C_M3V3)) {
+        _priv_update_firmware_version(priv);
+        _priv_update_properties(priv);
+        priv->device.update = _update_device;
+        priv->device.close = _close_device;
+        priv->device.getf = _getf;
+        priv->device.settings.automatic_update = 0;
+    } else if ((priv->sku == PLATFORM_SKU_S1_V5) || (priv->sku == PLATFORM_SKU_S1_V8)) {
+        // TODO
+    } else {
+        LOGE("unknown sku id: %04x", priv->sku);
+    }
+
+    // calculate projection eye projection matrices from the device properties
+    ohmd_calc_default_proj_matrices(&priv->device.properties);
+
+    return &priv->device;
+
+cleanup:
+    if (priv)
+        free(priv);
+
+    return NULL;
+}
+
+static void _get_device_list(ohmd_driver* driver, ohmd_device_list* list)
+{
+    int i;
+
+    // enumerate HID devices and add any 3Glasses HMD found to the device list
+    for (i = 0; i < sizeof(platform_sku) / sizeof(xgvr_platform_sku_t); i++) {
+        struct hid_device_info* devs = hid_enumerate(platform_sku[i].usb_vid, platform_sku[i].usb_pid);
+        struct hid_device_info* cur_dev = devs;
+
+        if (devs == NULL)
+            continue;
+
+        while (cur_dev) {
+            ohmd_device_desc* desc = &list->devices[list->num_devices++];
+
+            strcpy(desc->driver, "OpenHMD 3Glasses Driver");
+            strcpy(desc->vendor, "3Glasses");
+            strcpy(desc->product, platform_sku[i].desc);
+
+            desc->id = platform_sku[i].sku;
+
+            desc->device_class = OHMD_DEVICE_CLASS_HMD;
+            desc->device_flags = OHMD_DEVICE_FLAGS_ROTATIONAL_TRACKING;
+
+            strcpy(desc->path, cur_dev->path);
+            desc->driver_ptr = driver;
+            cur_dev = cur_dev->next;
+        }
+
+        hid_free_enumeration(devs);
+    }
+}
+
+static void _destroy_driver(ohmd_driver* drv)
+{
+    LOGD("shutting down 3Glasses driver");
+    hid_exit();
+    free(drv);
+}
+
+ohmd_driver* ohmd_create_xgvr_drv(ohmd_context* ctx)
+{
+    ohmd_driver* drv = ohmd_alloc(ctx, sizeof(ohmd_driver));
+    if (drv == NULL)
+        return NULL;
+
+    drv->get_device_list = _get_device_list;
+    drv->open_device = _open_device;
+    drv->destroy = _destroy_driver;
+    drv->ctx = ctx;
+
+    return drv;
+}

+ 38 - 0
src/drv_3glasses/xgvr.h

@@ -0,0 +1,38 @@
+/*
+ ***************************************************************************************************
+ *                     3Glasses HMD Driver - Internal Interface
+ *
+ * File   : xgvr.h
+ * Author : Duncan Li (duncan.li@3glasses.com)
+ *          Douglas Xie (dongyang.xie@3glasses.com )
+ * Version: V1.0
+ * Date   : 10-June-2018
+ ***************************************************************************************************
+ * Copyright (C) 2018 VR Technology Holdings Limited.  All rights reserved.
+ * Website:  www.3glasses.com    www.vrshow.com
+ ***************************************************************************************************
+ */
+
+#ifndef XGVR_H
+#define XGVR_H
+
+#include <stdint.h>
+#include "../openhmdi.h"
+
+typedef struct {
+    float acc[3];
+    float gyr[3];
+    float mag[3];
+    float quat[4];
+    uint16_t timestamp;
+    uint8_t temperature;
+    uint8_t panel_status;   // 0 for init, 1 for suspend, 2 for run.
+    uint8_t als;            // 0 for open, 1 for close
+    uint8_t button;         // 0 for open, 1 for pressed
+    uint8_t touch[2];       // not support.
+} xgvr_hmd_data_t;
+
+int xgvr_decode_version_packet(const unsigned char* buffer, int size,  uint8_t *bootloader_version_major, uint8_t *bootloader_version_minor, uint8_t *runtime_version_major, uint8_t *runtime_version_minor);
+int xgvr_decode_hmd_data_packet(const unsigned char* buffer, int size, xgvr_hmd_data_t *data);
+
+#endif

+ 4 - 0
src/openhmd.c

@@ -50,6 +50,10 @@ ohmd_context* OHMD_APIENTRY ohmd_ctx_create(void)
 	ctx->drivers[ctx->num_drivers++] = ohmd_create_nolo_drv(ctx);
 #endif
 
+#if DRIVER_XGVR
+	ctx->drivers[ctx->num_drivers++] = ohmd_create_xgvr_drv(ctx);
+#endif
+
 #if DRIVER_EXTERNAL
 	ctx->drivers[ctx->num_drivers++] = ohmd_create_external_drv(ctx);
 #endif

+ 1 - 0
src/openhmdi.h

@@ -147,6 +147,7 @@ ohmd_driver* ohmd_create_htc_vive_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_wmr_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_psvr_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_nolo_drv(ohmd_context* ctx);
+ohmd_driver* ohmd_create_xgvr_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx);
 ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx);