hid: Write to all layouts, implement circular buffers, set up controller metadata.
This commit is contained in:
parent
713c1ed203
commit
d20a883194
|
@ -65,44 +65,71 @@ private:
|
||||||
if (is_device_reload_pending.exchange(false))
|
if (is_device_reload_pending.exchange(false))
|
||||||
LoadInputDevices();
|
LoadInputDevices();
|
||||||
|
|
||||||
// TODO(shinyquagsire23): This is a hack!
|
// Set up controllers as neon red+blue Joy-Con attached to console
|
||||||
ControllerPadState& state =
|
ControllerHeader& controllerHeader = mem->controllers[Controller_Handheld].header;
|
||||||
mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons;
|
controllerHeader.type = ControllerType_Handheld | ControllerType_JoyconPair;
|
||||||
using namespace Settings::NativeButton;
|
controllerHeader.singleColorsDescriptor = ColorDesc_ColorsNonexistent;
|
||||||
state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus());
|
controllerHeader.rightColorBody = 0xFF3C28;
|
||||||
state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus());
|
controllerHeader.rightColorButtons = 0x1E0A0A;
|
||||||
state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus());
|
controllerHeader.leftColorBody = 0x0AB9E6;
|
||||||
state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus());
|
controllerHeader.leftColorButtons = 0x001E1E;
|
||||||
state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus());
|
|
||||||
|
|
||||||
state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus());
|
for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++)
|
||||||
state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus());
|
{
|
||||||
state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus());
|
ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx];
|
||||||
state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus());
|
layout.header.numEntries = HID_NUM_ENTRIES;
|
||||||
|
layout.header.maxEntryIndex = HID_NUM_ENTRIES - 1;
|
||||||
|
|
||||||
state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
// HID shared memory stores the state of the past 17 samples in a circlular buffer,
|
||||||
state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
// each with a timestamp in number of samples since boot.
|
||||||
state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
layout.header.timestampTicks = CoreTiming::GetTicks();
|
||||||
state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
layout.header.latestEntry = (layout.header.latestEntry + 1) % HID_NUM_ENTRIES;
|
||||||
|
|
||||||
state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
ControllerInputEntry& entry = layout.entries[layout.header.latestEntry];
|
||||||
state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
entry.connectionState = ConnectionState_Connected | ConnectionState_Wired;
|
||||||
state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
entry.timestamp++;
|
||||||
state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp?
|
||||||
|
|
||||||
state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus());
|
// TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future?
|
||||||
state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus());
|
// For now everything is just the default handheld layout, but split Joy-Con will
|
||||||
|
// rotate the face buttons and directions for certain layouts.
|
||||||
|
ControllerPadState& state = entry.buttons;
|
||||||
|
using namespace Settings::NativeButton;
|
||||||
|
state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
// TODO(shinyquagsire23): Analog stick vals
|
state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
// TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts)
|
state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
|
state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
|
state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
|
// TODO(shinyquagsire23): Analog stick vals
|
||||||
|
|
||||||
|
// TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(shinyquagsire23): Update touch info
|
// TODO(shinyquagsire23): Update touch info
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@ namespace HID {
|
||||||
|
|
||||||
// Begin enums and output structs
|
// Begin enums and output structs
|
||||||
|
|
||||||
|
constexpr u32 HID_NUM_ENTRIES = 17;
|
||||||
|
constexpr u32 HID_NUM_LAYOUTS = 7;
|
||||||
|
constexpr s32 HID_JOYSTICK_MAX = 0x8000;
|
||||||
|
constexpr s32 HID_JOYSTICK_MIN = -0x8000;
|
||||||
|
|
||||||
enum ControllerType : u32 {
|
enum ControllerType : u32 {
|
||||||
ControllerType_ProController = 1 << 0,
|
ControllerType_ProController = 1 << 0,
|
||||||
ControllerType_Handheld = 1 << 1,
|
ControllerType_Handheld = 1 << 1,
|
||||||
|
@ -215,7 +220,7 @@ struct ControllerHeader {
|
||||||
u32 leftColorBody;
|
u32 leftColorBody;
|
||||||
u32 leftColorButtons;
|
u32 leftColorButtons;
|
||||||
u32 rightColorBody;
|
u32 rightColorBody;
|
||||||
u32 rightColorbuttons;
|
u32 rightColorButtons;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ControllerHeader) == 0x28,
|
static_assert(sizeof(ControllerHeader) == 0x28,
|
||||||
"HID controller header structure has incorrect size");
|
"HID controller header structure has incorrect size");
|
||||||
|
|
Reference in New Issue