/*
 * imu.c: the XREAL glasses' motion sensors, fused (3DoF). Shared by the
 * compositor (tracker.c) and c8-xr's Monado driver, so nothing here
 * knows either: the host gives the loop it runs on and what it asks.
 */
#ifndef C8_IMU_H
#define C8_IMU_H

#include <stdbool.h>
#include <stdint.h>
#include <wayland-server-core.h>
#include "math3d.h"

struct c8_imu_host {
	/* The fd while connecting and the timers are added to it; c8_imu_*
	 * are called on the thread that dispatches it */
	struct wl_event_loop *loop;
	/* Tracking came, went or settled (settled: a fresh fix) */
	void (*changed)(void *data, bool settled);
	/* [glasses] tilt (degrees) and steady, asked as they're used, so a
	 * changed config takes at once */
	void (*settings)(void *data, double *tilt_deg, bool *steady);
	/* Wanted a while and nothing came: tell the person, once */
	void (*silent)(void *data);
	void *data;
};

struct c8_imu;
struct c8_imu *c8_imu_create(const struct c8_imu_host *host);
void c8_imu_destroy(struct c8_imu *imu);
void c8_imu_set_wanted(struct c8_imu *imu, bool wanted);
/* Takes what the stream has brought */
void c8_imu_read(struct c8_imu *imu);
/* Where the head will point at when_ns (CLOCK_MONOTONIC), in the head's
 * axes (+x right, +y up, -z ahead); false without tracking */
bool c8_imu_orientation(struct c8_imu *imu, int64_t when_ns,
	struct quat *out);
/* The network interface with our end of the glasses' link (16 bytes,
 * IF_NAMESIZE), false while it isn't up */
bool c8_imu_glasses_link(char name[16]);

#endif
