hid: Write to all layouts, implement circular buffers, set up controller metadata.

This commit is contained in:
shinyquagsire23 2018-01-16 03:14:27 -07:00
parent 713c1ed203
commit d20a883194
2 changed files with 65 additions and 33 deletions

View file

@ -65,9 +65,35 @@ private:
if (is_device_reload_pending.exchange(false))
LoadInputDevices();
// TODO(shinyquagsire23): This is a hack!
ControllerPadState& state =
mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons;
// Set up controllers as neon red+blue Joy-Con attached to console
ControllerHeader& controllerHeader = mem->controllers[Controller_Handheld].header;
controllerHeader.type = ControllerType_Handheld | ControllerType_JoyconPair;
controllerHeader.singleColorsDescriptor = ColorDesc_ColorsNonexistent;
controllerHeader.rightColorBody = 0xFF3C28;
controllerHeader.rightColorButtons = 0x1E0A0A;
controllerHeader.leftColorBody = 0x0AB9E6;
controllerHeader.leftColorButtons = 0x001E1E;
for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++)
{
ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx];
layout.header.numEntries = HID_NUM_ENTRIES;
layout.header.maxEntryIndex = HID_NUM_ENTRIES - 1;
// HID shared memory stores the state of the past 17 samples in a circlular buffer,
// each with a timestamp in number of samples since boot.
layout.header.timestampTicks = CoreTiming::GetTicks();
layout.header.latestEntry = (layout.header.latestEntry + 1) % HID_NUM_ENTRIES;
ControllerInputEntry& entry = layout.entries[layout.header.latestEntry];
entry.connectionState = ConnectionState_Connected | ConnectionState_Wired;
entry.timestamp++;
entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp?
// 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
// 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());
@ -103,6 +129,7 @@ private:
// TODO(shinyquagsire23): Analog stick vals
// TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts)
}
// TODO(shinyquagsire23): Update touch info

View file

@ -12,6 +12,11 @@ namespace HID {
// 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 {
ControllerType_ProController = 1 << 0,
ControllerType_Handheld = 1 << 1,
@ -215,7 +220,7 @@ struct ControllerHeader {
u32 leftColorBody;
u32 leftColorButtons;
u32 rightColorBody;
u32 rightColorbuttons;
u32 rightColorButtons;
};
static_assert(sizeof(ControllerHeader) == 0x28,
"HID controller header structure has incorrect size");