-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapticsengine.h
195 lines (161 loc) · 8.67 KB
/
adapticsengine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Automatically generated by Interoptopus.
#ifndef ADAPTICS_ENGINE_H
#define ADAPTICS_ENGINE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#ifndef ADAPTICS_EXPORT
# ifdef _MSC_VER
# define ADAPTICS_EXPORT __declspec(dllimport)
# else
# define ADAPTICS_EXPORT
# endif
#endif
typedef struct adaptics_engine_ffi_handle adaptics_engine_ffi_handle;
typedef enum adaptics_engine_ffi_error
{
ADAPTICS_ENGINE_FFI_ERROR_OK = 0,
ADAPTICS_ENGINE_FFI_ERROR_NULLPASSED = 1,
ADAPTICS_ENGINE_FFI_ERROR_PANIC = 2,
ADAPTICS_ENGINE_FFI_ERROR_OTHERERROR = 3,
ADAPTICS_ENGINE_FFI_ERROR_ADAPTICSENGINETHREADDISCONNECTEDCHECKDEINITFORMOREINFO = 4,
ADAPTICS_ENGINE_FFI_ERROR_ERRMSGPROVIDED = 5,
ADAPTICS_ENGINE_FFI_ERROR_ENABLEPLAYBACKUPDATESWASFALSE = 6,
ADAPTICS_ENGINE_FFI_ERROR_PARAMJSONDESERIALIZATIONFAILED = 8,
ADAPTICS_ENGINE_FFI_ERROR_HANDLEIDNOTFOUND = 9,
ADAPTICS_ENGINE_FFI_ERROR_PARAMUTF8ERROR = 10,
ADAPTICS_ENGINE_FFI_ERROR_MUTEXPOISONED = 11,
ADAPTICS_ENGINE_FFI_ERROR_PARAMASCIIERROR = 12,
ADAPTICS_ENGINE_FFI_ERROR_INTEROPUNSUPPORTED = 13,
ADAPTICS_ENGINE_FFI_ERROR_INTEROPFORMATERROR = 14,
ADAPTICS_ENGINE_FFI_ERROR_INTEROPUNKERROR = 15,
ADAPTICS_ENGINE_FFI_ERROR_TIMEERROR = 16,
ADAPTICS_ENGINE_FFI_ERROR_CASTERROR = 17,
ADAPTICS_ENGINE_FFI_ERROR_ADAPTICSERROR = 18,
ADAPTICS_ENGINE_FFI_ERROR_ERRMSGBUFFERNULL = 19,
} adaptics_engine_ffi_error;
/// !NOTE: y and z are swapped for Unity
typedef struct adaptics_engine_unity_eval_coords
{
double x;
double y;
double z;
} adaptics_engine_unity_eval_coords;
/// Defines a 4x4 matrix in row-major order for FFI.
typedef struct adaptics_engine_geo_matrix
{
double data[16];
} adaptics_engine_geo_matrix;
/// !NOTE: y and z are swapped for Unity
typedef struct adaptics_engine_unity_eval_result
{
/// !NOTE: y and z are swapped for Unity
adaptics_engine_unity_eval_coords coords;
double intensity;
double pattern_time;
bool stop;
} adaptics_engine_unity_eval_result;
///A pointer to an array of data someone else owns which may be modified.
typedef struct adaptics_engine_slice_mutu8
{
///Pointer to start of mutable data.
const uint8_t* data;
///Number of elements.
uint64_t len;
} adaptics_engine_slice_mutu8;
///A pointer to an array of data someone else owns which may be modified.
typedef struct adaptics_engine_slice_mut_unity_eval_result
{
///Pointer to start of mutable data.
const adaptics_engine_unity_eval_result* data;
///Number of elements.
uint64_t len;
} adaptics_engine_slice_mut_unity_eval_result;
/// Destroys the given instance.
///
/// # Safety
///
/// The passed parameter MUST have been created with the corresponding init function;
/// passing any other value results in undefined behavior.
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_destroy(adaptics_engine_ffi_handle** context);
/// Initializes the Adaptics Engine, returns a handle ID.
///
/// `use_mock_streaming`: if true, use mock streaming. if false, use ulhaptics streaming.
///
/// `enable_playback_updates`: if true, enable playback updates, `adaptics_engine_get_playback_updates` expected to be called at (1/`SECONDS_PER_PLAYBACK_UPDATE`)hz.
///
/// `vib_grid`: Alpha feature: Output to a vibrotactile grid device (e.g. a vest or glove) instead of a mid-air ultrasound haptic device.
/// If len is 0, the vibrotactile grid feature is disabled. If "auto", the device will attempt to auto-detect the device.
///
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_init_experimental(adaptics_engine_ffi_handle** context, bool use_mock_streaming, bool enable_playback_updates, const char* vib_grid, bool enable_ultraleap_tracking);
/// Initializes the Adaptics Engine, returns a handle ID.
///
/// `use_mock_streaming`: if true, use mock streaming. if false, use ulhaptics streaming.
///
/// `enable_playback_updates`: if true, enable playback updates, `adaptics_engine_get_playback_updates` expected to be called at (1/`SECONDS_PER_PLAYBACK_UPDATE`)hz.
///
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_init(adaptics_engine_ffi_handle** context, bool use_mock_streaming, bool enable_playback_updates);
/// Deinitializes the Adaptics Engine.
/// Returns with an error message if available.
///
/// The unity package uses a `err_msg` buffer of size 1024.
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_deinit(const adaptics_engine_ffi_handle* context, adaptics_engine_slice_mutu8 err_msg);
/// Updates the pattern to be played.
/// For further information, see [`PatternEvalUpdate::Pattern`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_pattern(const adaptics_engine_ffi_handle* context, const char* pattern_json);
/// Alias for [`crate::adaptics_engine_update_pattern()`]
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_tacton(const adaptics_engine_ffi_handle* context, const char* pattern_json);
/// Used to start and stop playback.
/// For further information, see [`PatternEvalUpdate::Playstart`].
///
/// To correctly start in the middle of a pattern, ensure that the time parameter is set appropriately before initiating playback.
/// Use [`adaptics_engine_update_time()`] or [`adaptics_engine_update_parameters()`] to set the time parameter.
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_playstart(const adaptics_engine_ffi_handle* context, double playstart, double playstart_offset);
/// Used to update all `evaluator_params`.
///
/// Accepts a JSON string representing the evaluator parameters. See [`PatternEvaluatorParameters`].
/// For further information, see [`PatternEvalUpdate::Parameters`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_parameters(const adaptics_engine_ffi_handle* context, const char* evaluator_params);
/// Resets all evaluator parameters to their default values.
/// For further information, see [`PatternEvalUpdate::Parameters`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_reset_parameters(const adaptics_engine_ffi_handle* context);
/// Updates `evaluator_params.time`.
///
/// To correctly start in the middle of a pattern, ensure that the time parameter is set appropriately before initiating playback.
///
/// # Notes
/// - `evaluator_params.time` will be overwritten by the playstart time computation during playback.
/// - Setting `evaluator_params.time` will not cause any pattern evaluation to occur (no playback updates).
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_time(const adaptics_engine_ffi_handle* context, double time);
/// Updates all user parameters.
/// Accepts a JSON string of user parameters in the format `{ [key: string]: double }`.
/// For further information, see [`PatternEvalUpdate::UserParameters`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_user_parameters(const adaptics_engine_ffi_handle* context, const char* user_parameters);
/// Updates a single user parameter.
/// Accepts a JSON string of user parameters in the format `{ [key: string]: double }`.
/// For further information, see [`PatternEvalUpdate::UserParameters`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_user_parameter(const adaptics_engine_ffi_handle* context, const char* name, double value);
/// Updates `geo_matrix`, a 4x4 matrix in row-major order, where `data[3]` is the fourth element of the first row (translate x).
/// For further information, see [`PatternEvalUpdate::GeoTransformMatrix`].
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_update_geo_transform_matrix(const adaptics_engine_ffi_handle* context, const adaptics_engine_geo_matrix* geo_matrix);
/// Actually Unsafe! This function is marked as unsafe because it dereferences a raw pointer.
///
/// Populate `eval_results` with the latest evaluation results.
/// `num_evals` will be set to the number of evaluations written to `eval_results`, or 0 if there are no new evaluations since the last call to this function.
///
/// # Safety
/// `num_evals` must be a valid pointer to a u32
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_get_playback_updates(const adaptics_engine_ffi_handle* context, adaptics_engine_slice_mut_unity_eval_result* eval_results, uint32_t* num_evals);
/// Higher level function to load a new pattern and instantly start playback.
ADAPTICS_EXPORT adaptics_engine_ffi_error adaptics_engine_adaptics_engine_play_tacton_immediate(const adaptics_engine_ffi_handle* context, const char* tacton_json);
/// Guard function used by bindings.
///
/// Change impl version in this comment to force bump the API version.
/// `impl_version`: 1
ADAPTICS_EXPORT uint64_t ffi_api_guard();
#ifdef __cplusplus
}
#endif
#endif /* ADAPTICS_ENGINE_H */