diff options
| author | 2024-01-16 12:17:18 -0600 | |
|---|---|---|
| committer | 2024-01-28 18:27:25 -0600 | |
| commit | 575183d6dcd8da9b10ee41e47be4b7d4f8631783 (patch) | |
| tree | d2898bdefae5be2fb68e7df97465422c0fae3991 /src/hid_core/resource_manager.cpp | |
| parent | Merge pull request #12555 from flodavid/fix-gamemode-setting (diff) | |
| download | yuzu-575183d6dcd8da9b10ee41e47be4b7d4f8631783.tar.gz yuzu-575183d6dcd8da9b10ee41e47be4b7d4f8631783.tar.xz yuzu-575183d6dcd8da9b10ee41e47be4b7d4f8631783.zip | |
service: hid: Fully implement touch resource
Diffstat (limited to 'src/hid_core/resource_manager.cpp')
| -rw-r--r-- | src/hid_core/resource_manager.cpp | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp index e78665d31..68ce2c7ae 100644 --- a/src/hid_core/resource_manager.cpp +++ b/src/hid_core/resource_manager.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "hid_core/resources/applet_resource.h" | 15 | #include "hid_core/resources/applet_resource.h" |
| 16 | #include "hid_core/resources/debug_pad/debug_pad.h" | 16 | #include "hid_core/resources/debug_pad/debug_pad.h" |
| 17 | #include "hid_core/resources/digitizer/digitizer.h" | 17 | #include "hid_core/resources/digitizer/digitizer.h" |
| 18 | #include "hid_core/resources/hid_firmware_settings.h" | ||
| 18 | #include "hid_core/resources/keyboard/keyboard.h" | 19 | #include "hid_core/resources/keyboard/keyboard.h" |
| 19 | #include "hid_core/resources/mouse/debug_mouse.h" | 20 | #include "hid_core/resources/mouse/debug_mouse.h" |
| 20 | #include "hid_core/resources/mouse/mouse.h" | 21 | #include "hid_core/resources/mouse/mouse.h" |
| @@ -29,6 +30,8 @@ | |||
| 29 | #include "hid_core/resources/system_buttons/sleep_button.h" | 30 | #include "hid_core/resources/system_buttons/sleep_button.h" |
| 30 | #include "hid_core/resources/touch_screen/gesture.h" | 31 | #include "hid_core/resources/touch_screen/gesture.h" |
| 31 | #include "hid_core/resources/touch_screen/touch_screen.h" | 32 | #include "hid_core/resources/touch_screen/touch_screen.h" |
| 33 | #include "hid_core/resources/touch_screen/touch_screen_driver.h" | ||
| 34 | #include "hid_core/resources/touch_screen/touch_screen_resource.h" | ||
| 32 | #include "hid_core/resources/unique_pad/unique_pad.h" | 35 | #include "hid_core/resources/unique_pad/unique_pad.h" |
| 33 | #include "hid_core/resources/vibration/gc_vibration_device.h" | 36 | #include "hid_core/resources/vibration/gc_vibration_device.h" |
| 34 | #include "hid_core/resources/vibration/n64_vibration_device.h" | 37 | #include "hid_core/resources/vibration/n64_vibration_device.h" |
| @@ -45,12 +48,16 @@ constexpr auto default_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; // | |||
| 45 | constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz) | 48 | constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz) |
| 46 | constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz) | 49 | constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz) |
| 47 | 50 | ||
| 48 | ResourceManager::ResourceManager(Core::System& system_) | 51 | ResourceManager::ResourceManager(Core::System& system_, |
| 49 | : system{system_}, service_context{system_, "hid"} { | 52 | std::shared_ptr<HidFirmwareSettings> settings) |
| 53 | : firmware_settings{settings}, system{system_}, service_context{system_, "hid"} { | ||
| 50 | applet_resource = std::make_shared<AppletResource>(system); | 54 | applet_resource = std::make_shared<AppletResource>(system); |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | ResourceManager::~ResourceManager() = default; | 57 | ResourceManager::~ResourceManager() { |
| 58 | system.CoreTiming().UnscheduleEvent(touch_update_event); | ||
| 59 | input_event->Finalize(); | ||
| 60 | }; | ||
| 54 | 61 | ||
| 55 | void ResourceManager::Initialize() { | 62 | void ResourceManager::Initialize() { |
| 56 | if (is_initialized) { | 63 | if (is_initialized) { |
| @@ -59,7 +66,9 @@ void ResourceManager::Initialize() { | |||
| 59 | 66 | ||
| 60 | system.HIDCore().ReloadInputDevices(); | 67 | system.HIDCore().ReloadInputDevices(); |
| 61 | 68 | ||
| 62 | handheld_config = std::make_shared<HandheldConfig>(); | 69 | input_event = service_context.CreateEvent("ResourceManager:InputEvent"); |
| 70 | |||
| 71 | InitializeHandheldConfig(); | ||
| 63 | InitializeHidCommonSampler(); | 72 | InitializeHidCommonSampler(); |
| 64 | InitializeTouchScreenSampler(); | 73 | InitializeTouchScreenSampler(); |
| 65 | InitializeConsoleSixAxisSampler(); | 74 | InitializeConsoleSixAxisSampler(); |
| @@ -154,6 +163,7 @@ Result ResourceManager::CreateAppletResource(u64 aruid) { | |||
| 154 | npad->Activate(); | 163 | npad->Activate(); |
| 155 | six_axis->Activate(); | 164 | six_axis->Activate(); |
| 156 | touch_screen->Activate(); | 165 | touch_screen->Activate(); |
| 166 | gesture->Activate(); | ||
| 157 | 167 | ||
| 158 | return GetNpad()->ActivateNpadResource(aruid); | 168 | return GetNpad()->ActivateNpadResource(aruid); |
| 159 | } | 169 | } |
| @@ -163,6 +173,17 @@ Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { | |||
| 163 | return applet_resource->CreateAppletResource(aruid); | 173 | return applet_resource->CreateAppletResource(aruid); |
| 164 | } | 174 | } |
| 165 | 175 | ||
| 176 | void ResourceManager::InitializeHandheldConfig() { | ||
| 177 | handheld_config = std::make_shared<HandheldConfig>(); | ||
| 178 | handheld_config->is_handheld_hid_enabled = true; | ||
| 179 | handheld_config->is_joycon_rail_enabled = true; | ||
| 180 | handheld_config->is_force_handheld_style_vibration = false; | ||
| 181 | handheld_config->is_force_handheld = false; | ||
| 182 | if (firmware_settings->IsHandheldForced()) { | ||
| 183 | handheld_config->is_joycon_rail_enabled = false; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 166 | void ResourceManager::InitializeHidCommonSampler() { | 187 | void ResourceManager::InitializeHidCommonSampler() { |
| 167 | debug_pad = std::make_shared<DebugPad>(system.HIDCore()); | 188 | debug_pad = std::make_shared<DebugPad>(system.HIDCore()); |
| 168 | mouse = std::make_shared<Mouse>(system.HIDCore()); | 189 | mouse = std::make_shared<Mouse>(system.HIDCore()); |
| @@ -170,7 +191,6 @@ void ResourceManager::InitializeHidCommonSampler() { | |||
| 170 | keyboard = std::make_shared<Keyboard>(system.HIDCore()); | 191 | keyboard = std::make_shared<Keyboard>(system.HIDCore()); |
| 171 | unique_pad = std::make_shared<UniquePad>(system.HIDCore()); | 192 | unique_pad = std::make_shared<UniquePad>(system.HIDCore()); |
| 172 | npad = std::make_shared<NPad>(system.HIDCore(), service_context); | 193 | npad = std::make_shared<NPad>(system.HIDCore(), service_context); |
| 173 | gesture = std::make_shared<Gesture>(system.HIDCore()); | ||
| 174 | home_button = std::make_shared<HomeButton>(system.HIDCore()); | 194 | home_button = std::make_shared<HomeButton>(system.HIDCore()); |
| 175 | sleep_button = std::make_shared<SleepButton>(system.HIDCore()); | 195 | sleep_button = std::make_shared<SleepButton>(system.HIDCore()); |
| 176 | capture_button = std::make_shared<CaptureButton>(system.HIDCore()); | 196 | capture_button = std::make_shared<CaptureButton>(system.HIDCore()); |
| @@ -185,7 +205,8 @@ void ResourceManager::InitializeHidCommonSampler() { | |||
| 185 | 205 | ||
| 186 | const auto settings = | 206 | const auto settings = |
| 187 | system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true); | 207 | system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true); |
| 188 | npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, settings); | 208 | npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, input_event, |
| 209 | &input_mutex, settings); | ||
| 189 | 210 | ||
| 190 | six_axis->SetAppletResource(applet_resource, &shared_mutex); | 211 | six_axis->SetAppletResource(applet_resource, &shared_mutex); |
| 191 | mouse->SetAppletResource(applet_resource, &shared_mutex); | 212 | mouse->SetAppletResource(applet_resource, &shared_mutex); |
| @@ -196,11 +217,25 @@ void ResourceManager::InitializeHidCommonSampler() { | |||
| 196 | } | 217 | } |
| 197 | 218 | ||
| 198 | void ResourceManager::InitializeTouchScreenSampler() { | 219 | void ResourceManager::InitializeTouchScreenSampler() { |
| 199 | gesture = std::make_shared<Gesture>(system.HIDCore()); | 220 | // This is nn.hid.TouchScreenSampler |
| 200 | touch_screen = std::make_shared<TouchScreen>(system.HIDCore()); | 221 | touch_resource = std::make_shared<TouchResource>(system); |
| 222 | touch_driver = std::make_shared<TouchDriver>(system.HIDCore()); | ||
| 223 | touch_screen = std::make_shared<TouchScreen>(touch_resource); | ||
| 224 | gesture = std::make_shared<Gesture>(touch_resource); | ||
| 225 | |||
| 226 | touch_update_event = Core::Timing::CreateEvent( | ||
| 227 | "HID::TouchUpdateCallback", | ||
| 228 | [this](s64 time, | ||
| 229 | std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { | ||
| 230 | touch_resource->OnTouchUpdate(time); | ||
| 231 | return std::nullopt; | ||
| 232 | }); | ||
| 201 | 233 | ||
| 202 | touch_screen->SetAppletResource(applet_resource, &shared_mutex); | 234 | touch_resource->SetTouchDriver(touch_driver); |
| 203 | gesture->SetAppletResource(applet_resource, &shared_mutex); | 235 | touch_resource->SetAppletResource(applet_resource, &shared_mutex); |
| 236 | touch_resource->SetInputEvent(input_event, &input_mutex); | ||
| 237 | touch_resource->SetHandheldConfig(handheld_config); | ||
| 238 | touch_resource->SetTimerEvent(touch_update_event); | ||
| 204 | } | 239 | } |
| 205 | 240 | ||
| 206 | void ResourceManager::InitializeConsoleSixAxisSampler() { | 241 | void ResourceManager::InitializeConsoleSixAxisSampler() { |
| @@ -388,13 +423,15 @@ Result ResourceManager::SendVibrationValue(u64 aruid, | |||
| 388 | return result; | 423 | return result; |
| 389 | } | 424 | } |
| 390 | 425 | ||
| 426 | Result ResourceManager::GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const { | ||
| 427 | return ResultSuccess; | ||
| 428 | } | ||
| 429 | |||
| 391 | void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) { | 430 | void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) { |
| 392 | auto& core_timing = system.CoreTiming(); | 431 | auto& core_timing = system.CoreTiming(); |
| 393 | debug_pad->OnUpdate(core_timing); | 432 | debug_pad->OnUpdate(core_timing); |
| 394 | digitizer->OnUpdate(core_timing); | 433 | digitizer->OnUpdate(core_timing); |
| 395 | unique_pad->OnUpdate(core_timing); | 434 | unique_pad->OnUpdate(core_timing); |
| 396 | gesture->OnUpdate(core_timing); | ||
| 397 | touch_screen->OnUpdate(core_timing); | ||
| 398 | palma->OnUpdate(core_timing); | 435 | palma->OnUpdate(core_timing); |
| 399 | home_button->OnUpdate(core_timing); | 436 | home_button->OnUpdate(core_timing); |
| 400 | sleep_button->OnUpdate(core_timing); | 437 | sleep_button->OnUpdate(core_timing); |