From a0567b670c3fef388d1a8939ee327849326fa436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 4 Jul 2019 21:10:56 +0200 Subject: [PATCH] Add Face Buttons to ChiakiControllerState --- gui/src/streamsession.cpp | 9 +++++++++ lib/include/chiaki/controller.h | 16 +++++++++++++++- lib/include/chiaki/feedback.h | 1 + lib/src/controller.c | 1 + lib/src/feedback.c | 1 + lib/src/feedbacksender.c | 1 + 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index 3be2589..3e5f0c3 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -113,6 +113,10 @@ void StreamSession::UpdateGamepads() { gamepad = new QGamepad(connected_pads[0], this); 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::axisLeftYChanged, this, &StreamSession::SendFeedbackState); connect(gamepad, &QGamepad::axisRightXChanged, this, &StreamSession::SendFeedbackState); @@ -128,6 +132,11 @@ void StreamSession::SendFeedbackState() if(!gamepad) return; 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(gamepad->axisLeftX() * 0x7fff); state.left_y = static_cast(gamepad->axisLeftY() * 0x7fff); state.right_x = static_cast(gamepad->axisRightX() * 0x7fff); diff --git a/lib/include/chiaki/controller.h b/lib/include/chiaki/controller.h index d60f820..e98307a 100644 --- a/lib/include/chiaki/controller.h +++ b/lib/include/chiaki/controller.h @@ -27,8 +27,21 @@ extern "C" { #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 { + /** + * Bitmask of ChiakiControllerButton + */ + uint32_t buttons; + int16_t left_x; int16_t left_y; 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) { - 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->right_x == b->right_x && a->right_y == b->right_y; diff --git a/lib/include/chiaki/feedback.h b/lib/include/chiaki/feedback.h index e0f548a..f35695f 100644 --- a/lib/include/chiaki/feedback.h +++ b/lib/include/chiaki/feedback.h @@ -29,6 +29,7 @@ extern "C" { typedef struct chiaki_feedback_state_t { + uint32_t buttons; int16_t left_x; int16_t left_y; int16_t right_x; diff --git a/lib/src/controller.c b/lib/src/controller.c index 864af11..5be5b1f 100644 --- a/lib/src/controller.c +++ b/lib/src/controller.c @@ -19,6 +19,7 @@ CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state) { + state->buttons = 0; state->left_x = 0; state->left_y = 0; state->right_x = 0; diff --git a/lib/src/feedback.c b/lib/src/feedback.c index f71c9f2..605c825 100644 --- a/lib/src/feedback.c +++ b/lib/src/feedback.c @@ -16,6 +16,7 @@ */ #include +#include #include diff --git a/lib/src/feedbacksender.c b/lib/src/feedbacksender.c index cff68b6..8b9e0ff 100644 --- a/lib/src/feedbacksender.c +++ b/lib/src/feedbacksender.c @@ -87,6 +87,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_feedback_sender_set_controller_state(Chiaki static void feedback_sender_send_state(ChiakiFeedbackSender *feedback_sender) { ChiakiFeedbackState state; + state.buttons = feedback_sender->controller_state.buttons; state.left_x = feedback_sender->controller_state.left_x; state.left_y = feedback_sender->controller_state.left_y; state.right_x = feedback_sender->controller_state.right_x;