From 81984b7d48b7459155353833b04016aa0f83a4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 31 Dec 2020 23:45:47 +0100 Subject: [PATCH] Add Rumble to Lib --- gui/src/streamsession.cpp | 7 +++++++ lib/include/chiaki/session.h | 8 ++++++++ lib/include/chiaki/takion.h | 1 + lib/src/streamconnection.c | 35 +++++++++++++++++++++++++++++++++-- lib/src/takion.c | 5 +++-- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index f5c4c89..886806f 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -381,6 +381,13 @@ void StreamSession::Event(ChiakiEvent *event) case CHIAKI_EVENT_LOGIN_PIN_REQUEST: emit LoginPINRequested(event->login_pin_request.pin_incorrect); break; + case CHIAKI_EVENT_RUMBLE: + // TODO + //CHIAKI_LOGD(GetChiakiLog(), "Rumble %#02x, %#02x, %#02x", + // event->rumble.unknown, event->rumble.left, event->rumble.right); + break; + default: + break; } } diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h index 1706e27..a3480c1 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -114,6 +114,12 @@ typedef struct chiaki_audio_stream_info_event_t ChiakiAudioHeader audio_header; } ChiakiAudioStreamInfoEvent; +typedef struct chiaki_rumble_event_t +{ + uint8_t unknown; + uint8_t left; + uint8_t right; +} ChiakiRumbleEvent; typedef enum { CHIAKI_EVENT_CONNECTED, @@ -121,6 +127,7 @@ typedef enum { CHIAKI_EVENT_KEYBOARD_OPEN, CHIAKI_EVENT_KEYBOARD_TEXT_CHANGE, CHIAKI_EVENT_KEYBOARD_REMOTE_CLOSE, + CHIAKI_EVENT_RUMBLE, CHIAKI_EVENT_QUIT, } ChiakiEventType; @@ -131,6 +138,7 @@ typedef struct chiaki_event_t { ChiakiQuitEvent quit; ChiakiKeyboardEvent keyboard; + ChiakiRumbleEvent rumble; struct { bool pin_incorrect; // false on first request, true if the pin entered before was incorrect diff --git a/lib/include/chiaki/takion.h b/lib/include/chiaki/takion.h index 3f7e96f..1715842 100644 --- a/lib/include/chiaki/takion.h +++ b/lib/include/chiaki/takion.h @@ -26,6 +26,7 @@ extern "C" { typedef enum chiaki_takion_message_data_type_t { CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF = 0, + CHIAKI_TAKION_MESSAGE_DATA_TYPE_RUMBLE = 7, CHIAKI_TAKION_MESSAGE_DATA_TYPE_9 = 9 } ChiakiTakionMessageDataType; diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index c8ed43c..28b22dc 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -45,6 +45,8 @@ void chiaki_session_send_event(ChiakiSession *session, ChiakiEvent *event); static void stream_connection_takion_cb(ChiakiTakionEvent *event, void *user); static void stream_connection_takion_data(ChiakiStreamConnection *stream_connection, ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size); +static void stream_connection_takion_data_protobuf(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size); +static void stream_connection_takion_data_rumble(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size); static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream_connection); static ChiakiErrorCode stream_connection_send_disconnect(ChiakiStreamConnection *stream_connection); static void stream_connection_takion_data_idle(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size); @@ -368,9 +370,21 @@ static void stream_connection_takion_cb(ChiakiTakionEvent *event, void *user) static void stream_connection_takion_data(ChiakiStreamConnection *stream_connection, ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size) { - if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF) - return; + switch(data_type) + { + case CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF: + stream_connection_takion_data_protobuf(stream_connection, buf, buf_size); + break; + case CHIAKI_TAKION_MESSAGE_DATA_TYPE_RUMBLE: + stream_connection_takion_data_rumble(stream_connection, buf, buf_size); + break; + default: + break; + } +} +static void stream_connection_takion_data_protobuf(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size) +{ chiaki_mutex_lock(&stream_connection->state_mutex); switch(stream_connection->state) { @@ -385,6 +399,23 @@ static void stream_connection_takion_data(ChiakiStreamConnection *stream_connect break; } chiaki_mutex_unlock(&stream_connection->state_mutex); + +} + +static void stream_connection_takion_data_rumble(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size) +{ + if(buf_size < 3) + { + CHIAKI_LOGE(stream_connection->log, "StreamConnection got rumble packet with size %#llx < 3", + (unsigned long long)buf_size); + return; + } + ChiakiEvent event = { 0 }; + event.type = CHIAKI_EVENT_RUMBLE; + event.rumble.unknown = buf[0]; + event.rumble.left = buf[1]; + event.rumble.right = buf[2]; + chiaki_session_send_event(stream_connection->session, &event); } static void stream_connection_takion_data_handle_disconnect(ChiakiStreamConnection *stream_connection, uint8_t *buf, size_t buf_size) diff --git a/lib/src/takion.c b/lib/src/takion.c index 48a1537..fe3e95b 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -56,7 +56,6 @@ typedef enum takion_packet_type_t { TAKION_PACKET_TYPE_HANDSHAKE = 4, TAKION_PACKET_TYPE_CONGESTION = 5, TAKION_PACKET_TYPE_FEEDBACK_STATE = 6, - TAKION_PACKET_TYPE_RUMBLE_EVENT = 7, TAKION_PACKET_TYPE_CLIENT_INFO = 8, TAKION_PACKET_TYPE_PAD_INFO_EVENT = 9 } TakionPacketType; @@ -961,7 +960,9 @@ static void takion_flush_data_queue(ChiakiTakion *takion) if(zero_a != 0) CHIAKI_LOGW(takion->log, "Takion received data with unexpected nonzero %#x at buf+6", zero_a); - if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF && data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_9) + if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF + && data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_RUMBLE + && data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_9) { CHIAKI_LOGW(takion->log, "Takion received data with unexpected data type %#x", data_type); chiaki_log_hexdump(takion->log, CHIAKI_LOG_WARNING, entry->packet_buf, entry->packet_size);