mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 05:53:12 -07:00
Add Motion to Feedback
This commit is contained in:
parent
170dcd4d65
commit
cb827a525a
8 changed files with 182 additions and 50 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue