Monado OpenXR Runtime
arduino_device.c File Reference

Arduino felxable input device code. More...

#include "xrt/xrt_device.h"
#include "xrt/xrt_prober.h"
#include "xrt/xrt_tracking.h"
#include "os/os_ble.h"
#include "os/os_time.h"
#include "os/os_threading.h"
#include "math/m_api.h"
#include "math/m_imu_pre.h"
#include "math/m_imu_3dof.h"
#include "util/u_var.h"
#include "util/u_time.h"
#include "util/u_misc.h"
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_bitwise.h"
#include "util/u_logging.h"
#include "arduino_interface.h"
#include <stdio.h>
#include <math.h>
#include <assert.h>
Include dependency graph for arduino_device.c:

Data Structures

struct  arduino_parsed_sample
 A parsed sample of accel and gyro. More...
 
struct  arduino_parsed_input
 
struct  arduino_device
 

Macros

#define ARDUINO_TRACE(d, ...)   U_LOG_XDEV_IFL_T(&d->base, d->log_level, __VA_ARGS__)
 
#define ARDUINO_DEBUG(d, ...)   U_LOG_XDEV_IFL_D(&d->base, d->log_level, __VA_ARGS__)
 
#define ARDUINO_INFO(d, ...)   U_LOG_XDEV_IFL_I(&d->base, d->log_level, __VA_ARGS__)
 
#define ARDUINO_WARN(d, ...)   U_LOG_XDEV_IFL_W(&d->base, d->log_level, __VA_ARGS__)
 
#define ARDUINO_ERROR(d, ...)   U_LOG_XDEV_IFL_E(&d->base, d->log_level, __VA_ARGS__)
 
#define DEG_TO_RAD   ((double)M_PI / 180.0)
 

Functions

static struct arduino_devicearduino_device (struct xrt_device *xdev)
 
static uint32_t calc_delta_and_handle_rollover (uint32_t next, uint32_t last)
 
static int16_t read_i16 (const uint8_t *buffer, size_t offset)
 
static void update_fusion (struct arduino_device *ad, struct arduino_parsed_sample *sample, timepoint_ns timestamp_ns, time_duration_ns delta_ns)
 
static void arduino_parse_input (struct arduino_device *ad, void *data, struct arduino_parsed_input *input)
 
static bool arduino_read_one_packet (struct arduino_device *ad, uint8_t *buffer, size_t size)
 Reads one packet from the device,handles locking and checking if the thread has been told to shut down. More...
 
static void * arduino_run_thread (void *ptr)
 
static xrt_result_t arduino_get_fusion_pose (struct arduino_device *ad, enum xrt_input_name name, struct xrt_space_relation *out_relation)
 
static void arduino_device_destroy (struct xrt_device *xdev)
 
static xrt_result_t arduino_device_update_inputs (struct xrt_device *xdev)
 
static xrt_result_t arduino_device_get_tracked_pose (struct xrt_device *xdev, enum xrt_input_name name, int64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
 
struct xrt_devicearduino_device_create (struct os_ble_device *ble)
 Create a arduino device from a ble notify. More...
 

Variables

static struct xrt_binding_input_pair simple_inputs [4]
 
static struct xrt_binding_profile binding_profiles [1]
 

Detailed Description

Function Documentation

◆ arduino_get_fusion_pose()

static xrt_result_t arduino_get_fusion_pose ( struct arduino_device ad,
enum xrt_input_name  name,
struct xrt_space_relation out_relation 
)
static
Todo:
assuming that orientation is actually currently tracked.

References m_imu_3dof::rot.

◆ arduino_read_one_packet()

static bool arduino_read_one_packet ( struct arduino_device ad,
uint8_t *  buffer,
size_t  size 
)
static

Reads one packet from the device,handles locking and checking if the thread has been told to shut down.

References os_ble_read(), os_thread_helper::os_thread_helper_is_running_locked(), os_thread_helper::os_thread_helper_lock(), and os_thread_helper::os_thread_helper_unlock().

Variable Documentation

◆ binding_profiles

struct xrt_binding_profile binding_profiles[1]
static
Initial value:
= {
{
.name = XRT_DEVICE_SIMPLE_CONTROLLER,
.inputs = simple_inputs,
.input_count = ARRAY_SIZE(simple_inputs),
.outputs = NULL,
.output_count = 0,
},
}
#define ARRAY_SIZE(a)
Array size helper.
Definition: xrt_compiler.h:30

◆ simple_inputs

struct xrt_binding_input_pair simple_inputs[4]
static
Initial value:
= {
{XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_DAYDREAM_BAR_CLICK},
{XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_DAYDREAM_CIRCLE_CLICK},
{XRT_INPUT_SIMPLE_GRIP_POSE, XRT_INPUT_DAYDREAM_POSE},
{XRT_INPUT_SIMPLE_AIM_POSE, XRT_INPUT_DAYDREAM_POSE},
}