diff options
| author | 2022-06-18 23:36:29 -0500 | |
|---|---|---|
| committer | 2022-07-23 19:40:25 -0500 | |
| commit | 57311b2c8b1b9ee1d2c5775866e9591605815246 (patch) | |
| tree | 52280f5afc5443a3fddb337cbca71e6e0d4707ab | |
| parent | yuzu: Hook qt camera to camera driver (diff) | |
| download | yuzu-57311b2c8b1b9ee1d2c5775866e9591605815246.tar.gz yuzu-57311b2c8b1b9ee1d2c5775866e9591605815246.tar.xz yuzu-57311b2c8b1b9ee1d2c5775866e9591605815246.zip | |
core: hid: Add cammera support
Diffstat (limited to '')
| -rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 59 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 40 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 14 | ||||
| -rw-r--r-- | src/core/hid/input_converter.h | 8 | ||||
| -rw-r--r-- | src/core/hid/irs_types.h | 304 |
6 files changed, 423 insertions, 3 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 11d554bad..1f8439f91 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -158,6 +158,7 @@ add_library(core STATIC | |||
| 158 | hid/input_converter.h | 158 | hid/input_converter.h |
| 159 | hid/input_interpreter.cpp | 159 | hid/input_interpreter.cpp |
| 160 | hid/input_interpreter.h | 160 | hid/input_interpreter.h |
| 161 | hid/irs_types.h | ||
| 161 | hid/motion_input.cpp | 162 | hid/motion_input.cpp |
| 162 | hid/motion_input.h | 163 | hid/motion_input.h |
| 163 | hle/api_version.h | 164 | hle/api_version.h |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index bd2384515..8c3895937 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -126,10 +126,14 @@ void EmulatedController::LoadDevices() { | |||
| 126 | battery_params[LeftIndex].Set("battery", true); | 126 | battery_params[LeftIndex].Set("battery", true); |
| 127 | battery_params[RightIndex].Set("battery", true); | 127 | battery_params[RightIndex].Set("battery", true); |
| 128 | 128 | ||
| 129 | camera_params = Common::ParamPackage{"engine:camera,camera:1"}; | ||
| 130 | |||
| 129 | output_params[LeftIndex] = left_joycon; | 131 | output_params[LeftIndex] = left_joycon; |
| 130 | output_params[RightIndex] = right_joycon; | 132 | output_params[RightIndex] = right_joycon; |
| 133 | output_params[2] = camera_params; | ||
| 131 | output_params[LeftIndex].Set("output", true); | 134 | output_params[LeftIndex].Set("output", true); |
| 132 | output_params[RightIndex].Set("output", true); | 135 | output_params[RightIndex].Set("output", true); |
| 136 | output_params[2].Set("output", true); | ||
| 133 | 137 | ||
| 134 | LoadTASParams(); | 138 | LoadTASParams(); |
| 135 | 139 | ||
| @@ -146,6 +150,7 @@ void EmulatedController::LoadDevices() { | |||
| 146 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 150 | Common::Input::CreateDevice<Common::Input::InputDevice>); |
| 147 | std::transform(battery_params.begin(), battery_params.end(), battery_devices.begin(), | 151 | std::transform(battery_params.begin(), battery_params.end(), battery_devices.begin(), |
| 148 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 152 | Common::Input::CreateDevice<Common::Input::InputDevice>); |
| 153 | camera_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(camera_params); | ||
| 149 | std::transform(output_params.begin(), output_params.end(), output_devices.begin(), | 154 | std::transform(output_params.begin(), output_params.end(), output_devices.begin(), |
| 150 | Common::Input::CreateDevice<Common::Input::OutputDevice>); | 155 | Common::Input::CreateDevice<Common::Input::OutputDevice>); |
| 151 | 156 | ||
| @@ -267,6 +272,14 @@ void EmulatedController::ReloadInput() { | |||
| 267 | motion_devices[index]->ForceUpdate(); | 272 | motion_devices[index]->ForceUpdate(); |
| 268 | } | 273 | } |
| 269 | 274 | ||
| 275 | if (camera_devices) { | ||
| 276 | camera_devices->SetCallback({ | ||
| 277 | .on_change = | ||
| 278 | [this](const Common::Input::CallbackStatus& callback) { SetCamera(callback); }, | ||
| 279 | }); | ||
| 280 | camera_devices->ForceUpdate(); | ||
| 281 | } | ||
| 282 | |||
| 270 | // Use a common UUID for TAS | 283 | // Use a common UUID for TAS |
| 271 | static constexpr Common::UUID TAS_UUID = Common::UUID{ | 284 | static constexpr Common::UUID TAS_UUID = Common::UUID{ |
| 272 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; | 285 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; |
| @@ -851,6 +864,25 @@ void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callbac | |||
| 851 | TriggerOnChange(ControllerTriggerType::Battery, true); | 864 | TriggerOnChange(ControllerTriggerType::Battery, true); |
| 852 | } | 865 | } |
| 853 | 866 | ||
| 867 | void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback) { | ||
| 868 | std::unique_lock lock{mutex}; | ||
| 869 | controller.camera_values = TransformToCamera(callback); | ||
| 870 | |||
| 871 | if (is_configuring) { | ||
| 872 | lock.unlock(); | ||
| 873 | TriggerOnChange(ControllerTriggerType::IrSensor, false); | ||
| 874 | return; | ||
| 875 | } | ||
| 876 | |||
| 877 | controller.camera_state.sample++; | ||
| 878 | controller.camera_state.format = | ||
| 879 | static_cast<Core::IrSensor::ImageTransferProcessorFormat>(controller.camera_values.format); | ||
| 880 | controller.camera_state.data = controller.camera_values.data; | ||
| 881 | |||
| 882 | lock.unlock(); | ||
| 883 | TriggerOnChange(ControllerTriggerType::IrSensor, true); | ||
| 884 | } | ||
| 885 | |||
| 854 | bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) { | 886 | bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) { |
| 855 | if (device_index >= output_devices.size()) { | 887 | if (device_index >= output_devices.size()) { |
| 856 | return false; | 888 | return false; |
| @@ -928,6 +960,23 @@ bool EmulatedController::SetPollingMode(Common::Input::PollingMode polling_mode) | |||
| 928 | return output_device->SetPollingMode(polling_mode) == Common::Input::PollingError::None; | 960 | return output_device->SetPollingMode(polling_mode) == Common::Input::PollingError::None; |
| 929 | } | 961 | } |
| 930 | 962 | ||
| 963 | bool EmulatedController::SetCameraFormat( | ||
| 964 | Core::IrSensor::ImageTransferProcessorFormat camera_format) { | ||
| 965 | LOG_INFO(Service_HID, "Set camera format {}", camera_format); | ||
| 966 | |||
| 967 | auto& right_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; | ||
| 968 | auto& camera_output_device = output_devices[2]; | ||
| 969 | |||
| 970 | if (right_output_device->SetCameraFormat(static_cast<Common::Input::CameraFormat>( | ||
| 971 | camera_format)) == Common::Input::CameraError::None) { | ||
| 972 | return true; | ||
| 973 | } | ||
| 974 | |||
| 975 | // Fallback to Qt camera if native device doesn't have support | ||
| 976 | return camera_output_device->SetCameraFormat(static_cast<Common::Input::CameraFormat>( | ||
| 977 | camera_format)) == Common::Input::CameraError::None; | ||
| 978 | } | ||
| 979 | |||
| 931 | void EmulatedController::SetLedPattern() { | 980 | void EmulatedController::SetLedPattern() { |
| 932 | for (auto& device : output_devices) { | 981 | for (auto& device : output_devices) { |
| 933 | if (!device) { | 982 | if (!device) { |
| @@ -1163,6 +1212,11 @@ BatteryValues EmulatedController::GetBatteryValues() const { | |||
| 1163 | return controller.battery_values; | 1212 | return controller.battery_values; |
| 1164 | } | 1213 | } |
| 1165 | 1214 | ||
| 1215 | CameraValues EmulatedController::GetCameraValues() const { | ||
| 1216 | std::scoped_lock lock{mutex}; | ||
| 1217 | return controller.camera_values; | ||
| 1218 | } | ||
| 1219 | |||
| 1166 | HomeButtonState EmulatedController::GetHomeButtons() const { | 1220 | HomeButtonState EmulatedController::GetHomeButtons() const { |
| 1167 | std::scoped_lock lock{mutex}; | 1221 | std::scoped_lock lock{mutex}; |
| 1168 | if (is_configuring) { | 1222 | if (is_configuring) { |
| @@ -1251,6 +1305,11 @@ BatteryLevelState EmulatedController::GetBattery() const { | |||
| 1251 | return controller.battery_state; | 1305 | return controller.battery_state; |
| 1252 | } | 1306 | } |
| 1253 | 1307 | ||
| 1308 | const CameraState& EmulatedController::GetCamera() const { | ||
| 1309 | std::scoped_lock lock{mutex}; | ||
| 1310 | return controller.camera_state; | ||
| 1311 | } | ||
| 1312 | |||
| 1254 | void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npad_service_update) { | 1313 | void EmulatedController::TriggerOnChange(ControllerTriggerType type, bool is_npad_service_update) { |
| 1255 | std::scoped_lock lock{callback_mutex}; | 1314 | std::scoped_lock lock{callback_mutex}; |
| 1256 | for (const auto& poller_pair : callback_list) { | 1315 | for (const auto& poller_pair : callback_list) { |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 3f02ed3c0..823c1700c 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -15,10 +15,12 @@ | |||
| 15 | #include "common/settings.h" | 15 | #include "common/settings.h" |
| 16 | #include "common/vector_math.h" | 16 | #include "common/vector_math.h" |
| 17 | #include "core/hid/hid_types.h" | 17 | #include "core/hid/hid_types.h" |
| 18 | #include "core/hid/irs_types.h" | ||
| 18 | #include "core/hid/motion_input.h" | 19 | #include "core/hid/motion_input.h" |
| 19 | 20 | ||
| 20 | namespace Core::HID { | 21 | namespace Core::HID { |
| 21 | const std::size_t max_emulated_controllers = 2; | 22 | const std::size_t max_emulated_controllers = 2; |
| 23 | const std::size_t output_devices = 3; | ||
| 22 | struct ControllerMotionInfo { | 24 | struct ControllerMotionInfo { |
| 23 | Common::Input::MotionStatus raw_status{}; | 25 | Common::Input::MotionStatus raw_status{}; |
| 24 | MotionInput emulated{}; | 26 | MotionInput emulated{}; |
| @@ -34,15 +36,16 @@ using TriggerDevices = | |||
| 34 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; | 36 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; |
| 35 | using BatteryDevices = | 37 | using BatteryDevices = |
| 36 | std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; | 38 | std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; |
| 37 | using OutputDevices = | 39 | using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; |
| 38 | std::array<std::unique_ptr<Common::Input::OutputDevice>, max_emulated_controllers>; | 40 | using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices>; |
| 39 | 41 | ||
| 40 | using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; | 42 | using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; |
| 41 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; | 43 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; |
| 42 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; | 44 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; |
| 43 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; | 45 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; |
| 44 | using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; | 46 | using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; |
| 45 | using OutputParams = std::array<Common::ParamPackage, max_emulated_controllers>; | 47 | using CameraParams = Common::ParamPackage; |
| 48 | using OutputParams = std::array<Common::ParamPackage, output_devices>; | ||
| 46 | 49 | ||
| 47 | using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>; | 50 | using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>; |
| 48 | using SticksValues = std::array<Common::Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; | 51 | using SticksValues = std::array<Common::Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; |
| @@ -51,6 +54,7 @@ using TriggerValues = | |||
| 51 | using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; | 54 | using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; |
| 52 | using ColorValues = std::array<Common::Input::BodyColorStatus, max_emulated_controllers>; | 55 | using ColorValues = std::array<Common::Input::BodyColorStatus, max_emulated_controllers>; |
| 53 | using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>; | 56 | using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>; |
| 57 | using CameraValues = Common::Input::CameraStatus; | ||
| 54 | using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>; | 58 | using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>; |
| 55 | 59 | ||
| 56 | struct AnalogSticks { | 60 | struct AnalogSticks { |
| @@ -70,6 +74,12 @@ struct BatteryLevelState { | |||
| 70 | NpadPowerInfo right{}; | 74 | NpadPowerInfo right{}; |
| 71 | }; | 75 | }; |
| 72 | 76 | ||
| 77 | struct CameraState { | ||
| 78 | Core::IrSensor::ImageTransferProcessorFormat format{}; | ||
| 79 | std::vector<u8> data{}; | ||
| 80 | std::size_t sample{}; | ||
| 81 | }; | ||
| 82 | |||
| 73 | struct ControllerMotion { | 83 | struct ControllerMotion { |
| 74 | Common::Vec3f accel{}; | 84 | Common::Vec3f accel{}; |
| 75 | Common::Vec3f gyro{}; | 85 | Common::Vec3f gyro{}; |
| @@ -96,6 +106,7 @@ struct ControllerStatus { | |||
| 96 | ColorValues color_values{}; | 106 | ColorValues color_values{}; |
| 97 | BatteryValues battery_values{}; | 107 | BatteryValues battery_values{}; |
| 98 | VibrationValues vibration_values{}; | 108 | VibrationValues vibration_values{}; |
| 109 | CameraValues camera_values{}; | ||
| 99 | 110 | ||
| 100 | // Data for HID serices | 111 | // Data for HID serices |
| 101 | HomeButtonState home_button_state{}; | 112 | HomeButtonState home_button_state{}; |
| @@ -107,6 +118,7 @@ struct ControllerStatus { | |||
| 107 | NpadGcTriggerState gc_trigger_state{}; | 118 | NpadGcTriggerState gc_trigger_state{}; |
| 108 | ControllerColors colors_state{}; | 119 | ControllerColors colors_state{}; |
| 109 | BatteryLevelState battery_state{}; | 120 | BatteryLevelState battery_state{}; |
| 121 | CameraState camera_state{}; | ||
| 110 | }; | 122 | }; |
| 111 | 123 | ||
| 112 | enum class ControllerTriggerType { | 124 | enum class ControllerTriggerType { |
| @@ -117,6 +129,7 @@ enum class ControllerTriggerType { | |||
| 117 | Color, | 129 | Color, |
| 118 | Battery, | 130 | Battery, |
| 119 | Vibration, | 131 | Vibration, |
| 132 | IrSensor, | ||
| 120 | Connected, | 133 | Connected, |
| 121 | Disconnected, | 134 | Disconnected, |
| 122 | Type, | 135 | Type, |
| @@ -269,6 +282,9 @@ public: | |||
| 269 | /// Returns the latest battery status from the controller with parameters | 282 | /// Returns the latest battery status from the controller with parameters |
| 270 | BatteryValues GetBatteryValues() const; | 283 | BatteryValues GetBatteryValues() const; |
| 271 | 284 | ||
| 285 | /// Returns the latest camera status from the controller with parameters | ||
| 286 | CameraValues GetCameraValues() const; | ||
| 287 | |||
| 272 | /// Returns the latest status of button input for the hid::HomeButton service | 288 | /// Returns the latest status of button input for the hid::HomeButton service |
| 273 | HomeButtonState GetHomeButtons() const; | 289 | HomeButtonState GetHomeButtons() const; |
| 274 | 290 | ||
| @@ -296,6 +312,9 @@ public: | |||
| 296 | /// Returns the latest battery status from the controller | 312 | /// Returns the latest battery status from the controller |
| 297 | BatteryLevelState GetBattery() const; | 313 | BatteryLevelState GetBattery() const; |
| 298 | 314 | ||
| 315 | /// Returns the latest camera status from the controller | ||
| 316 | const CameraState& GetCamera() const; | ||
| 317 | |||
| 299 | /** | 318 | /** |
| 300 | * Sends a specific vibration to the output device | 319 | * Sends a specific vibration to the output device |
| 301 | * @return true if vibration had no errors | 320 | * @return true if vibration had no errors |
| @@ -315,6 +334,13 @@ public: | |||
| 315 | */ | 334 | */ |
| 316 | bool SetPollingMode(Common::Input::PollingMode polling_mode); | 335 | bool SetPollingMode(Common::Input::PollingMode polling_mode); |
| 317 | 336 | ||
| 337 | /** | ||
| 338 | * Sets the desired camera format to be polled from a controller | ||
| 339 | * @param camera_format size of each frame | ||
| 340 | * @return true if SetCameraFormat was successfull | ||
| 341 | */ | ||
| 342 | bool SetCameraFormat(Core::IrSensor::ImageTransferProcessorFormat camera_format); | ||
| 343 | |||
| 318 | /// Returns the led pattern corresponding to this emulated controller | 344 | /// Returns the led pattern corresponding to this emulated controller |
| 319 | LedPattern GetLedPattern() const; | 345 | LedPattern GetLedPattern() const; |
| 320 | 346 | ||
| @@ -393,6 +419,12 @@ private: | |||
| 393 | void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index); | 419 | void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 394 | 420 | ||
| 395 | /** | 421 | /** |
| 422 | * Updates the camera status of the controller | ||
| 423 | * @param callback A CallbackStatus containing the camera status | ||
| 424 | */ | ||
| 425 | void SetCamera(const Common::Input::CallbackStatus& callback); | ||
| 426 | |||
| 427 | /** | ||
| 396 | * Triggers a callback that something has changed on the controller status | 428 | * Triggers a callback that something has changed on the controller status |
| 397 | * @param type Input type of the event to trigger | 429 | * @param type Input type of the event to trigger |
| 398 | * @param is_service_update indicates if this event should only be sent to HID services | 430 | * @param is_service_update indicates if this event should only be sent to HID services |
| @@ -417,6 +449,7 @@ private: | |||
| 417 | ControllerMotionParams motion_params; | 449 | ControllerMotionParams motion_params; |
| 418 | TriggerParams trigger_params; | 450 | TriggerParams trigger_params; |
| 419 | BatteryParams battery_params; | 451 | BatteryParams battery_params; |
| 452 | CameraParams camera_params; | ||
| 420 | OutputParams output_params; | 453 | OutputParams output_params; |
| 421 | 454 | ||
| 422 | ButtonDevices button_devices; | 455 | ButtonDevices button_devices; |
| @@ -424,6 +457,7 @@ private: | |||
| 424 | ControllerMotionDevices motion_devices; | 457 | ControllerMotionDevices motion_devices; |
| 425 | TriggerDevices trigger_devices; | 458 | TriggerDevices trigger_devices; |
| 426 | BatteryDevices battery_devices; | 459 | BatteryDevices battery_devices; |
| 460 | CameraDevices camera_devices; | ||
| 427 | OutputDevices output_devices; | 461 | OutputDevices output_devices; |
| 428 | 462 | ||
| 429 | // TAS related variables | 463 | // TAS related variables |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 18d9f042d..68d143a01 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -270,6 +270,20 @@ Common::Input::AnalogStatus TransformToAnalog(const Common::Input::CallbackStatu | |||
| 270 | return status; | 270 | return status; |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | Common::Input::CameraStatus TransformToCamera(const Common::Input::CallbackStatus& callback) { | ||
| 274 | Common::Input::CameraStatus camera{}; | ||
| 275 | switch (callback.type) { | ||
| 276 | case Common::Input::InputType::IrSensor: | ||
| 277 | camera = callback.camera_status; | ||
| 278 | break; | ||
| 279 | default: | ||
| 280 | LOG_ERROR(Input, "Conversion from type {} to camera not implemented", callback.type); | ||
| 281 | break; | ||
| 282 | } | ||
| 283 | |||
| 284 | return camera; | ||
| 285 | } | ||
| 286 | |||
| 273 | void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value) { | 287 | void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value) { |
| 274 | const auto& properties = analog.properties; | 288 | const auto& properties = analog.properties; |
| 275 | float& raw_value = analog.raw_value; | 289 | float& raw_value = analog.raw_value; |
diff --git a/src/core/hid/input_converter.h b/src/core/hid/input_converter.h index 2be36889f..143c50cc0 100644 --- a/src/core/hid/input_converter.h +++ b/src/core/hid/input_converter.h | |||
| @@ -77,6 +77,14 @@ Common::Input::TriggerStatus TransformToTrigger(const Common::Input::CallbackSta | |||
| 77 | Common::Input::AnalogStatus TransformToAnalog(const Common::Input::CallbackStatus& callback); | 77 | Common::Input::AnalogStatus TransformToAnalog(const Common::Input::CallbackStatus& callback); |
| 78 | 78 | ||
| 79 | /** | 79 | /** |
| 80 | * Converts raw input data into a valid camera status. | ||
| 81 | * | ||
| 82 | * @param callback Supported callbacks: Camera. | ||
| 83 | * @return A valid CameraObject object. | ||
| 84 | */ | ||
| 85 | Common::Input::CameraStatus TransformToCamera(const Common::Input::CallbackStatus& callback); | ||
| 86 | |||
| 87 | /** | ||
| 80 | * Converts raw analog data into a valid analog value | 88 | * Converts raw analog data into a valid analog value |
| 81 | * @param analog An analog object containing raw data and properties | 89 | * @param analog An analog object containing raw data and properties |
| 82 | * @param clamp_value determines if the value needs to be clamped between -1.0f and 1.0f. | 90 | * @param clamp_value determines if the value needs to be clamped between -1.0f and 1.0f. |
diff --git a/src/core/hid/irs_types.h b/src/core/hid/irs_types.h new file mode 100644 index 000000000..c73d008a0 --- /dev/null +++ b/src/core/hid/irs_types.h | |||
| @@ -0,0 +1,304 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "core/hid/hid_types.h" | ||
| 9 | |||
| 10 | namespace Core::IrSensor { | ||
| 11 | |||
| 12 | // This is nn::irsensor::CameraAmbientNoiseLevel | ||
| 13 | enum class CameraAmbientNoiseLevel : u32 { | ||
| 14 | Low, | ||
| 15 | Medium, | ||
| 16 | High, | ||
| 17 | Unkown3, // This level can't be reached | ||
| 18 | }; | ||
| 19 | |||
| 20 | // This is nn::irsensor::CameraLightTarget | ||
| 21 | enum class CameraLightTarget : u32 { | ||
| 22 | AllLeds, | ||
| 23 | BrightLeds, | ||
| 24 | DimLeds, | ||
| 25 | None, | ||
| 26 | }; | ||
| 27 | |||
| 28 | // This is nn::irsensor::PackedCameraLightTarget | ||
| 29 | enum class PackedCameraLightTarget : u8 { | ||
| 30 | AllLeds, | ||
| 31 | BrightLeds, | ||
| 32 | DimLeds, | ||
| 33 | None, | ||
| 34 | }; | ||
| 35 | |||
| 36 | // This is nn::irsensor::AdaptiveClusteringMode | ||
| 37 | enum class AdaptiveClusteringMode : u32 { | ||
| 38 | StaticFov, | ||
| 39 | DynamicFov, | ||
| 40 | }; | ||
| 41 | |||
| 42 | // This is nn::irsensor::AdaptiveClusteringTargetDistance | ||
| 43 | enum class AdaptiveClusteringTargetDistance : u32 { | ||
| 44 | Near, | ||
| 45 | Middle, | ||
| 46 | Far, | ||
| 47 | }; | ||
| 48 | |||
| 49 | // This is nn::irsensor::ImageTransferProcessorFormat | ||
| 50 | enum class ImageTransferProcessorFormat : u32 { | ||
| 51 | Size320x240, | ||
| 52 | Size160x120, | ||
| 53 | Size80x60, | ||
| 54 | Size40x30, | ||
| 55 | Size20x15, | ||
| 56 | }; | ||
| 57 | |||
| 58 | // This is nn::irsensor::PackedImageTransferProcessorFormat | ||
| 59 | enum class PackedImageTransferProcessorFormat : u8 { | ||
| 60 | Size320x240, | ||
| 61 | Size160x120, | ||
| 62 | Size80x60, | ||
| 63 | Size40x30, | ||
| 64 | Size20x15, | ||
| 65 | }; | ||
| 66 | |||
| 67 | // This is nn::irsensor::IrCameraStatus | ||
| 68 | enum class IrCameraStatus : u32 { | ||
| 69 | Available, | ||
| 70 | Unsupported, | ||
| 71 | Unconnected, | ||
| 72 | }; | ||
| 73 | |||
| 74 | // This is nn::irsensor::IrCameraInternalStatus | ||
| 75 | enum class IrCameraInternalStatus : u32 { | ||
| 76 | Stopped, | ||
| 77 | FirmwareUpdateNeeded, | ||
| 78 | Unkown2, | ||
| 79 | Unkown3, | ||
| 80 | Unkown4, | ||
| 81 | FirmwareVersionRequested, | ||
| 82 | FirmwareVersionIsInvalid, | ||
| 83 | Ready, | ||
| 84 | Setting, | ||
| 85 | }; | ||
| 86 | |||
| 87 | // This is nn::irsensor::detail::StatusManager::IrSensorMode | ||
| 88 | enum class IrSensorMode : u64 { | ||
| 89 | None, | ||
| 90 | MomentProcessor, | ||
| 91 | ClusteringProcessor, | ||
| 92 | ImageTransferProcessor, | ||
| 93 | PointingProcessorMarker, | ||
| 94 | TeraPluginProcessor, | ||
| 95 | IrLedProcessor, | ||
| 96 | }; | ||
| 97 | |||
| 98 | // This is nn::irsensor::ImageProcessorStatus | ||
| 99 | enum ImageProcessorStatus : u32 { | ||
| 100 | Stopped, | ||
| 101 | Running, | ||
| 102 | }; | ||
| 103 | |||
| 104 | // This is nn::irsensor::HandAnalysisMode | ||
| 105 | enum class HandAnalysisMode : u32 { | ||
| 106 | None, | ||
| 107 | Silhouette, | ||
| 108 | Image, | ||
| 109 | SilhoueteAndImage, | ||
| 110 | SilhuetteOnly, | ||
| 111 | }; | ||
| 112 | |||
| 113 | // This is nn::irsensor::IrSensorFunctionLevel | ||
| 114 | enum class IrSensorFunctionLevel : u8 { | ||
| 115 | unknown0, | ||
| 116 | unknown1, | ||
| 117 | unknown2, | ||
| 118 | unknown3, | ||
| 119 | unknown4, | ||
| 120 | }; | ||
| 121 | |||
| 122 | // This is nn::irsensor::MomentProcessorPreprocess | ||
| 123 | enum class MomentProcessorPreprocess : u32 { | ||
| 124 | Unkown0, | ||
| 125 | Unkown1, | ||
| 126 | }; | ||
| 127 | |||
| 128 | // This is nn::irsensor::PackedMomentProcessorPreprocess | ||
| 129 | enum class PackedMomentProcessorPreprocess : u8 { | ||
| 130 | Unkown0, | ||
| 131 | Unkown1, | ||
| 132 | }; | ||
| 133 | |||
| 134 | // This is nn::irsensor::PointingStatus | ||
| 135 | enum class PointingStatus : u32 { | ||
| 136 | Unkown0, | ||
| 137 | Unkown1, | ||
| 138 | }; | ||
| 139 | |||
| 140 | struct IrsRect { | ||
| 141 | s16 x; | ||
| 142 | s16 y; | ||
| 143 | s16 width; | ||
| 144 | s16 height; | ||
| 145 | }; | ||
| 146 | |||
| 147 | struct IrsCentroid { | ||
| 148 | f32 x; | ||
| 149 | f32 y; | ||
| 150 | }; | ||
| 151 | |||
| 152 | struct CameraConfig { | ||
| 153 | u64 exposure_time; | ||
| 154 | CameraLightTarget light_target; | ||
| 155 | u32 gain; | ||
| 156 | bool is_negative_used; | ||
| 157 | INSERT_PADDING_BYTES(7); | ||
| 158 | }; | ||
| 159 | static_assert(sizeof(CameraConfig) == 0x18, "CameraConfig is an invalid size"); | ||
| 160 | |||
| 161 | struct PackedCameraConfig { | ||
| 162 | u64 exposure_time; | ||
| 163 | PackedCameraLightTarget light_target; | ||
| 164 | u8 gain; | ||
| 165 | bool is_negative_used; | ||
| 166 | INSERT_PADDING_BYTES(5); | ||
| 167 | }; | ||
| 168 | static_assert(sizeof(PackedCameraConfig) == 0x10, "PackedCameraConfig is an invalid size"); | ||
| 169 | |||
| 170 | // This is nn::irsensor::IrCameraHandle | ||
| 171 | struct IrCameraHandle { | ||
| 172 | u8 npad_id{}; | ||
| 173 | Core::HID::NpadStyleIndex npad_type{Core::HID::NpadStyleIndex::None}; | ||
| 174 | INSERT_PADDING_BYTES(2); | ||
| 175 | }; | ||
| 176 | static_assert(sizeof(IrCameraHandle) == 4, "IrCameraHandle is an invalid size"); | ||
| 177 | |||
| 178 | // This is nn::irsensor::PackedMcuVersion | ||
| 179 | struct PackedMcuVersion { | ||
| 180 | u16 major; | ||
| 181 | u16 minor; | ||
| 182 | }; | ||
| 183 | static_assert(sizeof(PackedMcuVersion) == 4, "PackedMcuVersion is an invalid size"); | ||
| 184 | |||
| 185 | // This is nn::irsensor::PackedMomentProcessorConfig | ||
| 186 | struct PackedMomentProcessorConfig { | ||
| 187 | PackedCameraConfig camera_config; | ||
| 188 | IrsRect window_of_interest; | ||
| 189 | PackedMcuVersion required_mcu_version; | ||
| 190 | PackedMomentProcessorPreprocess preprocess; | ||
| 191 | u8 preprocess_intensity_threshold; | ||
| 192 | INSERT_PADDING_BYTES(2); | ||
| 193 | }; | ||
| 194 | static_assert(sizeof(PackedMomentProcessorConfig) == 0x20, | ||
| 195 | "PackedMomentProcessorConfig is an invalid size"); | ||
| 196 | |||
| 197 | // This is nn::irsensor::PackedClusteringProcessorConfig | ||
| 198 | struct PackedClusteringProcessorConfig { | ||
| 199 | PackedCameraConfig camera_config; | ||
| 200 | IrsRect window_of_interest; | ||
| 201 | PackedMcuVersion required_mcu_version; | ||
| 202 | u32 pixel_count_min; | ||
| 203 | u32 pixel_count_max; | ||
| 204 | u32 object_intensity_min; | ||
| 205 | bool is_external_light_filter_enabled; | ||
| 206 | INSERT_PADDING_BYTES(2); | ||
| 207 | }; | ||
| 208 | static_assert(sizeof(PackedClusteringProcessorConfig) == 0x30, | ||
| 209 | "PackedClusteringProcessorConfig is an invalid size"); | ||
| 210 | |||
| 211 | // This is nn::irsensor::PackedImageTransferProcessorConfig | ||
| 212 | struct PackedImageTransferProcessorConfig { | ||
| 213 | PackedCameraConfig camera_config; | ||
| 214 | PackedMcuVersion required_mcu_version; | ||
| 215 | PackedImageTransferProcessorFormat format; | ||
| 216 | INSERT_PADDING_BYTES(3); | ||
| 217 | }; | ||
| 218 | static_assert(sizeof(PackedImageTransferProcessorConfig) == 0x18, | ||
| 219 | "PackedImageTransferProcessorConfig is an invalid size"); | ||
| 220 | |||
| 221 | // This is nn::irsensor::PackedTeraPluginProcessorConfig | ||
| 222 | struct PackedTeraPluginProcessorConfig { | ||
| 223 | PackedMcuVersion required_mcu_version; | ||
| 224 | u8 mode; | ||
| 225 | u8 unknown_1; | ||
| 226 | u8 unknown_2; | ||
| 227 | u8 unknown_3; | ||
| 228 | }; | ||
| 229 | static_assert(sizeof(PackedTeraPluginProcessorConfig) == 0x8, | ||
| 230 | "PackedTeraPluginProcessorConfig is an invalid size"); | ||
| 231 | |||
| 232 | // This is nn::irsensor::PackedPointingProcessorConfig | ||
| 233 | struct PackedPointingProcessorConfig { | ||
| 234 | IrsRect window_of_interest; | ||
| 235 | PackedMcuVersion required_mcu_version; | ||
| 236 | }; | ||
| 237 | static_assert(sizeof(PackedPointingProcessorConfig) == 0xC, | ||
| 238 | "PackedPointingProcessorConfig is an invalid size"); | ||
| 239 | |||
| 240 | // This is nn::irsensor::PackedFunctionLevel | ||
| 241 | struct PackedFunctionLevel { | ||
| 242 | IrSensorFunctionLevel function_level; | ||
| 243 | INSERT_PADDING_BYTES(3); | ||
| 244 | }; | ||
| 245 | static_assert(sizeof(PackedFunctionLevel) == 0x4, "PackedFunctionLevel is an invalid size"); | ||
| 246 | |||
| 247 | // This is nn::irsensor::PackedImageTransferProcessorExConfig | ||
| 248 | struct PackedImageTransferProcessorExConfig { | ||
| 249 | PackedCameraConfig camera_config; | ||
| 250 | PackedMcuVersion required_mcu_version; | ||
| 251 | PackedImageTransferProcessorFormat origin_format; | ||
| 252 | PackedImageTransferProcessorFormat trimming_format; | ||
| 253 | u16 trimming_start_x; | ||
| 254 | u16 trimming_start_y; | ||
| 255 | bool is_external_light_filter_enabled; | ||
| 256 | INSERT_PADDING_BYTES(5); | ||
| 257 | }; | ||
| 258 | static_assert(sizeof(PackedImageTransferProcessorExConfig) == 0x20, | ||
| 259 | "PackedImageTransferProcessorExConfig is an invalid size"); | ||
| 260 | |||
| 261 | // This is nn::irsensor::PackedIrLedProcessorConfig | ||
| 262 | struct PackedIrLedProcessorConfig { | ||
| 263 | PackedMcuVersion required_mcu_version; | ||
| 264 | u8 light_target; | ||
| 265 | INSERT_PADDING_BYTES(3); | ||
| 266 | }; | ||
| 267 | static_assert(sizeof(PackedIrLedProcessorConfig) == 0x8, | ||
| 268 | "PackedIrLedProcessorConfig is an invalid size"); | ||
| 269 | |||
| 270 | // This is nn::irsensor::HandAnalysisConfig | ||
| 271 | struct HandAnalysisConfig { | ||
| 272 | HandAnalysisMode mode; | ||
| 273 | }; | ||
| 274 | static_assert(sizeof(HandAnalysisConfig) == 0x4, "HandAnalysisConfig is an invalid size"); | ||
| 275 | |||
| 276 | // This is nn::irsensor::detail::ProcessorState | ||
| 277 | struct ProcessorState { | ||
| 278 | u64 start{}; | ||
| 279 | u32 count{}; | ||
| 280 | INSERT_PADDING_BYTES(4); | ||
| 281 | std::array<u8, 0xE10> processor_raw_data{}; | ||
| 282 | }; | ||
| 283 | static_assert(sizeof(ProcessorState) == 0xE20, "ProcessorState is an invalid size"); | ||
| 284 | |||
| 285 | // This is nn::irsensor::detail::DeviceFormat | ||
| 286 | struct DeviceFormat { | ||
| 287 | Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Unconnected}; | ||
| 288 | Core::IrSensor::IrCameraInternalStatus camera_internal_status{ | ||
| 289 | Core::IrSensor::IrCameraInternalStatus::Ready}; | ||
| 290 | Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::None}; | ||
| 291 | ProcessorState state{}; | ||
| 292 | }; | ||
| 293 | static_assert(sizeof(DeviceFormat) == 0xE30, "DeviceFormat is an invalid size"); | ||
| 294 | |||
| 295 | // This is nn::irsensor::ImageTransferProcessorState | ||
| 296 | struct ImageTransferProcessorState { | ||
| 297 | u64 sampling_number; | ||
| 298 | Core::IrSensor::CameraAmbientNoiseLevel ambient_noise_level; | ||
| 299 | INSERT_PADDING_BYTES(4); | ||
| 300 | }; | ||
| 301 | static_assert(sizeof(ImageTransferProcessorState) == 0x10, | ||
| 302 | "ImageTransferProcessorState is an invalid size"); | ||
| 303 | |||
| 304 | } // namespace Core::IrSensor | ||