Monado OpenXR Runtime
daydream_device.h
Go to the documentation of this file.
1 // Copyright 2019-2020, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Interface to Daydream driver code.
6  * @author Pete Black <pete.black@collabora.com>
7  * @ingroup drv_daydream
8  */
9 
10 #pragma once
11 
12 #include "math/m_api.h"
13 #include "math/m_imu_pre.h"
14 #include "math/m_imu_3dof.h"
15 
16 #include "xrt/xrt_device.h"
17 
18 #include "os/os_threading.h"
19 #include "os/os_ble.h"
20 
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 /*!
28  * A parsed sample of accel and gyro.
29  */
31 {
32  struct xrt_vec3_i32 accel;
33  struct xrt_vec3_i32 gyro;
34  struct xrt_vec3_i32 mag;
35 };
36 
37 enum daydream_button_bits
38 {
39  DAYDREAM_TOUCHPAD_BUTTON_BIT = 0,
40  DAYDREAM_CIRCLE_BUTTON_BIT = 1,
41  DAYDREAM_BAR_BUTTON_BIT = 2,
42  DAYDREAM_VOLUP_BUTTON_BIT = 3,
43  DAYDREAM_VOLDN_BUTTON_BIT = 4,
44 };
45 
46 enum daydream_button_masks
47 {
48  DAYDREAM_TOUCHPAD_BUTTON_MASK = 1 << DAYDREAM_TOUCHPAD_BUTTON_BIT,
49  DAYDREAM_CIRCLE_BUTTON_MASK = 1 << DAYDREAM_CIRCLE_BUTTON_BIT,
50  DAYDREAM_BAR_BUTTON_MASK = 1 << DAYDREAM_BAR_BUTTON_BIT,
51  DAYDREAM_VOLUP_BUTTON_MASK = 1 << DAYDREAM_VOLUP_BUTTON_BIT,
52  DAYDREAM_VOLDN_BUTTON_MASK = 1 << DAYDREAM_VOLDN_BUTTON_BIT,
53 };
54 
56 {
57  uint8_t buttons;
58  int timestamp;
59  uint16_t timestamp_last;
60  struct xrt_vec2_i32 touchpad;
61  struct daydream_parsed_sample sample;
62 };
63 
65 {
66  struct xrt_device base;
67  struct os_ble_device *ble;
68  struct os_thread_helper oth;
69  char mac[128];
70  char path[128];
71 
72  struct
73  {
74  //! Lock for last and fusion.
75  struct os_mutex lock;
76 
77  //! Last sensor read.
78  struct daydream_parsed_input last;
79 
80  struct m_imu_pre_filter pre_filter;
81  struct m_imu_3dof fusion;
82  };
83 
84  bool print_spew;
85  bool print_debug;
86 
87  struct
88  {
89  bool last;
90  } gui;
91 };
92 
93 
94 struct daydream_device *
95 daydream_device_create(struct os_ble_device *ble,
96  bool print_spew,
97  bool print_debug);
98 
99 
100 #define DAYDREAM_SPEW(c, ...) \
101  do { \
102  if (c->print_spew) { \
103  fprintf(stderr, "%s - ", __func__); \
104  fprintf(stderr, __VA_ARGS__); \
105  fprintf(stderr, "\n"); \
106  } \
107  } while (false)
108 
109 #define DAYDREAM_DEBUG(c, ...) \
110  do { \
111  if (c->print_debug) { \
112  fprintf(stderr, "%s - ", __func__); \
113  fprintf(stderr, __VA_ARGS__); \
114  fprintf(stderr, "\n"); \
115  } \
116  } while (false)
117 
118 #define DAYDREAM_ERROR(c, ...) \
119  do { \
120  fprintf(stderr, "%s - ", __func__); \
121  fprintf(stderr, __VA_ARGS__); \
122  fprintf(stderr, "\n"); \
123  } while (false)
124 
125 
126 #ifdef __cplusplus
127 }
128 #endif
A IMU fusion specially made for 3dof devices.
This is a common IMU pre-filter which takes raw &#39;ticks&#39; from an IMU measurement and converts it into ...
Definition: m_imu_pre.h:46
A parsed sample of accel and gyro.
Definition: daydream_device.h:30
Wrapper around OS threading native functions.
IMU pre filter struct.
Header defining a xrt HMD device.
A 2 element vector with 32 bit integers.
Definition: xrt_defines.h:155
All in one helper that handles locking, waiting for change and starting a thread. ...
Definition: os_threading.h:149
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:143
Definition: daydream_device.h:55
Definition: daydream_device.h:64
A wrapper around a native mutex.
Definition: os_threading.h:39
Representing a single ble notify attribute on a device.
Definition: os_ble.h:27
A single HMD or input device.
Definition: xrt_device.h:203
C interface to math library.
Definition: m_imu_3dof.h:34
Wrapper around OS native BLE functions.