Add support for a few more feature reports default tip
authorThibaut Girka <thib@sitedethib.com>
Sun, 29 May 2016 17:59:36 +0200
changeset 33 760b375267af
parent 32 cde110e18a4f
Add support for a few more feature reports
src/backends/rift.c
--- a/src/backends/rift.c	Tue May 24 21:27:44 2016 +0200
+++ b/src/backends/rift.c	Sun May 29 17:59:36 2016 +0200
@@ -29,6 +29,8 @@
 #include <stdlib.h>
 #include <stdint.h>
 
+#include <stdio.h>
+
 #include <hidapi.h>
 
 #include <math.h>
@@ -343,11 +345,6 @@
 0b 0000 1f ffff  ce0c ffff ff7f fffffffffffffffe fffffffffffffffe fffffffffffffffe fffffffffffffffe 7f009f080000 0000000000000000ff7f00ffff7f
   */
 
-  printf("Debug: Sensors: ");
-  for (int i=0; i < size; i++) printf("%02x ", buffer[i]);
-  printf("\n");
-
-
   struct raw_sensor_data *sensor_data = &rift->raw_sensor_data;
   uint8_t nb_samples;
   struct raw_sample *sample;
@@ -449,6 +446,7 @@
         break;
       default:
         /* ??? */
+        printf("Unknown message! %d\n", buffer[0]);
         return -1;
     }
   }
@@ -523,12 +521,70 @@
 }
 
 
+int rift_cv1_get_hmd_serial_number(struct device *rift)
+{
+  uint8_t buffer[19] = { 0x1e };
+
+  if (hid_get_feature_report(rift->dev, buffer, 19) != 19)
+    return -1;
+
+  printf("Serial number: %s\n", buffer + 3);
+
+  return 0;
+}
+
+
+int rift_cv1_get_wireless_firmware_ver(struct device *rift)
+{
+  /* XXX: this is not completely reverse engineered and it might be WRONG,
+     use at your own risk! */
+  uint8_t buffer[40];
+
+  // Reset firmware request info
+  buffer[0] = 0x1b;
+  if (hid_send_feature_report(rift->dev, buffer, 31) != 31)
+  {
+    printf("Error clearing firmware info!\n");
+    return -1;
+  }
+
+  // Select component to get firmware info from?
+  buffer[0] = 0x1a;
+  buffer[3] = 1; // flags?
+  buffer[4] = 0x82; // device/component?
+  if (hid_send_feature_report(rift->dev, buffer, 6) != 6)
+  {
+    printf("Error selecting firmware info!\n");
+    return -1;
+  }
+
+  for (int attempt=0; attempt < 10; attempt++)
+  {
+    if (hid_get_feature_report(rift->dev, buffer, 6) != 6)
+    {
+      printf("Error trying to read firmware info!\n");
+      return -1;
+    }
+    if (buffer[3] == 1)
+    {
+      printf("Firmware info available at attempt #%d\n", attempt);
+      buffer[0] = 0x1b;
+      /* buffer[3-4] is the device/component-id? */
+      if (hid_get_feature_report(rift->dev, buffer, 40) < 4)
+        return -1;
+      printf("Firmware version: %s\n", buffer + 6);
+      break;
+    }
+  }
+}
+
+
 struct hmd *rift_open(void)
 {
   static const int ids[] = {
     0x0001, // DK1
     0x0031, // CV1
-    0x2031, // Also CV1?
+//    0x2031, // Also CV1?
   };
 
   struct hmd *hmd;
@@ -564,6 +620,8 @@
   hmd->get_rotation = rift_get_rotation;
   hmd->get_position = NULL;
   rift_get_sensor_config(rift);
+  rift_cv1_get_hmd_serial_number(rift);
+//  rift_cv1_get_wireless_firmware_ver(rift);
 //  rift_dk2_send_display(rift, 1, 1);
 //  rift_dk2_send_tracking(rift, 1);