mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 13:33:13 -07:00
Add Face Buttons to ChiakiControllerState
This commit is contained in:
parent
ebcf72fb10
commit
a0567b670c
6 changed files with 28 additions and 1 deletions
|
@ -113,6 +113,10 @@ void StreamSession::UpdateGamepads()
|
||||||
{
|
{
|
||||||
gamepad = new QGamepad(connected_pads[0], this);
|
gamepad = new QGamepad(connected_pads[0], this);
|
||||||
qDebug() << "gamepad" << connected_pads[0] << "connected: " << gamepad->name();
|
qDebug() << "gamepad" << connected_pads[0] << "connected: " << gamepad->name();
|
||||||
|
connect(gamepad, &QGamepad::buttonAChanged, this, &StreamSession::SendFeedbackState);
|
||||||
|
connect(gamepad, &QGamepad::buttonBChanged, this, &StreamSession::SendFeedbackState);
|
||||||
|
connect(gamepad, &QGamepad::buttonXChanged, this, &StreamSession::SendFeedbackState);
|
||||||
|
connect(gamepad, &QGamepad::buttonYChanged, this, &StreamSession::SendFeedbackState);
|
||||||
connect(gamepad, &QGamepad::axisLeftXChanged, this, &StreamSession::SendFeedbackState);
|
connect(gamepad, &QGamepad::axisLeftXChanged, this, &StreamSession::SendFeedbackState);
|
||||||
connect(gamepad, &QGamepad::axisLeftYChanged, this, &StreamSession::SendFeedbackState);
|
connect(gamepad, &QGamepad::axisLeftYChanged, this, &StreamSession::SendFeedbackState);
|
||||||
connect(gamepad, &QGamepad::axisRightXChanged, this, &StreamSession::SendFeedbackState);
|
connect(gamepad, &QGamepad::axisRightXChanged, this, &StreamSession::SendFeedbackState);
|
||||||
|
@ -128,6 +132,11 @@ void StreamSession::SendFeedbackState()
|
||||||
if(!gamepad)
|
if(!gamepad)
|
||||||
return;
|
return;
|
||||||
ChiakiControllerState state;
|
ChiakiControllerState state;
|
||||||
|
state.buttons = 0;
|
||||||
|
state.buttons |= gamepad->buttonA() ? CHIAKI_CONTROLLER_BUTTON_CROSS : 0;
|
||||||
|
state.buttons |= gamepad->buttonB() ? CHIAKI_CONTROLLER_BUTTON_MOON : 0;
|
||||||
|
state.buttons |= gamepad->buttonX() ? CHIAKI_CONTROLLER_BUTTON_BOX : 0;
|
||||||
|
state.buttons |= gamepad->buttonY() ? CHIAKI_CONTROLLER_BUTTON_PYRAMID : 0;
|
||||||
state.left_x = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
|
state.left_x = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
|
||||||
state.left_y = static_cast<int16_t>(gamepad->axisLeftY() * 0x7fff);
|
state.left_y = static_cast<int16_t>(gamepad->axisLeftY() * 0x7fff);
|
||||||
state.right_x = static_cast<int16_t>(gamepad->axisRightX() * 0x7fff);
|
state.right_x = static_cast<int16_t>(gamepad->axisRightX() * 0x7fff);
|
||||||
|
|
|
@ -27,8 +27,21 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum chiaki_controller_button_t
|
||||||
|
{
|
||||||
|
CHIAKI_CONTROLLER_BUTTON_CROSS = (1 << 0),
|
||||||
|
CHIAKI_CONTROLLER_BUTTON_MOON = (1 << 1),
|
||||||
|
CHIAKI_CONTROLLER_BUTTON_BOX = (1 << 2),
|
||||||
|
CHIAKI_CONTROLLER_BUTTON_PYRAMID = (1 << 3)
|
||||||
|
} ChiakiControllerButton;
|
||||||
|
|
||||||
typedef struct chiaki_controller_state_t
|
typedef struct chiaki_controller_state_t
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Bitmask of ChiakiControllerButton
|
||||||
|
*/
|
||||||
|
uint32_t buttons;
|
||||||
|
|
||||||
int16_t left_x;
|
int16_t left_x;
|
||||||
int16_t left_y;
|
int16_t left_y;
|
||||||
int16_t right_x;
|
int16_t right_x;
|
||||||
|
@ -39,7 +52,8 @@ CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state
|
||||||
|
|
||||||
static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b)
|
static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b)
|
||||||
{
|
{
|
||||||
return a->left_x == b->left_x
|
return a->buttons == b->buttons
|
||||||
|
&& a->left_x == b->left_x
|
||||||
&& a->left_y == b->left_y
|
&& a->left_y == b->left_y
|
||||||
&& a->right_x == b->right_x
|
&& a->right_x == b->right_x
|
||||||
&& a->right_y == b->right_y;
|
&& a->right_y == b->right_y;
|
||||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct chiaki_feedback_state_t
|
typedef struct chiaki_feedback_state_t
|
||||||
{
|
{
|
||||||
|
uint32_t buttons;
|
||||||
int16_t left_x;
|
int16_t left_x;
|
||||||
int16_t left_y;
|
int16_t left_y;
|
||||||
int16_t right_x;
|
int16_t right_x;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state)
|
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state)
|
||||||
{
|
{
|
||||||
|
state->buttons = 0;
|
||||||
state->left_x = 0;
|
state->left_x = 0;
|
||||||
state->left_y = 0;
|
state->left_y = 0;
|
||||||
state->right_x = 0;
|
state->right_x = 0;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <chiaki/feedback.h>
|
#include <chiaki/feedback.h>
|
||||||
|
#include <chiaki/controller.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_sender_set_controller_state(Chiaki
|
||||||
static void feedback_sender_send_state(ChiakiFeedbackSender *feedback_sender)
|
static void feedback_sender_send_state(ChiakiFeedbackSender *feedback_sender)
|
||||||
{
|
{
|
||||||
ChiakiFeedbackState state;
|
ChiakiFeedbackState state;
|
||||||
|
state.buttons = feedback_sender->controller_state.buttons;
|
||||||
state.left_x = feedback_sender->controller_state.left_x;
|
state.left_x = feedback_sender->controller_state.left_x;
|
||||||
state.left_y = feedback_sender->controller_state.left_y;
|
state.left_y = feedback_sender->controller_state.left_y;
|
||||||
state.right_x = feedback_sender->controller_state.right_x;
|
state.right_x = feedback_sender->controller_state.right_x;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue