Add Motion to Feedback

This commit is contained in:
Florian Märkl 2021-01-06 21:42:06 +01:00
commit cb827a525a
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
8 changed files with 182 additions and 50 deletions

View file

@ -66,6 +66,10 @@ typedef struct chiaki_controller_state_t
uint8_t touch_id_next;
ChiakiControllerTouch touches[CHIAKI_CONTROLLER_TOUCHES_MAX];
float gyro_x, gyro_y, gyro_z;
float accel_x, accel_y, accel_z;
float orient_x, orient_y, orient_z, orient_w;
} ChiakiControllerState;
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state);
@ -79,27 +83,12 @@ CHIAKI_EXPORT void chiaki_controller_state_stop_touch(ChiakiControllerState *sta
CHIAKI_EXPORT void chiaki_controller_state_set_touch_pos(ChiakiControllerState *state, uint8_t id, uint16_t x, uint16_t y);
static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b)
{
if(!(a->buttons == b->buttons
&& a->l2_state == b->l2_state
&& a->r2_state == b->r2_state
&& a->left_x == b->left_x
&& a->left_y == b->left_y
&& a->right_x == b->right_x
&& a->right_y == b->right_y))
return false;
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
{
if(a->touches[i].id != b->touches[i].id)
return false;
if(a->touches[i].id >= 0 && (a->touches[i].x != b->touches[i].x || a->touches[i].y != b->touches[i].y))
return false;
}
return true;
}
CHIAKI_EXPORT bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b);
/**
* Union of two controller states.
* Ignores gyro, accel and orient because it makes no sense there.
*/
CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b);
#ifdef __cplusplus

View file

@ -15,6 +15,9 @@ extern "C" {
typedef struct chiaki_feedback_state_t
{
float gyro_x, gyro_y, gyro_z;
float accel_x, accel_y, accel_z;
float orient_x, orient_y, orient_z, orient_w;
int16_t left_x;
int16_t left_y;
int16_t right_x;

View file

@ -4,6 +4,7 @@
#define CHIAKI_ORIENTATION_H
#include "common.h"
#include "controller.h"
#ifdef __cplusplus
extern "C" {
@ -20,13 +21,16 @@ typedef struct chiaki_orientation_t
} ChiakiOrientation;
CHIAKI_EXPORT void chiaki_orientation_init(ChiakiOrientation *orient);
CHIAKI_EXPORT void chiaki_orientation_update(ChiakiOrientation *orient, float gx, float gy, float gz, float ax, float ay, float az, float time_step_sec);
CHIAKI_EXPORT void chiaki_orientation_update(ChiakiOrientation *orient,
float gx, float gy, float gz, float ax, float ay, float az, float time_step_sec);
/**
* Extension of ChiakiOrientation, also tracking an absolute timestamp
* Extension of ChiakiOrientation, also tracking an absolute timestamp and the current gyro/accel state
*/
typedef struct chiaki_orientation_tracker_t
{
float gyro_x, gyro_y, gyro_z;
float accel_x, accel_y, accel_z;
ChiakiOrientation orient;
uint32_t timestamp;
bool first_sample;
@ -35,6 +39,8 @@ typedef struct chiaki_orientation_tracker_t
CHIAKI_EXPORT void chiaki_orientation_tracker_init(ChiakiOrientationTracker *tracker);
CHIAKI_EXPORT void chiaki_orientation_tracker_update(ChiakiOrientationTracker *tracker,
float gx, float gy, float gz, float ax, float ay, float az, uint32_t timestamp_us);
CHIAKI_EXPORT void chiaki_orientation_tracker_apply_to_controller_state(ChiakiOrientationTracker *tracker,
ChiakiControllerState *state);
#ifdef __cplusplus
}