summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_controller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
-rw-r--r--src/core/hid/emulated_controller.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 128101e8c..89638cb85 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -93,6 +93,7 @@ void EmulatedController::ReloadFromSettings() {
93 motion_params[index] = Common::ParamPackage(player.motions[index]); 93 motion_params[index] = Common::ParamPackage(player.motions[index]);
94 } 94 }
95 95
96 controller.color_values = {};
96 controller.colors_state.fullkey = { 97 controller.colors_state.fullkey = {
97 .body = GetNpadColor(player.body_color_left), 98 .body = GetNpadColor(player.body_color_left),
98 .button = GetNpadColor(player.button_color_left), 99 .button = GetNpadColor(player.button_color_left),
@@ -132,6 +133,11 @@ void EmulatedController::LoadDevices() {
132 trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; 133 trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL];
133 trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR]; 134 trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR];
134 135
136 color_params[LeftIndex] = left_joycon;
137 color_params[RightIndex] = right_joycon;
138 color_params[LeftIndex].Set("color", true);
139 color_params[RightIndex].Set("color", true);
140
135 battery_params[LeftIndex] = left_joycon; 141 battery_params[LeftIndex] = left_joycon;
136 battery_params[RightIndex] = right_joycon; 142 battery_params[RightIndex] = right_joycon;
137 battery_params[LeftIndex].Set("battery", true); 143 battery_params[LeftIndex].Set("battery", true);
@@ -160,6 +166,7 @@ void EmulatedController::LoadDevices() {
160 Common::Input::CreateInputDevice); 166 Common::Input::CreateInputDevice);
161 std::ranges::transform(battery_params, battery_devices.begin(), 167 std::ranges::transform(battery_params, battery_devices.begin(),
162 Common::Input::CreateInputDevice); 168 Common::Input::CreateInputDevice);
169 std::ranges::transform(color_params, color_devices.begin(), Common::Input::CreateInputDevice);
163 camera_devices = Common::Input::CreateInputDevice(camera_params); 170 camera_devices = Common::Input::CreateInputDevice(camera_params);
164 ring_analog_device = Common::Input::CreateInputDevice(ring_params); 171 ring_analog_device = Common::Input::CreateInputDevice(ring_params);
165 nfc_devices = Common::Input::CreateInputDevice(nfc_params); 172 nfc_devices = Common::Input::CreateInputDevice(nfc_params);
@@ -324,6 +331,19 @@ void EmulatedController::ReloadInput() {
324 battery_devices[index]->ForceUpdate(); 331 battery_devices[index]->ForceUpdate();
325 } 332 }
326 333
334 for (std::size_t index = 0; index < color_devices.size(); ++index) {
335 if (!color_devices[index]) {
336 continue;
337 }
338 color_devices[index]->SetCallback({
339 .on_change =
340 [this, index](const Common::Input::CallbackStatus& callback) {
341 SetColors(callback, index);
342 },
343 });
344 color_devices[index]->ForceUpdate();
345 }
346
327 for (std::size_t index = 0; index < motion_devices.size(); ++index) { 347 for (std::size_t index = 0; index < motion_devices.size(); ++index) {
328 if (!motion_devices[index]) { 348 if (!motion_devices[index]) {
329 continue; 349 continue;
@@ -429,6 +449,9 @@ void EmulatedController::UnloadInput() {
429 for (auto& battery : battery_devices) { 449 for (auto& battery : battery_devices) {
430 battery.reset(); 450 battery.reset();
431 } 451 }
452 for (auto& color : color_devices) {
453 color.reset();
454 }
432 for (auto& output : output_devices) { 455 for (auto& output : output_devices) {
433 output.reset(); 456 output.reset();
434 } 457 }
@@ -458,6 +481,11 @@ void EmulatedController::EnableConfiguration() {
458void EmulatedController::DisableConfiguration() { 481void EmulatedController::DisableConfiguration() {
459 is_configuring = false; 482 is_configuring = false;
460 483
484 // Get Joycon colors before turning on the controller
485 for (const auto& color_device : color_devices) {
486 color_device->ForceUpdate();
487 }
488
461 // Apply temporary npad type to the real controller 489 // Apply temporary npad type to the real controller
462 if (tmp_npad_type != npad_type) { 490 if (tmp_npad_type != npad_type) {
463 if (is_connected) { 491 if (is_connected) {
@@ -926,6 +954,58 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback
926 TriggerOnChange(ControllerTriggerType::Motion, true); 954 TriggerOnChange(ControllerTriggerType::Motion, true);
927} 955}
928 956
957void EmulatedController::SetColors(const Common::Input::CallbackStatus& callback,
958 std::size_t index) {
959 if (index >= controller.color_values.size()) {
960 return;
961 }
962 std::unique_lock lock{mutex};
963 controller.color_values[index] = TransformToColor(callback);
964
965 if (is_configuring) {
966 lock.unlock();
967 TriggerOnChange(ControllerTriggerType::Color, false);
968 return;
969 }
970
971 if (controller.color_values[index].body == 0) {
972 return;
973 }
974
975 controller.colors_state.fullkey = {
976 .body = GetNpadColor(controller.color_values[index].body),
977 .button = GetNpadColor(controller.color_values[index].buttons),
978 };
979 if (npad_type == NpadStyleIndex::ProController) {
980 controller.colors_state.left = {
981 .body = GetNpadColor(controller.color_values[index].left_grip),
982 .button = GetNpadColor(controller.color_values[index].buttons),
983 };
984 controller.colors_state.right = {
985 .body = GetNpadColor(controller.color_values[index].right_grip),
986 .button = GetNpadColor(controller.color_values[index].buttons),
987 };
988 } else {
989 switch (index) {
990 case LeftIndex:
991 controller.colors_state.left = {
992 .body = GetNpadColor(controller.color_values[index].body),
993 .button = GetNpadColor(controller.color_values[index].buttons),
994 };
995 break;
996 case RightIndex:
997 controller.colors_state.right = {
998 .body = GetNpadColor(controller.color_values[index].body),
999 .button = GetNpadColor(controller.color_values[index].buttons),
1000 };
1001 break;
1002 }
1003 }
1004
1005 lock.unlock();
1006 TriggerOnChange(ControllerTriggerType::Color, true);
1007}
1008
929void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback, 1009void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback,
930 std::size_t index) { 1010 std::size_t index) {
931 if (index >= controller.battery_values.size()) { 1011 if (index >= controller.battery_values.size()) {