Add Rumble to Lib

This commit is contained in:
Florian Märkl 2020-12-31 23:45:47 +01:00
parent fbb19f94ea
commit 81984b7d48
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
5 changed files with 52 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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;

View file

@ -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)

View file

@ -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);