Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Narr the Reg | b4ed06baa1 | |
Narr the Reg | 919b8fa000 | |
Narr the Reg | 94d1a9c761 | |
Narr the Reg | ad8ba6c0cf |
|
@ -549,6 +549,48 @@ add_library(core STATIC
|
|||
hle/service/hid/xcd.cpp
|
||||
hle/service/hid/xcd.h
|
||||
hle/service/hid/errors.h
|
||||
hle/service/hid/controllers/abstract/abstract_battery_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_battery_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_button_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_button_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_ir_sensor_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_ir_sensor_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_led_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_led_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_mcu_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_mcu_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_nfc_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_nfc_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_pad.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_pad.h
|
||||
hle/service/hid/controllers/abstract/abstract_pad_holder.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_pad_holder.h
|
||||
hle/service/hid/controllers/abstract/abstract_palma_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_palma_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_properties_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_properties_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_sixaxis_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_sixaxis_handler.h
|
||||
hle/service/hid/controllers/abstract/abstract_vibration_handler.cpp
|
||||
hle/service/hid/controllers/abstract/abstract_vibration_handler.h
|
||||
hle/service/hid/controllers/npad/assignment_handler.cpp
|
||||
hle/service/hid/controllers/npad/assignment_handler.h
|
||||
hle/service/hid/controllers/npad/gc_vibration_device.cpp
|
||||
hle/service/hid/controllers/npad/gc_vibration_device.h
|
||||
hle/service/hid/controllers/npad/n64_vibration_device.cpp
|
||||
hle/service/hid/controllers/npad/n64_vibration_device.h
|
||||
hle/service/hid/controllers/npad/npad_data.cpp
|
||||
hle/service/hid/controllers/npad/npad_data.h
|
||||
hle/service/hid/controllers/npad/npad_resource.cpp
|
||||
hle/service/hid/controllers/npad/npad_resource.h
|
||||
hle/service/hid/controllers/npad/palma_handler.cpp
|
||||
hle/service/hid/controllers/npad/palma_handler.h
|
||||
hle/service/hid/controllers/npad/unique_pad.cpp
|
||||
hle/service/hid/controllers/npad/unique_pad.h
|
||||
hle/service/hid/controllers/npad/vibration_device.cpp
|
||||
hle/service/hid/controllers/npad/vibration_device.h
|
||||
hle/service/hid/controllers/npad/vibration_handler.cpp
|
||||
hle/service/hid/controllers/npad/vibration_handler.h
|
||||
hle/service/hid/controllers/types/debug_pad_types.h
|
||||
hle/service/hid/controllers/types/keyboard_types.h
|
||||
hle/service/hid/controllers/types/mouse_types.h
|
||||
|
|
|
@ -47,7 +47,7 @@ void DefaultControllerApplet::ReconfigureControllers(ReconfigureCallback callbac
|
|||
// Connect controllers based on the following priority list from highest to lowest priority:
|
||||
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
|
||||
if (parameters.allow_pro_controller) {
|
||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController);
|
||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Fullkey);
|
||||
controller->Connect(true);
|
||||
} else if (parameters.allow_dual_joycons) {
|
||||
controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::JoyconDual);
|
||||
|
|
|
@ -220,6 +220,7 @@ enum class NpadIdType : u32 {
|
|||
};
|
||||
|
||||
enum class NpadInterfaceType : u8 {
|
||||
None = 0,
|
||||
Bluetooth = 1,
|
||||
Rail = 2,
|
||||
Usb = 3,
|
||||
|
@ -229,7 +230,7 @@ enum class NpadInterfaceType : u8 {
|
|||
// This is nn::hid::NpadStyleIndex
|
||||
enum class NpadStyleIndex : u8 {
|
||||
None = 0,
|
||||
ProController = 3,
|
||||
Fullkey = 3,
|
||||
Handheld = 4,
|
||||
HandheldNES = 4,
|
||||
JoyconDual = 5,
|
||||
|
@ -267,6 +268,7 @@ enum class NpadStyleSet : u32 {
|
|||
All = 0xFFFFFFFFU,
|
||||
};
|
||||
static_assert(sizeof(NpadStyleSet) == 4, "NpadStyleSet is an invalid size");
|
||||
DECLARE_ENUM_FLAG_OPERATORS(NpadStyleSet)
|
||||
|
||||
// This is nn::hid::VibrationDevicePosition
|
||||
enum class VibrationDevicePosition : u32 {
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_battery_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/shared_memory_format.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NpadAbstractBatteryHandler::NpadAbstractBatteryHandler(Core::System& system_) : system{system_} {}
|
||||
|
||||
NpadAbstractBatteryHandler::~NpadAbstractBatteryHandler() = default;
|
||||
|
||||
void NpadAbstractBatteryHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
|
||||
applet_resource_holder = applet_resource;
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
Result NpadAbstractBatteryHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractBatteryHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractBatteryHandler::UpdateBatteryState(u64 aruid) {
|
||||
const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId());
|
||||
AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid);
|
||||
if (aruid_data == nullptr) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
auto& npad_internal_state =
|
||||
aruid_data->shared_memory_format->npad.npad_entry[npad_index].internal_state;
|
||||
auto& system_properties = npad_internal_state.system_properties;
|
||||
|
||||
system_properties.is_charging_joy_dual.Assign(dual_battery.is_charging);
|
||||
system_properties.is_powered_joy_dual.Assign(dual_battery.is_powered);
|
||||
system_properties.is_charging_joy_left.Assign(left_battery.is_charging);
|
||||
system_properties.is_powered_joy_left.Assign(left_battery.is_powered);
|
||||
system_properties.is_charging_joy_right.Assign(right_battery.is_charging);
|
||||
system_properties.is_powered_joy_right.Assign(right_battery.is_powered);
|
||||
|
||||
npad_internal_state.battery_level_dual = dual_battery.battery_level;
|
||||
npad_internal_state.battery_level_left = left_battery.battery_level;
|
||||
npad_internal_state.battery_level_right = right_battery.battery_level;
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::UpdateBatteryState() {
|
||||
if (ref_counter == 0) {
|
||||
return;
|
||||
}
|
||||
has_new_battery_data = GetNewBatteryState();
|
||||
}
|
||||
|
||||
bool NpadAbstractBatteryHandler::GetNewBatteryState() {
|
||||
bool has_changed = false;
|
||||
Core::HID::NpadPowerInfo new_dual_battery_state{};
|
||||
Core::HID::NpadPowerInfo new_left_battery_state{};
|
||||
Core::HID::NpadPowerInfo new_right_battery_state{};
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
|
||||
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
const auto power_info = abstract_pad->power_info;
|
||||
if (power_info.battery_level > Core::HID::NpadBatteryLevel::Full) {
|
||||
// Abort
|
||||
}
|
||||
|
||||
const auto style = abstract_pad->assignament_style;
|
||||
|
||||
if (style.is_external_assigned || style.is_handheld_assigned) {
|
||||
new_dual_battery_state = power_info;
|
||||
}
|
||||
if (style.is_external_left_assigned || style.is_handheld_left_assigned) {
|
||||
new_left_battery_state = power_info;
|
||||
}
|
||||
if (style.is_external_right_assigned || style.is_external_right_assigned) {
|
||||
new_right_battery_state = power_info;
|
||||
}
|
||||
|
||||
if (abstract_pad->internal_flags.is_battery_low_ovln_required) {
|
||||
if (abstract_pad->interface_type == Core::HID::NpadInterfaceType::Rail) {
|
||||
// properties_handler->FUN_710005f988(&local_80, uvar5);
|
||||
// applet_resource_holder->handle_1->FUN_710008dfe4(&local_80);
|
||||
}
|
||||
abstract_pad->low_battery_display_delay_interval = system.CoreTiming().GetClockTicks();
|
||||
abstract_pad->internal_flags.is_battery_low_ovln_required.Assign(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (dual_battery.battery_level != new_dual_battery_state.battery_level ||
|
||||
dual_battery.is_charging != new_dual_battery_state.is_charging ||
|
||||
dual_battery.is_powered != new_dual_battery_state.is_powered) {
|
||||
has_changed = true;
|
||||
dual_battery = new_dual_battery_state;
|
||||
}
|
||||
|
||||
if (left_battery.battery_level != new_left_battery_state.battery_level ||
|
||||
left_battery.is_charging != new_left_battery_state.is_charging ||
|
||||
left_battery.is_powered != new_left_battery_state.is_powered) {
|
||||
has_changed = true;
|
||||
left_battery = new_left_battery_state;
|
||||
}
|
||||
|
||||
if (right_battery.battery_level != new_right_battery_state.battery_level ||
|
||||
right_battery.is_charging != new_right_battery_state.is_charging ||
|
||||
right_battery.is_powered != new_right_battery_state.is_powered) {
|
||||
has_changed = true;
|
||||
right_battery = new_right_battery_state;
|
||||
}
|
||||
|
||||
return has_changed;
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::UpdateCoreBatteryState() {
|
||||
if (ref_counter == 0) {
|
||||
return;
|
||||
}
|
||||
if (!has_new_battery_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBatteryState(0);
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::InitializeBatteryState(u64 aruid) {
|
||||
UpdateBatteryState(aruid);
|
||||
}
|
||||
|
||||
bool NpadAbstractBatteryHandler::HasBattery() const {
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
|
||||
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
const auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
return abstract_pad->disabled_feature_set.has_fullkey_battery ||
|
||||
abstract_pad->disabled_feature_set.has_left_right_joy_battery;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NpadAbstractBatteryHandler::HasLeftRightBattery(bool& has_left, bool& has_right) const {
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
|
||||
|
||||
has_left = false;
|
||||
has_right = false;
|
||||
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
const auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
if (!abstract_pad->disabled_feature_set.has_fullkey_battery &&
|
||||
!abstract_pad->disabled_feature_set.has_left_right_joy_battery) {
|
||||
continue;
|
||||
}
|
||||
has_left = abstract_pad->assignament_style.is_external_left_assigned ||
|
||||
abstract_pad->assignament_style.is_handheld_left_assigned;
|
||||
has_right = abstract_pad->assignament_style.is_external_right_assigned ||
|
||||
abstract_pad->assignament_style.is_handheld_right_assigned;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,56 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractBatteryHandler final {
|
||||
public:
|
||||
explicit NpadAbstractBatteryHandler(Core::System& system_);
|
||||
~NpadAbstractBatteryHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
Result UpdateBatteryState(u64 aruid);
|
||||
void UpdateBatteryState();
|
||||
bool GetNewBatteryState();
|
||||
void UpdateCoreBatteryState();
|
||||
void InitializeBatteryState(u64 aruid);
|
||||
|
||||
bool HasBattery() const;
|
||||
void HasLeftRightBattery(bool& has_left, bool& has_right) const;
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
Core::HID::NpadPowerInfo dual_battery{};
|
||||
Core::HID::NpadPowerInfo left_battery{};
|
||||
Core::HID::NpadPowerInfo right_battery{};
|
||||
bool has_new_battery_data{};
|
||||
INSERT_PADDING_BYTES(0x7);
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,94 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct NpadSharedMemoryEntry;
|
||||
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractButtonHandler final {
|
||||
public:
|
||||
explicit NpadAbstractButtonHandler();
|
||||
~NpadAbstractButtonHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
void FUN_7100067e7c();
|
||||
void FUN_7100067e84();
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
Result FUN_7100067ef0(u64 aruid);
|
||||
|
||||
void FUN_710006800c(bool is_enabled);
|
||||
void FUN_71000680c0(bool is_enabled);
|
||||
|
||||
void UpdateAllButtonLifo();
|
||||
void UpdateCoreBatteryState();
|
||||
void UpdateButtonState(u64 aruid);
|
||||
|
||||
Result FUN_7100068d40(bool is_enabled, u64 aruid);
|
||||
bool FUN_7100068e78();
|
||||
bool IsButtonPressedOnConsoleMode();
|
||||
void EnableCenterClamp();
|
||||
|
||||
void UpdateButtonLifo(NpadSharedMemoryEntry& shared_memory, u64 aruid, bool param_4,
|
||||
bool param_5, bool param_6);
|
||||
|
||||
void UpdateNpadFullkeyLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7,
|
||||
bool param_8, bool param_9);
|
||||
void UpdateHandheldLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7, bool param_8,
|
||||
bool param_9);
|
||||
void UpdateJoyconDualLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7,
|
||||
bool param_8, bool param_9);
|
||||
void UpdateJoyconLeftLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7,
|
||||
bool param_8, bool param_9);
|
||||
void UpdateJoyconRightLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7,
|
||||
bool param_8, bool param_9);
|
||||
void UpdateSystemExtLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7,
|
||||
bool param_8, bool param_9);
|
||||
void UpdatePalmaLifo(Core::HID::NpadStyleTag style_tag, int index, u64 aruid,
|
||||
NpadSharedMemoryEntry& param_5, u64 param_6, bool param_7, bool param_8,
|
||||
bool param_9);
|
||||
|
||||
u8 GetSomethingNotificationWake();
|
||||
void ResetSomethingNotificationWake();
|
||||
|
||||
void FUN_710006af40(u64 param_2, u32* param_3, u64* param_4, u64 param_5, u64* param_6);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
|
||||
bool is_button_pressed_on_console_mode;
|
||||
|
||||
u64 gc_sampling_number;
|
||||
struct GcTrigger {
|
||||
float left;
|
||||
float right;
|
||||
};
|
||||
GcTrigger gc_trigger_state;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,129 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
#include "core/hle/kernel/k_readable_event.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_ir_sensor_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NpadAbstractIrSensorHandler::NpadAbstractIrSensorHandler() {}
|
||||
|
||||
NpadAbstractIrSensorHandler::~NpadAbstractIrSensorHandler() = default;
|
||||
|
||||
void NpadAbstractIrSensorHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractIrSensorHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
Result NpadAbstractIrSensorHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractIrSensorHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractIrSensorHandler::UpdateIrSensorState() {
|
||||
const auto previous_state = sensor_state;
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
|
||||
|
||||
if (count == 0) {
|
||||
sensor_state = NpadIrSensorState::Disabled;
|
||||
if (sensor_state == previous_state) {
|
||||
return;
|
||||
}
|
||||
ir_sensor_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_found{};
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
if (!abstract_pad->disabled_feature_set.has_bluetooth_address) {
|
||||
continue;
|
||||
}
|
||||
// if (abstract_pad->vtable.UpdateIrState().IsError()) {
|
||||
// continue;
|
||||
// }
|
||||
is_found = true;
|
||||
xcd_handle = abstract_pad->xcd_handle;
|
||||
}
|
||||
|
||||
if (is_found) {
|
||||
if (sensor_state == NpadIrSensorState::Active) {
|
||||
return;
|
||||
}
|
||||
sensor_state = NpadIrSensorState::Available;
|
||||
if (sensor_state == previous_state) {
|
||||
return;
|
||||
}
|
||||
ir_sensor_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_state = NpadIrSensorState::Unavailable;
|
||||
if (sensor_state == previous_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
ir_sensor_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
Result NpadAbstractIrSensorHandler::ActivateIrSensor(bool is_enabled) {
|
||||
if (sensor_state == NpadIrSensorState::Unavailable) {
|
||||
return ResultIrSensorIsNotReady;
|
||||
}
|
||||
if (is_enabled && sensor_state == NpadIrSensorState::Available) {
|
||||
sensor_state = NpadIrSensorState::Active;
|
||||
} else {
|
||||
if (is_enabled) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
if (sensor_state != NpadIrSensorState::Active) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
sensor_state = NpadIrSensorState::Available;
|
||||
}
|
||||
ir_sensor_event->Signal();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractIrSensorHandler::GetIrSensorEventHandle(Kernel::KReadableEvent** out_event) {
|
||||
*out_event = &ir_sensor_event->GetReadableEvent();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractIrSensorHandler::GetXcdHandleForNpadWithIrSensor(u64& handle) const {
|
||||
if (sensor_state < NpadIrSensorState::Available) {
|
||||
return ResultIrSensorIsNotReady;
|
||||
}
|
||||
handle = xcd_handle;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NpadIrSensorState NpadAbstractIrSensorHandler::GetSensorState() const {
|
||||
return sensor_state;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,55 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Kernel {
|
||||
class KReadableEvent;
|
||||
}
|
||||
|
||||
enum class NpadIrSensorState : u32 {
|
||||
Disabled,
|
||||
Unavailable,
|
||||
Available,
|
||||
Active,
|
||||
};
|
||||
|
||||
namespace Service::HID {
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractIrSensorHandler final {
|
||||
public:
|
||||
explicit NpadAbstractIrSensorHandler();
|
||||
~NpadAbstractIrSensorHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void UpdateIrSensorState();
|
||||
Result ActivateIrSensor(bool param_2);
|
||||
|
||||
Result GetIrSensorEventHandle(Kernel::KReadableEvent** out_event);
|
||||
|
||||
Result GetXcdHandleForNpadWithIrSensor(u64& handle) const;
|
||||
|
||||
NpadIrSensorState GetSensorState() const;
|
||||
|
||||
private:
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
Kernel::KEvent* ir_sensor_event{nullptr};
|
||||
u64 xcd_handle{};
|
||||
NpadIrSensorState sensor_state{};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,139 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_led_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NpadAbstractLedHandler::NpadAbstractLedHandler(Core::System& system_) : system{system_} {}
|
||||
|
||||
NpadAbstractLedHandler::~NpadAbstractLedHandler() = default;
|
||||
|
||||
void NpadAbstractLedHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractLedHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
|
||||
applet_resource_holder = applet_resource;
|
||||
}
|
||||
|
||||
void NpadAbstractLedHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
Result NpadAbstractLedHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractLedHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractLedHandler::SetNpadLedHandlerLedPattern() {
|
||||
const auto npad_id = properties_handler->GetNpadId();
|
||||
|
||||
switch (npad_id) {
|
||||
case Core::HID::NpadIdType::Player1:
|
||||
left_pattern = Core::HID::LedPattern{1, 0, 0, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player2:
|
||||
left_pattern = Core::HID::LedPattern{1, 1, 0, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player3:
|
||||
left_pattern = Core::HID::LedPattern{1, 1, 1, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player4:
|
||||
left_pattern = Core::HID::LedPattern{1, 1, 1, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player5:
|
||||
left_pattern = Core::HID::LedPattern{1, 0, 0, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player6:
|
||||
left_pattern = Core::HID::LedPattern{1, 0, 1, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player7:
|
||||
left_pattern = Core::HID::LedPattern{1, 0, 1, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player8:
|
||||
left_pattern = Core::HID::LedPattern{0, 1, 1, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Other:
|
||||
case Core::HID::NpadIdType::Handheld:
|
||||
left_pattern = Core::HID::LedPattern{0, 0, 0, 0};
|
||||
break;
|
||||
default:
|
||||
ASSERT_MSG("Invalid npad id type");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (npad_id) {
|
||||
case Core::HID::NpadIdType::Player1:
|
||||
right_pattern = Core::HID::LedPattern{0, 0, 0, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player2:
|
||||
right_pattern = Core::HID::LedPattern{0, 1, 1, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player3:
|
||||
right_pattern = Core::HID::LedPattern{0, 1, 1, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player4:
|
||||
right_pattern = Core::HID::LedPattern{1, 1, 1, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player5:
|
||||
right_pattern = Core::HID::LedPattern{1, 0, 0, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player6:
|
||||
right_pattern = Core::HID::LedPattern{0, 1, 0, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player7:
|
||||
right_pattern = Core::HID::LedPattern{1, 1, 0, 1};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Player8:
|
||||
right_pattern = Core::HID::LedPattern{0, 1, 1, 0};
|
||||
break;
|
||||
case Core::HID::NpadIdType::Other:
|
||||
case Core::HID::NpadIdType::Handheld:
|
||||
right_pattern = Core::HID::LedPattern{0, 0, 0, 0};
|
||||
break;
|
||||
default:
|
||||
ASSERT_MSG("Invalid npad id type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NpadAbstractLedHandler::FUN_7100067550() {
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
|
||||
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void NpadAbstractLedHandler::SetLedBlinkingDevice(Core::HID::LedPattern pattern) {
|
||||
if ((pattern.raw & (led_blinking.raw ^ 0xffffffff)) != 0) {
|
||||
led_interval = system.CoreTiming().GetClockTicks();
|
||||
}
|
||||
led_blinking = pattern;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,51 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractLedHandler final {
|
||||
public:
|
||||
explicit NpadAbstractLedHandler(Core::System& system_);
|
||||
~NpadAbstractLedHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void SetNpadLedHandlerLedPattern();
|
||||
void FUN_7100067550();
|
||||
|
||||
void SetLedBlinkingDevice(Core::HID::LedPattern pattern);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
Core::HID::LedPattern led_blinking{0, 0, 0, 0};
|
||||
Core::HID::LedPattern left_pattern{0, 0, 0, 0};
|
||||
Core::HID::LedPattern right_pattern{0, 0, 0, 0};
|
||||
INSERT_PADDING_BYTES(0x6);
|
||||
u64 led_interval{};
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,104 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_mcu_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
void NpadAbstractMcuHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractMcuHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
Result NpadAbstractMcuHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractMcuHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractMcuHandler::UpdateMcuState() {
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = properties_handler->GetAbstractedPads(abstract_pads);
|
||||
|
||||
if (count == 0) {
|
||||
mcu_holder = {};
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
if (!abstract_pad->disabled_feature_set.has_left_joy_rail_bus) {
|
||||
if (!abstract_pad->disabled_feature_set.has_left_joy_six_axis_sensor &&
|
||||
!abstract_pad->disabled_feature_set.has_right_joy_six_axis_sensor) {
|
||||
continue;
|
||||
}
|
||||
if (mcu_holder[1].state != NpadMcuState::Active) {
|
||||
mcu_holder[1].state = NpadMcuState::Available;
|
||||
}
|
||||
mcu_holder[1].abstracted_pad = abstract_pad;
|
||||
continue;
|
||||
}
|
||||
if (mcu_holder[0].state != NpadMcuState::Active) {
|
||||
mcu_holder[0].state = NpadMcuState::Available;
|
||||
}
|
||||
mcu_holder[0].abstracted_pad = abstract_pad;
|
||||
}
|
||||
}
|
||||
|
||||
Result NpadAbstractMcuHandler::GetAbstractedPad(IAbstractedPad** data, u32 mcu_index) {
|
||||
if (mcu_holder[mcu_index].state == NpadMcuState::None ||
|
||||
mcu_holder[mcu_index].abstracted_pad == nullptr) {
|
||||
return ResultMcuIsNotReady;
|
||||
}
|
||||
*data = mcu_holder[mcu_index].abstracted_pad;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NpadMcuState NpadAbstractMcuHandler::GetMcuState(u32 mcu_index) {
|
||||
return mcu_holder[mcu_index].state;
|
||||
}
|
||||
|
||||
Result NpadAbstractMcuHandler::FUN_7100067d88(bool is_enabled, u32 mcu_index) {
|
||||
NpadMcuState& state = mcu_holder[mcu_index].state;
|
||||
|
||||
if (state == NpadMcuState::None) {
|
||||
return ResultMcuIsNotReady;
|
||||
}
|
||||
|
||||
if ((is_enabled) && (state == NpadMcuState::Available)) {
|
||||
state = NpadMcuState::Active;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
if (is_enabled) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
if (state != NpadMcuState::Active) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
state = NpadMcuState::Available;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,52 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct IAbstractedPad;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
enum class NpadMcuState : u32 {
|
||||
None,
|
||||
Available,
|
||||
Active,
|
||||
};
|
||||
|
||||
struct NpadMcuHolder {
|
||||
NpadMcuState state;
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
IAbstractedPad* abstracted_pad;
|
||||
};
|
||||
static_assert(sizeof(NpadMcuHolder) == 0x10, "NpadMcuHolder is an invalid size");
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractMcuHandler final {
|
||||
public:
|
||||
explicit NpadAbstractMcuHandler();
|
||||
~NpadAbstractMcuHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void UpdateMcuState();
|
||||
Result GetAbstractedPad(IAbstractedPad** data, u32 mcu_index);
|
||||
NpadMcuState GetMcuState(u32 mcu_index);
|
||||
Result FUN_7100067d88(bool is_enabled, u32 mcu_index);
|
||||
|
||||
private:
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
std::array<NpadMcuHolder, 2> mcu_holder{};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,140 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
#include "core/hle/kernel/k_readable_event.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_nfc_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
void NpadAbstractNfcHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractNfcHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
Result NpadAbstractNfcHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractNfcHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractNfcHandler::UpdateNfcState() {
|
||||
std::array<IAbstractedPad*, 5> abstract_pads{};
|
||||
const std::size_t count = properties_handler->GetAbstractedPads(abstract_pads);
|
||||
|
||||
if (count == 0) {
|
||||
if (sensor_state == NpadNfcState::Active) {
|
||||
nfc_activate_event->Signal();
|
||||
}
|
||||
if (sensor_state == NpadNfcState::Unavailable) {
|
||||
return;
|
||||
}
|
||||
sensor_state = NpadNfcState::Unavailable;
|
||||
input_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_found{};
|
||||
for (std::size_t i = 0; i < count; i++) {
|
||||
auto* abstract_pad = abstract_pads[i];
|
||||
if (!abstract_pad->internal_flags.is_connected) {
|
||||
continue;
|
||||
}
|
||||
if (!abstract_pad->disabled_feature_set.has_nfc) {
|
||||
continue;
|
||||
}
|
||||
is_found = true;
|
||||
xcd_handle = 0;
|
||||
//const Result result = (**(code**)(*plVar5 + 0x18))();
|
||||
//if (result.IsSuccess()) {
|
||||
// xcd_handle = GetXcdHandle();
|
||||
//}
|
||||
}
|
||||
|
||||
if (is_found) {
|
||||
if (sensor_state == NpadNfcState::Active) {
|
||||
return;
|
||||
}
|
||||
if (sensor_state == NpadNfcState::Available) {
|
||||
return;
|
||||
}
|
||||
sensor_state = NpadNfcState::Available;
|
||||
input_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
if (sensor_state == NpadNfcState::Active) {
|
||||
nfc_activate_event->Signal();
|
||||
}
|
||||
if (sensor_state == NpadNfcState::Unavailable) {
|
||||
return;
|
||||
}
|
||||
sensor_state = NpadNfcState::Unavailable;
|
||||
input_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
bool NpadAbstractNfcHandler::HasNfcSensor() {
|
||||
return sensor_state != NpadNfcState::Unavailable;
|
||||
}
|
||||
|
||||
bool NpadAbstractNfcHandler::IsNfcActivated() {
|
||||
return sensor_state == NpadNfcState::Active;
|
||||
}
|
||||
|
||||
Result NpadAbstractNfcHandler::GetAcquireNfcActivateEventHandle(
|
||||
Kernel::KReadableEvent** out_event) {
|
||||
*out_event = &nfc_activate_event->GetReadableEvent();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractNfcHandler::SetInputEvent(Kernel::KEvent* event) {
|
||||
input_event = event;
|
||||
}
|
||||
|
||||
Result NpadAbstractNfcHandler::ActivateNfc(bool is_enabled) {
|
||||
if (sensor_state == NpadNfcState::Active) {
|
||||
return ResultNfcIsNotReady;
|
||||
}
|
||||
|
||||
NpadNfcState new_state = NpadNfcState::Available;
|
||||
if (is_enabled) {
|
||||
new_state = NpadNfcState::Active;
|
||||
}
|
||||
if (sensor_state != new_state) {
|
||||
sensor_state = new_state;
|
||||
nfc_activate_event->Signal();
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractNfcHandler::GetXcdHandleWithNfc(u64& out_xcd_handle) const {
|
||||
if (sensor_state == NpadNfcState::Unavailable) {
|
||||
return ResultNfcIsNotReady;
|
||||
}
|
||||
if (xcd_handle == 0) {
|
||||
return ResultNfcXcdHandleIsNotInitialized;
|
||||
}
|
||||
|
||||
out_xcd_handle = xcd_handle;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,57 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Kernel {
|
||||
class KReadableEvent;
|
||||
}
|
||||
|
||||
enum class NpadNfcState : u32 {
|
||||
Unavailable,
|
||||
Available,
|
||||
Active,
|
||||
};
|
||||
|
||||
namespace Service::HID {
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractNfcHandler final {
|
||||
public:
|
||||
explicit NpadAbstractNfcHandler();
|
||||
~NpadAbstractNfcHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void UpdateNfcState();
|
||||
bool HasNfcSensor();
|
||||
bool IsNfcActivated();
|
||||
|
||||
Result GetAcquireNfcActivateEventHandle(Kernel::KReadableEvent** out_event);
|
||||
void SetInputEvent(Kernel::KEvent* event);
|
||||
|
||||
Result ActivateNfc(bool is_enabled);
|
||||
|
||||
Result GetXcdHandleWithNfc(u64& out_xcd_handle) const;
|
||||
|
||||
private:
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
Kernel::KEvent* nfc_activate_event;
|
||||
Kernel::KEvent* input_event;
|
||||
u64 xcd_handle;
|
||||
NpadNfcState sensor_state;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,319 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
void AbstractPad::SetExternals(AppletResourceHolder* applet_resource,
|
||||
CaptureButtonResource* capture_button_resource,
|
||||
HomeButtonResource* home_button_resource,
|
||||
SixAxisResource* sixaxis_resource, PalmaResource* palma_resource,
|
||||
VibrationHandler* vibration) {
|
||||
applet_resource_holder = applet_resource;
|
||||
|
||||
properties_handler.SetAppletResource(applet_resource_holder);
|
||||
properties_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
|
||||
led_handler.SetAppletResource(applet_resource_holder);
|
||||
led_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
led_handler.SetPropertiesHandler(&properties_handler);
|
||||
|
||||
ir_sensor_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
ir_sensor_handler.SetPropertiesHandler(&properties_handler);
|
||||
|
||||
nfc_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
nfc_handler.SetPropertiesHandler(&properties_handler);
|
||||
|
||||
vibration_gc.FUN_7100087ed4(param_7);
|
||||
|
||||
mcu_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
mcu_handler.SetPropertiesHandler(&properties_handler);
|
||||
|
||||
std::array<NpadVibrationDevice*, 2> vibration_devices{&vibration_left, &vibration_right};
|
||||
vibration_handler.SetAppletResource(applet_resource_holder);
|
||||
vibration_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
vibration_handler.SetPropertiesHandler(&properties_handler);
|
||||
vibration_handler.SetN64Vibration(&vibration_n64);
|
||||
vibration_handler.SetVibration(vibration_devices);
|
||||
vibration_handler.SetGcVibration(&vibration_gc);
|
||||
|
||||
sixaxis_handler.SetAppletResource(applet_resource_holder);
|
||||
sixaxis_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
sixaxis_handler.SetPropertiesHandler(&properties_handler);
|
||||
sixaxis_handler.FUN_71000722ac(&sixaxis_fullkey_handle, 0);
|
||||
sixaxis_handler.FUN_71000722ac(&sixaxis_handheld_handle, 1);
|
||||
sixaxis_handler.FUN_71000722ac(&sixaxis_joycon_handle, 2);
|
||||
sixaxis_handler.SetSixaxisResource(sixaxis_resource);
|
||||
sixaxis_handler.FUN_71000722c0(param_6);
|
||||
|
||||
button_handler.SetAppletResource(applet_resource_holder);
|
||||
button_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
button_handler.SetPropertiesHandler(&properties_handler);
|
||||
// capture_button_resource->FUN_710006c478();
|
||||
button_handler.FUN_7100067e7c();
|
||||
// home_button_resource->FUN_710006ca6c();
|
||||
button_handler.FUN_7100067e84();
|
||||
|
||||
battery_handler.SetAppletResource(applet_resource_holder);
|
||||
battery_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
battery_handler.SetPropertiesHandler(&properties_handler);
|
||||
|
||||
palma_handler.SetAbstractPadHolder(&abstract_pad_holder);
|
||||
palma_handler.SetPropertiesHandler(&properties_handler);
|
||||
palma_handler.SetPalmaResource(palma_resource);
|
||||
}
|
||||
|
||||
void AbstractPad::SetNpadId(Core::HID::NpadIdType npad_id) {
|
||||
properties_handler.SetNpadId(npad_id);
|
||||
}
|
||||
|
||||
Result AbstractPad::Activate() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
|
||||
if (ref_counter != 0) {
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
std::size_t stage = 0;
|
||||
Result result = ResultSuccess;
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = properties_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = led_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = ir_sensor_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = mcu_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = nfc_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = vibration_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = sixaxis_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = button_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = battery_handler.IncrementRefCounter();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
stage++;
|
||||
result = palma_handler.IncrementRefCounter();
|
||||
}
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
ref_counter++;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (stage > 9) {
|
||||
battery_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 8) {
|
||||
button_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 7) {
|
||||
sixaxis_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 6) {
|
||||
vibration_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 5) {
|
||||
nfc_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 4) {
|
||||
mcu_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 3) {
|
||||
ir_sensor_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 2) {
|
||||
led_handler.DecrementRefCounter();
|
||||
}
|
||||
if (stage > 1) {
|
||||
properties_handler.DecrementRefCounter();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Result AbstractPad::Deactivate() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadResourceNotInitialized;
|
||||
}
|
||||
|
||||
ref_counter--;
|
||||
battery_handler.DecrementRefCounter();
|
||||
button_handler.DecrementRefCounter();
|
||||
sixaxis_handler.DecrementRefCounter();
|
||||
vibration_handler.DecrementRefCounter();
|
||||
nfc_handler.DecrementRefCounter();
|
||||
ir_sensor_handler.DecrementRefCounter();
|
||||
mcu_handler.DecrementRefCounter();
|
||||
led_handler.DecrementRefCounter();
|
||||
properties_handler.DecrementRefCounter();
|
||||
palma_handler.DecrementRefCounter();
|
||||
}
|
||||
|
||||
Result AbstractPad::ActivateNpad(u64 aruid) {
|
||||
Result result = ResultSuccess;
|
||||
if (result.IsSuccess()) {
|
||||
result = properties_handler.ActivateNpadUnknown0x88(aruid);
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
result = button_handler.FUN_7100067ef0(aruid);
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
result = sixaxis_handler.UpdateSixAxis(aruid);
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
result = battery_handler.UpdateBatteryState(aruid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NpadAbstractedPadHolder* AbstractPad::GetAbstractedPadHolder() {
|
||||
return &abstract_pad_holder;
|
||||
}
|
||||
|
||||
NpadAbstractPropertiesHandler* AbstractPad::GetAbstractPropertiesHandler() {
|
||||
return &properties_handler;
|
||||
}
|
||||
|
||||
NpadAbstractLedHandler* AbstractPad::GetAbstractLedHandler() {
|
||||
return &led_handler;
|
||||
}
|
||||
|
||||
NpadAbstractIrSensorHandler* AbstractPad::GetAbstractIrSensorHandler() {
|
||||
return &ir_sensor_handler;
|
||||
}
|
||||
|
||||
NpadAbstractMcuHandler* AbstractPad::GetAbstractMcuHandler() {
|
||||
return &mcu_handler;
|
||||
}
|
||||
|
||||
NpadAbstractNfcHandler* AbstractPad::GetAbstractNfcHandler() {
|
||||
return &nfc_handler;
|
||||
}
|
||||
|
||||
NpadAbstractVibrationHandler* AbstractPad::GetAbstractVibrationHandler() {
|
||||
return &vibration_handler;
|
||||
}
|
||||
|
||||
NpadAbstractSixAxisHandler* AbstractPad::GetAbstractSixAxisHandler() {
|
||||
return &sixaxis_handler;
|
||||
}
|
||||
|
||||
NpadAbstractButtonHandler* AbstractPad::GetAbstractButtonHandler() {
|
||||
return &button_handler;
|
||||
}
|
||||
|
||||
NpadAbstractBatteryHandler* AbstractPad::GetAbstractBatteryHandler() {
|
||||
return &battery_handler;
|
||||
}
|
||||
|
||||
NpadN64VibrationDevice* AbstractPad::GetN64VibrationDevice() {
|
||||
return &vibration_n64;
|
||||
}
|
||||
|
||||
NpadVibrationDevice* AbstractPad::GetVibrationDevice(Core::HID::DeviceIndex device_index) {
|
||||
if (device_index == Core::HID::DeviceIndex::Right) {
|
||||
return &vibration_right;
|
||||
}
|
||||
return &vibration_left;
|
||||
}
|
||||
|
||||
void AbstractPad::FUN_710005d5b0(std::vector<NpadVibrationDevice*> list) {
|
||||
list.emplace_back(&vibration_left);
|
||||
list.emplace_back(&vibration_right);
|
||||
}
|
||||
|
||||
NpadGcVibrationDevice* AbstractPad::GetGCVibrationDevice() {
|
||||
return &vibration_gc;
|
||||
}
|
||||
|
||||
u8* AbstractPad::GetNpadSharedMemory(const Core::HID::SixAxisSensorHandle& handle) {
|
||||
return sixaxis_handler.GetNpadSharedMemory(handle);
|
||||
}
|
||||
|
||||
u8* AbstractPad::FUN_710005d5f4() {
|
||||
return &field_0x5bc0;
|
||||
}
|
||||
|
||||
u8* AbstractPad::FUN_710005d600(int param_2) {
|
||||
return &field_0x5f08 + (long)param_2 * 0x48;
|
||||
}
|
||||
|
||||
Core::HID::NpadIdType AbstractPad::GetLastActiveNpad() {
|
||||
return properties_handler.GetNpadId();
|
||||
}
|
||||
|
||||
void AbstractPad::FUN_710005d61c() {
|
||||
if (interface_type != properties_handler.GetInterfaceType()) {
|
||||
Update();
|
||||
}
|
||||
properties_handler.FUN_710005fd58();
|
||||
button_handler.FUN_710006800c(0);
|
||||
sixaxis_handler.FUN_7100074a94();
|
||||
battery_handler.UpdateBatteryState();
|
||||
led_handler.FUN_7100067550();
|
||||
}
|
||||
|
||||
void AbstractPad::Update() {
|
||||
properties_handler.FUN_710005fd70();
|
||||
properties_handler.UpdateDeviceType();
|
||||
led_handler.SetNpadLedHandlerLedPattern();
|
||||
vibration_handler.UpdateVibrationState();
|
||||
sixaxis_handler.UpdateSixaxisState();
|
||||
nfc_handler.UpdateNfcState();
|
||||
ir_sensor_handler.UpdateIrSensorState();
|
||||
mcu_handler.UpdateMcuState();
|
||||
palma_handler.UpdatePalmaState();
|
||||
battery_handler.UpdateBatteryState();
|
||||
button_handler.EnableCenterClamp();
|
||||
button_handler.FUN_710006800c(1);
|
||||
|
||||
interface_type = properties_handler.GetInterfaceType();
|
||||
|
||||
std::scoped_lock lock{*applet_resource_holder->shared_mutex};
|
||||
properties_handler.UpdateAllDeviceProperties();
|
||||
battery_handler.UpdateCoreBatteryState();
|
||||
button_handler.UpdateCoreBatteryState();
|
||||
}
|
||||
|
||||
void AbstractPad::FUN_710005d770() {
|
||||
button_handler.UpdateAllButtonLifo();
|
||||
sixaxis_handler.FUN_7100074ab0();
|
||||
battery_handler.UpdateCoreBatteryState();
|
||||
}
|
||||
|
||||
void AbstractPad::EnableAppletToGetInput(u64 aruid) {
|
||||
button_handler.UpdateButtonState(aruid);
|
||||
sixaxis_handler.FUN_7100074b70(aruid);
|
||||
battery_handler.UpdateBatteryState(aruid);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,135 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_battery_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_button_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_ir_sensor_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_led_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_mcu_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_nfc_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_palma_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_sixaxis_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/npad/gc_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/n64_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_device.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class AppletResource;
|
||||
class HandheldConfig;
|
||||
class SixAxisResource;
|
||||
class PalmaResource;
|
||||
class NPadResource;
|
||||
class AbstractPad;
|
||||
class NpadLastActiveHandler;
|
||||
class NpadIrNfcHandler;
|
||||
class UniquePads;
|
||||
class NpadPalmaHandler;
|
||||
class FirmwareResource;
|
||||
class NpadVibrationHandler;
|
||||
class NpadHighestBattery;
|
||||
class NpadGcVibration;
|
||||
|
||||
class CaptureButtonResource;
|
||||
class HomeButtonResource;
|
||||
class VibrationHandler;
|
||||
|
||||
struct SixAxisConfig {};
|
||||
|
||||
struct SixAxisConfigHolder {
|
||||
u8* pointer;
|
||||
// something
|
||||
SixAxisConfig config;
|
||||
};
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class AbstractPad final {
|
||||
public:
|
||||
explicit AbstractPad();
|
||||
~AbstractPad();
|
||||
|
||||
void SetExternals(AppletResourceHolder* applet_resource,
|
||||
CaptureButtonResource* capture_button_resource,
|
||||
HomeButtonResource* home_button_resource, SixAxisResource* sixaxis_resource,
|
||||
PalmaResource* palma_resource, VibrationHandler* vibration);
|
||||
void SetNpadId(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result Activate();
|
||||
Result Deactivate();
|
||||
|
||||
Result ActivateNpad(u64 aruid);
|
||||
|
||||
NpadAbstractedPadHolder* GetAbstractedPadHolder();
|
||||
NpadAbstractPropertiesHandler* GetAbstractPropertiesHandler();
|
||||
NpadAbstractLedHandler* GetAbstractLedHandler();
|
||||
NpadAbstractIrSensorHandler* GetAbstractIrSensorHandler();
|
||||
NpadAbstractMcuHandler* GetAbstractMcuHandler();
|
||||
NpadAbstractNfcHandler* GetAbstractNfcHandler();
|
||||
NpadAbstractVibrationHandler* GetAbstractVibrationHandler();
|
||||
NpadAbstractSixAxisHandler* GetAbstractSixAxisHandler();
|
||||
NpadAbstractButtonHandler* GetAbstractButtonHandler();
|
||||
NpadAbstractBatteryHandler* GetAbstractBatteryHandler();
|
||||
|
||||
NpadN64VibrationDevice* GetN64VibrationDevice();
|
||||
NpadVibrationDevice* GetVibrationDevice(Core::HID::DeviceIndex device_index);
|
||||
void FUN_710005d5b0(std::vector<NpadVibrationDevice*> list);
|
||||
NpadGcVibrationDevice* GetGCVibrationDevice();
|
||||
|
||||
u8* GetNpadSharedMemory(const Core::HID::SixAxisSensorHandle& handle);
|
||||
|
||||
long FUN_710005d5f4();
|
||||
long FUN_710005d600(int param_2);
|
||||
|
||||
Core::HID::NpadIdType GetLastActiveNpad();
|
||||
void FUN_710005d61c();
|
||||
void Update();
|
||||
|
||||
void FUN_710005d770();
|
||||
void EnableAppletToGetInput(u64 aruid);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder;
|
||||
NpadAbstractedPadHolder abstract_pad_holder;
|
||||
NpadAbstractPropertiesHandler properties_handler;
|
||||
NpadAbstractLedHandler led_handler;
|
||||
NpadAbstractIrSensorHandler ir_sensor_handler;
|
||||
NpadAbstractNfcHandler nfc_handler;
|
||||
NpadAbstractMcuHandler mcu_handler;
|
||||
NpadAbstractVibrationHandler vibration_handler;
|
||||
NpadAbstractSixAxisHandler sixaxis_handler;
|
||||
NpadAbstractButtonHandler button_handler;
|
||||
NpadAbstractBatteryHandler battery_handler;
|
||||
NpadAbstractPalmaHandler palma_handler;
|
||||
|
||||
NpadN64VibrationDevice vibration_n64;
|
||||
NpadVibrationDevice vibration_left;
|
||||
NpadVibrationDevice vibration_right;
|
||||
NpadGcVibrationDevice vibration_gc;
|
||||
|
||||
SixAxisConfigHolder fullkey_config;
|
||||
SixAxisConfigHolder handheld_config;
|
||||
SixAxisConfigHolder dual_left_config;
|
||||
SixAxisConfigHolder dual_right_config;
|
||||
SixAxisConfigHolder left_config;
|
||||
SixAxisConfigHolder right_config;
|
||||
|
||||
s32 ref_counter;
|
||||
Core::HID::NpadInterfaceType interface_type;
|
||||
};
|
||||
|
||||
using FullAbstractPad = std::array<AbstractPad, NpadCount>;
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,334 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Result NpadAbstractedPadHolder::RegisterAbstractPad(IAbstractedPad* abstracted_pad) {
|
||||
if (list_size >= assignment_list.size()) {
|
||||
return ResultNpadIsNotProController;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < list_size; i++) {
|
||||
if (assignment_list[i].device_type == abstracted_pad->device_type) {
|
||||
return ResultNpadIsNotProController;
|
||||
}
|
||||
}
|
||||
|
||||
assignment_list[list_size] = {
|
||||
.abstracted_pad = abstracted_pad,
|
||||
.device_type = abstracted_pad->device_type,
|
||||
.interface_type = abstracted_pad->interface_type,
|
||||
.controller_id = abstracted_pad->controller_id,
|
||||
};
|
||||
|
||||
list_size++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractedPadHolder::RemoveAbstractPadByControllerId(u64 controller_id) {
|
||||
if (list_size == 0) {
|
||||
return;
|
||||
}
|
||||
if (controller_id == 0) {
|
||||
return;
|
||||
}
|
||||
for (std::size_t i = 0; i < list_size; i++) {
|
||||
if (assignment_list[i].controller_id != controller_id) {
|
||||
continue;
|
||||
}
|
||||
for (std::size_t e = i+1; e < list_size; e++) {
|
||||
assignment_list[e - 1] = assignment_list[e];
|
||||
}
|
||||
list_size--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void NpadAbstractedPadHolder::DetachAbstractedPad() {
|
||||
while (list_size > 0) {
|
||||
for (std::size_t i = 1; i < list_size; i++) {
|
||||
assignment_list[i - 1] = assignment_list[i];
|
||||
}
|
||||
list_size--;
|
||||
}
|
||||
}
|
||||
|
||||
u64 NpadAbstractedPadHolder::RemoveAbstractPadByAssignmentStyle(Service::HID::AssignmentStyle assignment_style) {
|
||||
for (std::size_t i = 0; i < list_size; i++) {
|
||||
if ((assignment_style.raw & assignment_list[i].abstracted_pad->assignament_style.raw) == 0) {
|
||||
continue;
|
||||
}
|
||||
for (std::size_t e = i + 1; e < list_size; e++) {
|
||||
assignment_list[e - 1] = assignment_list[e];
|
||||
}
|
||||
list_size--;
|
||||
return list_size;
|
||||
}
|
||||
return list_size;
|
||||
}
|
||||
|
||||
int NpadAbstractedPadHolder::FUN_710005db00(u64 param_2)
|
||||
|
||||
{
|
||||
u64 lVar1;
|
||||
undefined2 uVar2;
|
||||
int iVar3;
|
||||
u32 uVar4;
|
||||
u32 uVar5;
|
||||
NpadAbstractAssignmentModeList* pNVar6;
|
||||
NpadAbstractAssignmentModeList* pNVar7;
|
||||
uu64 uVar8;
|
||||
u64 uVar9;
|
||||
u64 uVar10;
|
||||
u64 uVar11;
|
||||
|
||||
uVar5 = list_size;
|
||||
if ((int)uVar5 < 1) {
|
||||
iVar3 = 0;
|
||||
} else {
|
||||
uVar4 = 0;
|
||||
iVar3 = 0;
|
||||
do {
|
||||
while (((*(byte*)(*(u64*)(assignment_list + (int)uVar4) + 8) >> 1 & 1) == 0 ||
|
||||
(*(u64*)(*(u64*)(assignment_list + (int)uVar4) + 0x10) !=
|
||||
*(u64*)&assignment_list[(int)uVar4].field_0x10))) {
|
||||
if ((int)uVar4 < 0) {
|
||||
// WARNING: Subroutine does not return
|
||||
nn::diag::detail::AbortImpl();
|
||||
}
|
||||
uVar2 = *(undefined2*)&assignment_list[uVar4].field_0x8;
|
||||
if ((int)(uVar4 + 1) < (int)uVar5) {
|
||||
uVar8 = (uu64)uVar4;
|
||||
pNVar7 = assignment_list + uVar8 + 1;
|
||||
do {
|
||||
uVar9 = *(u64*)pNVar7;
|
||||
uVar10 = *(u64*)&pNVar7->field_0x8;
|
||||
pNVar6 = assignment_list + (int)uVar8;
|
||||
uVar11 = *(u64*)&pNVar7->field_0x10;
|
||||
pNVar7 = pNVar7 + 1;
|
||||
*(u64*)pNVar6 = uVar9;
|
||||
*(u64*)&pNVar6->field_0x8 = uVar10;
|
||||
*(u64*)&pNVar6->field_0x10 = uVar11;
|
||||
lVar1 = uVar8 + 2;
|
||||
uVar8 = uVar8 + 1;
|
||||
uVar5 = list_size;
|
||||
} while (lVar1 < (int)uVar5);
|
||||
}
|
||||
list_size = uVar5 - 1;
|
||||
*(u64*)(&DAT_ffffffffffffffe8 + (u64)(assignment_list + (int)uVar5)) = 0;
|
||||
*(undefined2*)((u64)(assignment_list + (int)uVar5 + -1) + 8) = 0;
|
||||
*(undefined2*)(param_2 + (u64)iVar3 * 2) = uVar2;
|
||||
iVar3 = iVar3 + 1;
|
||||
uVar5 = list_size;
|
||||
if ((int)uVar5 <= (int)uVar4) {
|
||||
return iVar3;
|
||||
}
|
||||
}
|
||||
uVar4 = uVar4 + 1;
|
||||
} while ((int)uVar4 < (int)uVar5);
|
||||
}
|
||||
return iVar3;
|
||||
}
|
||||
|
||||
bool NpadAbstractedPadHolder::FUN_710005dc00(u64* param_2)
|
||||
|
||||
{
|
||||
u32 uVar1;
|
||||
uu64 uVar2;
|
||||
bool bVar3;
|
||||
NpadAbstractAssignmentModeList* pNVar4;
|
||||
u64 lVar5;
|
||||
uu64 uVar6;
|
||||
|
||||
uVar1 = list_size;
|
||||
if (uVar1 == 0) {
|
||||
return false;
|
||||
}
|
||||
lVar5 = *param_2;
|
||||
bVar3 = false;
|
||||
if ((lVar5 != 0) && (0 < (int)uVar1)) {
|
||||
if (*(u64*)(*(u64*)assignment_list + 0x10) == lVar5) {
|
||||
return true;
|
||||
}
|
||||
pNVar4 = assignment_list;
|
||||
uVar2 = 1;
|
||||
do {
|
||||
uVar6 = uVar2;
|
||||
pNVar4 = pNVar4 + 1;
|
||||
if (uVar1 == uVar6)
|
||||
break;
|
||||
uVar2 = uVar6 + 1;
|
||||
} while (*(u64*)(*(u64*)pNVar4 + 0x10) != lVar5);
|
||||
bVar3 = uVar6 < uVar1;
|
||||
}
|
||||
return bVar3;
|
||||
}
|
||||
|
||||
u32 NpadAbstractedPadHolder::GetAbstractedPads(std::span<IAbstractedPad*> list) {
|
||||
u32 num_elements = std::min(static_cast<u32>(list.size()), list_size);
|
||||
for (std::size_t i = 0; i < num_elements; i++) {
|
||||
list[i] = assignment_list[i].style_index;
|
||||
}
|
||||
return num_elements;
|
||||
}
|
||||
|
||||
void NpadAbstractedPadHolder::SetAssignmentMode(const NpadJoyAssignmentMode& mode) {
|
||||
assignment_mode = mode;
|
||||
}
|
||||
|
||||
NpadJoyAssignmentMode NpadAbstractedPadHolder::GetAssignmentMode() {
|
||||
return assignment_mode;
|
||||
}
|
||||
|
||||
std::size_t NpadAbstractedPadHolder::FUN_710005dd10(std::span<u8> list) {
|
||||
for (std::size_t i = 0; i < list_size; i++) {
|
||||
list[i] = assignment_list[i].element_a;
|
||||
}
|
||||
return list_size;
|
||||
}
|
||||
|
||||
u32 NpadAbstractedPadHolder::FUN_710005dd60() {
|
||||
u32 uVar1;
|
||||
AbstracAssignmentMode* pNVar2;
|
||||
AbstracAssignmentMode* pNVar3;
|
||||
u32 uVar4;
|
||||
uu64 uVar5;
|
||||
AbstracAssignmentMode* pNVar6;
|
||||
|
||||
uVar1 = list_size;
|
||||
if (0 < (int)uVar1) {
|
||||
if (uVar1 == 1) {
|
||||
uVar5 = 0;
|
||||
uVar4 = 0;
|
||||
} else {
|
||||
uVar5 = 0;
|
||||
uVar4 = 0;
|
||||
pNVar6 = param_1;
|
||||
do {
|
||||
pNVar2 = pNVar6->assignment_list;
|
||||
uVar5 = uVar5 + 2;
|
||||
pNVar3 = pNVar6->assignment_list;
|
||||
pNVar6 = (NpadAbstractAssignmentMode*)(pNVar6->assignment_list + 2);
|
||||
uVar4 = *(u32*)(*(u64*)(pNVar3 + 1) + 0x40) | *(u32*)(*(u64*)pNVar2 + 0x40) | uVar4;
|
||||
} while (((uu64)uVar1 & 0xfffffffe) != uVar5);
|
||||
}
|
||||
if ((uVar1 & 1) != 0) {
|
||||
uVar4 = *(u32*)(*(u64*)(assignment_list + uVar5) + 0x40) | uVar4;
|
||||
}
|
||||
return uVar4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uu64 NpadAbstractedPadHolder::FUN_710005ddf0()
|
||||
|
||||
{
|
||||
u32 uVar1;
|
||||
uu64 uVar2;
|
||||
uu64 uVar3;
|
||||
NpadAbstractAssignmentMode* pNVar4;
|
||||
NpadAbstractAssignmentModeList* list2;
|
||||
NpadAbstractAssignmentModeList* list_1;
|
||||
|
||||
uVar1 = list_size;
|
||||
if (0 < (int)uVar1) {
|
||||
if (uVar1 == 1) {
|
||||
uVar3 = 0;
|
||||
uVar2 = 0;
|
||||
} else {
|
||||
uVar3 = 0;
|
||||
uVar2 = 0;
|
||||
pNVar4 = param_1;
|
||||
do {
|
||||
list_1 = pNVar4->assignment_list;
|
||||
uVar3 = uVar3 + 2;
|
||||
list2 = pNVar4->assignment_list;
|
||||
pNVar4 = (NpadAbstractAssignmentMode*)(pNVar4->assignment_list + 2);
|
||||
uVar2 = *(uu64*)(*(u64*)(*(u64*)(list2 + 1) + 0x48) + 0x10) |
|
||||
*(uu64*)(*(u64*)(*(u64*)list_1 + 0x48) + 0x10) | uVar2;
|
||||
} while (((uu64)uVar1 & 0xfffffffe) != uVar3);
|
||||
}
|
||||
if ((uVar1 & 1) != 0) {
|
||||
uVar2 = *(uu64*)(*(u64*)(*(u64*)(assignment_list + uVar3) + 0x48) + 0x10) | uVar2;
|
||||
}
|
||||
return uVar2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uu64 NpadAbstractedPadHolder::FUN_710005de90()
|
||||
|
||||
{
|
||||
u32 uVar1;
|
||||
NpadAbstractAssignmentModeList* pNVar2;
|
||||
NpadAbstractAssignmentModeList* pNVar3;
|
||||
uu64 uVar4;
|
||||
uu64 uVar5;
|
||||
NpadAbstractAssignmentMode* pNVar6;
|
||||
|
||||
uVar1 = list_size;
|
||||
if (0 < (int)uVar1) {
|
||||
if (uVar1 == 1) {
|
||||
uVar5 = 0;
|
||||
uVar4 = 0;
|
||||
} else {
|
||||
uVar5 = 0;
|
||||
uVar4 = 0;
|
||||
pNVar6 = param_1;
|
||||
do {
|
||||
pNVar2 = pNVar6->assignment_list;
|
||||
uVar5 = uVar5 + 2;
|
||||
pNVar3 = pNVar6->assignment_list;
|
||||
pNVar6 = (NpadAbstractAssignmentMode*)(pNVar6->assignment_list + 2);
|
||||
uVar4 =
|
||||
*(uu64*)(*(u64*)(pNVar3 + 1) + 0x38) | *(uu64*)(*(u64*)pNVar2 + 0x38) | uVar4;
|
||||
} while (((uu64)uVar1 & 0xfffffffe) != uVar5);
|
||||
}
|
||||
if ((uVar1 & 1) != 0) {
|
||||
uVar4 = *(uu64*)(*(u64*)(assignment_list + uVar5) + 0x38) | uVar4;
|
||||
}
|
||||
return uVar4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NpadAbstractedPadHolder::GetAbstractedPadIdDataFromNpad(u64 out_arg, u32 arg_size)
|
||||
|
||||
{
|
||||
u64 lVar1;
|
||||
int object_count;
|
||||
u64 index;
|
||||
NpadAbstractAssignmentMode* pNVar2;
|
||||
u32 some_value;
|
||||
|
||||
some_value = list_size;
|
||||
if ((int)arg_size <= (int)list_size) {
|
||||
some_value = arg_size;
|
||||
}
|
||||
if (0 < (int)some_value) {
|
||||
index = 0;
|
||||
object_count = 0;
|
||||
pNVar2 = param_1;
|
||||
do {
|
||||
lVar1 = (**(code**)(**(u64**)pNVar2->assignment_list + 0x1a8))();
|
||||
*(u64*)(out_arg + index * 8) = lVar1;
|
||||
if (lVar1 != -1) {
|
||||
object_count = object_count + 1;
|
||||
}
|
||||
index = index + 1;
|
||||
some_value = list_size;
|
||||
if ((int)arg_size <= (int)list_size) {
|
||||
some_value = arg_size;
|
||||
}
|
||||
pNVar2 = (NpadAbstractAssignmentMode*)(pNVar2->assignment_list + 1);
|
||||
} while (index < (int)some_value);
|
||||
return object_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,52 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct IAbstractedPad;
|
||||
|
||||
struct AbstracAssignmentHolder {
|
||||
IAbstractedPad* abstracted_pad;
|
||||
Core::HID::NpadStyleIndex device_type;
|
||||
Core::HID::NpadInterfaceType interface_type;
|
||||
INSERT_PADDING_BYTES(0x6);
|
||||
u64 controller_id;
|
||||
};
|
||||
static_assert(sizeof(AbstracAssignmentHolder) == 0x18, "AbstracAssignmentHolder is an invalid size");
|
||||
|
||||
/// This is nn::hid::server::NpadAbstractedPadHolder
|
||||
class NpadAbstractedPadHolder final {
|
||||
public:
|
||||
Result RegisterAbstractPad(IAbstractedPad* abstracted_pad);
|
||||
void RemoveAbstractPadByControllerId(u64 controller_id);
|
||||
void DetachAbstractedPad();
|
||||
u64 RemoveAbstractPadByAssignmentStyle(Service::HID::AssignmentStyle assignment_style);
|
||||
int FUN_710005db00(u64 param_2);
|
||||
bool FUN_710005dc00(u64* param_2);
|
||||
u32 GetAbstractedPads(std::span<IAbstractedPad*> list);
|
||||
|
||||
void SetAssignmentMode(const NpadJoyAssignmentMode& mode);
|
||||
NpadJoyAssignmentMode GetAssignmentMode();
|
||||
|
||||
std::size_t FUN_710005dd10(std::span<u8> list);
|
||||
u32 FUN_710005dd60();
|
||||
u64 FUN_710005ddf0();
|
||||
u64 FUN_710005de90();
|
||||
int GetAbstractedPadIdDataFromNpad(u64 out_arg, u32 arg_size);
|
||||
|
||||
private:
|
||||
std::array<AbstracAssignmentHolder, 5> assignment_list{};
|
||||
u32 list_size{};
|
||||
NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,48 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_palma_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/npad/assignment_handler.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NpadAbstractPalmaHandler::NpadAbstractPalmaHandler() {}
|
||||
|
||||
NpadAbstractPalmaHandler::~NpadAbstractPalmaHandler() = default;
|
||||
|
||||
void NpadAbstractPalmaHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractPalmaHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
return;
|
||||
}
|
||||
|
||||
void NpadAbstractPalmaHandler::SetPalmaResource(PalmaResource* resource) {
|
||||
palma_resource = resource;
|
||||
}
|
||||
|
||||
Result NpadAbstractPalmaHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractPalmaHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractPalmaHandler::UpdatePalmaState() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,37 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
class PalmaResource;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractPalmaHandler final {
|
||||
public:
|
||||
explicit NpadAbstractPalmaHandler();
|
||||
~NpadAbstractPalmaHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
void SetPalmaResource(PalmaResource* resource);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void UpdatePalmaState();
|
||||
|
||||
private:
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
PalmaResource* palma_resource{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
};
|
||||
} // namespace Service::HID
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,94 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct NpadSharedMemoryEntry;
|
||||
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
|
||||
struct ColorProperties {
|
||||
ColorAttribute attribute;
|
||||
Core::HID::NpadControllerColor color;
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
};
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractPropertiesHandler final {
|
||||
public:
|
||||
explicit NpadAbstractPropertiesHandler();
|
||||
~NpadAbstractPropertiesHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetNpadId(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Core::HID::NpadIdType GetNpadId();
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
Result ActivateNpadUnknown0x88(u64 aruid);
|
||||
|
||||
void UpdateDeviceType();
|
||||
void UpdateDeviceColor();
|
||||
void UpdateFooterAttributes();
|
||||
void FUN_710005e830();
|
||||
void UpdateAllDeviceProperties();
|
||||
u32 FUN_710005ec58();
|
||||
|
||||
Core::HID::NpadInterfaceType GetFullkeyInterfaceType();
|
||||
Core::HID::NpadInterfaceType GetInterfaceType();
|
||||
|
||||
Core::HID::NpadStyleTag GetStyleTag(u64 aruid);
|
||||
std::size_t GetAbstractedPadsWithStyleTag(std::span<IAbstractedPad*> list,
|
||||
Core::HID::NpadStyleTag style);
|
||||
std::size_t GetAbstractedPads(std::span<IAbstractedPad*> list);
|
||||
|
||||
AppletFooterUiType GetAppletFooterUiType();
|
||||
|
||||
AppletDetailedUiType GetAppletDetailedUiType();
|
||||
|
||||
AppletDetailedUiType FUN_710005f0b0(int param_2, int is_horizontal, u16* param_4, u32 param_5);
|
||||
void UpdateDeviceProperties(u64 aruid, NpadSharedMemoryEntry& internal_state);
|
||||
u64 GetAppletResourceIndex();
|
||||
|
||||
void FUN_710005f988(u32* param_2, u8* param_3);
|
||||
Core::HID::NpadInterfaceType GetNpadInterfaceType();
|
||||
|
||||
Result GetNpadFullKeyGripColor(Core::HID::NpadColor& main_color,
|
||||
Core::HID::NpadColor& sub_color) const;
|
||||
void FUN_710005fd58();
|
||||
bool FUN_710005fd70();
|
||||
|
||||
void GetNpadLeftRightInterfaceType(Core::HID::NpadInterfaceType& param_2,
|
||||
Core::HID::NpadInterfaceType& param_3) const;
|
||||
|
||||
AppletDetailedUiType FUN_7100060030(u8* param_1, u8* param_2);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
Core::HID::NpadIdType npad_id_type{Core::HID::NpadIdType::Invalid};
|
||||
s32 ref_counter{};
|
||||
Core::HID::DeviceIndex device_type{};
|
||||
AppletDetailedUiType applet_ui_type{};
|
||||
AppletFooterUiAttributes applet_ui_attributes{};
|
||||
u32 fiel_28;
|
||||
bool is_vertical;
|
||||
bool is_horizontal;
|
||||
bool use_plus;
|
||||
bool use_minus;
|
||||
bool has_directional_buttons;
|
||||
ColorProperties fullkey_color;
|
||||
ColorProperties left_color;
|
||||
ColorProperties right_color;
|
||||
bool is_soo_me_thing;
|
||||
};
|
||||
} // namespace Service::HID
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,82 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class SixAxisResource;
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAbstractSixAxisHandler final {
|
||||
public:
|
||||
explicit NpadAbstractSixAxisHandler();
|
||||
~NpadAbstractSixAxisHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
void FUN_71000722ac(u64 param_2, u32 param_3);
|
||||
void SetSixaxisResource(SixAxisResource* param_2);
|
||||
void FUN_71000722c0(u8* param_2);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
void FUN_7100072330();
|
||||
|
||||
Result DecrementRefCounter();
|
||||
Result UpdateSixAxis(u64 aruid);
|
||||
u64 IsFirmwareUpdateAvailable();
|
||||
u8* GetNpadSharedMemory(const Core::HID::SixAxisSensorHandle& handle);
|
||||
u64 GetSixAxisSensorConfig(const Core::HID::SixAxisSensorHandle& param_2);
|
||||
|
||||
Result ResetIsSixAxisSensorDeviceNewlyAssigned(u64 out_aruid,
|
||||
const Core::HID::SixAxisSensorHandle& handle);
|
||||
void UpdateSixaxisState();
|
||||
|
||||
u64 FUN_71000743d0();
|
||||
void FUN_71000745f0();
|
||||
|
||||
void FUN_71000748b0();
|
||||
|
||||
void FUN_7100074a94();
|
||||
|
||||
void FUN_7100074ab0();
|
||||
void FUN_7100074b70(u64 aruid);
|
||||
|
||||
void UpdateSixaxisInternalState(NpadSharedMemoryEntry& npad_entry, u64 aruid, bool param_4,
|
||||
bool param_5);
|
||||
NpadAbstractSixAxisHandler* UpdateSixaxisFullkeyLifo(u32 param_2, u64 param_3, u64 param_4,
|
||||
u32 param_5, u64 param_6, u32 param_7,
|
||||
u32 param_8);
|
||||
NpadAbstractSixAxisHandler* UpdateSixaxisHandheldLifo(u32 param_2, u64* param_3, u64 param_4,
|
||||
u32 param_5, u32 param_6, u32 param_7,
|
||||
u32 param_8);
|
||||
NpadAbstractSixAxisHandler* UpdateSixaxisDualLifo(u32 param_2, u64 param_3, u64 param_4,
|
||||
u32 param_5, u64 param_6, u32 param_7,
|
||||
u32 param_8);
|
||||
|
||||
NpadAbstractSixAxisHandler* UpdateSixaxisLeftLifo(u32 param_2, u64 param_3, u64 param_4,
|
||||
u32 param_5, u64 param_6, u32 param_7,
|
||||
u32 param_8);
|
||||
NpadAbstractSixAxisHandler* UpdateSixaxisRightLifo(NpadAbstractSixAxisHandler* sixaxis_handler,
|
||||
u32 param_2, u64 param_3, u64 param_4,
|
||||
u32 param_5, u64 param_6, u32 param_7,
|
||||
u32 param_8);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
SixAxisResource* six_axis_resource{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,153 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad_holder.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_properties_handler.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/npad/gc_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/n64_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
|
||||
namespace Service::HID {
|
||||
void NpadAbstractVibrationHandler::SetAbstractPadHolder(NpadAbstractedPadHolder* holder) {
|
||||
abstract_pad_holder = holder;
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::SetAppletResource(AppletResourceHolder* applet_resource) {
|
||||
applet_resource_holder = applet_resource;
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::SetPropertiesHandler(NpadAbstractPropertiesHandler* handler) {
|
||||
properties_handler = handler;
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::SetN64Vibration(NpadN64VibrationDevice* n64_device) {
|
||||
n64_vibration_device = n64_device;
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::SetVibration(std::span<NpadVibrationDevice*> device) {
|
||||
for (std::size_t i = 0; i < device.size() && i < vibration_device.size(); i++) {
|
||||
vibration_device[i] = device[i];
|
||||
}
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::SetGcVibration(NpadGcVibrationDevice* gc_device) {
|
||||
gc_vibration_device = gc_device;
|
||||
}
|
||||
|
||||
Result NpadAbstractVibrationHandler::IncrementRefCounter() {
|
||||
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultNpadHandlerOverflow;
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadAbstractVibrationHandler::DecrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
return ResultNpadHandlerNotInitialized;
|
||||
}
|
||||
ref_counter--;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadAbstractVibrationHandler::UpdateVibrationState() {
|
||||
const bool is_handheld_hid_enabled =
|
||||
applet_resource_holder->handheld_config->is_handheld_hid_enabled;
|
||||
const bool is_force_handheld_style_vibration =
|
||||
applet_resource_holder->handheld_config->is_force_handheld_style_vibration;
|
||||
|
||||
if (!is_handheld_hid_enabled && is_force_handheld_style_vibration) {
|
||||
const auto style_tag = properties_handler->GetStyleTag(
|
||||
applet_resource_holder->applet_resource->GetActiveAruid());
|
||||
const auto value = properties_handler->FUN_710005ef50(local_88, 5, NVar4 | 2);
|
||||
if (0 < (int)uVar5)
|
||||
goto LAB_71000792b0;
|
||||
LAB_7100079274:
|
||||
bVar3 = false;
|
||||
auVar17 = ZEXT816(0);
|
||||
uVar16 = 0;
|
||||
plVar11 = (long*)0x0;
|
||||
plVar14 = (long*)0x0;
|
||||
bVar2 = false;
|
||||
LAB_71000793a8:
|
||||
FUN_71000b6e0c(vibration[0]);
|
||||
uVar9 = vibration[1];
|
||||
if (!bVar2)
|
||||
goto LAB_7100079384;
|
||||
LAB_71000793bc:
|
||||
FUN_71000b6cc0(uVar9, plVar14, 2, vibration_resource);
|
||||
uVar9 = vibration3;
|
||||
if (bVar3)
|
||||
goto LAB_71000793d4;
|
||||
} else {
|
||||
uVar5 = NpadAbstractState::Unknown88::FUN_710005f04c(magic_88, local_88, 5);
|
||||
if ((int)uVar5 < 1)
|
||||
goto LAB_7100079274;
|
||||
LAB_71000792b0:
|
||||
plVar14 = (long*)0x0;
|
||||
bVar2 = false;
|
||||
plVar15 = (long*)0x0;
|
||||
bVar1 = false;
|
||||
auVar17 = ZEXT816(0);
|
||||
bVar3 = false;
|
||||
uVar16 = 0;
|
||||
uVar7 = (u64)uVar5;
|
||||
pplVar13 = local_88;
|
||||
plVar12 = (long*)0x0;
|
||||
do {
|
||||
plVar8 = *pplVar13;
|
||||
plVar11 = plVar12;
|
||||
if ((*(byte*)(plVar8 + 1) >> 1 & 1) != 0) {
|
||||
uVar10 = plVar8[7];
|
||||
if ((uVar10 & 0x20) != 0) {
|
||||
bVar1 = true;
|
||||
plVar15 = plVar8;
|
||||
}
|
||||
if ((uVar10 & 0x40) != 0) {
|
||||
bVar2 = true;
|
||||
plVar14 = plVar8;
|
||||
}
|
||||
plVar11 = plVar8;
|
||||
if ((uVar10 & 0x100) == 0) {
|
||||
plVar11 = plVar12;
|
||||
}
|
||||
uVar16 = (uint)((uVar10 & 0x100) >> 8) | uVar16;
|
||||
iVar6 = (**(code**)(*plVar8 + 0x18))();
|
||||
if ((iVar6 == 4) && (*(char*)(*pplVar13 + 7) < '\0')) {
|
||||
auVar17 = FUN_710006b318();
|
||||
bVar3 = true;
|
||||
}
|
||||
}
|
||||
pplVar13 = pplVar13 + 1;
|
||||
uVar7 = uVar7 - 1;
|
||||
plVar12 = plVar11;
|
||||
} while (uVar7 != 0);
|
||||
if (!bVar1)
|
||||
goto LAB_71000793a8;
|
||||
FUN_71000b6cc0(vibration[0], plVar15, 1, vibration_resource);
|
||||
uVar9 = vibration[1];
|
||||
if (bVar2)
|
||||
goto LAB_71000793bc;
|
||||
LAB_7100079384:
|
||||
FUN_71000b6e0c(uVar9);
|
||||
if (bVar3) {
|
||||
LAB_71000793d4:
|
||||
gc_vibration_device->FUN_71000880d8(auVar17._0_8_, auVar17._8_8_, vibration_handler);
|
||||
goto joined_r0x0071000793e8;
|
||||
}
|
||||
}
|
||||
gc_vibration_device->FUN_7100088150();
|
||||
joined_r0x0071000793e8:
|
||||
if (uVar16 == 0) {
|
||||
n64_vibration_device->FUN_71000b6898();
|
||||
} else {
|
||||
n64_vibration_device->FUN_71000b67b0(plVar11, vibration_resource);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,50 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct AppletResourceHolder;
|
||||
class NpadAbstractedPadHolder;
|
||||
class NpadAbstractPropertiesHandler;
|
||||
class NpadGcVibrationDevice;
|
||||
class NpadVibrationDevice;
|
||||
class NpadN64VibrationDevice;
|
||||
|
||||
/// Keeps track of battery levels and updates npad battery shared memory values
|
||||
class NpadAbstractVibrationHandler final {
|
||||
public:
|
||||
explicit NpadAbstractVibrationHandler();
|
||||
~NpadAbstractVibrationHandler();
|
||||
|
||||
void SetAbstractPadHolder(NpadAbstractedPadHolder* holder);
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetPropertiesHandler(NpadAbstractPropertiesHandler* handler);
|
||||
|
||||
void SetN64Vibration(NpadN64VibrationDevice* n64_device);
|
||||
void SetVibration(std::span<NpadVibrationDevice*> device);
|
||||
void SetGcVibration(NpadGcVibrationDevice* gc_device);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result DecrementRefCounter();
|
||||
|
||||
void UpdateVibrationState();
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
NpadAbstractedPadHolder* abstract_pad_holder{nullptr};
|
||||
NpadAbstractPropertiesHandler* properties_handler{nullptr};
|
||||
|
||||
NpadN64VibrationDevice* n64_vibration_device{nullptr};
|
||||
std::array<NpadVibrationDevice*, 2> vibration_device{nullptr};
|
||||
NpadGcVibrationDevice* gc_vibration_device{nullptr};
|
||||
NpadVibrationHandler* vibration_handler{nullptr};
|
||||
s32 ref_counter{};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -164,6 +164,22 @@ Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_mem
|
|||
return ResultSuccess;
|
||||
}
|
||||
|
||||
AruidData* AppletResource::GetAruidData(u64 aruid) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index == AruidIndexMax) {
|
||||
return nullptr;
|
||||
}
|
||||
return &data[aruid_index];
|
||||
}
|
||||
|
||||
AruidData* AppletResource::GetAruidDataByIndex(std::size_t aruid_index) {
|
||||
return &data[aruid_index];
|
||||
}
|
||||
|
||||
bool AppletResource::IsVibrationAruidActive(u64 aruid) const {
|
||||
return aruid == 0 || aruid == active_vibration_aruid;
|
||||
}
|
||||
|
||||
u64 AppletResource::GetIndexFromAruid(u64 aruid) {
|
||||
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||
if (registration_list.flag[i] == RegistrationStatus::Initialized &&
|
||||
|
|
|
@ -20,6 +20,59 @@ class KSharedMemory;
|
|||
|
||||
namespace Service::HID {
|
||||
struct SharedMemoryFormat;
|
||||
class AppletResource;
|
||||
class NPadResource;
|
||||
|
||||
static constexpr std::size_t AruidIndexMax = 0x20;
|
||||
|
||||
enum class RegistrationStatus : u32 {
|
||||
None,
|
||||
Initialized,
|
||||
PendingDelete,
|
||||
};
|
||||
|
||||
struct DataStatusFlag {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<0, 1, u32> is_initialized;
|
||||
BitField<1, 1, u32> is_assigned;
|
||||
BitField<16, 1, u32> enable_pad_input;
|
||||
BitField<17, 1, u32> enable_six_axis_sensor;
|
||||
BitField<18, 1, u32> bit_18;
|
||||
BitField<19, 1, u32> is_palma_connectable;
|
||||
BitField<20, 1, u32> enable_palma_boost_mode;
|
||||
BitField<21, 1, u32> enable_touchscreen;
|
||||
};
|
||||
};
|
||||
|
||||
struct AruidRegisterList {
|
||||
std::array<RegistrationStatus, AruidIndexMax> flag{};
|
||||
std::array<u64, AruidIndexMax> aruid{};
|
||||
};
|
||||
static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
|
||||
|
||||
struct AruidData {
|
||||
DataStatusFlag flag{};
|
||||
u64 aruid{};
|
||||
SharedMemoryFormat* shared_memory_format{nullptr};
|
||||
};
|
||||
|
||||
struct HandheldConfig {
|
||||
bool is_handheld_hid_enabled;
|
||||
bool is_force_handheld;
|
||||
bool is_joycon_rail_enabled;
|
||||
bool is_force_handheld_style_vibration;
|
||||
};
|
||||
static_assert(sizeof(HandheldConfig) == 0x4, "HandheldConfig is an invalid size");
|
||||
|
||||
struct AppletResourceHolder {
|
||||
std::shared_ptr<AppletResource> applet_resource{nullptr};
|
||||
std::recursive_mutex* shared_mutex{nullptr};
|
||||
NPadResource* shared_npad_resource{nullptr};
|
||||
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
|
||||
long* handle_1;
|
||||
};
|
||||
|
||||
class AppletResource {
|
||||
public:
|
||||
|
@ -36,6 +89,10 @@ public:
|
|||
u64 GetActiveAruid();
|
||||
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
||||
Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid);
|
||||
AruidData* GetAruidData(u64 aruid);
|
||||
AruidData* GetAruidDataByIndex(std::size_t aruid_index);
|
||||
|
||||
bool IsVibrationAruidActive(u64 aruid) const;
|
||||
|
||||
u64 GetIndexFromAruid(u64 aruid);
|
||||
|
||||
|
@ -52,46 +109,12 @@ public:
|
|||
Result UnregisterCoreAppletResource();
|
||||
|
||||
private:
|
||||
static constexpr std::size_t AruidIndexMax = 0x20;
|
||||
|
||||
enum RegistrationStatus : u32 {
|
||||
None,
|
||||
Initialized,
|
||||
PendingDelete,
|
||||
};
|
||||
|
||||
struct DataStatusFlag {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<0, 1, u32> is_initialized;
|
||||
BitField<1, 1, u32> is_assigned;
|
||||
BitField<16, 1, u32> enable_pad_input;
|
||||
BitField<17, 1, u32> enable_six_axis_sensor;
|
||||
BitField<18, 1, u32> bit_18;
|
||||
BitField<19, 1, u32> is_palma_connectable;
|
||||
BitField<20, 1, u32> enable_palma_boost_mode;
|
||||
BitField<21, 1, u32> enable_touchscreen;
|
||||
};
|
||||
};
|
||||
|
||||
struct AruidRegisterList {
|
||||
std::array<RegistrationStatus, AruidIndexMax> flag{};
|
||||
std::array<u64, AruidIndexMax> aruid{};
|
||||
};
|
||||
static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
|
||||
|
||||
struct AruidData {
|
||||
DataStatusFlag flag{};
|
||||
u64 aruid{};
|
||||
SharedMemoryFormat* shared_memory_format{nullptr};
|
||||
};
|
||||
|
||||
u64 active_aruid{};
|
||||
AruidRegisterList registration_list{};
|
||||
std::array<AruidData, AruidIndexMax> data{};
|
||||
std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{};
|
||||
s32 ref_counter{};
|
||||
u64 active_vibration_aruid;
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,202 +3,247 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/abstract/abstract_pad.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/npad/assignment_handler.h"
|
||||
#include "core/hle/service/hid/controllers/npad/npad_resource.h"
|
||||
#include "core/hle/service/hid/controllers/npad/palma_handler.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
enum class ControllerTriggerType;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Kernel {
|
||||
class KEvent;
|
||||
class KReadableEvent;
|
||||
} // namespace Kernel
|
||||
|
||||
namespace Service::KernelHelpers {
|
||||
class ServiceContext;
|
||||
} // namespace Service::KernelHelpers
|
||||
|
||||
union Result;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct NpadInternalState;
|
||||
struct NpadSixAxisSensorLifo;
|
||||
struct NpadSharedMemoryFormat;
|
||||
class AppletResource;
|
||||
class HandheldConfig;
|
||||
class SixAxisResource;
|
||||
class PalmaResource;
|
||||
class NpadLastActiveHandler;
|
||||
class NpadIrNfcHandler;
|
||||
class UniquePads;
|
||||
class UniquePadResource;
|
||||
class NpadVibrationHandler;
|
||||
class NpadHighestBattery;
|
||||
struct AppletResourceHolder;
|
||||
class NpadAppletResource;
|
||||
class NpadN64VibrationDevice;
|
||||
class NpadGcVibrationDevice;
|
||||
class NpadVibrationDevice;
|
||||
enum class NpadRevision : u32;
|
||||
|
||||
class NPad final : public ControllerBase {
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NPad final {
|
||||
public:
|
||||
explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format,
|
||||
KernelHelpers::ServiceContext& service_context_);
|
||||
~NPad() override;
|
||||
explicit NPad();
|
||||
~NPad();
|
||||
|
||||
// Called when the controller is initialized
|
||||
void OnInit() override;
|
||||
void SetExternals(Kernel::KEvent* input_event_, std::mutex* input_mutex_,
|
||||
std::shared_ptr<CaptureButtonResource> capture_button_resource,
|
||||
std::shared_ptr<HomeButtonResource> home_button_resource,
|
||||
std::shared_ptr<AppletResource> applet_resource,
|
||||
std::shared_ptr<SixAxisResource> sixaxis_resource,
|
||||
std::shared_ptr<HandheldConfig> handheld_config,
|
||||
std::shared_ptr<UniquePadResource> unique_resource,
|
||||
std::shared_ptr<PalmaResource> palma_resource);
|
||||
void SetAbstractNpadExternals(std::shared_ptr<CaptureButtonResource> capture_button_resource,
|
||||
std::shared_ptr<HomeButtonResource> home_button_resource,
|
||||
std::shared_ptr<SixAxisResource> sixaxis_resource,
|
||||
std::shared_ptr<PalmaResource> palma_resource);
|
||||
|
||||
// When the controller is released
|
||||
void OnRelease() override;
|
||||
Result Activate();
|
||||
Result Activate(u64 aruid);
|
||||
Result Deactivate();
|
||||
Result IsActive(bool& out_is_active) const;
|
||||
|
||||
// When the controller is requesting an update for the shared memory
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
Result SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet supported_style_set);
|
||||
Result GetSupportedNpadStyleSet(u64 aruid,
|
||||
Core::HID::NpadStyleSet& out_supported_style_set) const;
|
||||
Result GetMaskedSupportedNpadStyleSet(u64 aruid,
|
||||
Core::HID::NpadStyleSet& out_supported_style_set) const;
|
||||
|
||||
void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set);
|
||||
Core::HID::NpadStyleTag GetSupportedStyleSet() const;
|
||||
Result SetSupportedNpadIdType(u64 aruid,
|
||||
std::span<const Core::HID::NpadIdType> supported_npad_list);
|
||||
Result SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type);
|
||||
Result GetNpadJoyHoldType(u64 aruid, NpadJoyHoldType& out_hold_type) const;
|
||||
|
||||
Result SetSupportedNpadIdTypes(std::span<const u8> data);
|
||||
void GetSupportedNpadIdTypes(u32* data, std::size_t max_length);
|
||||
std::size_t GetSupportedNpadIdTypesSize() const;
|
||||
Result AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
|
||||
void SetHoldType(NpadJoyHoldType joy_hold_type);
|
||||
NpadJoyHoldType GetHoldType() const;
|
||||
void DisconnectNpad(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
void ForceDisconnectNpad(Core::HID::NpadIdType npad_id);
|
||||
|
||||
void SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode);
|
||||
NpadHandheldActivationMode GetNpadHandheldActivationMode() const;
|
||||
Result ApplyNpadSystemCommonPolicy(u64 aruid);
|
||||
Result ApplyNpadSystemCommonPolicyFull(u64 aruid);
|
||||
Result ClearNpadSystemCommonPolicy(u64 aruid);
|
||||
|
||||
void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_);
|
||||
NpadCommunicationMode GetNpadCommunicationMode() const;
|
||||
Result AssigningSingleOnSlSrPress(u64 aruid, bool is_enabled);
|
||||
|
||||
bool SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
|
||||
NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode);
|
||||
void SetNpadJoyAssignmentModeSingleByDefault(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
void SetNpadJoyAssignmentModeSingle(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
NpadJoyDeviceType npad_joy_device_type);
|
||||
bool SetNpadJoyAssignmentModeSingleWithDestination(Core::HID::NpadIdType& out_npad_id,
|
||||
u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
NpadJoyDeviceType npad_joy_device_type);
|
||||
void SetNpadJoyAssignmentModeDual(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
|
||||
bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
|
||||
const Core::HID::VibrationValue& vibration_value);
|
||||
|
||||
void VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle,
|
||||
const Core::HID::VibrationValue& vibration_value);
|
||||
|
||||
void VibrateControllers(
|
||||
std::span<const Core::HID::VibrationDeviceHandle> vibration_device_handles,
|
||||
std::span<const Core::HID::VibrationValue> vibration_values);
|
||||
|
||||
Core::HID::VibrationValue GetLastVibration(
|
||||
const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
|
||||
|
||||
void InitializeVibrationDevice(const Core::HID::VibrationDeviceHandle& vibration_device_handle);
|
||||
|
||||
void InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index);
|
||||
|
||||
void SetPermitVibrationSession(bool permit_vibration_session);
|
||||
|
||||
bool IsVibrationDeviceMounted(
|
||||
const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
|
||||
|
||||
Kernel::KReadableEvent& GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id);
|
||||
void SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
// Adds a new controller at an index.
|
||||
void AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id);
|
||||
// Adds a new controller at an index with connection status.
|
||||
void UpdateControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id,
|
||||
bool connected);
|
||||
|
||||
Result DisconnectNpad(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result IsFirmwareUpdateAvailableForSixAxisSensor(
|
||||
const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const;
|
||||
Result ResetIsSixAxisSensorDeviceNewlyAssigned(
|
||||
const Core::HID::SixAxisSensorHandle& sixaxis_handle);
|
||||
|
||||
NpadSixAxisSensorLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id);
|
||||
NpadSixAxisSensorLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
|
||||
Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
|
||||
bool& is_enabled) const;
|
||||
Result SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
void SetAnalogStickUseCenterClamp(bool use_center_clamp);
|
||||
void ClearAllConnectedControllers();
|
||||
void DisconnectAllConnectedControllers();
|
||||
void ConnectAllDisconnectedControllers();
|
||||
void ClearAllControllers();
|
||||
|
||||
Result MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
|
||||
Result MergeSingleJoyAsDualJoy(u64 aruid, Core::HID::NpadIdType npad_id_1,
|
||||
Core::HID::NpadIdType npad_id_2);
|
||||
void StartLRAssignmentMode();
|
||||
void StopLRAssignmentMode();
|
||||
Result SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2);
|
||||
Result SwapNpadAssignment(u64 aruid, Core::HID::NpadIdType npad_id_1,
|
||||
Core::HID::NpadIdType npad_id_2);
|
||||
|
||||
// Logical OR for all buttons presses on all controllers
|
||||
// Specifically for cheat engine and other features.
|
||||
Core::HID::NpadButton GetAndResetPressState();
|
||||
Result StartLrAssignmentMode(u64 aruid);
|
||||
Result StopLrAssignmentMode(u64 aruid);
|
||||
|
||||
void ApplyNpadSystemCommonPolicy();
|
||||
Result SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode mode);
|
||||
Result GetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode& out_mode) const;
|
||||
|
||||
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
|
||||
void SetNpadPlayerLedBlinkingDevice(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
Core::HID::LedPattern blinking_pattern);
|
||||
Core::HID::LedPattern GetPlayerLedPattern(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
Result AcquireNfcDeviceUpdateEventHandle(Kernel::KReadableEvent** out_event);
|
||||
Result GetNpadsWithNfc(u64 param_2, u32 param_3);
|
||||
Result GetXcdHandleForNpadWithNfc(u64* param_2, Core::HID::NpadIdType npad_id, u64 param_4);
|
||||
Result AcquireNfcActivateEventHandle(Kernel::KReadableEvent** out_event);
|
||||
Result ActivateNfc(u32 param_2, u32 param_3, u64 param_4);
|
||||
bool IsNfcActivated(Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result AcquireIrSensorEventHandle(Kernel::KReadableEvent** out_event,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
// ActivateIrSensor(NpadIdType param_2, u32 param_3, u64 param_4);
|
||||
|
||||
Result GetLastActiveNpad(Core::HID::NpadIdType& out_npad_id) const;
|
||||
|
||||
AppletFooterUiType GetAppletFooterUiType(Core::HID::NpadIdType npad_id) const;
|
||||
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
Result IsUsbFullKeyControllerConnected(bool& out_is_connected,
|
||||
Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
Result GetXcdHandleForNpadWithIrSensor(Core::HID::NpadIdType npad_id, u64* out_xcd_handle,
|
||||
u64 param_4);
|
||||
Result GetIrSensorState(Core::HID::NpadIdType npad_id, u32* param_3, u64 param_4);
|
||||
|
||||
// FUN_7100057c00
|
||||
// FUN_7100057c6c
|
||||
// FUN_7100057cf4
|
||||
// FUN_7100057d70
|
||||
|
||||
Result IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id) const;
|
||||
Result EnableUnintendedHomeButtonInputProtection(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
bool is_enabled);
|
||||
|
||||
u32 GetUniquePadsFromNpad(std::vector<Core::HID::UniquePadId> unique_pad_list,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result RegisterAppletResourceUserId(u64 aruid);
|
||||
void UnregisterAppletResourceUserId(u64 aruid);
|
||||
Result InitializeNpadStateByAruid(u64 aruid);
|
||||
void DestroyStyleSetUpdateEvents(u64 aruid);
|
||||
void SetAppletResourceUserId(u64 aruid);
|
||||
|
||||
Result InitializeNpadState();
|
||||
|
||||
Result FUN_71000581f0();
|
||||
void FUN_7100058230();
|
||||
void FUN_7100058268();
|
||||
|
||||
void UpdateHandheldAbstractNpad();
|
||||
void UpdateAllAbstractNpad();
|
||||
|
||||
void GetSixAxisNpadSharedMemory(const Core::HID::SixAxisSensorHandle& handle);
|
||||
u64 GetSixAxisSensorConfig(const Core::HID::SixAxisSensorHandle& handle);
|
||||
|
||||
std::shared_ptr<VibrationObj> GetVibrationObject(
|
||||
const Core::HID::VibrationDeviceHandle& handle);
|
||||
void FUN_7100058730(int* param_2, long param_3);
|
||||
|
||||
NpadN64VibrationDevice* GetN64VibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
NpadVibrationDevice* GetVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
NpadGcVibrationDevice* GetGCVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
NpadVibrationHandler* GetVibrationHandler();
|
||||
|
||||
u64 FUN_7100058a80(Core::HID::NpadIdType npad_id);
|
||||
u64 FUN_7100058ac8(Core::HID::NpadIdType npad_id, u32 param_3);
|
||||
u64 FUN_7100058b14(u64 param_2);
|
||||
|
||||
Result GetFirmwareVersion(u64 param_2, u64 param_3, u32 param_4, u32 param_5);
|
||||
Result GetDestinationFirmwareVersion(u64 param_2, u32 param_3, u32 param_4);
|
||||
|
||||
Result HasBattery(bool& out_has_battery, Core::HID::NpadIdType npad_id);
|
||||
Result HasLeftRightBattery(bool& out_has_left_battery, bool& out_has_right_battery,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result GetNpadInterfaceType(Core::HID::NpadInterfaceType& out_interface_type,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
Result GetNpadLeftRightInterfaceType(Core::HID::NpadInterfaceType& out_left_interface,
|
||||
Core::HID::NpadInterfaceType& out_right_interface,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result GetNpadFullKeyGripColor(Core::HID::NpadColor& out_main_color,
|
||||
Core::HID::NpadColor& out_sub_color,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
void EnableInput(u64 aruid);
|
||||
|
||||
void SetRevision(u64 aruid, NpadRevision revision);
|
||||
NpadRevision GetRevision(u64 aruid);
|
||||
|
||||
bool IsHandheldButtonPressedOnConsoleMode();
|
||||
bool IsFirmwareUpdateAvailableForSixAxisSensor(const Core::HID::SixAxisSensorHandle& handle);
|
||||
Result ResetIsSixAxisSensorDeviceNewlyAssigned(u64 aruid,
|
||||
const Core::HID::SixAxisSensorHandle& handle);
|
||||
void SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled);
|
||||
|
||||
u32 GetAbstractedPads(std::span<IAbstractedPad*> list, Core::HID::NpadIdType npad_id);
|
||||
bool AttachAbstractedPadToNpad(u64 param_2, Core::HID::NpadIdType npad_id, bool is_enabled);
|
||||
void DetachAbstractedPadAll();
|
||||
|
||||
Result SetNpadCaptureButtonAssignment(u64 aruid, Core::HID::NpadStyleSet npad_style,
|
||||
Core::HID::NpadButton button_assignment);
|
||||
u64 GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> list, u64 aruid);
|
||||
Result ClearNpadCaptureButtonAssignment(u64 aruid);
|
||||
|
||||
u64 IsFirmwareUpdateNeededForNotification(u32 param_2);
|
||||
bool IsFirmwareAvailableForNotification(u32 param_2, u64 param_3);
|
||||
void PrepareHidsForNotificationWake(long param_2, long param_3);
|
||||
|
||||
void ResetAllNpadsSomethingNotificationWake();
|
||||
Result GetNpadOfHighestBatteryLevel(u32* param_2, long param_3, u32 param_4);
|
||||
|
||||
Result GetIrSensorState(u64* aruid, bool is_enabled);
|
||||
|
||||
void ResetButtonConfig();
|
||||
u32 GetAbstractedPadIdDataFromNpad(u64 param_2, u32 param_3, Core::HID::NpadIdType in_npad_id);
|
||||
|
||||
private:
|
||||
struct VibrationData {
|
||||
bool device_mounted{};
|
||||
Core::HID::VibrationValue latest_vibration_value{};
|
||||
std::chrono::steady_clock::time_point last_vibration_timepoint{};
|
||||
};
|
||||
|
||||
struct NpadControllerData {
|
||||
Kernel::KEvent* styleset_changed_event{};
|
||||
NpadInternalState* shared_memory = nullptr;
|
||||
Core::HID::EmulatedController* device = nullptr;
|
||||
|
||||
std::array<VibrationData, 2> vibration{};
|
||||
bool unintended_home_button_input_protection{};
|
||||
bool is_connected{};
|
||||
|
||||
// Dual joycons can have only one side connected
|
||||
bool is_dual_left_connected{true};
|
||||
bool is_dual_right_connected{true};
|
||||
|
||||
// Current pad state
|
||||
NPadGenericState npad_pad_state{};
|
||||
NPadGenericState npad_libnx_state{};
|
||||
NpadGcTriggerState npad_trigger_state{};
|
||||
int callback_key{};
|
||||
};
|
||||
|
||||
void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx);
|
||||
void InitNewlyAddedController(Core::HID::NpadIdType npad_id);
|
||||
bool IsControllerSupported(Core::HID::NpadStyleIndex controller) const;
|
||||
void RequestPadStateUpdate(Core::HID::NpadIdType npad_id);
|
||||
void WriteEmptyEntry(NpadInternalState* npad);
|
||||
|
||||
NpadControllerData& GetControllerFromHandle(
|
||||
const Core::HID::VibrationDeviceHandle& device_handle);
|
||||
const NpadControllerData& GetControllerFromHandle(
|
||||
const Core::HID::VibrationDeviceHandle& device_handle) const;
|
||||
NpadControllerData& GetControllerFromHandle(
|
||||
const Core::HID::SixAxisSensorHandle& device_handle);
|
||||
const NpadControllerData& GetControllerFromHandle(
|
||||
const Core::HID::SixAxisSensorHandle& device_handle) const;
|
||||
NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
|
||||
const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
|
||||
const Core::HID::SixAxisSensorHandle& device_handle);
|
||||
const Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
|
||||
const Core::HID::SixAxisSensorHandle& device_handle) const;
|
||||
|
||||
std::atomic<u64> press_state{};
|
||||
|
||||
std::array<NpadControllerData, NpadCount> controller_data{};
|
||||
KernelHelpers::ServiceContext& service_context;
|
||||
std::mutex mutex;
|
||||
std::vector<Core::HID::NpadIdType> supported_npad_id_types{};
|
||||
NpadJoyHoldType hold_type{NpadJoyHoldType::Vertical};
|
||||
NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual};
|
||||
NpadCommunicationMode communication_mode{NpadCommunicationMode::Default};
|
||||
bool permit_vibration_session_enabled{false};
|
||||
bool analog_stick_use_center_clamp{false};
|
||||
bool is_in_lr_assignment_mode{false};
|
||||
bool is_controller_initialized{false};
|
||||
s32 ref_counter{};
|
||||
mutable std::mutex mutex;
|
||||
NPadResource npad_resource{};
|
||||
AppletResourceHolder applet_resource_holder{};
|
||||
Kernel::KEvent* input_event{nullptr};
|
||||
std::mutex* input_mutex{nullptr};
|
||||
// handle_1
|
||||
// handle_2
|
||||
// handle_3
|
||||
// handle_4
|
||||
// handle_5
|
||||
FullAbstractPad abstract_pad;
|
||||
NpadAssignmentHandler assignment_handler{};
|
||||
NpadLastActiveHandler last_active_npad_handler{};
|
||||
NpadIrNfcHandler ir_nfc_handler{};
|
||||
std::shared_ptr<UniquePads> unique_pads_handler{nullptr};
|
||||
NpadPalmaHandler palma_handler{};
|
||||
std::shared_ptr<UniquePadResource> unique_pad_resource{nullptr};
|
||||
std::shared_ptr<NpadHighestBattery> npad_highest_battery_handler{nullptr};
|
||||
NpadVibrationHandler vibration_handler{};
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,98 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct AppletResourceHolder;
|
||||
class AbstractPad;
|
||||
using FullAbstractPad = std::array<AbstractPad, NpadCount>;
|
||||
class LastActiveNpad;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadAssignmentHandler final {
|
||||
public:
|
||||
explicit NpadAssignmentHandler();
|
||||
~NpadAssignmentHandler();
|
||||
|
||||
void SetAppletResource(AppletResourceHolder* applet_resource);
|
||||
void SetAbstractPad(FullAbstractPad* pad);
|
||||
void SetLastActiveNpad(std::shared_ptr<LastActiveNpad> npad);
|
||||
|
||||
void FUN_710006cffc(u64 param_2);
|
||||
|
||||
Result Activate();
|
||||
Result Deactivate();
|
||||
|
||||
void FUN_710006d070();
|
||||
|
||||
void FUN_710006d0c4();
|
||||
|
||||
void FUN_710006d250(u64 param_2);
|
||||
void FUN_710006d380(NpadDataStructure* param_2);
|
||||
|
||||
void FUN_710006d48c();
|
||||
void FUN_710006d550(u64 param_2);
|
||||
|
||||
void FUN_710006d830(u64 param_2);
|
||||
void FUN_710006d9d0(NpadDataStructure* param_2);
|
||||
void FUN_710006db20();
|
||||
|
||||
void SetNpadJoyAssignmentModeDual(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
|
||||
void FUN_710006dd30();
|
||||
|
||||
void UpdateNpadAssignment();
|
||||
|
||||
void Update();
|
||||
|
||||
void DisconnectNpad(u64 param_2, Core::HID::NpadIdType npad_id);
|
||||
|
||||
void SetNpadJoyAssignmentModeSingleByDefault(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
void SetNpadJoyAssignmentModeSingle(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
NpadJoyDeviceType npad_joy_device_type);
|
||||
u32 SetNpadJoyAssignmentModeSingleWithDestination(Core::HID::NpadIdType& out_npad_id, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id,
|
||||
NpadJoyDeviceType npad_joy_device_type);
|
||||
|
||||
void FUN_710006e2ec(u32 param_2);
|
||||
u64 FUN_710006e350(u32* param_2, u64* param_3, u32 param_4, NpadDataStructure* npad_data);
|
||||
Result MergeSingleJoyAsDualJoy(u64 aruid, Core::HID::NpadIdType npad_id_1,
|
||||
Core::HID::NpadIdType npad_id_2);
|
||||
Result FUN_710006ea10(Core::HID::NpadIdType param_2, Core::HID::NpadIdType param_3);
|
||||
|
||||
Result SwapNpadAssignment(u64 param_2, Core::HID::NpadIdType param_3,
|
||||
Core::HID::NpadIdType param_4);
|
||||
|
||||
Result thunk_FUN_710006ea10(Core::HID::NpadIdType param_2, Core::HID::NpadIdType param_3);
|
||||
u32 GetAbstractedPads(std::span<IAbstractedPad*> list, Core::HID::NpadIdType npad_id);
|
||||
|
||||
u32 AttachAbstractedPadToNpad(u64 param_2, Core::HID::NpadIdType npad_id, u32 param_4);
|
||||
u32 FUN_710006f050(int param_2, undefined param_3, NpadDataStructure* param_4);
|
||||
u64 FUN_710006f154(u32 param_2, int param_3);
|
||||
u64 FUN_710006f240(NpadAbstractState** param_2, u64 param_3);
|
||||
|
||||
void FUN_710006f39c(NpadAbstractState* param_2, u64* param_3);
|
||||
void FUN_710006f500(u64* param_2, u64 param_3);
|
||||
void FUN_710006f774(u64 param_2, int param_3);
|
||||
NpadAssignmentModeAndConnection* FUN_710006f890(u64 param_2, int param_3);
|
||||
Result FUN_710006fa60(NpadAbstractState** param_2, u64 param_3);
|
||||
void FUN_710006fbc0(u32* param_2, u32* param_3);
|
||||
|
||||
private:
|
||||
AppletResourceHolder* applet_resource_holder{nullptr};
|
||||
FullAbstractPad* abstract_pad{nullptr};
|
||||
std::shared_ptr<LastActiveNpad> last_active_npad{nullptr};
|
||||
|
||||
s32 ref_counter{};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,156 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/gc_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
void NpadGcVibrationDevice::FUN_7100087ed4(u64 param_2) {
|
||||
*(u64*)&field_0x20 = param_2;
|
||||
return;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::IncrementRefCounter() {
|
||||
if (ref_counter == 0 && is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_7100088f4c(field_0x20, field_0x10, '\0');
|
||||
}
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command) {
|
||||
char cVar2;
|
||||
|
||||
if (!is_initialized) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume == 0.0) {
|
||||
cVar2 = '\0';
|
||||
} else {
|
||||
if (command > Core::HID::VibrationGcErmCommand::StopHard) {
|
||||
// Abort
|
||||
}
|
||||
cVar2 = (char)(0x100100 >> (u64)(((u32)*param_2 & 3) << 3));
|
||||
}
|
||||
FUN_7100088f4c(field_0x20, field_0x10, cVar2);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::DecrementRefCounter() {
|
||||
if (ref_counter == 1 && !is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_7100088f4c(field_0x20, field_0x10, '\0');
|
||||
}
|
||||
}
|
||||
|
||||
if (ref_counter > 1) {
|
||||
ref_counter--;
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NpadGcVibrationDevice* NpadGcVibrationDevice::FUN_7100088080() {
|
||||
pNVar2 = param_1;
|
||||
if (param_1->is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
nVar1 = FUN_7100088f4c(field_0x20, field_0x10, '\0');
|
||||
return (NpadGcVibrationDevice*)(u64)nVar1;
|
||||
}
|
||||
}
|
||||
return pNVar2;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::FUN_71000880d8(u64 param_2, u64 param_3,
|
||||
NpadVibrationHandler* handler) {
|
||||
int iVar1;
|
||||
u32 local_24;
|
||||
|
||||
*(u64*)&field_0x10 = param_2;
|
||||
*(u64*)&field_0x18 = param_3;
|
||||
is_initialized = true;
|
||||
vibration_handler = handler;
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
FUN_7100088f4c(field_0x20, field_0x10, '\0');
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::FUN_7100088150() {
|
||||
if (!is_initialized) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_7100088f4c(field_0x20, field_0x10, '\0');
|
||||
}
|
||||
|
||||
is_initialized = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::GetActualVibrationGcErmCommand(
|
||||
Core::HID::VibrationGcErmCommand& command) {
|
||||
if (!is_initialized) {
|
||||
command = Core::HID::VibrationGcErmCommand::Stop;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume == 0.0f) {
|
||||
command = Core::HID::VibrationGcErmCommand::Stop;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
command = FUN_7100089310(field_0x20, field_0x10);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadGcVibrationDevice::FUN_7100088270(Core::HID::VibrationGcErmCommand command) {
|
||||
if (!is_initialized) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume <= 0.0f) {
|
||||
command = Core::HID::VibrationGcErmCommand::Stop;
|
||||
}
|
||||
if (command > Core::HID::VibrationGcErmCommand::StopHard) {
|
||||
// Abort
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
FUN_71000891d0(field_0x20, field_0x10, (&DAT_71001b99a0 + (long)(int)command * 4));
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,43 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class NpadVibrationHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadGcVibrationDevice final {
|
||||
public:
|
||||
explicit NpadGcVibrationDevice();
|
||||
~NpadGcVibrationDevice();
|
||||
|
||||
void FUN_7100087ed4(u64 param_2);
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result SendVibrationGcErmCommand(Core::HID::VibrationGcErmCommand command);
|
||||
|
||||
Result DecrementRefCounter();
|
||||
|
||||
NpadGcVibrationDevice* FUN_7100088080();
|
||||
|
||||
Result FUN_71000880d8(u64 param_2, u64 param_3, NpadVibrationHandler* handler);
|
||||
Result FUN_7100088150();
|
||||
|
||||
Result GetActualVibrationGcErmCommand(Core::HID::VibrationGcErmCommand& command);
|
||||
Result FUN_7100088270(Core::HID::VibrationGcErmCommand command);
|
||||
|
||||
private:
|
||||
s32 ref_counter;
|
||||
bool is_initialized;
|
||||
NpadVibrationHandler* vibration_handler;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,130 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/n64_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Result NpadN64VibrationDevice::IncrementRefCounter() {
|
||||
if (ref_counter == 0 && is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_710011aa20(0, 0, xcd_handle);
|
||||
}
|
||||
}
|
||||
if (is_initialized && FUN_710011a950(local_4, 0, xcd_handle) == 0) &&
|
||||
(local_4[0] != '\x01')) {
|
||||
FUN_710011a8f0(1, 0, xcd_handle);
|
||||
}
|
||||
ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadN64VibrationDevice::SendValueInBool(bool is_vibrating) {
|
||||
if (ref_counter < 1) {
|
||||
return ResultVibrationNotInitialized;
|
||||
}
|
||||
if (is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
return FUN_710011aa20(volume != 0.0 && is_vibrating, 0, xcd_handle);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadN64VibrationDevice::DecrementRefCounter() {
|
||||
if (ref_counter == 1) {
|
||||
if (!is_initialized) {
|
||||
ref_counter = 0;
|
||||
if (is_initialized != false && FUN_710011a950(local_4, 0, xcd_handle) == 0) {
|
||||
FUN_710011a8f0(0, 0, xcd_handle);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_710011aa20(0, 0, xcd_handle);
|
||||
}
|
||||
}
|
||||
|
||||
ref_counter--;
|
||||
if (ref_counter > 0) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
ref_counter = 0;
|
||||
if (is_initialized != false && FUN_710011a950(local_4, 0, xcd_handle) == 0) {
|
||||
FUN_710011a8f0(0, 0, xcd_handle);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadN64VibrationDevice::FUN_71000b6750() {
|
||||
if (0 < ref_counter && is_initialized != false) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_710011aa20(0, 0, xcd_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result NpadN64VibrationDevice::FUN_71000b67b0(long* param_2, NpadVibrationHandler* handler) {
|
||||
int iVar1 = (**(code**)(*param_2 + 0x18))(param_2);
|
||||
if ((iVar1 == 0) && ((*(byte*)(param_2 + 1) >> 1 & 1) != 0)) {
|
||||
xcd_handle = GetXcdHandle(param_2);
|
||||
vibration_handler = handler;
|
||||
is_initialized = true;
|
||||
if (-1 < ref_counter) {
|
||||
iVar1 = FUN_710011a950(local_18, 0, uVar3);
|
||||
if ((iVar1 == 0) && (local_18[0] != '\x01')) {
|
||||
FUN_710011a8f0(1, 0, xcd_handle);
|
||||
}
|
||||
if ((0 < ref_counter) && (is_initialized != false)) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_710011aa20(0, 0, xcd_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadN64VibrationDevice::FUN_71000b6898() {
|
||||
if (0 < ref_counter && is_initialized) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
FUN_710011aa20(0, 0, xcd_handle);
|
||||
}
|
||||
}
|
||||
is_initialized = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadN64VibrationDevice::FUN_71000b6908(bool is_vibrating) {
|
||||
if (!is_initialized) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume <= 0.0) {
|
||||
is_vibrating = false;
|
||||
}
|
||||
return FUN_710011ab70(xcd_handle, is_vibrating);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,37 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class NpadVibrationHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadN64VibrationDevice final {
|
||||
public:
|
||||
explicit NpadN64VibrationDevice();
|
||||
~NpadN64VibrationDevice();
|
||||
|
||||
Result IncrementRefCounter();
|
||||
Result SendValueInBool(bool is_vibrating);
|
||||
Result DecrementRefCounter();
|
||||
void FUN_71000b6750();
|
||||
Result FUN_71000b67b0(long* param_2, NpadVibrationHandler* handler);
|
||||
Result FUN_71000b6898();
|
||||
Result FUN_71000b6908(u32 param_2);
|
||||
|
||||
private:
|
||||
u64 xcd_handle;
|
||||
s32 ref_counter;
|
||||
bool is_initialized;
|
||||
NpadVibrationHandler* vibration_handler;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,201 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/npad_data.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NPadData::NPadData() {
|
||||
ClearNpadSystemCommonPolicy();
|
||||
}
|
||||
|
||||
NPadData::~NPadData() = default;
|
||||
|
||||
NpadStatus NPadData::GetNpadStatus() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
void NPadData::SetNpadAnalogStickUseCenterClamp(bool is_enabled) {
|
||||
status.use_center_clamp.Assign(is_enabled);
|
||||
}
|
||||
|
||||
void NPadData::SetNpadSystemExtStateEnabled(bool is_enabled) {
|
||||
status.system_ext_state.Assign(is_enabled);
|
||||
}
|
||||
|
||||
bool NPadData::GetNpadSystemExtState() {
|
||||
return status.system_ext_state;
|
||||
}
|
||||
|
||||
Result NPadData::SetSupportedNpadIdType(std::span<const Core::HID::NpadIdType> list) {
|
||||
// Note: Real limit is 11. But array size is 10. N's bug?
|
||||
if (list.size() > NpadCount) {
|
||||
return ResultInvalidArraySize;
|
||||
}
|
||||
|
||||
supported_npad_id_types_count = static_cast<u32>(list.size());
|
||||
memcpy(supported_npad_id_types.data(), list.data(), list.size_bytes());
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NPadData::SetNpadSystemCommonPolicy(bool is_full_policy) {
|
||||
supported_npad_style_set = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::JoyDual |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
handheld_activation_mode = PackedNpadHandheldActivationMode::Dual;
|
||||
|
||||
status.is_supported_styleset_set.Assign(1);
|
||||
status.is_hold_type_set.Assign(1);
|
||||
status.lr_assignment_mode.Assign(0);
|
||||
status.is_policy.Assign(1);
|
||||
if (is_full_policy) {
|
||||
status.is_full_policy.Assign(1);
|
||||
}
|
||||
|
||||
supported_npad_id_types_count = 10;
|
||||
supported_npad_id_types[0] = Core::HID::NpadIdType::Player1;
|
||||
supported_npad_id_types[1] = Core::HID::NpadIdType::Player2;
|
||||
supported_npad_id_types[2] = Core::HID::NpadIdType::Player3;
|
||||
supported_npad_id_types[3] = Core::HID::NpadIdType::Player4;
|
||||
supported_npad_id_types[4] = Core::HID::NpadIdType::Player5;
|
||||
supported_npad_id_types[5] = Core::HID::NpadIdType::Player6;
|
||||
supported_npad_id_types[6] = Core::HID::NpadIdType::Player7;
|
||||
supported_npad_id_types[7] = Core::HID::NpadIdType::Player8;
|
||||
supported_npad_id_types[8] = Core::HID::NpadIdType::Other;
|
||||
supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld;
|
||||
|
||||
is_unintended_home_button_input_protection[0] = true;
|
||||
is_unintended_home_button_input_protection[1] = true;
|
||||
is_unintended_home_button_input_protection[2] = true;
|
||||
is_unintended_home_button_input_protection[3] = true;
|
||||
is_unintended_home_button_input_protection[4] = true;
|
||||
is_unintended_home_button_input_protection[5] = true;
|
||||
is_unintended_home_button_input_protection[6] = true;
|
||||
is_unintended_home_button_input_protection[7] = true;
|
||||
is_unintended_home_button_input_protection[8] = true;
|
||||
is_unintended_home_button_input_protection[9] = true;
|
||||
}
|
||||
|
||||
void NPadData::ClearNpadSystemCommonPolicy() {
|
||||
status.raw = 0;
|
||||
supported_npad_style_set = Core::HID::NpadStyleSet::All;
|
||||
npad_hold_type = PackedNpadJoyHoldType::Vertical;
|
||||
handheld_activation_mode = PackedNpadHandheldActivationMode::Dual;
|
||||
|
||||
npad_button_assignment[0] = Core::HID::NpadButton::None;
|
||||
npad_button_assignment[1] = Core::HID::NpadButton::None;
|
||||
npad_button_assignment[2] = Core::HID::NpadButton::None;
|
||||
npad_button_assignment[3] = Core::HID::NpadButton::None;
|
||||
npad_button_assignment[4] = Core::HID::NpadButton::None;
|
||||
npad_button_assignment[5] = Core::HID::NpadButton::None;
|
||||
|
||||
supported_npad_id_types_count = 10;
|
||||
supported_npad_id_types[0] = Core::HID::NpadIdType::Player1;
|
||||
supported_npad_id_types[1] = Core::HID::NpadIdType::Player2;
|
||||
supported_npad_id_types[2] = Core::HID::NpadIdType::Player3;
|
||||
supported_npad_id_types[3] = Core::HID::NpadIdType::Player4;
|
||||
supported_npad_id_types[4] = Core::HID::NpadIdType::Player5;
|
||||
supported_npad_id_types[5] = Core::HID::NpadIdType::Player6;
|
||||
supported_npad_id_types[6] = Core::HID::NpadIdType::Player7;
|
||||
supported_npad_id_types[7] = Core::HID::NpadIdType::Player8;
|
||||
supported_npad_id_types[8] = Core::HID::NpadIdType::Other;
|
||||
supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld;
|
||||
|
||||
is_unintended_home_button_input_protection[0] = true;
|
||||
is_unintended_home_button_input_protection[1] = true;
|
||||
is_unintended_home_button_input_protection[2] = true;
|
||||
is_unintended_home_button_input_protection[3] = true;
|
||||
is_unintended_home_button_input_protection[4] = true;
|
||||
is_unintended_home_button_input_protection[5] = true;
|
||||
is_unintended_home_button_input_protection[6] = true;
|
||||
is_unintended_home_button_input_protection[7] = true;
|
||||
is_unintended_home_button_input_protection[8] = true;
|
||||
is_unintended_home_button_input_protection[9] = true;
|
||||
}
|
||||
|
||||
void NPadData::SetNpadJoyHoldType(NpadJoyHoldType hold_type) {
|
||||
npad_hold_type = static_cast<PackedNpadJoyHoldType>(hold_type);
|
||||
status.is_hold_type_set.Assign(true);
|
||||
}
|
||||
|
||||
NpadJoyHoldType NPadData::GetNpadJoyHoldType() const {
|
||||
return static_cast<NpadJoyHoldType>(npad_hold_type);
|
||||
}
|
||||
|
||||
void NPadData::SetHandheldActivationMode(NpadHandheldActivationMode activation_mode) {
|
||||
handheld_activation_mode = static_cast<PackedNpadHandheldActivationMode>(activation_mode);
|
||||
}
|
||||
|
||||
NpadHandheldActivationMode NPadData::GetHandheldActivationMode() const {
|
||||
return static_cast<NpadHandheldActivationMode>(handheld_activation_mode);
|
||||
}
|
||||
|
||||
void NPadData::SetSupportedNpadStyleSet(Core::HID::NpadStyleSet style_set) {
|
||||
supported_npad_style_set = style_set;
|
||||
status.is_supported_styleset_set.Assign(true);
|
||||
status.is_hold_type_set.Assign(true);
|
||||
}
|
||||
|
||||
Core::HID::NpadStyleSet NPadData::GetSupportedNpadStyleSet() const {
|
||||
return supported_npad_style_set;
|
||||
}
|
||||
|
||||
bool NPadData::IsNpadIdTypeSupported(Core::HID::NpadIdType npad_id) const {
|
||||
for (std::size_t i = 0; i < supported_npad_id_types_count; i++) {
|
||||
if (supported_npad_id_types[i] == npad_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NPadData::SetLrAssignmentMode(bool is_enabled) {
|
||||
status.lr_assignment_mode.Assign(is_enabled);
|
||||
}
|
||||
|
||||
bool NPadData::GetLrAssignmentMode() const {
|
||||
return status.lr_assignment_mode;
|
||||
}
|
||||
|
||||
void NPadData::SetAssigningSingleOnSlSrPress(bool is_enabled) {
|
||||
status.assigning_single_on_sl_sr_press.Assign(is_enabled);
|
||||
}
|
||||
|
||||
bool NPadData::GetAssigningSingleOnSlSrPress() const {
|
||||
return status.assigning_single_on_sl_sr_press;
|
||||
}
|
||||
|
||||
void NPadData::SetHomeProtectionEnabled(bool is_enabled, Core::HID::NpadIdType npad_id) {
|
||||
is_unintended_home_button_input_protection[NpadIdTypeToIndex(npad_id)] = is_enabled;
|
||||
}
|
||||
|
||||
bool NPadData::GetHomeProtectionEnabled(Core::HID::NpadIdType npad_id) const {
|
||||
return is_unintended_home_button_input_protection[NpadIdTypeToIndex(npad_id)];
|
||||
}
|
||||
|
||||
void NPadData::SetCaptureButtonAssignment(Core::HID::NpadButton button_assignment,
|
||||
std::size_t style_index) {
|
||||
npad_button_assignment[style_index] = button_assignment;
|
||||
}
|
||||
|
||||
Core::HID::NpadButton NPadData::GetCaptureButtonAssignment(std::size_t style_index) const {
|
||||
return npad_button_assignment[style_index];
|
||||
}
|
||||
|
||||
std::size_t NPadData::GetNpadCaptureButtonAssignmentList(
|
||||
std::span<Core::HID::NpadButton> out_list) const {
|
||||
for (std::size_t i = 0; i < out_list.size(); i++) {
|
||||
Core::HID::NpadStyleSet style_set = GetStylesetByIndex(i);
|
||||
if ((style_set & supported_npad_style_set) == Core::HID::NpadStyleSet::None ||
|
||||
npad_button_assignment[i] == Core::HID::NpadButton::None) {
|
||||
return i;
|
||||
}
|
||||
out_list[i] = npad_button_assignment[i];
|
||||
}
|
||||
|
||||
return out_list.size();
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,83 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
struct NpadStatus {
|
||||
union {
|
||||
u32 raw{};
|
||||
|
||||
BitField<0, 1, u32> is_supported_styleset_set;
|
||||
BitField<1, 1, u32> is_hold_type_set;
|
||||
BitField<2, 1, u32> lr_assignment_mode;
|
||||
BitField<3, 1, u32> assigning_single_on_sl_sr_press;
|
||||
BitField<4, 1, u32> is_full_policy;
|
||||
BitField<5, 1, u32> is_policy;
|
||||
BitField<6, 1, u32> use_center_clamp;
|
||||
BitField<7, 1, u32> system_ext_state;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(NpadStatus) == 4, "NpadStatus is an invalid size");
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NPadData final {
|
||||
public:
|
||||
explicit NPadData();
|
||||
~NPadData();
|
||||
|
||||
NpadStatus GetNpadStatus() const;
|
||||
void SetNpadAnalogStickUseCenterClamp(bool is_enabled);
|
||||
|
||||
void SetNpadSystemExtStateEnabled(bool is_enabled);
|
||||
bool GetNpadSystemExtState();
|
||||
|
||||
Result SetSupportedNpadIdType(std::span<const Core::HID::NpadIdType> list);
|
||||
void SetNpadSystemCommonPolicy(bool is_full_policy);
|
||||
void ClearNpadSystemCommonPolicy();
|
||||
|
||||
void SetNpadJoyHoldType(NpadJoyHoldType hold_type);
|
||||
NpadJoyHoldType GetNpadJoyHoldType() const;
|
||||
|
||||
void SetHandheldActivationMode(NpadHandheldActivationMode activation_mode);
|
||||
NpadHandheldActivationMode GetHandheldActivationMode() const;
|
||||
|
||||
void SetSupportedNpadStyleSet(Core::HID::NpadStyleSet style_set);
|
||||
Core::HID::NpadStyleSet GetSupportedNpadStyleSet() const;
|
||||
bool IsNpadIdTypeSupported(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
void SetLrAssignmentMode(bool is_enabled);
|
||||
bool GetLrAssignmentMode() const;
|
||||
|
||||
void SetAssigningSingleOnSlSrPress(bool is_enabled);
|
||||
bool GetAssigningSingleOnSlSrPress() const;
|
||||
|
||||
void SetHomeProtectionEnabled(bool is_enabled, Core::HID::NpadIdType npad_id);
|
||||
bool GetHomeProtectionEnabled(Core::HID::NpadIdType npad_id) const;
|
||||
|
||||
void SetCaptureButtonAssignment(Core::HID::NpadButton button_assignment,
|
||||
std::size_t style_index);
|
||||
Core::HID::NpadButton GetCaptureButtonAssignment(std::size_t style_index) const;
|
||||
std::size_t GetNpadCaptureButtonAssignmentList(std::span<Core::HID::NpadButton> out_list) const;
|
||||
|
||||
private:
|
||||
NpadStatus status{};
|
||||
Core::HID::NpadStyleSet supported_npad_style_set{Core::HID::NpadStyleSet::All};
|
||||
PackedNpadJoyHoldType npad_hold_type{PackedNpadJoyHoldType::Vertical};
|
||||
PackedNpadHandheldActivationMode handheld_activation_mode{};
|
||||
std::array<Core::HID::NpadIdType, NpadCount> supported_npad_id_types{};
|
||||
std::array<Core::HID::NpadButton, 7> npad_button_assignment{};
|
||||
INSERT_PADDING_BYTES(0x30);
|
||||
u32 supported_npad_id_types_count{};
|
||||
std::array<bool, NpadCount> is_unintended_home_button_input_protection{};
|
||||
INSERT_PADDING_BYTES(0x2);
|
||||
};
|
||||
static_assert(sizeof(NPadData) == 0xB0, "DataStructure is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,598 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
#include "core/hle/kernel/k_readable_event.h"
|
||||
#include "core/hle/service/hid/controllers/npad/npad_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NPadResource::NPadResource(Core::System& system) : service_context{system, "hid"} {}
|
||||
|
||||
NPadResource::~NPadResource() = default;
|
||||
|
||||
void NPadResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
|
||||
DestroyStyleSetUpdateEvents(aruid);
|
||||
if (aruid_index < AruidIndexMax) {
|
||||
state[aruid_index] = {};
|
||||
registration_list.flag[aruid_index] = RegistrationStatus::PendingDelete;
|
||||
}
|
||||
}
|
||||
|
||||
NPadData* NPadResource::GetActiveData() {
|
||||
return &active_data;
|
||||
}
|
||||
|
||||
u64 NPadResource::GetActiveDataAruid() {
|
||||
return active_data_aruid;
|
||||
}
|
||||
|
||||
void NPadResource::SetAppletResourceUserId(u64 aruid) {
|
||||
if (active_data_aruid == aruid) {
|
||||
return;
|
||||
}
|
||||
|
||||
active_data_aruid = aruid;
|
||||
default_hold_type = active_data.GetNpadJoyHoldType();
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((~state[aruid_index].flag & 3) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
if (data.GetNpadStatus().is_policy || data.GetNpadStatus().is_full_policy) {
|
||||
data.SetNpadJoyHoldType(default_hold_type);
|
||||
}
|
||||
|
||||
active_data = data;
|
||||
if (data.GetNpadStatus().is_hold_type_set) {
|
||||
active_data.SetNpadJoyHoldType(default_hold_type);
|
||||
}
|
||||
}
|
||||
|
||||
Result NPadResource::ApplyNpadSystemCommonPolicy(u64 aruid, bool is_full_policy) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
data.SetNpadSystemCommonPolicy(is_full_policy);
|
||||
data.SetNpadJoyHoldType(default_hold_type);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetNpadSystemCommonPolicy(is_full_policy);
|
||||
active_data.SetNpadJoyHoldType(default_hold_type);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::ClearNpadSystemCommonPolicy(u64 aruid) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.ClearNpadSystemCommonPolicy();
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.ClearNpadSystemCommonPolicy();
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet style_set) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
data.SetSupportedNpadStyleSet(style_set);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetSupportedNpadStyleSet(style_set);
|
||||
active_data.SetNpadJoyHoldType(data.GetNpadJoyHoldType());
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_Set,
|
||||
u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
if (!data.GetNpadStatus().is_supported_styleset_set) {
|
||||
return ResultUndefinedStyleset;
|
||||
}
|
||||
|
||||
out_style_Set = data.GetSupportedNpadStyleSet();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetMaskedSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_set,
|
||||
u64 aruid) const {
|
||||
if (aruid == 0) {
|
||||
out_style_set = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Palma |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
if (!data.GetNpadStatus().is_supported_styleset_set) {
|
||||
return ResultUndefinedStyleset;
|
||||
}
|
||||
|
||||
Core::HID::NpadStyleSet mask{Core::HID::NpadStyleSet::None};
|
||||
out_style_set = data.GetSupportedNpadStyleSet();
|
||||
|
||||
switch (state[aruid_index].npad_revision) {
|
||||
case NpadRevision::Revision1:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::SystemExt |
|
||||
Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
case NpadRevision::Revision2:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
case NpadRevision::Revision3:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
|
||||
Core::HID::NpadStyleSet::HandheldLark | Core::HID::NpadStyleSet::Lucia |
|
||||
Core::HID::NpadStyleSet::Lagoon | Core::HID::NpadStyleSet::Lager |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
default:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::SystemExt |
|
||||
Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
}
|
||||
|
||||
out_style_set = out_style_set & mask;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetAvailableStyleset(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
if (!data.GetNpadStatus().is_supported_styleset_set) {
|
||||
return ResultUndefinedStyleset;
|
||||
}
|
||||
|
||||
Core::HID::NpadStyleSet mask{Core::HID::NpadStyleSet::None};
|
||||
out_style_set = data.GetSupportedNpadStyleSet();
|
||||
|
||||
switch (state[aruid_index].npad_revision) {
|
||||
case NpadRevision::Revision1:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::SystemExt |
|
||||
Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
case NpadRevision::Revision2:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
case NpadRevision::Revision3:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::Gc |
|
||||
Core::HID::NpadStyleSet::Palma | Core::HID::NpadStyleSet::Lark |
|
||||
Core::HID::NpadStyleSet::HandheldLark | Core::HID::NpadStyleSet::Lucia |
|
||||
Core::HID::NpadStyleSet::Lagoon | Core::HID::NpadStyleSet::Lager |
|
||||
Core::HID::NpadStyleSet::SystemExt | Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
default:
|
||||
mask = Core::HID::NpadStyleSet::Fullkey | Core::HID::NpadStyleSet::Handheld |
|
||||
Core::HID::NpadStyleSet::JoyDual | Core::HID::NpadStyleSet::JoyLeft |
|
||||
Core::HID::NpadStyleSet::JoyRight | Core::HID::NpadStyleSet::SystemExt |
|
||||
Core::HID::NpadStyleSet::System;
|
||||
break;
|
||||
}
|
||||
|
||||
out_style_set = out_style_set & mask;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NpadRevision NPadResource::GetNpadRevision(u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return NpadRevision::Revision0;
|
||||
}
|
||||
|
||||
return state[aruid_index].npad_revision;
|
||||
}
|
||||
|
||||
Result NPadResource::IsSupportedNpadStyleSet(bool& is_set, u64 aruid) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
is_set = state[aruid_index].data.GetNpadStatus().is_supported_styleset_set;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetNpadJoyHoldType(hold_type);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetNpadJoyHoldType(hold_type);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetNpadJoyHoldType(NpadJoyHoldType& hold_type, u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& data = state[aruid_index].data;
|
||||
if (data.GetNpadStatus().is_policy || data.GetNpadStatus().is_full_policy) {
|
||||
hold_type = active_data.GetNpadJoyHoldType();
|
||||
return ResultSuccess;
|
||||
}
|
||||
hold_type = data.GetNpadJoyHoldType();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetNpadHandheldActivationMode(u64 aruid,
|
||||
NpadHandheldActivationMode activation_mode) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetHandheldActivationMode(activation_mode);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetHandheldActivationMode(activation_mode);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetNpadHandheldActivationMode(NpadHandheldActivationMode& activation_mode,
|
||||
u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
activation_mode = state[aruid_index].data.GetHandheldActivationMode();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetSupportedNpadIdType(
|
||||
u64 aruid, std::span<const Core::HID::NpadIdType> supported_npad_list) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
if (supported_npad_list.size() > NpadCount) {
|
||||
return ResultInvalidArraySize;
|
||||
}
|
||||
|
||||
Result result = state[aruid_index].data.SetSupportedNpadIdType(supported_npad_list);
|
||||
if (result.IsSuccess() && active_data_aruid == aruid) {
|
||||
result = active_data.SetSupportedNpadIdType(supported_npad_list);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Result NPadResource::SetLrAssignmentMode(u64 aruid, bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetLrAssignmentMode(is_enabled);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetLrAssignmentMode(is_enabled);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetLrAssignmentMode(bool& is_enabled, u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
is_enabled = state[aruid_index].data.GetLrAssignmentMode();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetAssigningSingleOnSlSrPress(u64 aruid, bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetAssigningSingleOnSlSrPress(is_enabled);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetAssigningSingleOnSlSrPress(is_enabled);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::IsAssigningSingleOnSlSrPressEnabled(bool& is_enabled, u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
is_enabled = state[aruid_index].data.GetAssigningSingleOnSlSrPress();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::AcquireNpadStyleSetUpdateEventHandle(u64 aruid,
|
||||
Kernel::KReadableEvent** out_event,
|
||||
Core::HID::NpadIdType npad_id) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
auto& controller_state = state[aruid_index].controller_state[NpadIdTypeToIndex(npad_id)];
|
||||
if (!controller_state.is_styleset_update_event_initialized) {
|
||||
// Auto clear = true
|
||||
controller_state.style_set_update_event =
|
||||
service_context.CreateEvent("NpadResource:StylesetUpdateEvent");
|
||||
|
||||
// Assume creating the event succeeds otherwise crash the system here
|
||||
controller_state.is_styleset_update_event_initialized = true;
|
||||
}
|
||||
|
||||
*out_event = &controller_state.style_set_update_event->GetReadableEvent();
|
||||
|
||||
if (controller_state.is_styleset_update_event_initialized) {
|
||||
controller_state.style_set_update_event->Signal();
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SignalStyleSetUpdateEvent(u64 aruid, Core::HID::NpadIdType npad_id) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
auto controller = state[aruid_index].controller_state[NpadIdTypeToIndex(npad_id)];
|
||||
if (controller.is_styleset_update_event_initialized) {
|
||||
controller.style_set_update_event->Signal();
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::GetHomeProtectionEnabled(bool& is_enabled, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
is_enabled = state[aruid_index].data.GetHomeProtectionEnabled(npad_id);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetHomeProtectionEnabled(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetHomeProtectionEnabled(is_enabled, npad_id);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetHomeProtectionEnabled(is_enabled, npad_id);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetNpadAnalogStickUseCenterClamp(is_enabled);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetNpadAnalogStickUseCenterClamp(is_enabled);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::SetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id, std::size_t index,
|
||||
Core::HID::NpadButton button_config) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].button_config[NpadIdTypeToIndex(npad_id)][index] = button_config;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Core::HID::NpadButton NPadResource::GetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
std::size_t index, Core::HID::NpadButton mask,
|
||||
bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return Core::HID::NpadButton::None;
|
||||
}
|
||||
|
||||
auto& button_config = state[aruid_index].button_config[NpadIdTypeToIndex(npad_id)][index];
|
||||
if (is_enabled) {
|
||||
button_config = button_config | mask;
|
||||
return button_config;
|
||||
}
|
||||
|
||||
button_config = Core::HID::NpadButton::None;
|
||||
return Core::HID::NpadButton::None;
|
||||
}
|
||||
|
||||
void NPadResource::ResetButtonConfig() {
|
||||
for (auto& selected_state : state) {
|
||||
selected_state.button_config = {};
|
||||
}
|
||||
}
|
||||
|
||||
bool NPadResource::GetNextSamplingNumber(u64& next_sampling_number, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id, u64 style_index) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// auto lVar2 = index * 8 + NpadIdTypeToIndex(npad_id) * 0x38;
|
||||
// auto data = *(long*)(state[aruid_index]->aruid_data + lVar2) + 1;
|
||||
//*(long*)(state[aruid_index]->aruid_data + lVar2) = data;
|
||||
//*out_data = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NPadResource::GetNextGcSamplingNumber(u64& out_data, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return false;
|
||||
}
|
||||
// auto data =
|
||||
// *(long*)((long)state[aruid_index]->controller + NpadIdTypeToIndex(npad_id) * 8 + -0x50) +
|
||||
// 1;
|
||||
//(state[aruid_index]->controller + (u64)npad_id * 8 + -0x50) = data;
|
||||
// out_data = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
Result NPadResource::SetNpadCaptureButtonAssignment(u64 aruid,
|
||||
Core::HID::NpadStyleSet npad_style_set,
|
||||
Core::HID::NpadButton button_assignment) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
// Must be a power of two
|
||||
const auto raw_styleset = static_cast<u32>(npad_style_set);
|
||||
if (raw_styleset == 0 && (raw_styleset & (raw_styleset - 1)) != 0) {
|
||||
return ResultMultipleStyleSetSelected;
|
||||
}
|
||||
|
||||
int style_index{};
|
||||
Core::HID::NpadStyleSet style_selected{};
|
||||
for (style_index = 0; style_index < StyleIndexCount; ++style_index) {
|
||||
style_selected = GetStylesetByIndex(style_index);
|
||||
if (npad_style_set == style_selected) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (style_selected == Core::HID::NpadStyleSet::None) {
|
||||
return ResultMultipleStyleSetSelected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetCaptureButtonAssignment(button_assignment, style_index);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetCaptureButtonAssignment(button_assignment, style_index);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NPadResource::ClearNpadCaptureButtonAssignment(u64 aruid) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < StyleIndexCount; i++) {
|
||||
state[aruid_index].data.SetCaptureButtonAssignment(Core::HID::NpadButton::None, i);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetCaptureButtonAssignment(Core::HID::NpadButton::None, i);
|
||||
}
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
std::size_t NPadResource::GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> out_list,
|
||||
u64 aruid) const {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return 0;
|
||||
}
|
||||
return state[aruid_index].data.GetNpadCaptureButtonAssignmentList(out_list);
|
||||
}
|
||||
|
||||
void NPadResource::SetNpadRevision(u64 aruid, NpadRevision revision) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
state[aruid_index].npad_revision = revision;
|
||||
}
|
||||
|
||||
Result NPadResource::SetNpadSystemExtStateEnabled(u64 aruid, bool is_enabled) {
|
||||
const u64 aruid_index = GetIndexFromAruid(aruid);
|
||||
if (aruid_index >= AruidIndexMax) {
|
||||
return ResultNpadNotConnected;
|
||||
}
|
||||
|
||||
state[aruid_index].data.SetNpadAnalogStickUseCenterClamp(is_enabled);
|
||||
if (active_data_aruid == aruid) {
|
||||
active_data.SetNpadAnalogStickUseCenterClamp(is_enabled);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
u64 NPadResource::GetIndexFromAruid(u64 aruid) const {
|
||||
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||
if (registration_list.flag[i] == RegistrationStatus::Initialized &&
|
||||
registration_list.aruid[i] == aruid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return AruidIndexMax;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,134 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/npad/npad_data.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/kernel_helpers.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KReadableEvent;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct NpadControllerState {
|
||||
bool is_styleset_update_event_initialized{};
|
||||
INSERT_PADDING_BYTES(0x7);
|
||||
Kernel::KEvent* style_set_update_event = nullptr;
|
||||
INSERT_PADDING_BYTES(0x27);
|
||||
};
|
||||
|
||||
struct NpadState {
|
||||
u32 flag{};
|
||||
NPadData data{};
|
||||
std::array<std::array<Core::HID::NpadButton, StyleIndexCount>, NpadCount> button_config;
|
||||
// aruid_data
|
||||
std::array<NpadControllerState, NpadCount> controller_state;
|
||||
NpadRevision npad_revision;
|
||||
};
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NPadResource final {
|
||||
public:
|
||||
explicit NPadResource(Core::System& system);
|
||||
~NPadResource();
|
||||
|
||||
NPadData* GetActiveData();
|
||||
u64 GetActiveDataAruid();
|
||||
|
||||
Result RegisterAppletResourceUserId(u64 aruid);
|
||||
void UnregisterAppletResourceUserId(u64 aruid);
|
||||
|
||||
void DestroyStyleSetUpdateEvents(u64 aruid);
|
||||
Result InitializeNpadState(u64 aruid);
|
||||
Result InitializeNpadState();
|
||||
Result FUN_710005ab14();
|
||||
|
||||
void SetAppletResourceUserId(u64 aruid);
|
||||
|
||||
Result ApplyNpadSystemCommonPolicy(u64 aruid, bool is_full_policy);
|
||||
Result ClearNpadSystemCommonPolicy(u64 aruid);
|
||||
|
||||
Result SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet style_set);
|
||||
Result GetSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_Set, u64 aruid) const;
|
||||
Result GetMaskedSupportedNpadStyleSet(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const;
|
||||
Result GetAvailableStyleset(Core::HID::NpadStyleSet& out_style_set, u64 aruid) const;
|
||||
|
||||
NpadRevision GetNpadRevision(u64 aruid) const;
|
||||
void SetNpadRevision(u64 aruid, NpadRevision revision);
|
||||
|
||||
Result IsSupportedNpadStyleSet(bool& is_set, u64 aruid);
|
||||
|
||||
Result SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type);
|
||||
Result GetNpadJoyHoldType(NpadJoyHoldType& hold_type, u64 aruid) const;
|
||||
|
||||
Result SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode activation_mode);
|
||||
Result GetNpadHandheldActivationMode(NpadHandheldActivationMode& activation_mode,
|
||||
u64 aruid) const;
|
||||
|
||||
Result SetSupportedNpadIdType(u64 aruid,
|
||||
std::span<const Core::HID::NpadIdType> supported_npad_list);
|
||||
|
||||
Result SetLrAssignmentMode(u64 aruid, bool is_enabled);
|
||||
Result GetLrAssignmentMode(bool& is_enabled, u64 aruid) const;
|
||||
|
||||
Result SetAssigningSingleOnSlSrPress(u64 aruid, bool is_enabled);
|
||||
Result IsAssigningSingleOnSlSrPressEnabled(bool& is_enabled, u64 aruid) const;
|
||||
|
||||
Result AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
Result SignalStyleSetUpdateEvent(u64 aruid, Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result GetHomeProtectionEnabled(bool& is_enabled, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id) const;
|
||||
Result SetHomeProtectionEnabled(u64 aruid, Core::HID::NpadIdType npad_id, bool is_enabled);
|
||||
|
||||
Result SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled);
|
||||
|
||||
Result SetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id, std::size_t index,
|
||||
Core::HID::NpadButton button_config);
|
||||
|
||||
Core::HID::NpadButton GetButtonConfig(u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
std::size_t index, Core::HID::NpadButton mask,
|
||||
bool is_enabled);
|
||||
void ResetButtonConfig();
|
||||
|
||||
bool GetNextSamplingNumber(u64& next_sampling_number, u64 aruid, Core::HID::NpadIdType npad_id,
|
||||
u64 style_index);
|
||||
bool GetNextGcSamplingNumber(u64& next_sampling_number, u64 aruid,
|
||||
Core::HID::NpadIdType npad_id);
|
||||
|
||||
Result SetNpadCaptureButtonAssignment(u64 aruid, Core::HID::NpadStyleSet npad_style_set,
|
||||
Core::HID::NpadButton button_assignment);
|
||||
Result ClearNpadCaptureButtonAssignment(u64 aruid);
|
||||
std::size_t GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> out_list,
|
||||
u64 aruid) const;
|
||||
|
||||
Result SetNpadSystemExtStateEnabled(u64 aruid, bool is_enabled);
|
||||
|
||||
u64 GetIndexFromAruid(u64 aruid) const;
|
||||
|
||||
private:
|
||||
NPadData active_data;
|
||||
AruidRegisterList registration_list{};
|
||||
std::array<NpadState, AruidIndexMax> state;
|
||||
u64 active_data_aruid;
|
||||
u32 some_value;
|
||||
NpadJoyHoldType default_hold_type;
|
||||
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/npad_resource.h"
|
||||
#include "core/hle/service/hid/controllers/npad/palma_handler.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
NpadPalmaHandler::NpadPalmaHandler() {}
|
||||
|
||||
NpadPalmaHandler::~NpadPalmaHandler() = default;
|
||||
|
||||
void NpadPalmaHandler::SetIsPalmaPairedConnectable() {
|
||||
bool is_enabled = npad_resource->GetActiveData()->npad_style_set.palma;
|
||||
palma_resource->SetIsPalmaPairedConnectable(is_enabled);
|
||||
}
|
||||
|
||||
void NpadPalmaHandler::SetNpadResource(NPadResource* resource) {
|
||||
npad_resource = resource;
|
||||
}
|
||||
|
||||
void NpadPalmaHandler::SetPalmaResource(std::shared_ptr<PalmaResource> resource) {
|
||||
palma_resource = resource;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,27 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class NPadResource;
|
||||
class PalmaResource;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadPalmaHandler final {
|
||||
public:
|
||||
explicit NpadPalmaHandler();
|
||||
~NpadPalmaHandler();
|
||||
|
||||
void SetIsPalmaPairedConnectable();
|
||||
void SetNpadResource(NPadResource* resource);
|
||||
void SetPalmaResource(std::shared_ptr<PalmaResource> resource);
|
||||
|
||||
private:
|
||||
NPadResource* npad_resource{nullptr};
|
||||
std::shared_ptr<PalmaResource> palma_resource{nullptr};
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {} // namespace Service::HID
|
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
/// Handles Npad request from HID interfaces
|
||||
class UniquePad final {
|
||||
public:
|
||||
explicit UniquePad();
|
||||
~UniquePad();
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,189 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Result NpadVibrationDevice::IncrementRefCounter() {
|
||||
if (ref_counter == 0) {
|
||||
FUN_71000b6a1c();
|
||||
}
|
||||
|
||||
ref_counter++;
|
||||
if (is_mounted != false && xcd_handle->FUN_710011a950(local_4, device_index) != '\x01') {
|
||||
xcd_handle->FUN_710011a8f0(true, device_index);
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void NpadVibrationDevice::FUN_71000b6a1c() {
|
||||
if (ref_counter == 0) {
|
||||
return;
|
||||
}
|
||||
if (is_mounted) {
|
||||
f32 volume = 1.0;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
xcd_handle->SendVibrationValue(Core::HID::DEFAULT_VIBRATION_VALUE, device_index);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_mounted) {
|
||||
f32 volume = 1.0;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return;
|
||||
}
|
||||
xcd_handle->SendVibrationNotificationPattern(0);
|
||||
}
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::DecrementRefCounter() {
|
||||
int iVar1;
|
||||
char local_4[4];
|
||||
|
||||
if (ref_counter == 1) {
|
||||
FUN_71000b6a1c();
|
||||
}
|
||||
ref_counter--;
|
||||
if (ref_counter > 0) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
ref_counter = 0;
|
||||
if (is_mounted && FUN_710011a950(local_4, device_index) == 0) {
|
||||
xcd_handle->FUN_710011a8f0(0, device_index);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::SendVibrationValue(const Core::HID::VibrationValue& value) {
|
||||
if (ref_counter == 0) {
|
||||
return ResultVibrationNotInitialized;
|
||||
}
|
||||
if (!is_mounted) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume <= 0.0f) {
|
||||
return xcd_handle->FUN_710011a9b0(Core::HID::DEFAULT_VIBRATION_VALUE, device_index);
|
||||
}
|
||||
|
||||
Core::HID::VibrationValue vibration_value = value;
|
||||
vibration_value.high_amplitude *= volume;
|
||||
vibration_value.low_amplitude *= volume;
|
||||
|
||||
return xcd_handle->FUN_710011a9b0(vibration_value, device_index);
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::SendVibrationNotificationPattern(u32 param_2) {
|
||||
if (!is_mounted) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
if (volume <= 0.0) {
|
||||
param_2 = 0;
|
||||
}
|
||||
|
||||
return xcd_handle->SendVibrationNotificationPattern(param_2);
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::FUN_71000b6cc0(IAbstractedPad* abstracted_pad,
|
||||
Core::HID::VibrationDevicePosition position,
|
||||
NpadVibrationHandler* handler) {
|
||||
|
||||
Result result = abstracted_pad->driver->UpdateState();
|
||||
if (result.IsError()) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
if (!abstracted_pad->internal_flags.is_connected) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
xcd_handle = abstracted_pad->xcd_handle;
|
||||
|
||||
switch (position) {
|
||||
case Core::HID::VibrationDevicePosition ::Left:
|
||||
device_index = 0;
|
||||
break;
|
||||
case Core::HID::VibrationDevicePosition ::Right:
|
||||
device_index = 1;
|
||||
break;
|
||||
default:
|
||||
// Abort
|
||||
return;
|
||||
}
|
||||
|
||||
vibration_handler = handler;
|
||||
is_mounted = true;
|
||||
|
||||
if (ref_counter == 0) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
result = FUN_710011a950(&local_48);
|
||||
if (result.IsSuccess() && (local_48._0_1_ != '\x01')) {
|
||||
xcd_handle->FUN_710011a8f0(1, device_index);
|
||||
}
|
||||
if (ref_counter != 0 && is_mounted) {
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsSuccess()) {
|
||||
xcd_handle->FUN_710011a9b0(Core::HID::DEFAULT_VIBRATION_VALUE, device_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::FUN_71000b6e0c() {
|
||||
if (ref_counter == 0 || !is_mounted) {
|
||||
is_mounted = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
f32 volume = 1.0f;
|
||||
const auto result = vibration_handler->GetVibrationVolume(volume);
|
||||
if (result.IsError()) {
|
||||
is_mounted = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
is_mounted = false;
|
||||
xcd_handle->FUN_710011a9b0(Core::HID::DEFAULT_VIBRATION_VALUE, device_index);
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationDevice::GetActualVibrationValue(Core::HID::VibrationValue& out_value) {
|
||||
if (ref_counter < 1) {
|
||||
return ResultVibrationNotInitialized;
|
||||
}
|
||||
|
||||
out_value = Core::HID::DEFAULT_VIBRATION_VALUE;
|
||||
if (!is_mounted) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
return xcd_handle->GetActualVibrationValue(out_value, device_index);
|
||||
}
|
||||
|
||||
bool NpadVibrationDevice::IsVibrationMounted() {
|
||||
return is_mounted;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,45 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
class IAbstractedPad;
|
||||
class NpadVibrationHandler;
|
||||
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadVibrationDevice final {
|
||||
public:
|
||||
explicit NpadVibrationDevice();
|
||||
~NpadVibrationDevice();
|
||||
|
||||
Result IncrementRefCounter();
|
||||
void FUN_71000b6a1c();
|
||||
|
||||
Result DecrementRefCounter();
|
||||
|
||||
Result SendVibrationValue(const Core::HID::VibrationValue& value);
|
||||
Result SendVibrationNotificationPattern(u32 param_2);
|
||||
|
||||
Result FUN_71000b6cc0(IAbstractedPad* abstracted_pad, Core::HID::VibrationDevicePosition position,
|
||||
NpadVibrationHandler* handler);
|
||||
Result FUN_71000b6e0c();
|
||||
Result GetActualVibrationValue(Core::HID::VibrationValue& out_value);
|
||||
bool IsVibrationMounted();
|
||||
|
||||
private:
|
||||
u64 xcd_handle;
|
||||
u32 device_index;
|
||||
s32 ref_counter;
|
||||
bool is_mounted;
|
||||
NpadVibrationHandler* vibration_handler;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,77 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
#include "core/hle/service/hid/errors.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
Result NpadVibrationHandler::Activate() {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
|
||||
if (master_volume < 0.0f && master_volume > 1.0f) {
|
||||
return ResultVibrationStrenghtOutOfRange;
|
||||
}
|
||||
|
||||
volume = master_volume;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::Deactivate() {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::SetVibrationMasterVolume(f32 master_volume) {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
if (master_volume < 0.0f && master_volume > 1.0f) {
|
||||
return ResultVibrationStrenghtOutOfRange;
|
||||
}
|
||||
|
||||
volume = master_volume;
|
||||
// nn::settings::system::SetVibrationMasterVolume(master_volume);
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::GetVibrationVolume(f32& out_volume) const {
|
||||
std::scoped_lock lock{mutex};
|
||||
out_volume = volume;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::GetVibrationMasterVolume(f32& out_volume) const {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
|
||||
if (master_volume < 0.0f && master_volume > 1.0f) {
|
||||
return ResultVibrationStrenghtOutOfRange;
|
||||
}
|
||||
|
||||
out_volume = master_volume;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::BeginPermitVibrationSession(u64 aruid) {
|
||||
std::scoped_lock lock{mutex};
|
||||
aruid = aruid;
|
||||
volume = 1.0;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result NpadVibrationHandler::EndPermitVibrationSession() {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
const f32 master_volume = 1.0f; // nn::settings::system::GetVibrationMasterVolume();
|
||||
if (master_volume < 0.0f && master_volume > 1.0f) {
|
||||
return ResultVibrationStrenghtOutOfRange;
|
||||
}
|
||||
|
||||
volume = master_volume;
|
||||
aruid = 0;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
|
@ -0,0 +1,37 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/hid_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/hid/controllers/applet_resource.h"
|
||||
#include "core/hle/service/hid/controllers/types/npad_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
/// Handles Npad request from HID interfaces
|
||||
class NpadVibrationHandler final {
|
||||
public:
|
||||
explicit NpadVibrationHandler();
|
||||
~NpadVibrationHandler();
|
||||
|
||||
Result Activate();
|
||||
Result Deactivate();
|
||||
|
||||
Result SetVibrationMasterVolume(f32 master_volume);
|
||||
Result GetVibrationVolume(f32& out_volume) const;
|
||||
Result GetVibrationMasterVolume(f32& out_volume) const;
|
||||
|
||||
Result BeginPermitVibrationSession(u64 aruid);
|
||||
Result EndPermitVibrationSession();
|
||||
|
||||
private:
|
||||
f32 volume;
|
||||
u64 aruid;
|
||||
mutable std::mutex mutex;
|
||||
};
|
||||
} // namespace Service::HID
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
namespace Service::HID {
|
||||
static constexpr std::size_t NpadCount = 10;
|
||||
static constexpr std::size_t StyleIndexCount = 7;
|
||||
static constexpr std::size_t MaxSupportedNpadIdTypes = 10;
|
||||
|
||||
// This is nn::hid::NpadJoyHoldType
|
||||
enum class NpadJoyHoldType : u64 {
|
||||
|
@ -17,6 +19,11 @@ enum class NpadJoyHoldType : u64 {
|
|||
Horizontal = 1,
|
||||
};
|
||||
|
||||
enum class PackedNpadJoyHoldType : u32 {
|
||||
Vertical = 0,
|
||||
Horizontal = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadJoyAssignmentMode
|
||||
enum class NpadJoyAssignmentMode : u32 {
|
||||
Dual = 0,
|
||||
|
@ -37,6 +44,13 @@ enum class NpadHandheldActivationMode : u64 {
|
|||
MaxActivationMode = 3,
|
||||
};
|
||||
|
||||
enum class PackedNpadHandheldActivationMode : u32 {
|
||||
Dual = 0,
|
||||
Single = 1,
|
||||
None = 2,
|
||||
MaxActivationMode = 3,
|
||||
};
|
||||
|
||||
// This is nn::hid::system::AppletFooterUiAttributesSet
|
||||
struct AppletFooterUiAttributes {
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
|
@ -68,15 +82,6 @@ enum class AppletFooterUiType : u8 {
|
|||
Lagon = 21,
|
||||
};
|
||||
|
||||
using AppletFooterUiVariant = u8;
|
||||
|
||||
// This is "nn::hid::system::AppletDetailedUiType".
|
||||
struct AppletDetailedUiType {
|
||||
AppletFooterUiVariant ui_variant;
|
||||
INSERT_PADDING_BYTES(0x2);
|
||||
AppletFooterUiType footer;
|
||||
};
|
||||
static_assert(sizeof(AppletDetailedUiType) == 0x4, "AppletDetailedUiType is an invalid size");
|
||||
// This is nn::hid::NpadCommunicationMode
|
||||
enum class NpadCommunicationMode : u64 {
|
||||
Mode_5ms = 0,
|
||||
|
@ -100,6 +105,46 @@ enum class ColorAttribute : u32 {
|
|||
};
|
||||
static_assert(sizeof(ColorAttribute) == 4, "ColorAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLarkType
|
||||
enum class NpadLarkType : u32 {
|
||||
Invalid,
|
||||
H1,
|
||||
H2,
|
||||
NL,
|
||||
NR,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLuciaType
|
||||
enum class NpadLuciaType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagonType
|
||||
enum class NpadLagonType : u32 {
|
||||
Invalid,
|
||||
};
|
||||
|
||||
// This is nn::hid::NpadLagerType
|
||||
enum class NpadLagerType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
};
|
||||
|
||||
using AppletFooterUiVariant = u8;
|
||||
|
||||
// This is "nn::hid::system::AppletDetailedUiType".
|
||||
struct AppletDetailedUiType {
|
||||
AppletFooterUiVariant ui_variant;
|
||||
INSERT_PADDING_BYTES(0x2);
|
||||
AppletFooterUiType footer;
|
||||
};
|
||||
static_assert(sizeof(AppletDetailedUiType) == 0x4, "AppletDetailedUiType is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::NpadFullKeyColorState
|
||||
struct NpadFullKeyColorState {
|
||||
ColorAttribute attribute{ColorAttribute::NoController};
|
||||
|
@ -221,34 +266,104 @@ struct NfcXcdDeviceHandleStateImpl {
|
|||
static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18,
|
||||
"NfcXcdDeviceHandleStateImpl is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLarkType
|
||||
enum class NpadLarkType : u32 {
|
||||
Invalid,
|
||||
H1,
|
||||
H2,
|
||||
NL,
|
||||
NR,
|
||||
// nn::hidtypes::FeatureType
|
||||
struct FeatureType {
|
||||
union {
|
||||
u64 raw{};
|
||||
BitField<0, 1, u64> has_left_analog_stick;
|
||||
BitField<1, 1, u64> has_right_analog_stick;
|
||||
BitField<2, 1, u64> has_left_joy_six_axis_sensor;
|
||||
BitField<3, 1, u64> has_right_joy_six_axis_sensor;
|
||||
BitField<4, 1, u64> has_fullkey_joy_six_axis_sensor;
|
||||
BitField<5, 1, u64> has_left_Lra_vibration_device;
|
||||
BitField<6, 1, u64> has_right_Lra_vibration_device;
|
||||
BitField<7, 1, u64> has_gc_vibration_device;
|
||||
BitField<8, 1, u64> has_erm_vibration_device;
|
||||
BitField<9, 1, u64> has_left_joy_rail_bus;
|
||||
BitField<10, 1, u64> has_right_joy_rail_bus;
|
||||
BitField<11, 1, u64> has_internal_bus;
|
||||
BitField<12, 1, u64> is_palma;
|
||||
BitField<13, 1, u64> has_nfc;
|
||||
BitField<14, 1, u64> has_ir_sensor;
|
||||
BitField<15, 1, u64> is_analog_stick_calibration_supported;
|
||||
BitField<16, 1, u64> is_six_axis_Sensor_user_calibration_supported;
|
||||
BitField<17, 1, u64> has_left_right_joy_battery;
|
||||
BitField<18, 1, u64> has_fullkey_battery;
|
||||
BitField<19, 1, u64> is_disconnect_controller_if_battery_none;
|
||||
BitField<20, 1, u64> has_controller_color;
|
||||
BitField<21, 1, u64> has_grip_color;
|
||||
BitField<22, 1, u64> has_identification_code;
|
||||
BitField<23, 1, u64> has_bluetooth_address;
|
||||
BitField<24, 1, u64> has_mcu;
|
||||
BitField<25, 1, u64> has_notification_led;
|
||||
BitField<26, 1, u64> has_directional_buttons;
|
||||
BitField<27, 1, u64> has_indicator_led;
|
||||
BitField<28, 1, u64> is_button_config_embedded_supported;
|
||||
BitField<29, 1, u64> is_button_config_full_supported;
|
||||
BitField<30, 1, u64> is_button_config_left_supported;
|
||||
BitField<31, 1, u64> is_button_config_right_supported;
|
||||
BitField<32, 1, u64> is_usb_hid_device;
|
||||
BitField<33, 1, u64> is_kuina_device;
|
||||
BitField<34, 1, u64> is_direct_usb_to_bt_switching_device;
|
||||
BitField<35, 1, u64> is_normalize_analog_stick_with_inner_cross;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(FeatureType) == 8, "FeatureType is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLuciaType
|
||||
enum class NpadLuciaType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
// nn::hidtypes::AssignmentStyle
|
||||
struct AssignmentStyle {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> is_external_assigned;
|
||||
BitField<1, 1, u32> is_external_left_assigned;
|
||||
BitField<2, 1, u32> is_external_right_assigned;
|
||||
BitField<3, 1, u32> is_handheld_assigned;
|
||||
BitField<4, 1, u32> is_handheld_left_assigned;
|
||||
BitField<5, 1, u32> is_handheld_right_assigned;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(AssignmentStyle) == 4, "AssignmentStyle is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLagonType
|
||||
enum class NpadLagonType : u32 {
|
||||
Invalid,
|
||||
// This is nn::hid::server::IAbstractedPad::InternalFlags
|
||||
struct InternalFlags {
|
||||
union {
|
||||
u32 raw{};
|
||||
BitField<0, 1, u32> is_bound;
|
||||
BitField<1, 1, u32> is_connected;
|
||||
BitField<2, 1, u32> is_battery_low_ovln_required;
|
||||
BitField<3, 1, u32> is_battery_low_ovln_delay_required;
|
||||
BitField<4, 1, u32> is_sample_recieved;
|
||||
BitField<5, 1, u32> is_virtual_input;
|
||||
BitField<6, 1, u32> is_wired;
|
||||
BitField<8, 1, u32> use_center_clamp;
|
||||
BitField<9, 1, u32> has_virtual_six_axis_sensor_acceleration;
|
||||
BitField<10, 1, u32> has_virtual_six_axis_sensor_angle;
|
||||
BitField<11, 1, u32> is_debug_pad;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(InternalFlags) == 4, "InternalFlags is an invalid size");
|
||||
|
||||
// This is nn::hid::NpadLagerType
|
||||
enum class NpadLagerType : u32 {
|
||||
Invalid,
|
||||
J,
|
||||
E,
|
||||
U,
|
||||
/// This is nn::hid::server::IAbstractedPad
|
||||
struct IAbstractedPad {
|
||||
u64 vtable;
|
||||
InternalFlags internal_flags;
|
||||
u64 controller_id;
|
||||
u32 controller_number;
|
||||
u64 low_battery_display_delay_time;
|
||||
u64 low_battery_display_delay_interval;
|
||||
FeatureType feature_set;
|
||||
FeatureType disabled_feature_set;
|
||||
AssignmentStyle assignament_style;
|
||||
Core::HID::NpadStyleIndex device_type;
|
||||
Core::HID::NpadInterfaceType interface_type;
|
||||
Core::HID::NpadPowerInfo power_info;
|
||||
u32 pad_state;
|
||||
u32 button_mask;
|
||||
u32 system_button_mask;
|
||||
u8 indicator;
|
||||
std::vector<f32> virtual_six_axis_sensor_acceleration;
|
||||
std::vector<f32> virtual_six_axis_sensor_angle;
|
||||
u64 xcd_handle;
|
||||
u64 color;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
||||
|
|
|
@ -10,15 +10,32 @@ namespace Service::HID {
|
|||
constexpr Result PalmaResultSuccess{ErrorModule::HID, 0};
|
||||
constexpr Result NpadInvalidHandle{ErrorModule::HID, 100};
|
||||
constexpr Result NpadDeviceIndexOutOfRange{ErrorModule::HID, 107};
|
||||
constexpr Result VibrationInvalidStyleIndex{ErrorModule::HID, 122};
|
||||
constexpr Result VibrationInvalidNpadId{ErrorModule::HID, 123};
|
||||
constexpr Result VibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
|
||||
|
||||
constexpr Result ResultVibrationNotInitialized{ErrorModule::HID, 121};
|
||||
constexpr Result ResultVibrationInvalidStyleIndex{ErrorModule::HID, 122};
|
||||
constexpr Result ResultVibrationInvalidNpadId{ErrorModule::HID, 123};
|
||||
constexpr Result ResultVibrationDeviceIndexOutOfRange{ErrorModule::HID, 124};
|
||||
constexpr Result ResultVibrationStrenghtOutOfRange{ErrorModule::HID, 126};
|
||||
constexpr Result ResultVibrationArraySizeMismatch{ErrorModule::HID, 131};
|
||||
|
||||
constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
|
||||
|
||||
constexpr Result ResultNfcIsNotReady{ErrorModule::HID, 461};
|
||||
constexpr Result ResultNfcXcdHandleIsNotInitialized{ErrorModule::HID, 464};
|
||||
constexpr Result ResultIrSensorIsNotReady{ErrorModule::HID, 501};
|
||||
constexpr Result ResultMcuIsNotReady{ErrorModule::HID, 541};
|
||||
|
||||
constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
|
||||
constexpr Result NpadIsSameType{ErrorModule::HID, 602};
|
||||
constexpr Result InvalidNpadId{ErrorModule::HID, 709};
|
||||
constexpr Result NpadNotConnected{ErrorModule::HID, 710};
|
||||
constexpr Result InvalidArraySize{ErrorModule::HID, 715};
|
||||
constexpr Result ResultNpadIsNotProController{ErrorModule::HID, 604};
|
||||
|
||||
constexpr Result ResultInvalidNpadId{ErrorModule::HID, 709};
|
||||
constexpr Result ResultNpadNotConnected{ErrorModule::HID, 710};
|
||||
constexpr Result ResultNpadHandlerOverflow{ErrorModule::HID, 711};
|
||||
constexpr Result ResultNpadHandlerNotInitialized{ErrorModule::HID, 712};
|
||||
constexpr Result ResultInvalidArraySize{ErrorModule::HID, 715};
|
||||
constexpr Result ResultUndefinedStyleset{ErrorModule::HID, 716};
|
||||
constexpr Result ResultMultipleStyleSetSelected{ErrorModule::HID, 717};
|
||||
|
||||
constexpr Result ResultAppletResourceOverflow{ErrorModule::HID, 1041};
|
||||
constexpr Result ResultAppletResourceNotInitialized{ErrorModule::HID, 1042};
|
||||
|
@ -27,6 +44,9 @@ constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
|
|||
constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
|
||||
constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};
|
||||
|
||||
constexpr Result ResultNpadResourceOverflow{ErrorModule::HID, 2001};
|
||||
constexpr Result ResultNpadResourceNotInitialized{ErrorModule::HID, 2002};
|
||||
|
||||
constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
|
||||
|
||||
} // namespace Service::HID
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
#include "core/hle/service/hid/controllers/keyboard.h"
|
||||
#include "core/hle/service/hid/controllers/mouse.h"
|
||||
#include "core/hle/service/hid/controllers/npad.h"
|
||||
#include "core/hle/service/hid/controllers/npad/gc_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/n64_vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_device.h"
|
||||
#include "core/hle/service/hid/controllers/npad/vibration_handler.h"
|
||||
#include "core/hle/service/hid/controllers/palma.h"
|
||||
#include "core/hle/service/hid/controllers/seven_six_axis.h"
|
||||
#include "core/hle/service/hid/controllers/six_axis.h"
|
||||
|
@ -39,7 +43,7 @@ public:
|
|||
: ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &IActiveVibrationDeviceList::InitializeVibrationDevice, "InitializeVibrationDevice"},
|
||||
{0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
@ -47,12 +51,12 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void InitializeVibrationDevice(HLERequestContext& ctx) {
|
||||
void ActivateVibrationDevice(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()};
|
||||
|
||||
if (resource_manager != nullptr && resource_manager->GetNpad()) {
|
||||
resource_manager->GetNpad()->InitializeVibrationDevice(vibration_device_handle);
|
||||
resource_manager->GetNpad()->ActivateVibrationDevice(vibration_device_handle);
|
||||
}
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}",
|
||||
|
@ -783,20 +787,19 @@ void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ct
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
bool is_firmware_available{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->IsFirmwareUpdateAvailableForSixAxisSensor(parameters.sixaxis_handle,
|
||||
is_firmware_available);
|
||||
|
||||
LOG_WARNING(
|
||||
Service_HID,
|
||||
"(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
|
||||
parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id,
|
||||
parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const bool is_firmware_available =
|
||||
npad->IsFirmwareUpdateAvailableForSixAxisSensor(parameters.sixaxis_handle);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(is_firmware_available);
|
||||
rb.Push<u8>(is_firmware_available);
|
||||
}
|
||||
|
||||
void IHidServer::EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx) {
|
||||
|
@ -923,16 +926,16 @@ void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx)
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
controller->ResetIsSixAxisSensorDeviceNewlyAssigned(parameters.sixaxis_handle);
|
||||
|
||||
LOG_WARNING(
|
||||
Service_HID,
|
||||
"(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
|
||||
parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id,
|
||||
parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->ResetIsSixAxisSensorDeviceNewlyAssigned(
|
||||
parameters.applet_resource_user_id, parameters.sixaxis_handle);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
@ -970,7 +973,7 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) {
|
|||
void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
struct Parameters {
|
||||
Core::HID::NpadStyleSet supported_styleset;
|
||||
Core::HID::NpadStyleSet supported_style_set;
|
||||
INSERT_PADDING_WORDS_NOINIT(1);
|
||||
u64 applet_resource_user_id;
|
||||
};
|
||||
|
@ -978,13 +981,25 @@ void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetSupportedStyleSet({parameters.supported_styleset});
|
||||
LOG_DEBUG(Service_HID, "called, supported_style_set={}, applet_resource_user_id={}",
|
||||
parameters.supported_style_set, parameters.applet_resource_user_id);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, supported_styleset={}, applet_resource_user_id={}",
|
||||
parameters.supported_styleset, parameters.applet_resource_user_id);
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const Result result = npad->SetSupportedNpadStyleSet(parameters.applet_resource_user_id,
|
||||
parameters.supported_style_set);
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
Core::HID::NpadStyleTag style_tag{parameters.supported_style_set};
|
||||
const auto revision = npad->GetRevision(parameters.applet_resource_user_id);
|
||||
|
||||
if (style_tag.gamecube != 0 && revision < NpadRevision::Revision3) {
|
||||
// GetResourceManager()->GetPalma()->EnableBoostMode(parameters.applet_resource_user_id,
|
||||
// true);
|
||||
}
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) {
|
||||
|
@ -993,19 +1008,31 @@ void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) {
|
|||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Core::HID::NpadStyleSet supported_style_set{};
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
npad->GetSupportedNpadStyleSet(applet_resource_user_id, supported_style_set);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw);
|
||||
rb.Push(result);
|
||||
rb.PushEnum(supported_style_set);
|
||||
}
|
||||
|
||||
void IHidServer::SetSupportedNpadIdType(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
const auto result = GetResourceManager()->GetNpad()->SetSupportedNpadIdTypes(ctx.ReadBuffer());
|
||||
const auto buffer = ctx.ReadBuffer();
|
||||
const std::size_t elements = ctx.GetReadBufferNumElements<Core::HID::NpadIdType>();
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
std::vector<Core::HID::NpadIdType> supported_npad_list(elements);
|
||||
memcpy(supported_npad_list.data(), buffer.data(), buffer.size());
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const Result result =
|
||||
npad->SetSupportedNpadIdType(applet_resource_user_id, supported_npad_list);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
@ -1018,7 +1045,7 @@ void IHidServer::ActivateNpad(HLERequestContext& ctx) {
|
|||
|
||||
auto npad = GetResourceManager()->GetNpad();
|
||||
|
||||
// TODO: npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0);
|
||||
npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0);
|
||||
const Result result = npad->Activate(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
|
@ -1052,13 +1079,14 @@ void IHidServer::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) {
|
|||
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}",
|
||||
parameters.npad_id, parameters.applet_resource_user_id, parameters.unknown);
|
||||
|
||||
// Games expect this event to be signaled after calling this function
|
||||
GetResourceManager()->GetNpad()->SignalStyleSetChangedEvent(parameters.npad_id);
|
||||
Kernel::KReadableEvent* out_event = nullptr;
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->AcquireNpadStyleSetUpdateEventHandle(
|
||||
parameters.applet_resource_user_id, &out_event, parameters.npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushCopyObjects(
|
||||
GetResourceManager()->GetNpad()->GetStyleSetChangedEvent(parameters.npad_id));
|
||||
rb.Push(result);
|
||||
rb.PushCopyObjects(out_event);
|
||||
}
|
||||
|
||||
void IHidServer::DisconnectNpad(HLERequestContext& ctx) {
|
||||
|
@ -1073,7 +1101,7 @@ void IHidServer::DisconnectNpad(HLERequestContext& ctx) {
|
|||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->DisconnectNpad(parameters.npad_id);
|
||||
controller->DisconnectNpad(parameters.applet_resource_user_id, parameters.npad_id);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||
parameters.applet_resource_user_id);
|
||||
|
@ -1086,14 +1114,13 @@ void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
Core::HID::LedPattern pattern{0, 0, 0, 0};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result = controller->GetLedPattern(npad_id, pattern);
|
||||
const auto pattern = controller->GetPlayerLedPattern(npad_id);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(result);
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(pattern.raw);
|
||||
}
|
||||
|
||||
|
@ -1125,13 +1152,19 @@ void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) {
|
|||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto hold_type{rp.PopEnum<NpadJoyHoldType>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetHoldType(hold_type);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}",
|
||||
applet_resource_user_id, hold_type);
|
||||
|
||||
if (hold_type != NpadJoyHoldType::Horizontal && hold_type != NpadJoyHoldType::Vertical) {
|
||||
// This should crash console
|
||||
ASSERT_MSG("Invalid npad joy hold type");
|
||||
}
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->SetNpadJoyHoldType(applet_resource_user_id, hold_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) {
|
||||
|
@ -1140,9 +1173,13 @@ void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) {
|
|||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
NpadJoyHoldType hold_type{};
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->GetNpadJoyHoldType(applet_resource_user_id, hold_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(GetResourceManager()->GetNpad()->GetHoldType());
|
||||
rb.Push(result);
|
||||
rb.PushEnum(hold_type);
|
||||
}
|
||||
|
||||
void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) {
|
||||
|
@ -1156,14 +1193,13 @@ void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx)
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, NpadJoyDeviceType::Left,
|
||||
NpadJoyAssignmentMode::Single);
|
||||
|
||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||
parameters.applet_resource_user_id);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
npad->SetNpadJoyAssignmentModeSingleByDefault(parameters.applet_resource_user_id,
|
||||
parameters.npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1180,15 +1216,14 @@ void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type,
|
||||
NpadJoyAssignmentMode::Single);
|
||||
|
||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
|
||||
parameters.npad_id, parameters.applet_resource_user_id,
|
||||
parameters.npad_joy_device_type);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
npad->SetNpadJoyAssignmentModeSingle(parameters.applet_resource_user_id, parameters.npad_id,
|
||||
parameters.npad_joy_device_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1204,12 +1239,11 @@ void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, {}, NpadJoyAssignmentMode::Dual);
|
||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||
parameters.applet_resource_user_id);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
|
||||
parameters.applet_resource_user_id); // Spams a lot when controller applet is open
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
npad->SetNpadJoyAssignmentModeDual(parameters.applet_resource_user_id, parameters.npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -1221,12 +1255,13 @@ void IHidServer::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) {
|
|||
const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result = controller->MergeSingleJoyAsDualJoy(npad_id_1, npad_id_2);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
|
||||
npad_id_1, npad_id_2, applet_resource_user_id);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
npad->MergeSingleJoyAsDualJoy(applet_resource_user_id, npad_id_1, npad_id_2);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
@ -1235,10 +1270,10 @@ void IHidServer::StartLrAssignmentMode(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->StartLRAssignmentMode();
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->StartLrAssignmentMode(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1247,10 +1282,10 @@ void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->StopLRAssignmentMode();
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->StopLrAssignmentMode(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1260,11 +1295,21 @@ void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) {
|
|||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto activation_mode{rp.PopEnum<NpadHandheldActivationMode>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(activation_mode);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}",
|
||||
applet_resource_user_id, activation_mode);
|
||||
|
||||
if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) {
|
||||
// Console should crash here
|
||||
ASSERT_MSG("Activation mode should be always None, Single or Dual");
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
npad->SetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1275,9 +1320,14 @@ void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) {
|
|||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
NpadHandheldActivationMode activation_mode{};
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
npad->GetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadHandheldActivationMode());
|
||||
rb.Push(result);
|
||||
rb.PushEnum(activation_mode);
|
||||
}
|
||||
|
||||
void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) {
|
||||
|
@ -1286,12 +1336,12 @@ void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) {
|
|||
const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result = controller->SwapNpadAssignment(npad_id_1, npad_id_2);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
|
||||
npad_id_1, npad_id_2, applet_resource_user_id);
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->SwapNpadAssignment(applet_resource_user_id, npad_id_1, npad_id_2);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
@ -1307,17 +1357,23 @@ void IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext&
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
bool is_enabled = false;
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
controller->IsUnintendedHomeButtonInputProtectionEnabled(parameters.npad_id, is_enabled);
|
||||
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}",
|
||||
parameters.npad_id, parameters.applet_resource_user_id);
|
||||
|
||||
if (!IsNpadIdValid(parameters.npad_id)) {
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultInvalidNpadId);
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_enabled{};
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->IsUnintendedHomeButtonInputProtectionEnabled(
|
||||
is_enabled, parameters.applet_resource_user_id, parameters.npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(result);
|
||||
rb.Push(is_enabled);
|
||||
rb.Push<u8>(is_enabled);
|
||||
}
|
||||
|
||||
void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx) {
|
||||
|
@ -1332,13 +1388,19 @@ void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ct
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto result = controller->SetUnintendedHomeButtonInputProtectionEnabled(
|
||||
parameters.is_enabled, parameters.npad_id);
|
||||
LOG_WARNING(Service_HID,
|
||||
"(STUBBED) called, is_enabled={}, npad_id={}, applet_resource_user_id={}",
|
||||
parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id);
|
||||
|
||||
LOG_DEBUG(Service_HID,
|
||||
"(STUBBED) called, is_enabled={}, npad_id={}, applet_resource_user_id={}",
|
||||
parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id);
|
||||
if (!IsNpadIdValid(parameters.npad_id)) {
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultInvalidNpadId);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto result = npad->EnableUnintendedHomeButtonInputProtection(
|
||||
parameters.applet_resource_user_id, parameters.npad_id, parameters.is_enabled);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
|
@ -1356,16 +1418,16 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
auto controller = GetResourceManager()->GetNpad();
|
||||
const auto is_reassigned =
|
||||
controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type,
|
||||
NpadJoyAssignmentMode::Single);
|
||||
|
||||
LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
|
||||
parameters.npad_id, parameters.applet_resource_user_id,
|
||||
parameters.npad_joy_device_type);
|
||||
|
||||
Core::HID::NpadIdType new_npad_id{};
|
||||
const auto npad = GetResourceManager()->GetNpad();
|
||||
const auto is_reassigned = npad->SetNpadJoyAssignmentModeSingleWithDestination(
|
||||
new_npad_id, parameters.applet_resource_user_id, parameters.npad_id,
|
||||
parameters.npad_joy_device_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(is_reassigned);
|
||||
|
@ -1375,7 +1437,7 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext
|
|||
void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
struct Parameters {
|
||||
bool analog_stick_use_center_clamp;
|
||||
bool use_center_clamp;
|
||||
INSERT_PADDING_BYTES_NOINIT(7);
|
||||
u64 applet_resource_user_id;
|
||||
};
|
||||
|
@ -1383,12 +1445,11 @@ void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetAnalogStickUseCenterClamp(
|
||||
parameters.analog_stick_use_center_clamp);
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called, use_center_clamp={}, applet_resource_user_id={}",
|
||||
parameters.use_center_clamp, parameters.applet_resource_user_id);
|
||||
|
||||
LOG_WARNING(Service_HID,
|
||||
"(STUBBED) called, analog_stick_use_center_clamp={}, applet_resource_user_id={}",
|
||||
parameters.analog_stick_use_center_clamp, parameters.applet_resource_user_id);
|
||||
GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(
|
||||
parameters.applet_resource_user_id, parameters.use_center_clamp);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -1434,7 +1495,7 @@ void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) {
|
|||
bool check_device_index = false;
|
||||
|
||||
switch (vibration_device_handle.npad_type) {
|
||||
case Core::HID::NpadStyleIndex::ProController:
|
||||
case Core::HID::NpadStyleIndex::Fullkey:
|
||||
case Core::HID::NpadStyleIndex::Handheld:
|
||||
case Core::HID::NpadStyleIndex::JoyconDual:
|
||||
case Core::HID::NpadStyleIndex::JoyconLeft:
|
||||
|
@ -1496,15 +1557,16 @@ void IHidServer::SendVibrationValue(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle,
|
||||
parameters.vibration_value);
|
||||
|
||||
LOG_DEBUG(Service_HID,
|
||||
"called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
|
||||
parameters.vibration_device_handle.npad_type,
|
||||
parameters.vibration_device_handle.npad_id,
|
||||
parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->SendVibrationValue(parameters.applet_resource_user_id,
|
||||
parameters.vibration_device_handle,
|
||||
parameters.vibration_value);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1544,25 +1606,27 @@ void IHidServer::PermitVibration(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto can_vibrate{rp.Pop<bool>()};
|
||||
|
||||
// nnSDK saves this value as a float. Since it can only be 1.0f or 0.0f we simplify this value
|
||||
// by converting it to a bool
|
||||
Settings::values.vibration_enabled.SetValue(can_vibrate);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, can_vibrate={}", can_vibrate);
|
||||
|
||||
const auto result =
|
||||
GetResourceManager()->GetNpad()->GetVibrationHandler()->SetVibrationMasterVolume(
|
||||
can_vibrate ? 1.0f : 0.0f);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::IsVibrationPermitted(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_HID, "called");
|
||||
|
||||
// nnSDK checks if a float is greater than zero. We return the bool we stored earlier
|
||||
const auto is_enabled = Settings::values.vibration_enabled.GetValue();
|
||||
f32 master_volume{};
|
||||
const auto result =
|
||||
GetResourceManager()->GetNpad()->GetVibrationHandler()->GetVibrationMasterVolume(
|
||||
master_volume);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(is_enabled);
|
||||
rb.Push(result);
|
||||
rb.Push(master_volume > 0.0f);
|
||||
}
|
||||
|
||||
void IHidServer::SendVibrationValues(HLERequestContext& ctx) {
|
||||
|
@ -1580,12 +1644,22 @@ void IHidServer::SendVibrationValues(HLERequestContext& ctx) {
|
|||
auto vibration_values = std::span(
|
||||
reinterpret_cast<const Core::HID::VibrationValue*>(vibration_data.data()), vibration_count);
|
||||
|
||||
GetResourceManager()->GetNpad()->VibrateControllers(vibration_device_handles, vibration_values);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Result result = ResultSuccess;
|
||||
if (handle_count != vibration_count) {
|
||||
result = ResultVibrationArraySizeMismatch;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < handle_count; i++) {
|
||||
if (result.IsSuccess()) {
|
||||
result = GetResourceManager()->SendVibrationValue(
|
||||
applet_resource_user_id, vibration_device_handles[i], vibration_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) {
|
||||
|
@ -1600,43 +1674,6 @@ void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
/**
|
||||
* Note: This uses yuzu-specific behavior such that the StopHard command produces
|
||||
* vibrations where freq_low == 0.0f and freq_high == 0.0f, as defined below,
|
||||
* in order to differentiate between Stop and StopHard commands.
|
||||
* This is done to reuse the controller vibration functions made for regular controllers.
|
||||
*/
|
||||
const auto vibration_value = [parameters] {
|
||||
switch (parameters.gc_erm_command) {
|
||||
case Core::HID::VibrationGcErmCommand::Stop:
|
||||
return Core::HID::VibrationValue{
|
||||
.low_amplitude = 0.0f,
|
||||
.low_frequency = 160.0f,
|
||||
.high_amplitude = 0.0f,
|
||||
.high_frequency = 320.0f,
|
||||
};
|
||||
case Core::HID::VibrationGcErmCommand::Start:
|
||||
return Core::HID::VibrationValue{
|
||||
.low_amplitude = 1.0f,
|
||||
.low_frequency = 160.0f,
|
||||
.high_amplitude = 1.0f,
|
||||
.high_frequency = 320.0f,
|
||||
};
|
||||
case Core::HID::VibrationGcErmCommand::StopHard:
|
||||
return Core::HID::VibrationValue{
|
||||
.low_amplitude = 0.0f,
|
||||
.low_frequency = 0.0f,
|
||||
.high_amplitude = 0.0f,
|
||||
.high_frequency = 0.0f,
|
||||
};
|
||||
default:
|
||||
return Core::HID::DEFAULT_VIBRATION_VALUE;
|
||||
}
|
||||
}();
|
||||
|
||||
GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle,
|
||||
vibration_value);
|
||||
|
||||
LOG_DEBUG(Service_HID,
|
||||
"called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, "
|
||||
"gc_erm_command={}",
|
||||
|
@ -1645,8 +1682,23 @@ void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) {
|
|||
parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id,
|
||||
parameters.gc_erm_command);
|
||||
|
||||
bool has_active_aruid{};
|
||||
NpadGcVibrationDevice* gc_device{nullptr};
|
||||
Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
|
||||
has_active_aruid);
|
||||
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
result = IsVibrationHandleValid(parameters.vibration_device_handle);
|
||||
}
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle);
|
||||
}
|
||||
if (gc_device != nullptr) {
|
||||
result = gc_device->SendVibrationGcErmCommand(parameters.gc_erm_command);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) {
|
||||
|
@ -1659,33 +1711,31 @@ void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) {
|
|||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
const auto last_vibration =
|
||||
GetResourceManager()->GetNpad()->GetLastVibration(parameters.vibration_device_handle);
|
||||
|
||||
const auto gc_erm_command = [last_vibration] {
|
||||
if (last_vibration.low_amplitude != 0.0f || last_vibration.high_amplitude != 0.0f) {
|
||||
return Core::HID::VibrationGcErmCommand::Start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This uses yuzu-specific behavior such that the StopHard command produces
|
||||
* vibrations where freq_low == 0.0f and freq_high == 0.0f, as defined in the HID function
|
||||
* SendVibrationGcErmCommand, in order to differentiate between Stop and StopHard commands.
|
||||
* This is done to reuse the controller vibration functions made for regular controllers.
|
||||
*/
|
||||
if (last_vibration.low_frequency == 0.0f && last_vibration.high_frequency == 0.0f) {
|
||||
return Core::HID::VibrationGcErmCommand::StopHard;
|
||||
}
|
||||
|
||||
return Core::HID::VibrationGcErmCommand::Stop;
|
||||
}();
|
||||
|
||||
LOG_DEBUG(Service_HID,
|
||||
"called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
|
||||
parameters.vibration_device_handle.npad_type,
|
||||
parameters.vibration_device_handle.npad_id,
|
||||
parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
|
||||
|
||||
bool has_active_aruid{};
|
||||
NpadGcVibrationDevice* gc_device{nullptr};
|
||||
Core::HID::VibrationGcErmCommand gc_erm_command{};
|
||||
Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
|
||||
has_active_aruid);
|
||||
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
result = IsVibrationHandleValid(parameters.vibration_device_handle);
|
||||
}
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle);
|
||||
}
|
||||
if (gc_device != nullptr) {
|
||||
result = gc_device->GetActualVibrationGcErmCommand(gc_erm_command);
|
||||
}
|
||||
if (result.IsError()) {
|
||||
gc_erm_command = Core::HID::VibrationGcErmCommand::Stop;
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(gc_erm_command);
|
||||
|
@ -1695,19 +1745,21 @@ void IHidServer::BeginPermitVibrationSession(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetPermitVibrationSession(true);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
const auto result =
|
||||
GetResourceManager()->GetNpad()->GetVibrationHandler()->BeginPermitVibrationSession(
|
||||
applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::EndPermitVibrationSession(HLERequestContext& ctx) {
|
||||
GetResourceManager()->GetNpad()->SetPermitVibrationSession(false);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called");
|
||||
|
||||
GetResourceManager()->GetNpad()->GetVibrationHandler()->EndPermitVibrationSession();
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -1729,10 +1781,21 @@ void IHidServer::IsVibrationDeviceMounted(HLERequestContext& ctx) {
|
|||
parameters.vibration_device_handle.npad_id,
|
||||
parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
|
||||
|
||||
bool is_mounted{};
|
||||
NpadVibrationDevice* device{nullptr};
|
||||
Result result = IsVibrationHandleValid(parameters.vibration_device_handle);
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
device = GetResourceManager()->GetVibrationDevice(parameters.vibration_device_handle);
|
||||
}
|
||||
|
||||
if (device != nullptr) {
|
||||
is_mounted = device->IsVibrationMounted();
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(GetResourceManager()->GetNpad()->IsVibrationDeviceMounted(
|
||||
parameters.vibration_device_handle));
|
||||
rb.Push(result);
|
||||
rb.Push(is_mounted);
|
||||
}
|
||||
|
||||
void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) {
|
||||
|
@ -2315,10 +2378,10 @@ void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) {
|
|||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
const auto communication_mode{rp.PopEnum<NpadCommunicationMode>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->SetNpadCommunicationMode(communication_mode);
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}",
|
||||
applet_resource_user_id, communication_mode);
|
||||
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}, communication_mode={}",
|
||||
applet_resource_user_id, communication_mode);
|
||||
// This function has been stubbed since 2.0.0+
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -2326,12 +2389,15 @@ void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) {
|
|||
|
||||
void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called");
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
// This function has been stubbed since 2.0.0+
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadCommunicationMode());
|
||||
rb.PushEnum(NpadCommunicationMode::Default);
|
||||
}
|
||||
|
||||
void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) {
|
||||
|
|
|
@ -34,7 +34,7 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
|
|||
{215, nullptr, "IsNfcActivated"},
|
||||
{230, nullptr, "AcquireIrSensorEventHandle"},
|
||||
{231, nullptr, "ActivateIrSensor"},
|
||||
{232, nullptr, "GetIrSensorState"},
|
||||
{232, nullptr, "SetNpadSystemExtStateEnabled"},
|
||||
{233, nullptr, "GetXcdHandleForNpadWithIrSensor"},
|
||||
{301, nullptr, "ActivateNpadSystem"},
|
||||
{303, &IHidSystemServer::ApplyNpadSystemCommonPolicy, "ApplyNpadSystemCommonPolicy"},
|
||||
|
@ -240,40 +240,59 @@ IHidSystemServer::~IHidSystemServer() {
|
|||
};
|
||||
|
||||
void IHidSystemServer::ApplyNpadSystemCommonPolicy(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_HID, "called");
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy();
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void IHidSystemServer::EnableAssigningSingleOnSlSrPress(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called");
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->AssigningSingleOnSlSrPress(applet_resource_user_id, true);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void IHidSystemServer::DisableAssigningSingleOnSlSrPress(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called");
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->AssigningSingleOnSlSrPress(applet_resource_user_id, false);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetLastActiveNpad(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called"); // Spams a lot when controller applet is running
|
||||
Core::HID::NpadIdType npad_id{};
|
||||
const Result result = GetResourceManager()->GetNpad()->GetLastActiveNpad(npad_id);
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(system.HIDCore().GetLastActiveController());
|
||||
rb.Push(result);
|
||||
rb.PushEnum(npad_id);
|
||||
}
|
||||
|
||||
void IHidSystemServer::ApplyNpadSystemCommonPolicyFull(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_HID, "called");
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy();
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicyFull(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -283,51 +302,54 @@ void IHidSystemServer::GetNpadFullKeyGripColor(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
Core::HID::NpadColor left_color{};
|
||||
Core::HID::NpadColor right_color{};
|
||||
// TODO: Get colors from Npad
|
||||
Core::HID::NpadColor main_color{};
|
||||
Core::HID::NpadColor sub_color{};
|
||||
const auto result = GetResourceManager()->GetNpad()->GetNpadFullKeyGripColor(
|
||||
main_color, sub_color, npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushRaw(left_color);
|
||||
rb.PushRaw(right_color);
|
||||
rb.Push(result);
|
||||
rb.PushRaw(main_color);
|
||||
rb.PushRaw(sub_color);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetMaskedSupportedNpadStyleSet(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_INFO(Service_HID, "(STUBBED) called");
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Core::HID::NpadStyleSet supported_styleset =
|
||||
GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw;
|
||||
Core::HID::NpadStyleSet supported_styleset{};
|
||||
const auto& npad = GetResourceManager()->GetNpad();
|
||||
const Result result =
|
||||
npad->GetMaskedSupportedNpadStyleSet(applet_resource_user_id, supported_styleset);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
rb.PushEnum(supported_styleset);
|
||||
}
|
||||
|
||||
void IHidSystemServer::SetSupportedNpadStyleSetAll(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_INFO(Service_HID, "(STUBBED) called");
|
||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Core::HID::NpadStyleSet supported_styleset =
|
||||
GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw;
|
||||
const auto& npad = GetResourceManager()->GetNpad();
|
||||
const auto result =
|
||||
npad->SetSupportedNpadStyleSet(applet_resource_user_id, Core::HID::NpadStyleSet::All);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(supported_styleset);
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetAppletDetailedUiType(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
const AppletDetailedUiType detailed_ui_type =
|
||||
GetResourceManager()->GetNpad()->GetAppletDetailedUiType(npad_id_type);
|
||||
|
@ -341,55 +363,62 @@ void IHidSystemServer::GetNpadInterfaceType(HLERequestContext& ctx) {
|
|||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
Core::HID::NpadInterfaceType interface_type{};
|
||||
const auto result =
|
||||
GetResourceManager()->GetNpad()->GetNpadInterfaceType(interface_type, npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth);
|
||||
rb.Push(result);
|
||||
rb.PushEnum(interface_type);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetNpadLeftRightInterfaceType(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
Core::HID::NpadInterfaceType left_interface_type{};
|
||||
Core::HID::NpadInterfaceType right_interface_type{};
|
||||
const auto result = GetResourceManager()->GetNpad()->GetNpadLeftRightInterfaceType(
|
||||
left_interface_type, right_interface_type, npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth);
|
||||
rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth);
|
||||
rb.Push(result);
|
||||
rb.PushEnum(left_interface_type);
|
||||
rb.PushEnum(right_interface_type);
|
||||
}
|
||||
|
||||
void IHidSystemServer::HasBattery(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
bool has_battery{};
|
||||
const auto result = GetResourceManager()->GetNpad()->HasBattery(has_battery, npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(false);
|
||||
rb.Push(result);
|
||||
rb.Push<u8>(has_battery);
|
||||
}
|
||||
|
||||
void IHidSystemServer::HasLeftRightBattery(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type);
|
||||
|
||||
struct LeftRightBattery {
|
||||
bool left;
|
||||
bool right;
|
||||
};
|
||||
|
||||
LeftRightBattery left_right_battery{
|
||||
.left = false,
|
||||
.right = false,
|
||||
};
|
||||
LeftRightBattery left_right_battery{};
|
||||
const auto result = GetResourceManager()->GetNpad()->HasLeftRightBattery(
|
||||
left_right_battery.left, left_right_battery.right, npad_id_type);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -399,11 +428,13 @@ void IHidSystemServer::HasLeftRightBattery(HLERequestContext& ctx) {
|
|||
void IHidSystemServer::GetUniquePadsFromNpad(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto npad_id_type{rp.PopEnum<Core::HID::NpadIdType>()};
|
||||
const auto entries{ctx.GetWriteBufferNumElements<Core::HID::UniquePadId>()};
|
||||
|
||||
LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}",
|
||||
npad_id_type); // Spams a lot when controller applet is running
|
||||
LOG_DEBUG(Service_HID, " called, npad_id_type={}", npad_id_type);
|
||||
|
||||
const std::vector<Core::HID::UniquePadId> unique_pads{};
|
||||
std::vector<Core::HID::UniquePadId> unique_pads(entries);
|
||||
const auto total_size =
|
||||
GetResourceManager()->GetNpad()->GetUniquePadsFromNpad(unique_pads, npad_id_type);
|
||||
|
||||
if (!unique_pads.empty()) {
|
||||
ctx.WriteBuffer(unique_pads);
|
||||
|
@ -411,7 +442,7 @@ void IHidSystemServer::GetUniquePadsFromNpad(HLERequestContext& ctx) {
|
|||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(static_cast<u32>(unique_pads.size()));
|
||||
rb.Push(total_size);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetIrSensorState(HLERequestContext& ctx) {
|
||||
|
@ -422,6 +453,7 @@ void IHidSystemServer::GetIrSensorState(HLERequestContext& ctx) {
|
|||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void IHidSystemServer::RegisterAppletResourceUserId(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
struct Parameters {
|
||||
|
@ -440,8 +472,8 @@ void IHidSystemServer::RegisterAppletResourceUserId(HLERequestContext& ctx) {
|
|||
parameters.applet_resource_user_id, parameters.enable_input);
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
// result = GetResourceManager()->GetNpad()->RegisterAppletResourceUserId(
|
||||
// parameters.applet_resource_user_id);
|
||||
result = GetResourceManager()->GetNpad()->RegisterAppletResourceUserId(
|
||||
parameters.applet_resource_user_id);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
|
@ -455,7 +487,7 @@ void IHidSystemServer::UnregisterAppletResourceUserId(HLERequestContext& ctx) {
|
|||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||
// GetResourceManager()->GetNpad()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||
GetResourceManager()->GetNpad()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||
// GetResourceManager()->GetPalma()->UnregisterAppletResourceUserId(applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
|
@ -477,7 +509,7 @@ void IHidSystemServer::EnableAppletToGetInput(HLERequestContext& ctx) {
|
|||
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->EnableInput(parameters.applet_resource_user_id, parameters.is_enabled);
|
||||
// GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||
GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
@ -519,7 +551,7 @@ void IHidSystemServer::EnableAppletToGetPadInput(HLERequestContext& ctx) {
|
|||
parameters.is_enabled, parameters.applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->EnablePadInput(parameters.applet_resource_user_id, parameters.is_enabled);
|
||||
// GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||
GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
|
|
|
@ -31,7 +31,7 @@ constexpr Result IsSixaxisHandleValid(const Core::HID::SixAxisSensorHandle& hand
|
|||
const bool device_index = handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex;
|
||||
|
||||
if (!npad_id) {
|
||||
return InvalidNpadId;
|
||||
return ResultInvalidNpadId;
|
||||
}
|
||||
if (!device_index) {
|
||||
return NpadDeviceIndexOutOfRange;
|
||||
|
@ -42,7 +42,7 @@ constexpr Result IsSixaxisHandleValid(const Core::HID::SixAxisSensorHandle& hand
|
|||
|
||||
constexpr Result IsVibrationHandleValid(const Core::HID::VibrationDeviceHandle& handle) {
|
||||
switch (handle.npad_type) {
|
||||
case Core::HID::NpadStyleIndex::ProController:
|
||||
case Core::HID::NpadStyleIndex::Fullkey:
|
||||
case Core::HID::NpadStyleIndex::Handheld:
|
||||
case Core::HID::NpadStyleIndex::JoyconDual:
|
||||
case Core::HID::NpadStyleIndex::JoyconLeft:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "core/core_timing.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/kernel/k_shared_memory.h"
|
||||
#include "core/hle/service/hid/hid_util.h"
|
||||
#include "core/hle/service/hid/resource_manager.h"
|
||||
#include "core/hle/service/ipc_helpers.h"
|
||||
|
||||
|
@ -261,6 +262,48 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
|
|||
console_six_axis->OnUpdate(core_timing);
|
||||
}
|
||||
|
||||
Result ResourceManager::IsVibrationAruidActive(u64 aruid, bool& is_active) {
|
||||
std::scoped_lock lock{shared_mutex};
|
||||
is_active = applet_resource->IsVibrationAruidActive(aruid);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
NpadN64VibrationDevice* ResourceManager::GetN64VibrationDevice(
|
||||
const Core::HID::VibrationDeviceHandle& handle) {
|
||||
return npad->GetN64VibrationDevice(handle);
|
||||
}
|
||||
|
||||
NpadVibrationDevice* ResourceManager::GetVibrationDevice(
|
||||
const Core::HID::VibrationDeviceHandle& handle) {
|
||||
return npad->GetVibrationDevice(handle);
|
||||
}
|
||||
|
||||
NpadGcVibrationDevice* ResourceManager::GetGcVibrationDevice(
|
||||
const Core::HID::VibrationDeviceHandle& handle) {
|
||||
return npad->GetGCVibrationDevice(handle);
|
||||
}
|
||||
|
||||
Result ResourceManager::SendVibrationValue(u64 aruid,
|
||||
const Core::HID::VibrationDeviceHandle& handle,
|
||||
const Core::HID::VibrationValue& value) {
|
||||
|
||||
bool has_active_aruid{};
|
||||
NpadVibrationDevice* device{nullptr};
|
||||
Core::HID::VibrationGcErmCommand gc_erm_command{};
|
||||
Result result = IsVibrationAruidActive(aruid, has_active_aruid);
|
||||
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
result = IsVibrationHandleValid(handle);
|
||||
}
|
||||
if (result.IsSuccess() && has_active_aruid) {
|
||||
device = GetVibrationDevice(handle);
|
||||
}
|
||||
if (device != nullptr) {
|
||||
result = device->SendVibrationValue(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||
u64 applet_resource_user_id)
|
||||
: ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id},
|
||||
|
|
|
@ -27,6 +27,7 @@ class Gesture;
|
|||
class Keyboard;
|
||||
class Mouse;
|
||||
class NPad;
|
||||
class NpadGcVibrationDevice;
|
||||
class Palma;
|
||||
class SevenSixAxis;
|
||||
class SixAxis;
|
||||
|
@ -86,6 +87,13 @@ public:
|
|||
void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||
|
||||
Result IsVibrationAruidActive(u64 aruid, bool& is_active);
|
||||
NpadN64VibrationDevice* GetN64VibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
NpadVibrationDevice* GetVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
NpadGcVibrationDevice* GetGcVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
||||
Result SendVibrationValue(u64 aruid, const Core::HID::VibrationDeviceHandle& handle,
|
||||
const Core::HID::VibrationValue& value);
|
||||
|
||||
private:
|
||||
Result CreateAppletResourceImpl(u64 aruid);
|
||||
|
||||
|
|
Loading…
Reference in New Issue