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 #include "util/u_logging.h"
22 
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 
29 /*!
30  * A parsed sample of accel and gyro.
31  */
33 {
34  struct xrt_vec3_i32 accel;
35  struct xrt_vec3_i32 gyro;
36  struct xrt_vec3_i32 mag;
37 };
38 
39 enum daydream_button_bits
40 {
41  DAYDREAM_TOUCHPAD_BUTTON_BIT = 0,
42  DAYDREAM_CIRCLE_BUTTON_BIT = 1,
43  DAYDREAM_BAR_BUTTON_BIT = 2,
44  DAYDREAM_VOLUP_BUTTON_BIT = 3,
45  DAYDREAM_VOLDN_BUTTON_BIT = 4,
46 };
47 
48 enum daydream_button_masks
49 {
50  DAYDREAM_TOUCHPAD_BUTTON_MASK = 1 << DAYDREAM_TOUCHPAD_BUTTON_BIT,
51  DAYDREAM_CIRCLE_BUTTON_MASK = 1 << DAYDREAM_CIRCLE_BUTTON_BIT,
52  DAYDREAM_BAR_BUTTON_MASK = 1 << DAYDREAM_BAR_BUTTON_BIT,
53  DAYDREAM_VOLUP_BUTTON_MASK = 1 << DAYDREAM_VOLUP_BUTTON_BIT,
54  DAYDREAM_VOLDN_BUTTON_MASK = 1 << DAYDREAM_VOLDN_BUTTON_BIT,
55 };
56 
58 {
59  uint8_t buttons;
60  int timestamp;
61  uint16_t timestamp_last;
62  struct xrt_vec2_i32 touchpad;
63  struct daydream_parsed_sample sample;
64 };
65 
66 /*!
67  * @implements xrt_device
68  */
70 {
71  struct xrt_device base;
72  struct os_ble_device *ble;
73  struct os_thread_helper oth;
74  char mac[128];
75  char path[128];
76 
77  struct
78  {
79  //! Lock for last and fusion.
80  struct os_mutex lock;
81 
82  //! Last sensor read.
84 
85  struct m_imu_pre_filter pre_filter;
86  struct m_imu_3dof fusion;
87  };
88 
89  enum u_logging_level log_level;
90 
91  struct
92  {
93  bool last;
94  } gui;
95 };
96 
97 
98 struct daydream_device *
99 daydream_device_create(struct os_ble_device *ble);
100 
101 
102 #define DAYDREAM_TRACE(d, ...) U_LOG_XDEV_IFL_T(&d->base, d->log_level, __VA_ARGS__)
103 #define DAYDREAM_DEBUG(d, ...) U_LOG_XDEV_IFL_D(&d->base, d->log_level, __VA_ARGS__)
104 #define DAYDREAM_INFO(d, ...) U_LOG_XDEV_IFL_I(&d->base, d->log_level, __VA_ARGS__)
105 #define DAYDREAM_WARN(d, ...) U_LOG_XDEV_IFL_W(&d->base, d->log_level, __VA_ARGS__)
106 #define DAYDREAM_ERROR(d, ...) U_LOG_XDEV_IFL_E(&d->base, d->log_level, __VA_ARGS__)
107 
108 
109 #ifdef __cplusplus
110 }
111 #endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
C interface to math library.
A IMU fusion specially made for 3dof devices.
IMU pre filter struct.
Wrapper around OS native BLE functions.
Wrapper around OS threading native functions.
Definition: daydream_device.h:70
struct os_mutex lock
Lock for last and fusion.
Definition: daydream_device.h:80
struct daydream_parsed_input last
Last sensor read.
Definition: daydream_device.h:83
Definition: daydream_device.h:58
A parsed sample of accel and gyro.
Definition: daydream_device.h:33
Definition: m_imu_3dof.h:35
This is a common IMU pre-filter which takes raw 'ticks' from an IMU measurement and converts it into ...
Definition: m_imu_pre.h:47
Representing a single ble notify attribute on a device.
Definition: os_ble.h:29
A wrapper around a native mutex.
Definition: os_threading.h:55
All in one helper that handles locking, waiting for change and starting a thread.
Definition: os_threading.h:453
A single HMD or input device.
Definition: xrt_device.h:230
A 2 element vector with 32 bit integers.
Definition: xrt_defines.h:348
A 3 element vector with 32 bit integers.
Definition: xrt_defines.h:336
Basic logging functionality.
Header defining an xrt display or controller device.