Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
55ded706
There was an error fetching the commit references. Please try again later.
Commit
55ded706
authored
6 years ago
by
Zach Hilman
Browse files
Options
Downloads
Patches
Plain Diff
hid/npad: Update NPad to use player controller bindings and type
parent
e9145c3e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/hle/service/hid/controllers/npad.cpp
+101
-53
101 additions, 53 deletions
src/core/hle/service/hid/controllers/npad.cpp
src/core/hle/service/hid/controllers/npad.h
+7
-2
7 additions, 2 deletions
src/core/hle/service/hid/controllers/npad.h
with
108 additions
and
55 deletions
src/core/hle/service/hid/controllers/npad.cpp
+
101
−
53
View file @
55ded706
...
...
@@ -17,11 +17,6 @@
#include
"core/settings.h"
namespace
Service
::
HID
{
constexpr
u32
JOYCON_BODY_NEON_RED
=
0xFF3C28
;
constexpr
u32
JOYCON_BUTTONS_NEON_RED
=
0x1E0A0A
;
constexpr
u32
JOYCON_BODY_NEON_BLUE
=
0x0AB9E6
;
constexpr
u32
JOYCON_BUTTONS_NEON_BLUE
=
0x001E1E
;
constexpr
s32
HID_JOYSTICK_MAX
=
0x7fff
;
constexpr
s32
HID_JOYSTICK_MIN
=
-
0x7fff
;
constexpr
std
::
size_t
NPAD_OFFSET
=
0x9A00
;
...
...
@@ -40,6 +35,22 @@ enum class JoystickId : std::size_t {
Joystick_Right
,
};
static
Controller_NPad
::
NPadControllerType
MapSettingsTypeToNPad
(
Settings
::
ControllerType
type
)
{
switch
(
type
)
{
case
Settings
::
ControllerType
::
ProController
:
return
Controller_NPad
::
NPadControllerType
::
ProController
;
case
Settings
::
ControllerType
::
DualJoycon
:
return
Controller_NPad
::
NPadControllerType
::
JoyDual
;
case
Settings
::
ControllerType
::
LeftJoycon
:
return
Controller_NPad
::
NPadControllerType
::
JoyLeft
;
case
Settings
::
ControllerType
::
RightJoycon
:
return
Controller_NPad
::
NPadControllerType
::
JoyRight
;
default:
UNREACHABLE
();
return
Controller_NPad
::
NPadControllerType
::
JoyDual
;
}
}
static
std
::
size_t
NPadIdToIndex
(
u32
npad_id
)
{
switch
(
npad_id
)
{
case
0
:
...
...
@@ -126,10 +137,11 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
controller
.
single_color
.
button_color
=
0
;
controller
.
dual_color_error
=
ColorReadError
::
ReadOk
;
controller
.
left_color
.
body_color
=
JOYCON_BODY_NEON_BLUE
;
controller
.
left_color
.
button_color
=
JOYCON_BUTTONS_NEON_BLUE
;
controller
.
right_color
.
body_color
=
JOYCON_BODY_NEON_RED
;
controller
.
right_color
.
button_color
=
JOYCON_BUTTONS_NEON_RED
;
controller
.
left_color
.
body_color
=
Settings
::
values
.
players
[
controller_idx
].
body_color_left
;
controller
.
left_color
.
button_color
=
Settings
::
values
.
players
[
controller_idx
].
button_color_left
;
controller
.
right_color
.
body_color
=
Settings
::
values
.
players
[
controller_idx
].
body_color_right
;
controller
.
right_color
.
button_color
=
Settings
::
values
.
players
[
controller_idx
].
button_color_right
;
controller
.
battery_level
[
0
]
=
BATTERY_FULL
;
controller
.
battery_level
[
1
]
=
BATTERY_FULL
;
...
...
@@ -154,6 +166,25 @@ void Controller_NPad::OnInit() {
style
.
pro_controller
.
Assign
(
1
);
style
.
pokeball
.
Assign
(
1
);
}
std
::
transform
(
Settings
::
values
.
players
.
begin
(),
Settings
::
values
.
players
.
end
(),
connected_controllers
.
begin
(),
[](
const
Settings
::
PlayerInput
&
player
)
{
return
ControllerHolder
{
MapSettingsTypeToNPad
(
player
.
type
),
player
.
connected
};
});
std
::
stable_partition
(
connected_controllers
.
begin
(),
connected_controllers
.
begin
()
+
8
,
[](
const
ControllerHolder
&
holder
)
{
return
holder
.
is_connected
;
});
// Account for handheld
if
(
connected_controllers
[
8
].
is_connected
)
connected_controllers
[
8
].
type
=
NPadControllerType
::
Handheld
;
supported_npad_id_types
.
resize
(
npad_id_list
.
size
());
std
::
memcpy
(
supported_npad_id_types
.
data
(),
npad_id_list
.
data
(),
npad_id_list
.
size
()
*
sizeof
(
u32
));
// Add a default dual joycon controller if none are present.
if
(
std
::
none_of
(
connected_controllers
.
begin
(),
connected_controllers
.
end
(),
[](
const
ControllerHolder
&
controller
)
{
return
controller
.
is_connected
;
}))
{
supported_npad_id_types
.
resize
(
npad_id_list
.
size
());
...
...
@@ -161,15 +192,25 @@ void Controller_NPad::OnInit() {
npad_id_list
.
size
()
*
sizeof
(
u32
));
AddNewController
(
PREFERRED_CONTROLLER
);
}
for
(
std
::
size_t
i
=
0
;
i
<
connected_controllers
.
size
();
++
i
)
{
const
auto
&
controller
=
connected_controllers
[
i
];
if
(
controller
.
is_connected
)
{
AddNewControllerAt
(
controller
.
type
,
IndexToNPad
(
i
));
}
}
}
void
Controller_NPad
::
OnLoadInputDevices
()
{
std
::
transform
(
Settings
::
values
.
buttons
.
begin
()
+
Settings
::
NativeButton
::
BUTTON_HID_BEGIN
,
Settings
::
values
.
buttons
.
begin
()
+
Settings
::
NativeButton
::
BUTTON_HID_END
,
buttons
.
begin
(),
Input
::
CreateDevice
<
Input
::
ButtonDevice
>
);
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
>
);
const
auto
&
players
=
Settings
::
values
.
players
;
for
(
std
::
size_t
i
=
0
;
i
<
players
.
size
();
++
i
)
{
std
::
transform
(
players
[
i
].
buttons
.
begin
()
+
Settings
::
NativeButton
::
BUTTON_HID_BEGIN
,
players
[
i
].
buttons
.
begin
()
+
Settings
::
NativeButton
::
BUTTON_HID_END
,
buttons
[
i
].
begin
(),
Input
::
CreateDevice
<
Input
::
ButtonDevice
>
);
std
::
transform
(
players
[
i
].
analogs
.
begin
()
+
Settings
::
NativeAnalog
::
STICK_HID_BEGIN
,
players
[
i
].
analogs
.
begin
()
+
Settings
::
NativeAnalog
::
STICK_HID_END
,
sticks
[
i
].
begin
(),
Input
::
CreateDevice
<
Input
::
AnalogDevice
>
);
}
}
void
Controller_NPad
::
OnRelease
()
{}
...
...
@@ -183,42 +224,45 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
auto
&
pad_state
=
npad_pad_states
[
controller_idx
].
pad_states
;
auto
&
lstick_entry
=
npad_pad_states
[
controller_idx
].
l_stick
;
auto
&
rstick_entry
=
npad_pad_states
[
controller_idx
].
r_stick
;
const
auto
&
button_state
=
buttons
[
controller_idx
];
const
auto
&
analog_state
=
sticks
[
controller_idx
];
using
namespace
Settings
::
NativeButton
;
pad_state
.
a
.
Assign
(
button
s
[
A
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
b
.
Assign
(
button
s
[
B
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
x
.
Assign
(
button
s
[
X
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
y
.
Assign
(
button
s
[
Y
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick
.
Assign
(
button
s
[
LStick
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick
.
Assign
(
button
s
[
RStick
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l
.
Assign
(
button
s
[
L
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r
.
Assign
(
button
s
[
R
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
zl
.
Assign
(
button
s
[
ZL
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
zr
.
Assign
(
button
s
[
ZR
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
plus
.
Assign
(
button
s
[
Plus
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
minus
.
Assign
(
button
s
[
Minus
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_left
.
Assign
(
button
s
[
DLeft
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_up
.
Assign
(
button
s
[
DUp
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_right
.
Assign
(
button
s
[
DRight
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_down
.
Assign
(
button
s
[
DDown
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_left
.
Assign
(
button
s
[
LStick_Left
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_up
.
Assign
(
button
s
[
LStick_Up
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_right
.
Assign
(
button
s
[
LStick_Right
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_down
.
Assign
(
button
s
[
LStick_Down
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_left
.
Assign
(
button
s
[
RStick_Left
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_up
.
Assign
(
button
s
[
RStick_Up
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_right
.
Assign
(
button
s
[
RStick_Right
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_down
.
Assign
(
button
s
[
RStick_Down
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
left_sl
.
Assign
(
button
s
[
SL
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
left_sr
.
Assign
(
button
s
[
SR
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
a
.
Assign
(
button
_state
[
A
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
b
.
Assign
(
button
_state
[
B
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
x
.
Assign
(
button
_state
[
X
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
y
.
Assign
(
button
_state
[
Y
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick
.
Assign
(
button
_state
[
LStick
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick
.
Assign
(
button
_state
[
RStick
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l
.
Assign
(
button
_state
[
L
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r
.
Assign
(
button
_state
[
R
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
zl
.
Assign
(
button
_state
[
ZL
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
zr
.
Assign
(
button
_state
[
ZR
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
plus
.
Assign
(
button
_state
[
Plus
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
minus
.
Assign
(
button
_state
[
Minus
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_left
.
Assign
(
button
_state
[
DLeft
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_up
.
Assign
(
button
_state
[
DUp
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_right
.
Assign
(
button
_state
[
DRight
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
d_down
.
Assign
(
button
_state
[
DDown
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_left
.
Assign
(
button
_state
[
LStick_Left
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_up
.
Assign
(
button
_state
[
LStick_Up
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_right
.
Assign
(
button
_state
[
LStick_Right
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
l_stick_down
.
Assign
(
button
_state
[
LStick_Down
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_left
.
Assign
(
button
_state
[
RStick_Left
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_up
.
Assign
(
button
_state
[
RStick_Up
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_right
.
Assign
(
button
_state
[
RStick_Right
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
r_stick_down
.
Assign
(
button
_state
[
RStick_Down
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
left_sl
.
Assign
(
button
_state
[
SL
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
pad_state
.
left_sr
.
Assign
(
button
_state
[
SR
-
BUTTON_HID_BEGIN
]
->
GetStatus
());
const
auto
[
stick_l_x_f
,
stick_l_y_f
]
=
sticks
[
static_cast
<
std
::
size_t
>
(
JoystickId
::
Joystick_Left
)]
->
GetStatus
();
analog_state
[
static_cast
<
std
::
size_t
>
(
JoystickId
::
Joystick_Left
)]
->
GetStatus
();
const
auto
[
stick_r_x_f
,
stick_r_y_f
]
=
sticks
[
static_cast
<
std
::
size_t
>
(
JoystickId
::
Joystick_Right
)]
->
GetStatus
();
analog_state
[
static_cast
<
std
::
size_t
>
(
JoystickId
::
Joystick_Right
)]
->
GetStatus
();
lstick_entry
.
x
=
static_cast
<
s32
>
(
stick_l_x_f
*
HID_JOYSTICK_MAX
);
lstick_entry
.
y
=
static_cast
<
s32
>
(
stick_l_y_f
*
HID_JOYSTICK_MAX
);
rstick_entry
.
x
=
static_cast
<
s32
>
(
stick_r_x_f
*
HID_JOYSTICK_MAX
);
...
...
@@ -285,8 +329,10 @@ void Controller_NPad::OnUpdate(u8* data, std::size_t data_len) {
state
.
d_left
.
Assign
(
pad_state
.
pad_states
.
d_up
.
Value
());
state
.
d_right
.
Assign
(
pad_state
.
pad_states
.
d_down
.
Value
());
state
.
d_up
.
Assign
(
pad_state
.
pad_states
.
d_right
.
Value
());
state
.
l
.
Assign
(
pad_state
.
pad_states
.
l
.
Value
()
|
pad_state
.
pad_states
.
sl
.
Value
());
state
.
r
.
Assign
(
pad_state
.
pad_states
.
r
.
Value
()
|
pad_state
.
pad_states
.
sr
.
Value
());
state
.
l
.
Assign
(
pad_state
.
pad_states
.
l
.
Value
()
|
pad_state
.
pad_states
.
left_sl
.
Value
());
state
.
r
.
Assign
(
pad_state
.
pad_states
.
r
.
Value
()
|
pad_state
.
pad_states
.
left_sr
.
Value
());
state
.
zl
.
Assign
(
pad_state
.
pad_states
.
zl
.
Value
());
state
.
plus
.
Assign
(
pad_state
.
pad_states
.
minus
.
Value
());
...
...
@@ -302,8 +348,10 @@ void Controller_NPad::OnUpdate(u8* data, std::size_t data_len) {
state
.
b
.
Assign
(
pad_state
.
pad_states
.
y
.
Value
());
state
.
y
.
Assign
(
pad_state
.
pad_states
.
b
.
Value
());
state
.
l
.
Assign
(
pad_state
.
pad_states
.
l
.
Value
()
|
pad_state
.
pad_states
.
sl
.
Value
());
state
.
r
.
Assign
(
pad_state
.
pad_states
.
r
.
Value
()
|
pad_state
.
pad_states
.
sr
.
Value
());
state
.
l
.
Assign
(
pad_state
.
pad_states
.
l
.
Value
()
|
pad_state
.
pad_states
.
right_sl
.
Value
());
state
.
r
.
Assign
(
pad_state
.
pad_states
.
r
.
Value
()
|
pad_state
.
pad_states
.
right_sr
.
Value
());
state
.
zr
.
Assign
(
pad_state
.
pad_states
.
zr
.
Value
());
state
.
plus
.
Assign
(
pad_state
.
pad_states
.
plus
.
Value
());
...
...
@@ -570,7 +618,7 @@ Controller_NPad::NPadControllerType Controller_NPad::DecideBestController(
if
(
IsControllerSupported
(
priority
))
{
return
priority
;
}
const
auto
is_docked
=
Settings
::
values
->
use_docked_mode
;
const
auto
is_docked
=
Settings
::
values
.
use_docked_mode
;
if
(
is_docked
&&
priority
==
NPadControllerType
::
Handheld
)
{
priority
=
NPadControllerType
::
JoyDual
;
if
(
IsControllerSupported
(
priority
))
{
...
...
@@ -659,7 +707,7 @@ bool Controller_NPad::IsControllerSupported(NPadControllerType controller) {
return
false
;
}
// Handheld should not be supported in docked mode
if
(
Settings
::
values
->
use_docked_mode
)
{
if
(
Settings
::
values
.
use_docked_mode
)
{
return
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/core/hle/service/hid/controllers/npad.h
+
7
−
2
View file @
55ded706
...
...
@@ -285,9 +285,14 @@ private:
NPadType
style
{};
std
::
array
<
NPadEntry
,
10
>
shared_memory_entries
{};
std
::
array
<
std
::
unique_ptr
<
Input
::
ButtonDevice
>
,
Settings
::
NativeButton
::
NUM_BUTTONS_HID
>
std
::
array
<
std
::
array
<
std
::
unique_ptr
<
Input
::
ButtonDevice
>
,
Settings
::
NativeButton
::
NUM_BUTTONS_HID
>
,
10
>
buttons
;
std
::
array
<
std
::
unique_ptr
<
Input
::
AnalogDevice
>
,
Settings
::
NativeAnalog
::
NUM_STICKS_HID
>
sticks
;
std
::
array
<
std
::
array
<
std
::
unique_ptr
<
Input
::
AnalogDevice
>
,
Settings
::
NativeAnalog
::
NUM_STICKS_HID
>
,
10
>
sticks
;
std
::
vector
<
u32
>
supported_npad_id_types
{};
NpadHoldType
hold_type
{
NpadHoldType
::
Vertical
};
Kernel
::
SharedPtr
<
Kernel
::
Event
>
styleset_changed_event
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment