Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
e56b1b69b7 | |||
56bff126d2 |
@ -24,7 +24,6 @@ enum class InputType {
|
|||||||
Analog,
|
Analog,
|
||||||
Trigger,
|
Trigger,
|
||||||
Motion,
|
Motion,
|
||||||
VirtualMotion,
|
|
||||||
Touch,
|
Touch,
|
||||||
Color,
|
Color,
|
||||||
Vibration,
|
Vibration,
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/quaternion.h"
|
|
||||||
#include "core/hid/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
@ -83,7 +81,7 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
Common::Input::MotionStatus status{};
|
Common::Input::MotionStatus status{};
|
||||||
switch (callback.type) {
|
switch (callback.type) {
|
||||||
case Common::Input::InputType::Button: {
|
case Common::Input::InputType::Button: {
|
||||||
const Common::Input::AnalogProperties properties{
|
Common::Input::AnalogProperties properties{
|
||||||
.deadzone = 0.0f,
|
.deadzone = 0.0f,
|
||||||
.range = 1.0f,
|
.range = 1.0f,
|
||||||
.offset = 0.0f,
|
.offset = 0.0f,
|
||||||
@ -95,18 +93,31 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
.raw_value = 0.0f,
|
.raw_value = 0.0f,
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
};
|
};
|
||||||
status.delta_timestamp = 5000;
|
status.accel.y = {
|
||||||
status.force_update = true;
|
.value = 0.0f,
|
||||||
status.accel.x = default_analog_status;
|
.raw_value = 0.0f,
|
||||||
status.accel.y = default_analog_status;
|
.properties = properties,
|
||||||
|
};
|
||||||
status.accel.z = {
|
status.accel.z = {
|
||||||
.value = 0.0f,
|
.value = 0.0f,
|
||||||
.raw_value = -1.0f,
|
.raw_value = -1.0f,
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
};
|
};
|
||||||
status.gyro.x = default_analog_status;
|
status.gyro.x = {
|
||||||
status.gyro.y = default_analog_status;
|
.value = 0.0f,
|
||||||
status.gyro.z = default_analog_status;
|
.raw_value = 0.0f,
|
||||||
|
.properties = properties,
|
||||||
|
};
|
||||||
|
status.gyro.y = {
|
||||||
|
.value = 0.0f,
|
||||||
|
.raw_value = 0.0f,
|
||||||
|
.properties = properties,
|
||||||
|
};
|
||||||
|
status.gyro.z = {
|
||||||
|
.value = 0.0f,
|
||||||
|
.raw_value = 0.0f,
|
||||||
|
.properties = properties,
|
||||||
|
};
|
||||||
if (TransformToButton(callback).value) {
|
if (TransformToButton(callback).value) {
|
||||||
std::random_device device;
|
std::random_device device;
|
||||||
std::mt19937 gen(device());
|
std::mt19937 gen(device());
|
||||||
@ -123,9 +134,6 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
case Common::Input::InputType::Motion:
|
case Common::Input::InputType::Motion:
|
||||||
status = callback.motion_status;
|
status = callback.motion_status;
|
||||||
break;
|
break;
|
||||||
case Common::Input::InputType::VirtualMotion:
|
|
||||||
status = GetVirtualMotion(callback.motion_status);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Input, "Conversion from type {} to motion not implemented", callback.type);
|
LOG_ERROR(Input, "Conversion from type {} to motion not implemented", callback.type);
|
||||||
break;
|
break;
|
||||||
@ -429,32 +437,4 @@ void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Input::MotionStatus GetVirtualMotion(Common::Input::MotionStatus input_data,
|
|
||||||
Common::Vec3f last_giro) {
|
|
||||||
Common::Input::MotionStatus motion_status = input_data;
|
|
||||||
|
|
||||||
// Axis data is stored in the gyro value
|
|
||||||
float wx = input_data.gyro.x.raw_value;
|
|
||||||
float wy = input_data.gyro.y.raw_value;
|
|
||||||
|
|
||||||
float rotX = (wy * 2 - 1.0f) * 135.0f; // up/down best
|
|
||||||
float rotY = (wx * 2 - 1.0f) * -180.0f; // left/right
|
|
||||||
float rotZ = input_data.gyro.y.raw_value * 14.0f + m_lastGyroRotation.z;
|
|
||||||
|
|
||||||
Common::Vec3f rotation(rotX - m_lastGyroRotation.x, (rotY - m_lastGyroRotation.y) * 15.0f,
|
|
||||||
rotZ - m_lastGyroRotation.z);
|
|
||||||
|
|
||||||
rotation.x = std::min(1.0f, std::max(-1.0f, rotation.x / 360.0f));
|
|
||||||
rotation.y = std::min(1.0f, std::max(-1.0f, rotation.y / 360.0f));
|
|
||||||
rotation.z = std::min(1.0f, std::max(-1.0f, rotation.z / 360.0f));
|
|
||||||
|
|
||||||
motion_status.gyro.x.raw_value = rotation.x;
|
|
||||||
motion_status.gyro.y.raw_value = rotation.y;
|
|
||||||
motion_status.gyro.z.raw_value = rotation.z;
|
|
||||||
|
|
||||||
motion_status.accel.x.raw_value = 0.0f;
|
|
||||||
motion_status.accel.y.raw_value = 0.0f;
|
|
||||||
motion_status.accel.z.raw_value = -1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core::HID
|
} // namespace Core::HID
|
||||||
|
@ -116,21 +116,4 @@ void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value);
|
|||||||
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
||||||
bool clamp_value);
|
bool clamp_value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts raw stick data into a valid stick value
|
|
||||||
* @param analog_x raw analog data and properties for the x-axis
|
|
||||||
* @param analog_y raw analog data and properties for the y-axis
|
|
||||||
* @param clamp_value bool that determines if the value needs to be clamped into the unit circle.
|
|
||||||
*/
|
|
||||||
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
|
||||||
bool clamp_value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the accelerometer value needed to reach the axis position as if it was a pointer to a screen
|
|
||||||
*
|
|
||||||
* @param input_data Motion status containing the position of all 3 axis
|
|
||||||
* @return Motion status with accelerometer data
|
|
||||||
*/
|
|
||||||
Common::Input::MotionStatus GetVirtualMotion(Common::Input::MotionStatus input_data);
|
|
||||||
|
|
||||||
} // namespace Core::HID
|
} // namespace Core::HID
|
||||||
|
@ -281,10 +281,10 @@ static_assert(sizeof(ProcessorState) == 0xE20, "ProcessorState is an invalid siz
|
|||||||
|
|
||||||
// This is nn::irsensor::detail::DeviceFormat
|
// This is nn::irsensor::detail::DeviceFormat
|
||||||
struct DeviceFormat {
|
struct DeviceFormat {
|
||||||
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Unconnected};
|
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Available};
|
||||||
Core::IrSensor::IrCameraInternalStatus camera_internal_status{
|
Core::IrSensor::IrCameraInternalStatus camera_internal_status{
|
||||||
Core::IrSensor::IrCameraInternalStatus::Ready};
|
Core::IrSensor::IrCameraInternalStatus::Stopped};
|
||||||
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::None};
|
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::ImageTransferProcessor};
|
||||||
ProcessorState state{};
|
ProcessorState state{};
|
||||||
};
|
};
|
||||||
static_assert(sizeof(DeviceFormat) == 0xE30, "DeviceFormat is an invalid size");
|
static_assert(sizeof(DeviceFormat) == 0xE30, "DeviceFormat is an invalid size");
|
||||||
|
@ -296,7 +296,7 @@ void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) {
|
|||||||
|
|
||||||
if (result.IsSuccess()) {
|
if (result.IsSuccess()) {
|
||||||
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle);
|
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle);
|
||||||
MakeProcessor<TeraPluginProcessor>(parameters.camera_handle, device);
|
MakeProcessorWithCoreContext<TeraPluginProcessor>(parameters.camera_handle, device);
|
||||||
auto& image_transfer_processor =
|
auto& image_transfer_processor =
|
||||||
GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
|
GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
|
||||||
image_transfer_processor.SetConfig(parameters.processor_config);
|
image_transfer_processor.SetConfig(parameters.processor_config);
|
||||||
|
@ -1,29 +1,103 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include "core/hid/emulated_controller.h"
|
||||||
|
#include "core/hid/hid_core.h"
|
||||||
#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
|
#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
|
||||||
|
|
||||||
namespace Service::IRS {
|
namespace Service::IRS {
|
||||||
TeraPluginProcessor::TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format)
|
TeraPluginProcessor::TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||||
: device(device_format) {
|
Core::IrSensor::DeviceFormat& device_format,
|
||||||
|
std::size_t npad_index)
|
||||||
|
: device{device_format} {
|
||||||
|
npad_device = hid_core_.GetEmulatedControllerByIndex(npad_index);
|
||||||
|
|
||||||
device.mode = Core::IrSensor::IrSensorMode::TeraPluginProcessor;
|
device.mode = Core::IrSensor::IrSensorMode::TeraPluginProcessor;
|
||||||
device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected;
|
device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected;
|
||||||
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped;
|
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped;
|
||||||
|
|
||||||
|
shared_memory = std::construct_at(
|
||||||
|
reinterpret_cast<TeraSharedMemory*>(&device_format.state.processor_raw_data));
|
||||||
|
|
||||||
|
Core::HID::ControllerUpdateCallback engine_callback{
|
||||||
|
.on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); },
|
||||||
|
.is_npad_service = true,
|
||||||
|
};
|
||||||
|
callback_key = npad_device->SetCallback(engine_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
TeraPluginProcessor::~TeraPluginProcessor() = default;
|
TeraPluginProcessor::~TeraPluginProcessor() {
|
||||||
|
npad_device->DeleteCallback(callback_key);
|
||||||
|
};
|
||||||
|
|
||||||
void TeraPluginProcessor::StartProcessor() {}
|
void TeraPluginProcessor::StartProcessor() {
|
||||||
|
device.camera_status = Core::IrSensor::IrCameraStatus::Available;
|
||||||
|
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready;
|
||||||
|
}
|
||||||
|
|
||||||
void TeraPluginProcessor::SuspendProcessor() {}
|
void TeraPluginProcessor::SuspendProcessor() {}
|
||||||
|
|
||||||
void TeraPluginProcessor::StopProcessor() {}
|
void TeraPluginProcessor::StopProcessor() {}
|
||||||
|
|
||||||
|
void TeraPluginProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) {
|
||||||
|
if (type != Core::HID::ControllerTriggerType::IrSensor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
next_state = {};
|
||||||
|
const auto camera_data = npad_device->GetCamera();
|
||||||
|
auto filtered_image = camera_data.data;
|
||||||
|
|
||||||
|
memcpy(next_state.data.data(), filtered_image.data(), GetDataSize(format));
|
||||||
|
|
||||||
|
// These 4 bytes seem to control the brightness of a image
|
||||||
|
next_state.data[0] = 1;
|
||||||
|
next_state.data[1] = 2;
|
||||||
|
next_state.data[2] = 0xde;
|
||||||
|
next_state.data[3] = 0x07;
|
||||||
|
|
||||||
|
// Data from HW
|
||||||
|
/* next_state.data = {
|
||||||
|
0x01, 0x02, 0xde, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4,
|
||||||
|
0x41, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x06, 0x00, 0xc0, 0x28,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x3c, 0x00, 0x05, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x20, 0xa8, 0x09, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04,
|
||||||
|
0x12, 0x41, 0x00, 0x00, 0x13, 0x86, 0x02, 0x00, 0x00, 0x00, 0x1e, 0xc0, 0x02, 0x00, 0x00, 0x00,
|
||||||
|
0x40, 0x0f, 0x00, 0x00, 0x00, 0x30, 0xcd, 0x34, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x10, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00, 0x80, 0xf3, 0x01, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x36, 0x08, 0x04, 0x60, 0x02, 0x00, 0x76, 0x80, 0x09, 0x00, 0x00, 0x88, 0xd1,
|
||||||
|
0x20, 0x00, 0x00, 0x00, 0x65, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x28, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x40, 0x01, 0x68, 0x00, 0x00, 0x00,
|
||||||
|
0x80, 0xf2, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00,
|
||||||
|
0x04, 0x00, 0x00, 0x00, 0x04, 0x80, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x06, 0x00,
|
||||||
|
0x00, 0x00, 0x04, 0xa0, 0x57, 0x02, 0x04, 0x40, 0x51, 0x02, 0x00, 0x40, 0xc1, 0x01, 0x00, 0x50,
|
||||||
|
0x86, 0x02, 0x00, 0x50, 0x0d, 0x04, 0x00, 0xb0, 0x05, 0x00, 0x00, 0x50, 0x04, 0x00, 0x00, 0xb0,
|
||||||
|
0x09, 0x00, 0x00, 0xb0, 0x01, 0xc0, 0x06, 0xc0, 0x0e, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x20,
|
||||||
|
0x01, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x20, 0x05, 0x00, 0x00, 0x80,
|
||||||
|
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x86, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
|
||||||
|
0x00,
|
||||||
|
};*/
|
||||||
|
next_state.sampling_number = camera_data.sample;
|
||||||
|
next_state.timestamp = next_state.sampling_number + 131;
|
||||||
|
next_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low;
|
||||||
|
|
||||||
|
shared_memory->tera_lifo.WriteNextEntry(next_state);
|
||||||
|
|
||||||
|
if (!IsProcessorActive()) {
|
||||||
|
StartProcessor();
|
||||||
|
}
|
||||||
|
}
|
||||||
void TeraPluginProcessor::SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config) {
|
void TeraPluginProcessor::SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config) {
|
||||||
current_config.mode = config.mode;
|
current_config.mode = config.mode;
|
||||||
current_config.unknown_1 = config.unknown_1;
|
current_config.unknown_1 = config.unknown_1;
|
||||||
current_config.unknown_2 = config.unknown_2;
|
current_config.unknown_2 = config.unknown_2;
|
||||||
current_config.unknown_3 = config.unknown_3;
|
current_config.unknown_3 = config.unknown_3;
|
||||||
|
|
||||||
|
LOG_ERROR(Service_IRS, "{} {} {} {}", config.mode, config.unknown_1, config.unknown_2,
|
||||||
|
config.unknown_3);
|
||||||
|
npad_device->SetCameraFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::IRS
|
} // namespace Service::IRS
|
||||||
|
@ -3,15 +3,21 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hid/irs_types.h"
|
#include "core/hid/irs_types.h"
|
||||||
|
#include "core/hle/service/hid/irs_ring_lifo.h"
|
||||||
#include "core/hle/service/hid/irsensor/processor_base.h"
|
#include "core/hle/service/hid/irsensor/processor_base.h"
|
||||||
|
|
||||||
|
namespace Core::HID {
|
||||||
|
class EmulatedController;
|
||||||
|
} // namespace Core::HID
|
||||||
|
|
||||||
namespace Service::IRS {
|
namespace Service::IRS {
|
||||||
class TeraPluginProcessor final : public ProcessorBase {
|
class TeraPluginProcessor final : public ProcessorBase {
|
||||||
public:
|
public:
|
||||||
explicit TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format);
|
explicit TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||||
|
Core::IrSensor::DeviceFormat& device_format,
|
||||||
|
std::size_t npad_index);
|
||||||
~TeraPluginProcessor() override;
|
~TeraPluginProcessor() override;
|
||||||
|
|
||||||
// Called when the processor is initialized
|
// Called when the processor is initialized
|
||||||
@ -27,6 +33,10 @@ public:
|
|||||||
void SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config);
|
void SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size20x15;
|
||||||
|
static constexpr std::size_t width = 40;
|
||||||
|
static constexpr std::size_t height = 30;
|
||||||
|
|
||||||
// This is nn::irsensor::TeraPluginProcessorConfig
|
// This is nn::irsensor::TeraPluginProcessorConfig
|
||||||
struct TeraPluginProcessorConfig {
|
struct TeraPluginProcessorConfig {
|
||||||
u8 mode;
|
u8 mode;
|
||||||
@ -46,8 +56,22 @@ private:
|
|||||||
static_assert(sizeof(TeraPluginProcessorState) == 0x140,
|
static_assert(sizeof(TeraPluginProcessorState) == 0x140,
|
||||||
"TeraPluginProcessorState is an invalid size");
|
"TeraPluginProcessorState is an invalid size");
|
||||||
|
|
||||||
|
struct TeraSharedMemory {
|
||||||
|
Service::IRS::Lifo<TeraPluginProcessorState, 6> tera_lifo;
|
||||||
|
static_assert(sizeof(tera_lifo) == 0x790, "tera_lifo is an invalid size");
|
||||||
|
INSERT_PADDING_WORDS(0x1A4);
|
||||||
|
};
|
||||||
|
static_assert(sizeof(TeraSharedMemory) == 0xE20, "TeraSharedMemory is an invalid size");
|
||||||
|
|
||||||
|
void OnControllerUpdate(Core::HID::ControllerTriggerType type);
|
||||||
|
|
||||||
|
TeraSharedMemory* shared_memory = nullptr;
|
||||||
|
TeraPluginProcessorState next_state{};
|
||||||
|
|
||||||
TeraPluginProcessorConfig current_config{};
|
TeraPluginProcessorConfig current_config{};
|
||||||
Core::IrSensor::DeviceFormat& device;
|
Core::IrSensor::DeviceFormat& device;
|
||||||
|
Core::HID::EmulatedController* npad_device;
|
||||||
|
int callback_key{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::IRS
|
} // namespace Service::IRS
|
||||||
|
@ -674,7 +674,7 @@ public:
|
|||||||
|
|
||||||
void ForceUpdate() override {
|
void ForceUpdate() override {
|
||||||
const Common::Input::CallbackStatus status{
|
const Common::Input::CallbackStatus status{
|
||||||
.type = Common::Input::InputType::VirtualMotion,
|
.type = Common::Input::InputType::Motion,
|
||||||
.motion_status = GetStatus(),
|
.motion_status = GetStatus(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -686,7 +686,7 @@ public:
|
|||||||
|
|
||||||
void OnChange() {
|
void OnChange() {
|
||||||
const Common::Input::CallbackStatus status{
|
const Common::Input::CallbackStatus status{
|
||||||
.type = Common::Input::InputType::VirtualMotion,
|
.type = Common::Input::InputType::Motion,
|
||||||
.motion_status = GetStatus(),
|
.motion_status = GetStatus(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1039,28 +1039,21 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
|
||||||
const Common::ParamPackage& params) {
|
Common::ParamPackage params) {
|
||||||
const PadIdentifier identifier = {
|
const PadIdentifier identifier = {
|
||||||
.guid = Common::UUID{params.Get("guid", "")},
|
.guid = Common::UUID{params.Get("guid", "")},
|
||||||
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
||||||
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto motion_sensor = params.Get("motion", 0);
|
if (params.Has("motion")) {
|
||||||
const auto gyro_threshold = params.Get("threshold", 0.007f);
|
const auto motion_sensor = params.Get("motion", 0);
|
||||||
input_engine->PreSetController(identifier);
|
const auto gyro_threshold = params.Get("threshold", 0.007f);
|
||||||
input_engine->PreSetMotion(identifier, motion_sensor);
|
input_engine->PreSetController(identifier);
|
||||||
return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold,
|
input_engine->PreSetMotion(identifier, motion_sensor);
|
||||||
input_engine.get());
|
return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold,
|
||||||
}
|
input_engine.get());
|
||||||
|
}
|
||||||
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateVirtualMotionDevice(
|
|
||||||
const Common::ParamPackage& params) {
|
|
||||||
const PadIdentifier identifier = {
|
|
||||||
.guid = Common::UUID{params.Get("guid", "")},
|
|
||||||
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
||||||
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f);
|
const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f);
|
||||||
const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
|
const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
|
||||||
@ -1154,7 +1147,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create(
|
|||||||
return CreateHatButtonDevice(params);
|
return CreateHatButtonDevice(params);
|
||||||
}
|
}
|
||||||
if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
|
if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
|
||||||
return CreateVirtualMotionDevice(params);
|
return CreateMotionDevice(params);
|
||||||
}
|
}
|
||||||
if (params.Has("motion")) {
|
if (params.Has("motion")) {
|
||||||
return CreateMotionDevice(params);
|
return CreateMotionDevice(params);
|
||||||
|
@ -204,19 +204,6 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Creates a motion device from the parameters given.
|
* Creates a motion device from the parameters given.
|
||||||
* @param params contains parameters for creating the device:
|
* @param params contains parameters for creating the device:
|
||||||
* - "motion": index of the motion sensor
|
|
||||||
* - "threshold": gyro deadzone to avoid drifting
|
|
||||||
* - "guid": text string for identifying controllers
|
|
||||||
* - "port": port of the connected device
|
|
||||||
* - "pad": slot of the connected controller
|
|
||||||
* @returns a unique input device with the parameters specified
|
|
||||||
*/
|
|
||||||
std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(
|
|
||||||
const Common::ParamPackage& params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a virtual motion device from the parameters given.
|
|
||||||
* @param params contains parameters for creating the device:
|
|
||||||
* - "axis_x": the controller horizontal axis id to bind with the input
|
* - "axis_x": the controller horizontal axis id to bind with the input
|
||||||
* - "axis_y": the controller vertical axis id to bind with the input
|
* - "axis_y": the controller vertical axis id to bind with the input
|
||||||
* - "axis_z": the controller forward axis id to bind with the input
|
* - "axis_z": the controller forward axis id to bind with the input
|
||||||
@ -233,8 +220,7 @@ private:
|
|||||||
* - "pad": slot of the connected controller
|
* - "pad": slot of the connected controller
|
||||||
* @returns a unique input device with the parameters specified
|
* @returns a unique input device with the parameters specified
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Common::Input::InputDevice> CreateVirtualMotionDevice(
|
std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
|
||||||
const Common::ParamPackage& params);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a camera device from the parameters given.
|
* Creates a camera device from the parameters given.
|
||||||
|
Reference in New Issue
Block a user