forked from ShuriZma/suyu
1
0
Fork 0

hid: Tweaks, Analog Sticks (#435)

* hid: Update mouse/keyboard state

* hid: Working analog sticks

* hid: Nits

* hid: Nits

* hid: Update mystery sections

* hid: Tweaks
This commit is contained in:
Max Thomas 2018-05-07 09:06:02 -06:00 committed by bunnei
parent 9eccb5de9d
commit 266703b50e
3 changed files with 215 additions and 59 deletions

View File

@ -60,7 +60,10 @@ private:
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
// TODO(shinyquagsire23): sticks, gyro, touch, mouse, keyboard std::transform(Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_END,
sticks.begin(), Input::CreateDevice<Input::AnalogDevice>);
// TODO(shinyquagsire23): gyro, touch, mouse, keyboard
} }
void UpdatePadCallback(u64 userdata, int cycles_late) { void UpdatePadCallback(u64 userdata, int cycles_late) {
@ -79,8 +82,9 @@ private:
controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; controller_header.left_color_body = JOYCON_BODY_NEON_BLUE;
controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE;
for (size_t controller = 0; controller < mem.controllers.size(); controller++) {
for (int index = 0; index < HID_NUM_LAYOUTS; index++) { for (int index = 0; index < HID_NUM_LAYOUTS; index++) {
ControllerLayout& layout = mem.controllers[Controller_Handheld].layouts[index]; ControllerLayout& layout = mem.controllers[controller].layouts[index];
layout.header.num_entries = HID_NUM_ENTRIES; layout.header.num_entries = HID_NUM_ENTRIES;
layout.header.max_entry_index = HID_NUM_ENTRIES - 1; layout.header.max_entry_index = HID_NUM_ENTRIES - 1;
@ -92,7 +96,12 @@ private:
ControllerInputEntry& entry = layout.entries[layout.header.latest_entry]; ControllerInputEntry& entry = layout.entries[layout.header.latest_entry];
entry.connection_state = ConnectionState_Connected | ConnectionState_Wired; entry.connection_state = ConnectionState_Connected | ConnectionState_Wired;
entry.timestamp++; entry.timestamp++;
entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp? // TODO(shinyquagsire23): Is this always identical to timestamp?
entry.timestamp_2++;
// TODO(shinyquagsire23): More than just handheld input
if (controller != Controller_Handheld)
continue;
// TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future? // TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future?
// For now everything is just the default handheld layout, but split Joy-Con will // For now everything is just the default handheld layout, but split Joy-Con will
@ -130,10 +139,13 @@ private:
state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus());
state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus());
// TODO(shinyquagsire23): Analog stick vals const auto [stick_l_x_f, stick_l_y_f] = sticks[Joystick_Left]->GetStatus();
const auto [stick_r_x_f, stick_r_y_f] = sticks[Joystick_Right]->GetStatus();
// TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, entry.joystick_left_x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX);
// layouts) entry.joystick_left_y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX);
entry.joystick_right_x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX);
entry.joystick_right_y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX);
}
} }
// TODO(bunnei): Properly implement the touch screen, the below will just write empty data // TODO(bunnei): Properly implement the touch screen, the below will just write empty data
@ -151,6 +163,71 @@ private:
touchscreen.entries[curr_entry].header.timestamp = sample_counter; touchscreen.entries[curr_entry].header.timestamp = sample_counter;
touchscreen.entries[curr_entry].header.num_touches = 0; touchscreen.entries[curr_entry].header.num_touches = 0;
// TODO(shinyquagsire23): Properly implement mouse
Mouse& mouse = mem.mouse;
const u64 last_mouse_entry = mouse.header.latest_entry;
const u64 curr_mouse_entry = (mouse.header.latest_entry + 1) % mouse.entries.size();
const u64 mouse_sample_counter = mouse.entries[last_mouse_entry].timestamp + 1;
mouse.header.timestamp_ticks = timestamp;
mouse.header.num_entries = mouse.entries.size();
mouse.header.max_entry_index = mouse.entries.size();
mouse.header.latest_entry = curr_mouse_entry;
mouse.entries[curr_mouse_entry].timestamp = mouse_sample_counter;
mouse.entries[curr_mouse_entry].timestamp_2 = mouse_sample_counter;
// TODO(shinyquagsire23): Properly implement keyboard
Keyboard& keyboard = mem.keyboard;
const u64 last_keyboard_entry = keyboard.header.latest_entry;
const u64 curr_keyboard_entry =
(keyboard.header.latest_entry + 1) % keyboard.entries.size();
const u64 keyboard_sample_counter = keyboard.entries[last_keyboard_entry].timestamp + 1;
keyboard.header.timestamp_ticks = timestamp;
keyboard.header.num_entries = keyboard.entries.size();
keyboard.header.latest_entry = last_keyboard_entry;
keyboard.header.max_entry_index = keyboard.entries.size();
keyboard.entries[curr_keyboard_entry].timestamp = keyboard_sample_counter;
keyboard.entries[curr_keyboard_entry].timestamp_2 = keyboard_sample_counter;
// TODO(shinyquagsire23): Figure out what any of these are
for (size_t i = 0; i < mem.unk_input_1.size(); i++) {
UnkInput1& input = mem.unk_input_1[i];
const u64 last_input_entry = input.header.latest_entry;
const u64 curr_input_entry = (input.header.latest_entry + 1) % input.entries.size();
const u64 input_sample_counter = input.entries[last_input_entry].timestamp + 1;
input.header.timestamp_ticks = timestamp;
input.header.num_entries = input.entries.size();
input.header.latest_entry = last_input_entry;
input.header.max_entry_index = input.entries.size();
input.entries[curr_input_entry].timestamp = input_sample_counter;
input.entries[curr_input_entry].timestamp_2 = input_sample_counter;
}
for (size_t i = 0; i < mem.unk_input_2.size(); i++) {
UnkInput2& input = mem.unk_input_2[i];
input.header.timestamp_ticks = timestamp;
input.header.num_entries = 17;
input.header.latest_entry = 0;
input.header.max_entry_index = 0;
}
UnkInput3& input = mem.unk_input_3;
const u64 last_input_entry = input.header.latest_entry;
const u64 curr_input_entry = (input.header.latest_entry + 1) % input.entries.size();
const u64 input_sample_counter = input.entries[last_input_entry].timestamp + 1;
input.header.timestamp_ticks = timestamp;
input.header.num_entries = input.entries.size();
input.header.latest_entry = last_input_entry;
input.header.max_entry_index = input.entries.size();
input.entries[curr_input_entry].timestamp = input_sample_counter;
input.entries[curr_input_entry].timestamp_2 = input_sample_counter;
// TODO(shinyquagsire23): Signal events // TODO(shinyquagsire23): Signal events
std::memcpy(shared_mem->GetPointer(), &mem, sizeof(SharedMemory)); std::memcpy(shared_mem->GetPointer(), &mem, sizeof(SharedMemory));
@ -169,6 +246,7 @@ private:
std::atomic<bool> is_device_reload_pending{true}; std::atomic<bool> is_device_reload_pending{true};
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
buttons; buttons;
std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID> sticks;
}; };
class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> {

View File

@ -48,6 +48,11 @@ enum ControllerConnectionState {
ConnectionState_Wired = 1 << 1, ConnectionState_Wired = 1 << 1,
}; };
enum ControllerJoystick {
Joystick_Left = 0,
Joystick_Right = 1,
};
enum ControllerID { enum ControllerID {
Controller_Player1 = 0, Controller_Player1 = 0,
Controller_Player2 = 1, Controller_Player2 = 1,
@ -63,6 +68,34 @@ enum ControllerID {
// End enums and output structs // End enums and output structs
// Begin UnkInput3
struct UnkInput3Header {
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
};
static_assert(sizeof(UnkInput3Header) == 0x20, "HID UnkInput3 header structure has incorrect size");
struct UnkInput3Entry {
u64 timestamp;
u64 timestamp_2;
u64 unk_8;
u64 unk_10;
u64 unk_18;
};
static_assert(sizeof(UnkInput3Entry) == 0x28, "HID UnkInput3 entry structure has incorrect size");
struct UnkInput3 {
UnkInput3Header header;
std::array<UnkInput3Entry, 17> entries;
std::array<u8, 0x138> padding;
};
static_assert(sizeof(UnkInput3) == 0x400, "HID UnkInput3 structure has incorrect size");
// End UnkInput3
// Begin TouchScreen // Begin TouchScreen
struct TouchScreenHeader { struct TouchScreenHeader {
@ -204,6 +237,52 @@ static_assert(sizeof(Keyboard) == 0x400, "HID keyboard structure has incorrect s
// End Keyboard // End Keyboard
// Begin UnkInput1
struct UnkInput1Header {
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
};
static_assert(sizeof(UnkInput1Header) == 0x20, "HID UnkInput1 header structure has incorrect size");
struct UnkInput1Entry {
u64 timestamp;
u64 timestamp_2;
u64 unk_8;
u64 unk_10;
u64 unk_18;
};
static_assert(sizeof(UnkInput1Entry) == 0x28, "HID UnkInput1 entry structure has incorrect size");
struct UnkInput1 {
UnkInput1Header header;
std::array<UnkInput1Entry, 17> entries;
std::array<u8, 0x138> padding;
};
static_assert(sizeof(UnkInput1) == 0x400, "HID UnkInput1 structure has incorrect size");
// End UnkInput1
// Begin UnkInput2
struct UnkInput2Header {
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
};
static_assert(sizeof(UnkInput2Header) == 0x20, "HID UnkInput2 header structure has incorrect size");
struct UnkInput2 {
UnkInput2Header header;
std::array<u8, 0x1E0> padding;
};
static_assert(sizeof(UnkInput2) == 0x200, "HID UnkInput2 structure has incorrect size");
// End UnkInput2
// Begin Controller // Begin Controller
struct ControllerMAC { struct ControllerMAC {
@ -283,10 +362,10 @@ struct ControllerInputEntry {
u64 timestamp; u64 timestamp;
u64 timestamp_2; u64 timestamp_2;
ControllerPadState buttons; ControllerPadState buttons;
u32 joystick_left_x; s32 joystick_left_x;
u32 joystick_left_y; s32 joystick_left_y;
u32 joystick_right_x; s32 joystick_right_x;
u32 joystick_right_y; s32 joystick_right_y;
u64 connection_state; u64 connection_state;
}; };
static_assert(sizeof(ControllerInputEntry) == 0x30, static_assert(sizeof(ControllerInputEntry) == 0x30,
@ -312,17 +391,12 @@ static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorr
// End Controller // End Controller
struct SharedMemory { struct SharedMemory {
std::array<u8, 0x400> header; UnkInput3 unk_input_3;
TouchScreen touchscreen; TouchScreen touchscreen;
Mouse mouse; Mouse mouse;
Keyboard keyboard; Keyboard keyboard;
std::array<u8, 0x400> unk_section_1; std::array<UnkInput1, 4> unk_input_1;
std::array<u8, 0x400> unk_section_2; std::array<UnkInput2, 3> unk_input_2;
std::array<u8, 0x400> unk_section_3;
std::array<u8, 0x400> unk_section_4;
std::array<u8, 0x200> unk_section_5;
std::array<u8, 0x200> unk_section_6;
std::array<u8, 0x200> unk_section_7;
std::array<u8, 0x800> unk_section_8; std::array<u8, 0x800> unk_section_8;
std::array<u8, 0x4000> controller_serials; std::array<u8, 0x4000> controller_serials;
std::array<Controller, 10> controllers; std::array<Controller, 10> controllers;

View File

@ -99,6 +99,10 @@ enum Values {
NumAnalogs, NumAnalogs,
}; };
constexpr int STICK_HID_BEGIN = LStick;
constexpr int STICK_HID_END = NumAnalogs;
constexpr int NUM_STICKS_HID = NumAnalogs;
static const std::array<const char*, NumAnalogs> mapping = {{ static const std::array<const char*, NumAnalogs> mapping = {{
"lstick", "lstick",
"rstick", "rstick",