The daydream controller is awesome and we want to be able to use it in my AR app. It pairs via bluetooth to the HoloLens just fine, but not sure if I can view it in Unity.
Both HoloLens and daydream require their own Unity technical previews. The gvr Controller code is online but seems to speak directly to GVR C api.
Any thoughts on if accessing daydream controller in Unity outside the daydream tech preview is even possible?
It is very possible to access the daydream controller without the GVR services. I am in fact working on that myself and can share what I know.
Getting the data
Using bluetooth gatt you can view all the data available and subscribe to the ID you want. I don't know how you would do this within Hololens/Unity specifically. Basically you want to:
0000fe55-0000-1000-8000-00805f9b34fb
)00000001-1000-1000-8000-00805f9b34fb
)00002902-0000-1000-8000-00805f9b34fb
)Android Example:
I suggest looking up Bluetooth Gatt to understand more about services and characteristics. I also used the BLE Scanner app on the playstore to view a lot of this information before starting with code.
Parsing the data
The device gives 20 bytes of data to work with. It is comprised of time, orientation, acceleration, raw gyro, touch position, and button flags.
Example (laying flat on a table):
Example (using touch pad):
The byte definition is below:
With this I have the touch pad and buttons able to work with any bluetooth device I can build apps for. In addition, you would need to add back functionality to reset the device position, control audio, etc.
Using this definition on Android:
This could be optimized but it assigns all the bits except for the last byte. The code
value = (value << 19) >> 19
can also bevalue = (value >> 12) == 0 ? value : ~0x1FFF | value
. It is just to extend the signed bit to a 32bit signed int.I hope this helps and look forward to additional answers.
-- Update 2 --
After looking at the gvr code I found I had some issues with my previous assumptions. It's actually Orientation/Acceleration/Gyro. Also there was 1 more bit for sequence and 1 less for time. I've updated the byte definition and android example.
In addition the X,Y,Z values need to be scaled to floats. For Unity you could put the ints into Vector3s and then use the following. I also negated the x and y in oriVector, for Unity.
Then to get the rotation you just need the oriVector. Which is actually an axis-angle stored as: unit vector * angle.
That is everything related to getting daydream working with regular bluetooth devices. I also used the above C# code within Unity3D.
-- Update 1 --
Added a more complete byte definition. The values missing before were the gyro, magnetometer, and acceleration data. They each have three 13bit signed ints. There also seems to be a sequence number tucked in with the time bits.Going forward
In order to use the device data with other platforms you would need to put the data through similar equations used for 9DoF/IMU devices. I don't have knowledge of exactly how to address this.
The last byte
This is likely reserved for flags and I'm not sure on the meaning but I have some findings to list. Version number is the firmware version of the controller.